[PATCH master 1/3] dm: verity: don't let the superblock override the root hash
Ahmad Fatoum
a.fatoum at barebox.org
Thu Nov 26 08:10:21 PST 2026
dm_verity_config_from_sb() pastes the hash algorithm name from the
superblock into the table unchecked, although the superblock is no more
trusted than the data it protects.
A name containing a space adds an argument to the table. If the
superblock has no salt as well, the empty salt column removes one again:
the second word of the name becomes the root digest and the root hash
given by the user the salt. "crc32 <digest>" fits into the 32-byte
field, so veritysetup open accepts modified data against a hash tree
forged by the attacker. The name needn't be NUL-terminated either.
Let's only accept a NUL-terminated name without whitespace.
Fixes: f2cc4a0a5f3c ("dm: verity: Add helper to parse superblock information")
Signed-off-by: Ahmad Fatoum <a.fatoum at barebox.org>
---
drivers/block/dm/dm-verity.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/drivers/block/dm/dm-verity.c b/drivers/block/dm/dm-verity.c
index d7b212fba60a..63616ce86f0e 100644
--- a/drivers/block/dm/dm-verity.c
+++ b/drivers/block/dm/dm-verity.c
@@ -15,6 +15,7 @@
#include <digest.h>
#include <disks.h>
#include <fcntl.h>
+#include <string.h>
#include <xfuncs.h>
#include <unistd.h>
@@ -501,6 +502,11 @@ char *dm_verity_config_from_sb(const char *data_dev, const char *hash_dev,
if (le32_to_cpu(sb.version) != 1)
return ERR_PTR(-ENOTSUPP);
+ /* The name is pasted into the table, so it must be a single word */
+ if (!memchr(sb.algorithm, '\0', sizeof(sb.algorithm)) ||
+ strpbrk(sb.algorithm, " \t\n"))
+ return ERR_PTR(-EINVAL);
+
sects = le32_to_cpu(sb.data_block_size) >> SECTOR_SHIFT;
if (!sects)
return ERR_PTR(-ERANGE);
--
2.47.3
More information about the barebox
mailing list