From: Jake Joyner <jake@jakejoyner.com>
To: Alasdair Kergon <agk@redhat.com>,
Mike Snitzer <snitzer@kernel.org>,
Mikulas Patocka <mpatocka@redhat.com>,
Benjamin Marzinski <bmarzins@redhat.com>
Cc: dm-devel@lists.linux.dev, linux-kernel@vger.kernel.org,
Jake Joyner <jake@jakejoyner.com>,
syzbot+3f8f5b65af8de862dcec@syzkaller.appspotmail.com
Subject: [PATCH] dm-verity: fix shift-out-of-bounds when computing hash level sizes
Date: Mon, 23 Nov 2026 12:34:13 -0800 [thread overview]
Message-ID: <20261123203413.145298-1-jake@jakejoyner.com> (raw)
verity_ctr() computes the number of hash blocks at each level of the
hash tree as
s = (data_blocks + (1 << n) - 1) >> n
where n = (i + 1) * hash_per_block_bits, i.e. data_blocks / 2^n rounded
up.
The loop that counts the levels only stops once
hash_per_block_bits * levels is 64 or more, so n can be 64 or larger for
the top level. For example, with 1024-byte hash blocks and sha512,
hash_per_block_bits is 4, and a large enough number of data blocks gives
16 levels and n = 64. Shifting a 64-bit value by 64 or more is undefined
behaviour, and UBSAN reports:
UBSAN: shift-out-of-bounds in drivers/md/dm-verity-target.c:1598:38
shift exponent 64 is too large for 64-bit type 'long long unsigned int'
data_blocks is non-zero here (levels is 0 otherwise) and smaller than
2^64, so data_blocks / 2^n rounded up is 1 whenever n >= 64. Use that
value directly instead of shifting.
With this change the syzbot reproducer no longer triggers the report on
v7.4-rc4 in QEMU, and the table is still rejected with "Hash device is
too small".
Fixes: b1bf2de07271 ("dm verity: fix inability to use a few specific devices sizes")
Reported-by: syzbot+3f8f5b65af8de862dcec@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=3f8f5b65af8de862dcec
Signed-off-by: Jake Joyner <jake@jakejoyner.com>
---
The code change is mine. An AI assistant (Claude) helped me reproduce
the syzbot report, reviewed the change and helped word this description.
drivers/md/dm-verity-target.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/drivers/md/dm-verity-target.c b/drivers/md/dm-verity-target.c
index 306ed1f6c118..78fe3c8f23b4 100644
--- a/drivers/md/dm-verity-target.c
+++ b/drivers/md/dm-verity-target.c
@@ -1593,10 +1593,13 @@ static int verity_ctr(struct dm_target *ti, unsigned int argc, char **argv)
hash_position = v->hash_start;
for (i = v->levels - 1; i >= 0; i--) {
sector_t s;
+ unsigned int shift = (i + 1) * v->hash_per_block_bits;
v->hash_level_block[i] = hash_position;
- s = (v->data_blocks + ((sector_t)1 << ((i + 1) * v->hash_per_block_bits)) - 1)
- >> ((i + 1) * v->hash_per_block_bits);
+ if (shift >= 64)
+ s = 1;
+ else
+ s = (v->data_blocks + ((sector_t)1 << shift) - 1) >> shift;
if (hash_position + s < hash_position) {
ti->error = "Hash device offset overflow";
r = -E2BIG;
--
2.56.0
next reply other threads:[~2026-11-23 20:34 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-23 20:34 Jake Joyner [this message]
2026-11-23 20:42 ` [PATCH] dm-verity: fix shift-out-of-bounds when computing hash level sizes sashiko-bot
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=20261123203413.145298-1-jake@jakejoyner.com \
--to=jake@jakejoyner.com \
--cc=agk@redhat.com \
--cc=bmarzins@redhat.com \
--cc=dm-devel@lists.linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=mpatocka@redhat.com \
--cc=snitzer@kernel.org \
--cc=syzbot+3f8f5b65af8de862dcec@syzkaller.appspotmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.