Skip to content

Commit 5d37a11

Browse files
committed
fsverity: explicitly check that there is no algorithm 0
Since libfsverity and some other code would break if 0 is ever allocated as an FS_VERITY_HASH_ALG_* value, make fsverity_check_hash_algs() explicitly check that there is no algorithm 0. Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Eric Biggers <[email protected]>
1 parent 06c2afb commit 5d37a11

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

fs/verity/hash_algs.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,14 @@ void __init fsverity_check_hash_algs(void)
226226
if (!alg->name)
227227
continue;
228228

229+
/*
230+
* 0 must never be allocated as an FS_VERITY_HASH_ALG_* value,
231+
* as it is reserved for users that use 0 to mean unspecified or
232+
* a default value. fs/verity/ itself doesn't care and doesn't
233+
* have a default algorithm, but some users make use of this.
234+
*/
235+
BUG_ON(i == 0);
236+
229237
BUG_ON(alg->digest_size > FS_VERITY_MAX_DIGEST_SIZE);
230238

231239
/*

0 commit comments

Comments
 (0)