Re: [PATCH v3] libceph: reject monitor replies with oversized data segment

From: Raphael Zimmer

Date: Mon May 04 2026 - 04:34:56 EST




On 02.05.26 7:22 AM, Dhiraj Mishra wrote:
> Monitor messages can be allocated from preallocated reply messages or
> with ceph_msg_new(), both of which may provide only front-buffer storage
> and no data items. The messenger receive path copies the wire header
> into the selected ceph_msg and later uses hdr.data_len to decide whether
> to initialize a data cursor.
>
> If a malicious or compromised monitor advertises a non-zero data segment
> for one of these front-only replies, the receive path can call
> ceph_msg_data_cursor_init() with length greater than msg->data_length and
> hit its BUG_ON() checks, crashing the client kernel.
>
> I verified the issue against v7.1-rc1-123-ge75a43c7cec4. The msgr2
> trigger path is present since commit cd1a677cad99 ("libceph, ceph:
> implement msgr2.1 protocol (crc and secure modes)"), which is contained
> in v5.11-rc1 and later. The monitor allocator pattern is older, but I
> have not tested older msgr1-only kernels.
>
> A concrete trigger is a monitor connection over msgr2 after
> CEPH_CON_S_OPEN where a FRAME_TAG_MESSAGE contains a monitor reply type
> handled by mon_alloc_msg(), a valid front_len for that message type and
> data_len = 1. CEPH_MSG_MON_MAP is one such example: the message is
> allocated with ceph_msg_new(), leaving msg->data_length and
> msg->num_data_items as zero.
>
> Reject monitor replies whose wire data segment is larger than the data
> backing allocated for the selected ceph_msg, mirroring the existing OSD
> reply hardening.
>
> Fixes: cd1a677cad99 ("libceph, ceph: implement msgr2.1 protocol (crc and secure modes)")
> Signed-off-by: Dhiraj Mishra <mishra.dhiraj95@xxxxxxxxx>
> ---
> v3:
> - Remove the impossible !req->reply check for generic requests.
> - Use pr_warn_ratelimited() for malicious-monitor log spam resistance.
> - Avoid adding __func__ to the new mon_client warnings.
> - Add a blank line between the front_len and data_len checks.
>
> v2:
> - Resend as an inline plain-text patch.
> - Add full email address to the From and Signed-off-by identities.
> - Add ceph-devel and LKML to the recipient list when sending.
>
> net/ceph/mon_client.c | 17 +++++++++++++++++
> 1 file changed, 17 insertions(+)
>
> diff --git a/net/ceph/mon_client.c b/net/ceph/mon_client.c
> index d2cdc8ee3155..9f1c7ca42f36 100644
> --- a/net/ceph/mon_client.c
> +++ b/net/ceph/mon_client.c
> @@ -712,6 +712,7 @@ static struct ceph_msg *get_generic_reply(struct ceph_connection *con,
> struct ceph_mon_client *monc = con->private;
> struct ceph_mon_generic_request *req;
> u64 tid = le64_to_cpu(hdr->tid);
> + u32 data_len = le32_to_cpu(hdr->data_len);
> struct ceph_msg *m;
>
> mutex_lock(&monc->mutex);
> @@ -720,6 +721,11 @@ static struct ceph_msg *get_generic_reply(struct ceph_connection *con,
> dout("get_generic_reply %lld dne\n", tid);
> *skip = 1;
> m = NULL;
> + } else if (data_len > req->reply->data_length) {
> + pr_warn_ratelimited("mon generic reply tid %llu data %u > preallocated %zu, skipping\n",
> + tid, data_len, req->reply->data_length);
> + *skip = 1;
> + m = NULL;
> } else {
> dout("get_generic_reply %lld got %p\n", tid, req->reply);
> *skip = 0;
> @@ -1499,6 +1505,7 @@ static struct ceph_msg *mon_alloc_msg(struct ceph_connection *con,
> struct ceph_mon_client *monc = con->private;
> int type = le16_to_cpu(hdr->type);
> int front_len = le32_to_cpu(hdr->front_len);
> + u32 data_len = le32_to_cpu(hdr->data_len);
> struct ceph_msg *m = NULL;
>
> *skip = 0;
> @@ -1545,5 +1552,15 @@ static struct ceph_msg *mon_alloc_msg(struct ceph_connection *con,
> m = ceph_msg_new(type, front_len, GFP_NOFS, false);
> }
>
> + if (m && data_len > m->data_length) {
> + pr_warn_ratelimited("mon message data %u > prealloc %zu (%u#%llu), skipping\n",
> + data_len, m->data_length,
> + (unsigned int)con->peer_name.type,
> + le64_to_cpu(con->peer_name.num));
> + ceph_msg_put(m);
> + m = NULL;
> + *skip = 1;
> + }
> +
> return m;
> }

Hi Dhiraj,
as far as I can see, the same issue can also occur on MDS connections
here:
https://elixir.bootlin.com/linux/v7.0.1/source/fs/ceph/mds_client.c#L6477
I guess a similar check should also be added there. Maybe this can be
done in one patch.

Best regards,
Raphael