mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@barebox.org>
To: barebox@lists.infradead.org
Cc: Tobias Waldekranz <tobias@waldekranz.com>,
	Ahmad Fatoum <a.fatoum@barebox.org>
Subject: [PATCH master 2/3] dm: verity: don't read past the superblock salt
Date: Thu, 26 Nov 2026 17:10:22 +0100	[thread overview]
Message-ID: <20261126161025.1929975-2-a.fatoum@barebox.org> (raw)
In-Reply-To: <20261126161025.1929975-1-a.fatoum@barebox.org>

dm_verity_config_from_sb() formats salt_size bytes of the 256-byte salt
with %*phN, but salt_size is a 16-bit field from the superblock and
barebox doesn't cap %*phN at 64 bytes like Linux. veritysetup thus reads
up to 64K of stack into the table, which veritysetup dump prints.

Let's reject superblocks whose salt doesn't fit.

Fixes: f2cc4a0a5f3c ("dm: verity: Add helper to parse superblock information")
Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
 drivers/block/dm/dm-verity.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/block/dm/dm-verity.c b/drivers/block/dm/dm-verity.c
index 63616ce86f0e..c4f88852b5f2 100644
--- a/drivers/block/dm/dm-verity.c
+++ b/drivers/block/dm/dm-verity.c
@@ -483,6 +483,7 @@ char *dm_verity_config_from_sb(const char *data_dev, const char *hash_dev,
 			       const char *root_hash)
 {
 	struct dm_verity_sb sb;
+	unsigned int salt_size;
 	blkcnt_t sects;
 	ssize_t n;
 	int fd;
@@ -507,6 +508,10 @@ char *dm_verity_config_from_sb(const char *data_dev, const char *hash_dev,
 	    strpbrk(sb.algorithm, " \t\n"))
 		return ERR_PTR(-EINVAL);
 
+	salt_size = le16_to_cpu(sb.salt_size);
+	if (salt_size > sizeof(sb.salt))
+		return ERR_PTR(-EINVAL);
+
 	sects = le32_to_cpu(sb.data_block_size) >> SECTOR_SHIFT;
 	if (!sects)
 		return ERR_PTR(-ERANGE);
@@ -518,6 +523,6 @@ char *dm_verity_config_from_sb(const char *data_dev, const char *hash_dev,
 			 le32_to_cpu(sb.data_block_size),
 			 le32_to_cpu(sb.hash_block_size),
 			 le64_to_cpu(sb.data_blocks), sb.algorithm, root_hash,
-			 le16_to_cpu(sb.salt_size), sb.salt);
+			 salt_size, sb.salt);
 }
 EXPORT_SYMBOL(dm_verity_config_from_sb);
-- 
2.47.3




  reply	other threads:[~2026-11-26 16:12 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-26 16:10 [PATCH master 1/3] dm: verity: don't let the superblock override the root hash Ahmad Fatoum
2026-11-26 16:10 ` Ahmad Fatoum [this message]
2026-11-26 16:10 ` [PATCH master 3/3] dm: verity: support superblocks without a salt Ahmad Fatoum

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261126161025.1929975-2-a.fatoum@barebox.org \
    --to=a.fatoum@barebox.org \
    --cc=barebox@lists.infradead.org \
    --cc=tobias@waldekranz.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox