From nobody Mon May 4 13:06:35 2026 Received: from mail-lf1-f41.google.com (mail-lf1-f41.google.com [209.85.167.41]) (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 2686E376481 for ; Mon, 4 May 2026 09:16:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777886212; cv=none; b=mmVBrJkM/YBN9Es3kHYvnWxp++UeOBx6Lil9v8SBhYyeij5tczwlN5lt/prJ/2V6QnnI9yDaqR6EtFuCX++ldiSVx+H7qo/qa2C/Z3aIYJKDjcJXQKOph35E28mrlqLU9g+XKXk5Iyev/vIxya//sBuFPFsLyamAriiDX2ueACg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777886212; c=relaxed/simple; bh=bjp9+6ZHh5kA2wJX5YbiN76yptloXxxSyjk/HkLLCC4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bGrBq05YeUED5k9He+EGnz++O+DZb2gBqnf3jOkX2cgkAQJhIJGmd+vW3dXqT2/BevDuXV9eqxYTYL5VDAuosqgP4npKYglQFdLCPdlEeiDxAcRnMaMY/TXO4ylS+v7AChxaE+6vMOAc0g36kJWuK8/k+fogjHMB4c8muNpscfo= 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=C1Oe0GeI; arc=none smtp.client-ip=209.85.167.41 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="C1Oe0GeI" Received: by mail-lf1-f41.google.com with SMTP id 2adb3069b0e04-59dcdf60427so3374338e87.3 for ; Mon, 04 May 2026 02:16:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1777886209; x=1778491009; 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=t9ZzvHzMTTp2n6bNSS7kPEE/1daWHQcLfOR7eCRpzzs=; b=C1Oe0GeIWEd25D2EkWJUNgWMOiDmWIQTjsxrm8FRziuyT4mDNliB/G5qX7yCPuvBZw 9EgS+NuGr3j7VJ17+BmJYlNVFBzw0DiYpchPZ+cO3ZGoKSi8y/h8IEyqaD2gHfsCrP/D CBxMhzeF3j5fNQtPBQWSXtk05RsXc0gEiVziHogxolCOOmF45hZMY7yqOmR+ozEvYJea lWJ9jbMyQcKlQJZg/H0r3V2R1oTnNoS1rNN+jzcSipLXaTIWXWEPpubaA07A3Tnb//nl 51nxHdAayYC04hSeyE19TRlu56q6EOhtyJqQM36k9ytJNDQjekc1o2wGq0BPMksPf547 aJwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777886209; x=1778491009; 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=t9ZzvHzMTTp2n6bNSS7kPEE/1daWHQcLfOR7eCRpzzs=; b=jUAGPkBKDCFQ4pMjiRAgvql1A6n2n7Su01iQk6/zXaqUviwdsjv456ERzH2Pdr62ZL ghD+/XCWmMApcTGVYl6YBWUWTbUUEOpf8FJc01LTIXzuSdmYLnY7w75EpLBlWhcsZhS4 QZmu8TLdcGYrtrARot/XCh9BOZ0UexwJA2bHDbA+grf4YRh3rOYATPlpWCe4W1RGARDn af0cWbq/XDHK6qbx5886YLdv/WioiUEwSmqvqA6UVdWzstCTB19AmgbxchqKKLpBGfGn iMJ+C3izan17ZuKYvyOd1aco6J7ZJ37FA9uvYcEO+ZnWXtHfC/HtsgCnQTr6StPVRIzK WOuw== X-Forwarded-Encrypted: i=1; AFNElJ/F+pfdSs5zK4lNah9/fyVfbzmPD0dsGDSZiuHDoWfRJdPxvzll21fQLOWKPLXsHVhUKQk2D9k/1Xnezqo=@vger.kernel.org X-Gm-Message-State: AOJu0YzybNLkp+QaX0Ct2idlQHOBTtaJAKpWq/XytbXeTcTDLr53VsvW GtNZwnimJc8oFziooXQTjWlxVY7s0sJ5no5dtmm1Qqzmthjfv/E26YTt X-Gm-Gg: AeBDietocaMH7tbY08BHRwuox6NTyUq93tPtlMJ75HLiZ+7qXsorOeSQp1juyLFInws 7LlgwdVpcWgcy6NS1RcG4OZlGV8NkP451dTgDyu9CK4yMzK8uBDAY9o/Ic68Q4HqDVbN9yvvelK +PXmVpf5ydyQHljFYuWLDeAJVegRkoICXP8bdcl66ro9c/LATAdQaPrxeYjrEZxxhMdq1/JDXmE 76ngvLUm8LFC210CxCVMzyEupDtI7VlO4TvQVTC0I5ifLxBSTJsRIyOusvQkofv0g5pouljbPGP iXb6ln4f7oYXeBhaEBbJ7VGbI3CBaR0NX0BBY3QRDIKfAf1ml8Tg/TmhD+bK/w0zATIYR/glbEd FVHT1C96dKqFV8F8Qfh2pAzmEp4dAZ8IKir06fVlmT4ZrLIeTlWeolr4whrzM+kBcO8SEZ1Pxyd sVfLOB9woLRo1qVDUiGRw1UhbcQFCPKn76zarM+9WRADOKIrxYH5SB+x3SJ7OnppcTBvMKXVN73 4i19/v2yXpRxQZap6x0VqoJvO5v0KF2ttBckOH9tg== X-Received: by 2002:a05:6512:3ba4:b0:5a7:42e2:db4 with SMTP id 2adb3069b0e04-5a862fbd93fmr2848737e87.15.1777886208914; Mon, 04 May 2026 02:16:48 -0700 (PDT) Received: from localhost.localdomain ([94.204.104.200]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5a86c7a1698sm1377703e87.3.2026.05.04.02.16.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 May 2026 02:16:48 -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 v4] libceph, ceph: reject oversized mon and MDS data segments Date: Mon, 4 May 2026 13:16:35 +0400 Message-ID: <20260504091635.17215-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 --- 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 | 13 +++++++++++++ net/ceph/mon_client.c | 17 +++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/fs/ceph/mds_client.c b/fs/ceph/mds_client.c index ed17e0023705..3b92d37983d1 100644 --- a/fs/ceph/mds_client.c +++ b/fs/ceph/mds_client.c @@ -6543,9 +6543,12 @@ static int mds_handle_auth_bad_method(struct ceph_co= nnection *con, static struct ceph_msg *mds_alloc_msg(struct ceph_connection *con, struct ceph_msg_header *hdr, int *skip) { + struct ceph_mds_session *s =3D con->private; + struct ceph_client *cl =3D s->s_mdsc->fsc->client; 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; @@ -6558,6 +6561,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 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_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; @@ -1545,5 +1552,15 @@ static struct ceph_msg *mon_alloc_msg(struct ceph_co= nnection *con, m =3D ceph_msg_new(type, front_len, GFP_NOFS, false); } =20 + if (m && 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; + } + return m; }