Skip to content

drbd: validate payload sizes received from the peer

Yibo Liu drbd-dev linux-block lkml 1 version New

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest2 patches 0 repliesNew

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/2drbd: reject data replies whose size does not match the requestdrivers/block/drbd/drbd_receiver.c+3 -20 replies
2/2drbd: validate digest size in checksum resync and verify requestsdrivers/block/drbd/drbd_receiver.c drivers/block/drbd/drbd_worker.c+13 -40 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [PATCH 0/2] drbd: validate payload sizes received from the peer

Two places in the DRBD receive path take a payload size from the peer's packet header and use it without comparing it to the size they expect. Commit bd910a7660d2 ("drbd: reject data replies with an out-of-range payload size") already rejects negative sizes in recv_dless_read(); these patches cover the remaining cases:

1/2 rejects a P_DATA_REPLY whose size differs from the read request.
A short reply currently completes the read successfully with part of the bio never written.

2/2 rejects P_CSUM_RS_REQUEST and P_OV_REPLY packets whose digest
length does not match the configured algorithm, and makes the worker compare digests only when their sizes match. A short digest currently causes an out-of-bounds read in memcmp(), and a huge one triggers a page allocator warning.

Like the earlier fixes, this only matters for a peer that does not follow the protocol; a correct peer always sends the expected sizes.

The problems were found with the help of an AI coding assistant and were reproduced on block-7.3 before posting (details below the "---" of each patch). Testing:
- before/after runs of the reproducer in an arm64 virtme-ng KASAN guest
- a complete csums-alg resync and an online verify as regression tests
- each patch built with W=1 and sparse (C=2), arm64, gcc 13.3: no new warnings
- checkpatch.pl --strict clean
Not built with clang or for other architectures.

Yibo Liu (2):
drbd: reject data replies whose size does not match the request
drbd: validate digest size in checksum resync and verify requests

 drivers/block/drbd/drbd_receiver.c | 14 ++++++++++++--
 drivers/block/drbd/drbd_worker.c   |  8 ++++----
 2 files changed, 16 insertions(+), 6 deletions(-)

base-commit: 41cab3a71dc7be62114d91cc849424879062d324

Signature · 1 line
2.39.5 (Apple Git-154)