From nobody Sat Jun 13 11:26:23 2026 Received: from mail-lj1-f177.google.com (mail-lj1-f177.google.com [209.85.208.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C23CF3F661F for ; Thu, 7 May 2026 19:19:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778181570; cv=none; b=aqId6uVczNZguvr7VKhujqC3cIBfqC5TT2ScVuWeRtqNRDiB8pfs5Hfl0CX68gzF15fP8pc9fl+YM7OSu4+AW+F6mzozbiD0NioldbQLh9HfMyC76fX1y4/x7Oo+eLV7nrRrJ2oDVdW+3xKrFf8R9K6Z/us0Pu5PRJN96NmaAGs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778181570; c=relaxed/simple; bh=kH0c2VDSK24pnhVZwXR2a+FovCJSpzb1a+1sHK8BpvQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Wryh60Dg9PtsBN9wcqLcUs6V1LriASiDsJCtODsKQGSwKH4GDE9LWsVaYRK1EdAOX26KC6dzwB5k1ysJ1djBYVb3uO70If+yYHnnXVk/aZbn9OXKsTXM2lOtRiT35wkWPbtp0SqKQjMYjvTCt0JrIU/P4NvYJjA1Jp3Ja2o4/Uo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=QdWhhavn; arc=none smtp.client-ip=209.85.208.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="QdWhhavn" Received: by mail-lj1-f177.google.com with SMTP id 38308e7fff4ca-393925cb1baso12767481fa.0 for ; Thu, 07 May 2026 12:19:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778181567; x=1778786367; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=UYp8OKwBJc9iMgiS1ViaQ6sOjDvnki6o66u8rr1zm9c=; b=QdWhhavnwdznf+d38tgp+1W30leHllkSwfPeqlXmjWzBvazR6DIxkdRcAVBAsMFN9W EmR86TnoIhvtsljVk+HZOmsWJWUlxq3TD9hMRqFaByx7NxQZ1t0K1K3O/dKUmTmRJsRj L6S+f/qLNOGjJBmGYo2uCl7iDz4aUuB0+8SqfhxdHIvHQvHmybKC/z1/J6AcRiKi3gUI 1dc3ZI4pA7Vp2jbXg7C056rv79kmvXDJeJxF6Gp8Swp7lJObQj3R2/zyGnVzC8W+Kn5d Bsm4hq+x0mUTZ+FXVB5iP2z8nGr+ooP8XSDSCjwdByhrKqCXy+sGp62gdNpG0plI/Wst mKow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778181567; x=1778786367; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=UYp8OKwBJc9iMgiS1ViaQ6sOjDvnki6o66u8rr1zm9c=; b=Vxbb7HVPmt5WFryiMoL7wE9brZQa4DcrUf/EZFTV1VlB6s/I6Z0rikj3kx+9OOLmOY v/OHMBvCW5VtB17UV+ey/WOD1XIpaQ5Yz+EMAo+TDgt6CYjm0kEKBHuIcfcKkj7CSFXW wq+HTNei9+DjXrcBMcvxcthrPUuyXcjk/z18MFMVf5SOVE1OMAhn7W+eo4X+VX/0+NMQ KxgfpFgEFhh92d6l8sAmOapKwGS819ClWAbRW9hKrXAX3XRwB00RSmaT+lgt5F/sDHab 9FUOneI+YbDt3sK7sVPNv/APHbXip5KETGvQIVMTYvTEQZyLDm6Repv77R9qENUU3Zhx V9Jw== X-Forwarded-Encrypted: i=1; AFNElJ+Uk99qJyCahQFABU8G/+jb22ubThBVfXpJ+50YcR+qH+z/+D9DA04GHnRSHLYIHb1D02DcYrkQ4r7YvmY=@vger.kernel.org X-Gm-Message-State: AOJu0Yy6j56Lhu1VvX5qyFycyLzotS3ptGq/gi9sHqu8xTYbHUJDE8xw TQ1vgJBndyE40wGp04XYbRIExAvG06GuRFrUuP2VE8nZIQ9QqeVUDei/ X-Gm-Gg: AeBDievF98uGFQIt7RzN6mgD4WoFsrJSoDwYGf1tn2yFBvISDB6EPmuhyLYrQR7vUwm LxzuYhWFRNW8C5TV0YLx3eWtjWLY2/eRGL+Gcwvn547kIsAhon3fjmKjBWK20KUPX2hMIwaoNnI tIccf++DfjTOoG/PLh/N2QR9tLEBj9X0cnlzXVzT1/xybz8EiT5KmPkpNSSymTrY5Ayhtv6Uj27 AALwvKTAILDtzgbpFApjjY246Ukj2Pu7s/26vthsN8wH4n683/bK/Df8D2Fr6eNeT8jwBVvtdh7 qhHWA55PQxpLm23o2n9YHsrPFMfCLxHNMr5lkXcM0GMZNANGq9CY9bgr9nmTajgrM7pFivvlvbP TVR9L+onvXO41i+713+Ow30HAp/fuyHirQOA+BsTVMn+dM6+a188KUgHv+O6bH+tMwIsFkfXM5P yNIN07LxIiPA1vkVoLGMk3g2Xe/jtuaSbZUVqFpxgENF39fM89MCUvYlXHON0hQGsMsaAhXryUV Czu0k+Qon0OMvZQ X-Received: by 2002:a2e:9a14:0:b0:38d:fca1:4a6c with SMTP id 38308e7fff4ca-393c41c7591mr36921581fa.17.1778181566568; Thu, 07 May 2026 12:19:26 -0700 (PDT) Received: from localhost.localdomain ([87.201.39.98]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-393ef2c3e24sm1646721fa.20.2026.05.07.12.19.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 May 2026 12:19:25 -0700 (PDT) From: Dhiraj Mishra To: Ilya Dryomov , Alex Markuze , Viacheslav Dubeyko Cc: Raphael Zimmer , ceph-devel@vger.kernel.org, linux-kernel@vger.kernel.org, Greg Kroah-Hartman , Willy Tarreau , security@kernel.org, Dhiraj Mishra Subject: [PATCH v5] libceph, ceph: reject oversized mon and MDS data segments Date: Thu, 7 May 2026 23:19:19 +0400 Message-ID: <20260507191919.4985-1-mishra.dhiraj95@gmail.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <3fb2610b-5240-41ff-a5d9-699a445dffd3@tu-ilmenau.de> References: <3fb2610b-5240-41ff-a5d9-699a445dffd3@tu-ilmenau.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Monitor and MDS messages can be allocated with 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 peer advertises a non-zero data segment for one of these front-only messages, 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 monitor 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 allocator patterns are older, but I have not tested older msgr1-only kernels. A concrete monitor 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 =3D 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. The MDS allocation path has the same issue: mds_alloc_msg() allocates the incoming message with ceph_msg_new(type, front_len, GFP_NOFS, false), leaving msg->data_length as zero for a front-only message selected from an attacker-controlled wire header. Reject monitor and MDS messages whose wire data segment is larger than the data backing allocated for the selected ceph_msg, mirroring the existing OSD reply hardening. Fixes: 53ded495c6ac ("libceph: define mds_alloc_msg() method") Fixes: cd1a677cad99 ("libceph, ceph: implement msgr2.1 protocol (crc and se= cure modes)") Signed-off-by: Dhiraj Mishra Reviewed-by: Viacheslav Dubeyko Tested-by: Viacheslav Dubeyko --- v5: - Restructure mon_alloc_msg() control flow per review. - Return early for unknown types and front-buffer reallocation failure. - Keep the data_len guard on the final message allocation. v4: - Add the same oversized data_len guard to the MDS allocation path. 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. fs/ceph/mds_client.c | 16 ++++++++++++++++ net/ceph/mon_client.c | 24 +++++++++++++++++++++++- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/fs/ceph/mds_client.c b/fs/ceph/mds_client.c index ed17e0023705e6d4e387ff7e5bd7fb53efdbaeb7..c84d12384717bbcaad369f353b0= 0ccb8a7f2fcb0 100644 --- a/fs/ceph/mds_client.c +++ b/fs/ceph/mds_client.c @@ -6543,13 +6543,19 @@ static int mds_handle_auth_bad_method(struct ceph_c= onnection *con, static struct ceph_msg *mds_alloc_msg(struct ceph_connection *con, struct ceph_msg_header *hdr, int *skip) { + struct ceph_mds_session *s; + struct ceph_client *cl; struct ceph_msg *msg; int type =3D (int) le16_to_cpu(hdr->type); int front_len =3D (int) le32_to_cpu(hdr->front_len); + u32 data_len =3D le32_to_cpu(hdr->data_len); =20 if (con->in_msg) return con->in_msg; =20 + s =3D con->private; + cl =3D s->s_mdsc->fsc->client; + *skip =3D 0; msg =3D ceph_msg_new(type, front_len, GFP_NOFS, false); if (!msg) { @@ -6558,6 +6564,16 @@ static struct ceph_msg *mds_alloc_msg(struct ceph_co= nnection *con, return NULL; } =20 + if (data_len > msg->data_length) { + pr_warn_ratelimited_client(cl, + "mds%d message data %u > prealloc %zu, skipping\n", + s->s_mds, data_len, + msg->data_length); + ceph_msg_put(msg); + *skip =3D 1; + return NULL; + } + return msg; } =20 diff --git a/net/ceph/mon_client.c b/net/ceph/mon_client.c index d2cdc8ee31551eb99ad062f191ac3cf984970130..66c0d6d6b33d37a25141117845b= 0f804664540ef 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_c= onnection *con, struct ceph_mon_client *monc =3D con->private; struct ceph_mon_generic_request *req; u64 tid =3D le64_to_cpu(hdr->tid); + u32 data_len =3D le32_to_cpu(hdr->data_len); struct ceph_msg *m; =20 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 =3D 1; m =3D 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 =3D 1; + m =3D NULL; } else { dout("get_generic_reply %lld got %p\n", tid, req->reply); *skip =3D 0; @@ -1499,6 +1505,7 @@ static struct ceph_msg *mon_alloc_msg(struct ceph_con= nection *con, struct ceph_mon_client *monc =3D con->private; int type =3D le16_to_cpu(hdr->type); int front_len =3D le32_to_cpu(hdr->front_len); + u32 data_len =3D le32_to_cpu(hdr->data_len); struct ceph_msg *m =3D NULL; =20 *skip =3D 0; @@ -1536,13 +1543,28 @@ static struct ceph_msg *mon_alloc_msg(struct ceph_c= onnection *con, if (!m) { pr_info("alloc_msg unknown type %d\n", type); *skip =3D 1; - } else if (front_len > m->front_alloc_len) { + return m; + } + + if (front_len > m->front_alloc_len) { pr_warn("mon_alloc_msg front %d > prealloc %d (%u#%llu)\n", front_len, m->front_alloc_len, (unsigned int)con->peer_name.type, le64_to_cpu(con->peer_name.num)); ceph_msg_put(m); m =3D ceph_msg_new(type, front_len, GFP_NOFS, false); + if (!m) + return m; + } + + if (data_len > m->data_length) { + pr_warn_ratelimited("mon message data %u > prealloc %zu (%u#%llu), skipp= ing\n", + data_len, m->data_length, + (unsigned int)con->peer_name.type, + le64_to_cpu(con->peer_name.num)); + ceph_msg_put(m); + m =3D NULL; + *skip =3D 1; } =20 return m; --=20 2.54.0