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, Yibo Liu <yiboliume@gmail.com>
Subject: [PATCH 1/2] drbd: reject data replies whose size does not match the request
Date: Thu, 15 Oct 2026 15:27:59 -0700 [thread overview]
Message-ID: <20261015222800.85928-2-yiboliume@gmail.com> (raw)
In-Reply-To: <20261015222800.85928-1-yiboliume@gmail.com>
A node that reads from its peer (it has no local disk, the area is not
up to date locally, or read-balancing chose the peer) sends a
P_DATA_REQUEST for req->i.size bytes, and recv_dless_read() copies the
matching P_DATA_REPLY into the original bio. Commit bd910a7660d2
("drbd: reject data replies with an out-of-range payload size") rejects
a negative payload size, but a reply that is shorter or longer than the
request is still accepted.
A shorter reply only fills the start of the bio. data_size still drops
to zero in the copy loop, so the final D_ASSERT() does not fire, and
the read completes successfully although the rest of the caller's
buffer was never written. With a proxy that cut one reply down to
1 KiB, a 4 KiB O_DIRECT read returned 4096 with the last 3 KiB of the
buffer unchanged and nothing in the kernel log. A longer reply leaves
the excess in the socket, where it is parsed as the next packet header.
A correct peer always replies with exactly the requested size. Reject
any other size, as is already done for negative sizes.
Fixes: b411b3637fa7 ("The DRBD driver")
Cc: stable@vger.kernel.org
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Yibo Liu <yiboliume@gmail.com>
---
Notes:
- Reproduced on block-7.3 (41cab3a71dc7) in an arm64 virtme-ng guest,
with two DRBD 8.4 resources connected over loopback through a proxy
that rewrites packets. A diskless Primary read 4 KiB with O_DIRECT
while the proxy cut the P_DATA_REPLY to 1 KiB of data. Before: read()
returned 4096, the last 3072 bytes of the buffer were never written,
and nothing was logged. After: "Invalid data reply size 1024, expected
4096", the connection is dropped and the read fails with -EIO.
Unmodified 4 KiB reads succeed before and after. The harness is
available on request.
- recv_dless_read() in LINBIT's DRBD 9 tree, which the pending DRBD 9
rework series is based on, has the same check, so the series probably
needs this change too. I have not checked the posted series itself.
drivers/block/drbd/drbd_receiver.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
index 2135c14354a8..97b306676626 100644
--- a/drivers/block/drbd/drbd_receiver.c
+++ b/drivers/block/drbd/drbd_receiver.c
@@ -1810,8 +1810,9 @@ static int recv_dless_read(struct drbd_peer_device *peer_device, struct drbd_req
data_size -= digest_size;
}
- if (data_size < 0) {
- drbd_err(peer_device, "Invalid data reply size\n");
+ if (data_size < 0 || data_size != req->i.size) {
+ drbd_err(peer_device, "Invalid data reply size %d, expected %u\n",
+ data_size, req->i.size);
return -EIO;
}
--
2.39.5 (Apple Git-154)
next prev parent reply other threads:[~2026-10-15 22:28 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-15 22:27 [PATCH 0/2] drbd: validate payload sizes received from the peer Yibo Liu
2026-10-15 22:27 ` Yibo Liu [this message]
2026-10-15 22:28 ` [PATCH 2/2] drbd: validate digest size in checksum resync and verify requests Yibo Liu
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=20261015222800.85928-2-yiboliume@gmail.com \
--to=yiboliume@gmail.com \
--cc=axboe@kernel.dk \
--cc=christoph.boehmwalder@linbit.com \
--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 \
/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