Skip to contentSkip to conversation

fsverity: explicitly check that there is no algorithm 0

PATCH New Eric Biggers 1 participant 1 message Jul 5, 2023 fs-verity: read-only file-based authenticity protection

lore
Share & tools
lore

Eric Biggers

author maintainer
#0 lore raw

PATCH 1/1 fsverity: explicitly check that there is no algorithm 0

From: Eric Biggers <[email protected]>

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.

---
 fs/verity/hash_algs.c | 8 ++++++++
 1 file changed, 8 insertions(+)
fs/verity/hash_algs.c +8 -0
index c598d20354763..6b08b1d9a7d7c 100644
@@ -226,6 +226,14 @@ void __init fsverity_check_hash_algs(void)
 		if (!alg->name)
 			continue;
 
+		/*
+		 * 0 must never be allocated as an FS_VERITY_HASH_ALG_* value,
+		 * as it is reserved for users that use 0 to mean unspecified or
+		 * a default value.  fs/verity/ itself doesn't care and doesn't
+		 * have a default algorithm, but some users make use of this.
+		 */
+		BUG_ON(i == 0);
+
 		BUG_ON(alg->digest_size > FS_VERITY_MAX_DIGEST_SIZE);
 
 		/*

base-commit: ace1ba1c9038b30f29c5759bc4726bbed7748f15

Signature · 1 line
2.41.0