summaryrefslogtreecommitdiffstats
path: root/fs/ubifs/tnc.c
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2018-09-07 08:36:34 -0400
committerRichard Weinberger <richard@nod.at>2018-10-23 07:48:39 -0400
commit823838a486888cf484e739ab37df14cb04dfddb5 (patch)
treef9ea86215e41e177e14e31c8a8281734a2811f15 /fs/ubifs/tnc.c
parenta384b47e4954a0f834749fcbe1c096c40ff5eb35 (diff)
ubifs: Add hashes to the tree node cache
As part of the UBIFS authentication support every branch in the index gets a hash covering the referenced node. To make that happen the tree node cache needs hashes over the nodes. This patch adds a hash argument to ubifs_tnc_add() and ubifs_tnc_add_nm(). The hashes are calculated from the callers of these functions which actually prepare the nodes. With this patch all the leaf nodes of the index tree get hashes, but currently nothing is done with these hashes, this is left for a later patch. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Signed-off-by: Richard Weinberger <richard@nod.at>
Diffstat (limited to 'fs/ubifs/tnc.c')
-rw-r--r--fs/ubifs/tnc.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/fs/ubifs/tnc.c b/fs/ubifs/tnc.c
index 8502c07c1e0a..bb5f989a6e06 100644
--- a/fs/ubifs/tnc.c
+++ b/fs/ubifs/tnc.c
@@ -2260,13 +2260,14 @@ do_split:
2260 * @lnum: LEB number of node 2260 * @lnum: LEB number of node
2261 * @offs: node offset 2261 * @offs: node offset
2262 * @len: node length 2262 * @len: node length
2263 * @hash: The hash over the node
2263 * 2264 *
2264 * This function adds a node with key @key to TNC. The node may be new or it may 2265 * This function adds a node with key @key to TNC. The node may be new or it may
2265 * obsolete some existing one. Returns %0 on success or negative error code on 2266 * obsolete some existing one. Returns %0 on success or negative error code on
2266 * failure. 2267 * failure.
2267 */ 2268 */
2268int ubifs_tnc_add(struct ubifs_info *c, const union ubifs_key *key, int lnum, 2269int ubifs_tnc_add(struct ubifs_info *c, const union ubifs_key *key, int lnum,
2269 int offs, int len) 2270 int offs, int len, const u8 *hash)
2270{ 2271{
2271 int found, n, err = 0; 2272 int found, n, err = 0;
2272 struct ubifs_znode *znode; 2273 struct ubifs_znode *znode;
@@ -2281,6 +2282,7 @@ int ubifs_tnc_add(struct ubifs_info *c, const union ubifs_key *key, int lnum,
2281 zbr.lnum = lnum; 2282 zbr.lnum = lnum;
2282 zbr.offs = offs; 2283 zbr.offs = offs;
2283 zbr.len = len; 2284 zbr.len = len;
2285 ubifs_copy_hash(c, hash, zbr.hash);
2284 key_copy(c, key, &zbr.key); 2286 key_copy(c, key, &zbr.key);
2285 err = tnc_insert(c, znode, &zbr, n + 1); 2287 err = tnc_insert(c, znode, &zbr, n + 1);
2286 } else if (found == 1) { 2288 } else if (found == 1) {
@@ -2291,6 +2293,7 @@ int ubifs_tnc_add(struct ubifs_info *c, const union ubifs_key *key, int lnum,
2291 zbr->lnum = lnum; 2293 zbr->lnum = lnum;
2292 zbr->offs = offs; 2294 zbr->offs = offs;
2293 zbr->len = len; 2295 zbr->len = len;
2296 ubifs_copy_hash(c, hash, zbr->hash);
2294 } else 2297 } else
2295 err = found; 2298 err = found;
2296 if (!err) 2299 if (!err)
@@ -2392,13 +2395,14 @@ out_unlock:
2392 * @lnum: LEB number of node 2395 * @lnum: LEB number of node
2393 * @offs: node offset 2396 * @offs: node offset
2394 * @len: node length 2397 * @len: node length
2398 * @hash: The hash over the node
2395 * @nm: node name 2399 * @nm: node name
2396 * 2400 *
2397 * This is the same as 'ubifs_tnc_add()' but it should be used with keys which 2401 * This is the same as 'ubifs_tnc_add()' but it should be used with keys which
2398 * may have collisions, like directory entry keys. 2402 * may have collisions, like directory entry keys.
2399 */ 2403 */
2400int ubifs_tnc_add_nm(struct ubifs_info *c, const union ubifs_key *key, 2404int ubifs_tnc_add_nm(struct ubifs_info *c, const union ubifs_key *key,
2401 int lnum, int offs, int len, 2405 int lnum, int offs, int len, const u8 *hash,
2402 const struct fscrypt_name *nm) 2406 const struct fscrypt_name *nm)
2403{ 2407{
2404 int found, n, err = 0; 2408 int found, n, err = 0;
@@ -2441,6 +2445,7 @@ int ubifs_tnc_add_nm(struct ubifs_info *c, const union ubifs_key *key,
2441 zbr->lnum = lnum; 2445 zbr->lnum = lnum;
2442 zbr->offs = offs; 2446 zbr->offs = offs;
2443 zbr->len = len; 2447 zbr->len = len;
2448 ubifs_copy_hash(c, hash, zbr->hash);
2444 goto out_unlock; 2449 goto out_unlock;
2445 } 2450 }
2446 } 2451 }
@@ -2452,6 +2457,7 @@ int ubifs_tnc_add_nm(struct ubifs_info *c, const union ubifs_key *key,
2452 zbr.lnum = lnum; 2457 zbr.lnum = lnum;
2453 zbr.offs = offs; 2458 zbr.offs = offs;
2454 zbr.len = len; 2459 zbr.len = len;
2460 ubifs_copy_hash(c, hash, zbr.hash);
2455 key_copy(c, key, &zbr.key); 2461 key_copy(c, key, &zbr.key);
2456 err = tnc_insert(c, znode, &zbr, n + 1); 2462 err = tnc_insert(c, znode, &zbr, n + 1);
2457 if (err) 2463 if (err)