From: Yibo Liu <yiboliume@gmail.com>
To: "Philipp Reisner" <philipp.reisner@linbit.com>,
"Lars Ellenberg" <lars.ellenberg@linbit.com>,
"Christoph Böhmwalder" <christoph.boehmwalder@linbit.com>,
"Jens Axboe" <axboe@kernel.dk>
Cc: drbd-dev@lists.linux.dev, linux-block@vger.kernel.org,
linux-kernel@vger.kernel.org, co+0845f49852fd568f@bugs.sh,
Yibo Liu <yiboliume@gmail.com>,
stable@vger.kernel.org
Subject: [PATCH v2] drbd: validate digest size in checksum resync and verify requests
Date: Tue, 20 Oct 2026 18:22:00 +0000 [thread overview]
Message-ID: <20261020182200.236875-1-yiboliume@gmail.com> (raw)
receive_DataRequest() sizes the digest buffer of P_CSUM_RS_REQUEST and
P_OV_REPLY packets from the length the peer puts in the packet header,
without checking it against the digest size of the negotiated csums-alg
or verify-alg. w_e_end_csum_rs_req() and w_e_end_ov_reply() later
memcmp() crypto_shash_digestsize() bytes of that buffer; the D_ASSERT()
on the size only logs a message.
A peer that sends a shorter digest thus causes a slab-out-of-bounds read
in the worker, and a peer that declares a huge length makes the receiver
attempt an oversized kmalloc() that triggers a page allocator warning.
BUG: KASAN: slab-out-of-bounds in memcmp (lib/string.c:676)
Read of size 8 at addr ff11000007b9d630 by task drbd_w_r0/601
Call Trace:
memcmp (lib/string.c:676)
w_e_end_csum_rs_req (drivers/block/drbd/drbd_worker.c:1182)
drbd_worker (drivers/block/drbd/drbd_worker.c:2189)
drbd_thread_setup (drivers/block/drbd/drbd_main.c:314)
kthread (kernel/kthread.c:436)
ret_from_fork (arch/x86/kernel/process.c:158)
ret_from_fork_asm (arch/x86/entry/entry_64.S:245)
Allocated by task 605:
__kmalloc_noprof (mm/slub.c:5439)
receive_DataRequest (drivers/block/drbd/drbd_receiver.c:2715)
drbd_receiver (drivers/block/drbd/drbd_receiver.c:5371)
drbd_thread_setup (drivers/block/drbd/drbd_main.c:314)
kthread (kernel/kthread.c:436)
Reject the packet and drop the connection unless the declared digest
length matches the digest size of the corresponding transform, or if
no such transform is configured.
Fixes: b411b3637fa7 ("The DRBD driver")
Cc: stable@vger.kernel.org
Reported-by: co+0845f49852fd568f@bugs.sh
Signed-off-by: Yibo Liu <yiboliume@gmail.com>
---
Changes in v2:
- Drop patch 1/2 (P_DATA_REPLY size check); this is now a single patch.
- Check the digest length only in receive_DataRequest(), before the
buffer is allocated, and leave drbd_worker.c unchanged: with the exact
size enforced on receive, the sizes compared in the worker always match.
v1: https://lore.kernel.org/all/20261015222800.85928-1-yiboliume@gmail.com/
drivers/block/drbd/drbd_receiver.c | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
index 2135c14354a8..d45c4e68f83b 100644
--- a/drivers/block/drbd/drbd_receiver.c
+++ b/drivers/block/drbd/drbd_receiver.c
@@ -2711,7 +2711,17 @@ static int receive_DataRequest(struct drbd_connection *connection, struct packet
break;
case P_OV_REPLY:
- case P_CSUM_RS_REQUEST:
+ case P_CSUM_RS_REQUEST: {
+ struct crypto_shash *tfm = pi->cmd == P_CSUM_RS_REQUEST ?
+ peer_device->connection->csums_tfm :
+ peer_device->connection->verify_tfm;
+
+ if (!tfm || pi->size != crypto_shash_digestsize(tfm)) {
+ drbd_err(device, "%s: unexpected digest size %u\n",
+ cmdname(pi->cmd), pi->size);
+ goto out_free_e;
+ }
+
di = kmalloc(sizeof(*di) + pi->size, GFP_NOIO);
if (!di)
goto out_free_e;
@@ -2742,6 +2752,7 @@ static int receive_DataRequest(struct drbd_connection *connection, struct packet
goto submit_for_resync;
}
break;
+ }
case P_OV_REQUEST:
if (device->ov_start_sector == ~(sector_t)0 &&
base-commit: c03c1a14507dfaf8b856c2608f9ac216021fc222
--
2.34.1
reply other threads:[~2026-10-20 18:22 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20261020182200.236875-1-yiboliume@gmail.com \
--to=yiboliume@gmail.com \
--cc=axboe@kernel.dk \
--cc=christoph.boehmwalder@linbit.com \
--cc=co+0845f49852fd568f@bugs.sh \
--cc=drbd-dev@lists.linux.dev \
--cc=lars.ellenberg@linbit.com \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=philipp.reisner@linbit.com \
--cc=stable@vger.kernel.org \
/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