mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Weiming Shi <bestswngs@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.linbit.com, linux-block@vger.kernel.org,
	linux-kernel@vger.kernel.org, co+4618907cccdeffa@bugs.sh,
	Xiang Mei <xmei5@asu.edu>, Weiming Shi <bestswngs@gmail.com>,
	stable@vger.kernel.org
Subject: [PATCH] drbd: keep discarded packet size unsigned
Date: Sun, 27 Sep 2026 22:20:34 +0800	[thread overview]
Message-ID: <20260927142033.297349-2-bestswngs@gmail.com> (raw)

Packet lengths are decoded into an unsigned int, but
ignore_remaining_packet() stores pi->size in an int.  Values above
INT_MAX therefore become negative; min_t(int, ...) preserves the negative
value and drbd_recv() converts it to size_t, allowing the receive to
overrun the 4 KiB rbuf.

Keep the remaining size unsigned and clamp it as an unsigned value so that
each receive is bounded by DRBD_SOCKET_BUFFER_SIZE.

A KASAN reproducer reported:

  BUG: KASAN: slab-out-of-bounds in _copy_to_iter
  Write of size 32672 at addr ffff888027129000 by task drbd_r_r0/5002
  Call Trace:
   _copy_to_iter lib/iov_iter.c:197
   simple_copy_to_iter net/core/datagram.c:521
   __skb_datagram_iter net/core/datagram.c:435
   skb_copy_datagram_iter net/core/datagram.c:537
   tcp_recvmsg_locked net/ipv4/tcp.c:2846
   tcp_recvmsg net/ipv4/tcp.c:2949
   inet_recvmsg net/ipv4/af_inet.c:896
   sock_recvmsg net/socket.c:1159
   drbd_recv_short drivers/block/drbd/drbd_receiver.c:322
   drbd_recv drivers/block/drbd/drbd_receiver.c:331
   config_unknown_volume drivers/block/drbd/drbd_receiver.c:3624
   receive_SyncParam drivers/block/drbd/drbd_receiver.c:3671
   drbd_receiver drivers/block/drbd/drbd_receiver.c:5366

Fixes: 4a76b1612f35 ("drbd: Map from (connection, volume number) to device in the receive handlers")
Cc: stable@vger.kernel.org
Reported-by: <co+4618907cccdeffa@bugs.sh>
Assisted-by: LLM
Signed-off-by: Weiming Shi <bestswngs@gmail.com>
---
 drivers/block/drbd/drbd_receiver.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
index 58b95bf4bdca6..3fb73fbfd5f27 100644
--- a/drivers/block/drbd/drbd_receiver.c
+++ b/drivers/block/drbd/drbd_receiver.c
@@ -3616,10 +3616,10 @@ static struct crypto_shash *drbd_crypto_alloc_digest_safe(
 static int ignore_remaining_packet(struct drbd_connection *connection, struct packet_info *pi)
 {
 	void *buffer = connection->data.rbuf;
-	int size = pi->size;
+	unsigned int size = pi->size;
 
 	while (size) {
-		int s = min_t(int, size, DRBD_SOCKET_BUFFER_SIZE);
+		int s = min_t(unsigned int, size, DRBD_SOCKET_BUFFER_SIZE);
 		s = drbd_recv(connection, buffer, s);
 		if (s <= 0) {
 			if (s < 0)
-- 
2.55.0


                 reply	other threads:[~2026-09-27 14:20 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=20260927142033.297349-2-bestswngs@gmail.com \
    --to=bestswngs@gmail.com \
    --cc=axboe@kernel.dk \
    --cc=christoph.boehmwalder@linbit.com \
    --cc=co+4618907cccdeffa@bugs.sh \
    --cc=drbd-dev@lists.linbit.com \
    --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 \
    --cc=xmei5@asu.edu \
    /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

all inboxes | Powered by JetHome®