Skip to content

Commit 3c3c32f

Browse files
ebiggersrichardweinberger
authored andcommitted
ubifs: fix wrong use of crypto_shash_descsize()
crypto_shash_descsize() returns the size of the shash_desc context needed to compute the hash, not the size of the hash itself. crypto_shash_digestsize() would be correct, or alternatively using c->hash_len and c->hmac_desc_len which already store the correct values. But actually it's simpler to just use stack arrays, so do that instead. Fixes: 49525e5 ("ubifs: Add helper functions for authentication support") Fixes: da8ef65 ("ubifs: Authenticate replayed journal") Cc: <[email protected]> # v4.20+ Cc: Sascha Hauer <[email protected]> Signed-off-by: Eric Biggers <[email protected]> Acked-by: Sascha Hauer <[email protected]> Signed-off-by: Richard Weinberger <[email protected]>
1 parent ecf8409 commit 3c3c32f

File tree

2 files changed

+6
-24
lines changed

2 files changed

+6
-24
lines changed

fs/ubifs/auth.c

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,9 @@ int ubifs_prepare_auth_node(struct ubifs_info *c, void *node,
7979
struct shash_desc *inhash)
8080
{
8181
struct ubifs_auth_node *auth = node;
82-
u8 *hash;
82+
u8 hash[UBIFS_HASH_ARR_SZ];
8383
int err;
8484

85-
hash = kmalloc(crypto_shash_descsize(c->hash_tfm), GFP_NOFS);
86-
if (!hash)
87-
return -ENOMEM;
88-
8985
{
9086
SHASH_DESC_ON_STACK(hash_desc, c->hash_tfm);
9187

@@ -94,21 +90,16 @@ int ubifs_prepare_auth_node(struct ubifs_info *c, void *node,
9490

9591
err = crypto_shash_final(hash_desc, hash);
9692
if (err)
97-
goto out;
93+
return err;
9894
}
9995

10096
err = ubifs_hash_calc_hmac(c, hash, auth->hmac);
10197
if (err)
102-
goto out;
98+
return err;
10399

104100
auth->ch.node_type = UBIFS_AUTH_NODE;
105101
ubifs_prepare_node(c, auth, ubifs_auth_node_sz(c), 0);
106-
107-
err = 0;
108-
out:
109-
kfree(hash);
110-
111-
return err;
102+
return 0;
112103
}
113104

114105
static struct shash_desc *ubifs_get_desc(const struct ubifs_info *c,

fs/ubifs/replay.c

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -601,18 +601,12 @@ static int authenticate_sleb(struct ubifs_info *c, struct ubifs_scan_leb *sleb,
601601
struct ubifs_scan_node *snod;
602602
int n_nodes = 0;
603603
int err;
604-
u8 *hash, *hmac;
604+
u8 hash[UBIFS_HASH_ARR_SZ];
605+
u8 hmac[UBIFS_HMAC_ARR_SZ];
605606

606607
if (!ubifs_authenticated(c))
607608
return sleb->nodes_cnt;
608609

609-
hash = kmalloc(crypto_shash_descsize(c->hash_tfm), GFP_NOFS);
610-
hmac = kmalloc(c->hmac_desc_len, GFP_NOFS);
611-
if (!hash || !hmac) {
612-
err = -ENOMEM;
613-
goto out;
614-
}
615-
616610
list_for_each_entry(snod, &sleb->nodes, list) {
617611

618612
n_nodes++;
@@ -662,9 +656,6 @@ static int authenticate_sleb(struct ubifs_info *c, struct ubifs_scan_leb *sleb,
662656
err = 0;
663657
}
664658
out:
665-
kfree(hash);
666-
kfree(hmac);
667-
668659
return err ? err : n_nodes - n_not_auth;
669660
}
670661

0 commit comments

Comments
 (0)