From: Kaho Jiang <kj2864@nyu.edu>
To: idryomov@gmail.com, amarkuze@redhat.com, slava@dubeyko.com
Cc: ceph-devel@vger.kernel.org, linux-kernel@vger.kernel.org,
co+a9f1a2fc804a2921@bugs.sh, Kaho Jiang <kj2864@nyu.edu>,
stable@vger.kernel.org
Subject: [PATCH v1] libceph: replace undersized receive middle buffers
Date: Tue, 17 Nov 2026 19:36:42 -0500 [thread overview]
Message-ID: <20261118003641.1069010-2-kj2864@nyu.edu> (raw)
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
reply other threads:[~2026-11-18 0:37 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=20261118003641.1069010-2-kj2864@nyu.edu \
--to=kj2864@nyu.edu \
--cc=amarkuze@redhat.com \
--cc=ceph-devel@vger.kernel.org \
--cc=co+a9f1a2fc804a2921@bugs.sh \
--cc=idryomov@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=slava@dubeyko.com \
--cc=stable@vger.kernel.org \
/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®