mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v1] libceph: replace undersized receive middle buffers
@ 2026-11-18  0:36 Kaho Jiang
  0 siblings, 0 replies; only message in thread
From: Kaho Jiang @ 2026-11-18  0:36 UTC (permalink / raw)
  To: idryomov, amarkuze, slava
  Cc: ceph-devel, linux-kernel, co+a9f1a2fc804a2921, Kaho Jiang, stable

ceph_con_in_msg_alloc() can reuse a message whose middle buffer is too
small for the incoming middle length. The receive path copies that
many bytes into the buffer, causing a slab out-of-bounds write.

BUG: KASAN: slab-out-of-bounds in _copy_to_iter (lib/iov_iter.c:77 ./include/linux/iov_iter.h:86 ./include/linux/iov_iter.h:308 ./include/linux/iov_iter.h:332 lib/iov_iter.c:197)
Write of size 4096 at addr ffff888023765000 by task kworker/1:3/4983
CPU: 1 UID: 0 PID: 4983 Comm: kworker/1:3 Not tainted 7.4.0-rc3-g666539eecdf4 #1 PREEMPT(full)
Hardware name: QEMU Ubuntu 24.04 PC v2 (i440FX + PIIX, arch_caps fix, 1996), BIOS 1.16.3-debian-1.16.3-2 04/01/2014
Workqueue: ceph-msgr ceph_con_workfn
Call Trace:
 <TASK>
 dump_stack_lvl (lib/dump_stack.c:94 lib/dump_stack.c:120)
 print_report (mm/kasan/report.c:378 mm/kasan/report.c:482)
 kasan_check_range (mm/kasan/generic.c:186 mm/kasan/generic.c:200)
 __asan_memcpy (mm/kasan/shadow.c:106 (discriminator 1))
 _copy_to_iter (lib/iov_iter.c:77 ./include/linux/iov_iter.h:86 ./include/linux/iov_iter.h:308 ./include/linux/iov_iter.h:332 lib/iov_iter.c:197)
 simple_copy_to_iter (./include/linux/uio.h:228 net/core/datagram.c:521)
 __skb_datagram_iter (net/core/datagram.c:435 (discriminator 1))
 skb_copy_datagram_iter (net/core/datagram.c:535)
 tcp_recvmsg_locked (./include/linux/skbuff.h:4268 net/ipv4/tcp.c:2851)
 tcp_recvmsg (net/ipv4/tcp.c:2955)
 inet_recvmsg (net/ipv4/af_inet.c:894 (discriminator 1))
 sock_recvmsg (net/socket.c:1154 (discriminator 1) net/socket.c:1176 (discriminator 1))
 ceph_tcp_recvmsg (net/ceph/messenger_v1.c:34)
 read_partial_message_chunk (net/ceph/messenger_v1.c:975 net/ceph/messenger_v1.c:964)
 ceph_con_v1_try_read (net/ceph/messenger_v1.c:992 net/ceph/messenger_v1.c:1245 net/ceph/messenger_v1.c:1417)
 ceph_con_workfn (net/ceph/messenger.c:1576)
 process_one_work (kernel/workqueue.c:3495)
 worker_thread (kernel/workqueue.c:3578 kernel/workqueue.c:3659)
 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)
 </TASK>
Kernel Offset: disabled

Release the existing buffer if its capacity is smaller than the
incoming middle length, then allocate a new buffer through the
existing allocation path.

Fixes: bb257664f748 ("ceph: simplify ceph_msg_new")
Cc: stable@vger.kernel.org
Reported-by: co+a9f1a2fc804a2921@bugs.sh
Assisted-by: LLM
Signed-off-by: Kaho Jiang <kj2864@nyu.edu>
---
 net/ceph/messenger.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
index 212e7797f9e4..ccb650708663 100644
--- a/net/ceph/messenger.c
+++ b/net/ceph/messenger.c
@@ -2098,6 +2098,10 @@ int ceph_con_in_msg_alloc(struct ceph_connection *con,
 	}
 	memcpy(&con->in_msg->hdr, hdr, sizeof(*hdr));
 
+	if (con->in_msg->middle && middle_len > con->in_msg->middle->alloc_len) {
+		ceph_buffer_put(con->in_msg->middle);
+		con->in_msg->middle = NULL;
+	}
 	if (middle_len && !con->in_msg->middle) {
 		ret = ceph_alloc_middle(con, con->in_msg);
 		if (ret < 0) {
-- 
2.43.0


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-18  0:37 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-18  0:36 [PATCH v1] libceph: replace undersized receive middle buffers Kaho Jiang

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®