[PATCH 1/2] drbd: reject data replies whose size does not match the request

From: Yibo Liu

Date: Thu Oct 15 2026 - 18:29:54 EST


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@xxxxxxxxxxxxxxx
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Yibo Liu <yiboliume@xxxxxxxxx>
---

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)