From nobody Sun Jun 14 06:11:19 2026 Received: from mail-lf1-f51.google.com (mail-lf1-f51.google.com [209.85.167.51]) (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 652B92989B7 for ; Sat, 2 May 2026 05:22:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777699376; cv=none; b=mqumymOjI6LPyO4pCXufq8WHZgDLHAVL1C+GcVHmtpjJVteChWwmNyG3QLrfaOCIPomwi4+K0HmBAUYB1/8BrMjF571V0eIps7/z1532Fb8tchZn6vMfAVHRwAY8tMjVY0TkOfLwZq9sUTznw82R+sQY7h9RiG4HxB2qmtkjZu0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777699376; c=relaxed/simple; bh=klkuNC9n1JBOD9ygDaA6GEg4ImuFQZg/JhDtWlAuQQ4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tp4UzUcCOm5S9ilUFh8zVua+S2NjcBpldGjoPEOMz1SvImFc7YTcM0/zeEXOR64AQyNkhtqg4A0O5Wmhndy87BllYyKs//m9l2LNBhPP21PpF2Ck1Gdgi1w85/dtea2jG1xj1A5lanWPX768yutmxuUDLM+sHNFuTiYJJWBm91s= 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=SAIrqOep; arc=none smtp.client-ip=209.85.167.51 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="SAIrqOep" Received: by mail-lf1-f51.google.com with SMTP id 2adb3069b0e04-5a41099fa86so2702248e87.2 for ; Fri, 01 May 2026 22:22:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1777699372; x=1778304172; 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=NfdJ9DeevY/kQSFjrfpUduVPMDhOYMJs3EHm3Wf83iM=; b=SAIrqOepEhdcgyx0LuHuw2RrX40oG9FoaKT/5rBAWC9e139yQkaDUZee0X4EpUahJI gHVrOYSijsa+OEFnsE0+7n1Dw/d6uCq2DOyMAhws39aT/P/Am+KlroobDLdZ/dEz+zsV 7FBL27KTtNUuHG9jjrVad5PjeQryHaBxSxqQhMkD5Jh0ee7gt5mJhACrCqXPYk/Hwpgg k/59sZy7wZc4ynBnyK56L7ZrxOGE4O9lgQqleArA/jPeRq1WcnjSuZlRZE8elxsNacXR vTaKVjO3f8LWv5CsTZqlwgjKBsKl+7qBTmTLGOvkGxdW3Gdn9xmqvPLWg2xwWGvhacKI 0/jA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777699372; x=1778304172; 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=NfdJ9DeevY/kQSFjrfpUduVPMDhOYMJs3EHm3Wf83iM=; b=U/zJUAQqeHaHs7hBnAbwnsmW+Pr6ydZim+jResjoL5YISBfres2YkffOOFbI9p3LHd +f9HNPFExk7cRakD30/S3h7gA4rfNrx7UpU+ohAI5ioLcmegENEz/iW6755ewh6wALBN 3Y/dHH7R2S4iintCx95eR71BzeH4l1T4XlFwPt42kw4LqywP6Kz0c2jCHJDPveez0012 qAN+uUv2UEFKXazcd/g5BCEkDHD28H8IdqePwk5vmakeUf/DDil1rMvNi5tXOJJPxelC RZqUN5KJM8NpZladp9Gc0CNYQlBLg1rsLL0uGdmKhbw1gMIas4tRITnb9Tmp7w62tNoM xQow== X-Forwarded-Encrypted: i=1; AFNElJ8GRzSuxUpM7hoMmB8HuNzBD0Nf2EQ44RPmzNGJAzH82ERfM9zvo7dEDewp/pS68fqjqjth7IqJ1UyXyBU=@vger.kernel.org X-Gm-Message-State: AOJu0YxRR5e1z7zuyr2v2M8QAzf9uMAnIA4WxPtdoiDP7sZJymtwY4FU G7OBQf1ZLqnv6QNBkcs9yLb+J1wTCsI9WRR2+ecqq3kWd4gJDjbQY2XX X-Gm-Gg: AeBDiet0XCAb7QKAUkY7rD257k9P0sopYUfiA8oXvS30dX9e1rChUveFlmpw4Dm2t7b DBP9f/h7aR/lrTy7LWJ7K3JEAwCHm9jIhMf+Es8EB6ful11IOP1Bw6Mwsmv+IBy5JUt935sNn9v RqnfcsCz/Ma3l33nhqA0Nyabeb4c65evemNHIAKX2+Iw7kHYeClNgQLhWUpad86zhFiHVKcljd6 fO2YDLRj2WVi87DgUBEiRkvbBxVL5KFH3F2e9S62uMmG8yjo0H00mRB9oVnb2s7ZMx9v+sQAot6 ItYglDN+6l+EupY9MH8HNLCm/eVrAW41DF6qdvDtl2/dbpG7dedf9hNrpZbw4H76xrDc60DUehj Tcdz8+NqQgkXkV1i6LmLIgNd2yMTGSGf4D0EhQq1adp8rqqH/UpRTHjLCfyeG/QvsRI5pz6rZQx vu2ojIHZQcx2lM+pfj613/pwN6HM0O7RiCkgivQvg0PVTVPAp+X2SrD9hrkzw+cgZNojY0JznK4 wz9CjGPcNR+4Qev6ymqryjXFmjaz/lhc+QH8ilDYbQlzzqEmD5pmgffSI4vlame6w== X-Received: by 2002:a05:6512:3d15:b0:5a8:5276:962a with SMTP id 2adb3069b0e04-5a862ec0f83mr437710e87.9.1777699372154; Fri, 01 May 2026 22:22:52 -0700 (PDT) Received: from localhost.localdomain (bba-92-98-184-214.alshamil.net.ae. [92.98.184.214]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5a85c233192sm1002087e87.36.2026.05.01.22.22.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 May 2026 22:22:51 -0700 (PDT) From: Dhiraj Mishra To: Ilya Dryomov , Alex Markuze , Viacheslav Dubeyko Cc: ceph-devel@vger.kernel.org, linux-kernel@vger.kernel.org, Greg Kroah-Hartman , Willy Tarreau , security@kernel.org, Dhiraj Mishra Subject: [PATCH v3] libceph: reject monitor replies with oversized data segment Date: Sat, 2 May 2026 09:22:42 +0400 Message-ID: <20260502052242.33396-1-mishra.dhiraj95@gmail.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260501193722.25194-1-mishra.dhiraj95@gmail.com> References: <20260501193722.25194-1-mishra.dhiraj95@gmail.com> 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 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 =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. 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 se= cure modes)") Signed-off-by: Dhiraj Mishra --- 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_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; }