Re: [PATCH] libceph: don't reuse a middle buffer that is too small

From: Xiubo Li

Date: Sun Nov 29 2026 - 21:26:05 EST


> diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
> index cc7db8c61db37..754d051fe771b 100644
> --- a/net/ceph/messenger.c
> +++ b/net/ceph/messenger.c
> @@ -2098,7 +2098,11 @@ int ceph_con_in_msg_alloc(struct ceph_connection *con,
> }
> memcpy(&con->in_msg->hdr, hdr, sizeof(*hdr));
>
> - if (middle_len && !con->in_msg->middle) {
> + if (middle_len &&
> + (!con->in_msg->middle || middle_len > con->in_msg->middle->alloc_len)) {
> + ceph_buffer_put(con->in_msg->middle);
> + con->in_msg->middle = NULL;
> +

Hi Xingyuan,

Thanks for the report and the detailed analysis.

The same fix is already queued in the ceph-client testing branch:

5d2e1e3b4ae8 ("libceph: refresh middle buffers for incoming messages")

It makes exactly the same change to ceph_con_in_msg_alloc() (the
condition is only written as "alloc_len < middle_len"), with the same
Fixes: tag and Cc: stable, so I think this one can be dropped.

For the record, I tested both versions against a fake monitor on a
KASAN kernel (7.4.0-rc2), with libceph built from testing with
5d2e1e3b4ae8 reverted ("base"), base + your patch, and testing as is:

- msgr1 (ms_mode=legacy), two AUTH_REPLY messages with middle 64 then
2048 and 8 then 256 bytes: base hits slab-out-of-bounds writes in
_copy_to_iter() (Write of size 2048 / 256), same as your report;
clean with either fix.
- msgr2 (ms_mode=crc), MON_SUBSCRIBE_ACK messages (m_subscribe_ack
singleton) with middle 64,2048 / 8,256 / 2048,64,4096 / 4096,0,8192:
base triggers the WARN_ON() at messenger_v2.c:3089 in
__handle_control() and then the same out-of-bounds write (sizes
2048/256/4096/8192); with either fix there is no warning, no KASAN
report and no crc error, including the shrink-then-grow sequences.

So your description of the v2 side is right too.

Thanks,
Xiubo