From nobody Sun Jun 14 07:40:58 2026 Received: from mail-lf1-f46.google.com (mail-lf1-f46.google.com [209.85.167.46]) (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 F0306346E46 for ; Fri, 1 May 2026 19:37:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777664254; cv=none; b=ptMI6urXsQPBpXbJgYlfMPo5EcTLCroqnO8dz8kepNahUwVc5vUzhxq/xeKzRKzCg2lJmZ+GNfJ8Fh4NzVS898XCIyVo/XTYlQM8LH5Z0VyFTwxVWoLgh3WMsAKO7ipeN1rgp0Uclry6xmJTH5CgIOCrJe75Xlo6AlF9MyVSws8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777664254; c=relaxed/simple; bh=VYJbZJzslFD4b8QuqfR1IU5anj5rce7lywSdea4tNW8=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=t9Kv4QFJZOKzcE+7dU1IdTyH5wXZH5jf3QroVLW/lQaaheACmpJG0Wimgeh6tKWr8hD5mBso9dcYfzbV+QU2i0Av9D74K1BYzbRE4599wsMcgnLN8aHFGaWJBK2P5dMJWSjQRbFZhXZpjVxW9wLxgsdOLCGG26V4I74odjn+9rc= 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=kYtm0Dng; arc=none smtp.client-ip=209.85.167.46 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="kYtm0Dng" Received: by mail-lf1-f46.google.com with SMTP id 2adb3069b0e04-5a41099fa86so2340253e87.2 for ; Fri, 01 May 2026 12:37:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1777664251; x=1778269051; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=84KWYYkdGr7OYA/h0dhqW+Pzo6IgELFrs8AW+9UxHKc=; b=kYtm0DngY2EhGQngPwJYYkTXXpBjX3du4soV9DRR0xPQ8OWCsFXZ7gvSyop1tyuIW2 R9zjVNWEl6aOAe1RPE8z4VtLdCqZgcwfaZeqtS9qHNktJtEYYSZ7yJrMbwXkHhqe88By mv4QMB88DJ/r1YdjbZiEFgizW7Lvt5XRULp/7Gp4aDw8YraU63NsZwpE9drpxX6r16bT A057AoeXXWayhQYDrCaGlw/n4YeUlZBV0yaVb/kS9Gea3KmrDWONmFPzGa1j4NQz/859 vVst+rHoB7xJGgZUKsZs9FGe0q32xxXCosaXRt78h9c5eN6PwYFvXmPcz9CPNxJquoKb Nmng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777664251; x=1778269051; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=84KWYYkdGr7OYA/h0dhqW+Pzo6IgELFrs8AW+9UxHKc=; b=GJAZ3XEUgv157S2mMANTjMPWKECVzzgH6WEX6G+feCFnEWGJ1J4jIJGsoA5px71+PI h2n+aL+rgULlDdbzjqJxyMkNiQxU5fr75o1EG389BJEvG4SibD7b0nprfaq4MG6Pz1i1 i5S8clgVwVNV5LI1T2iL0F0I2zR1gQPi4TPLpHYWylUsXqjKZ8H+l4uTBzBXj5klHalm X4W2mt4ZJGZ3LtNaxdVqRGpG/ocZ9O1JM650Ap/3Rr+Co5V9PhKgGGI8WeAsdPxQem5X CEz274szlKUPUZ3IScK+BHVwrM7YpENUxo1fTNOAPekSriW0fEYmfEVrIJ9OAOhIaXG+ y2uQ== X-Forwarded-Encrypted: i=1; AFNElJ+Z8Z0Ut5OdmRHbWDw229TWaJ2uXmZRkPKgKra762t80wcK+qz3/gll2P9hXYVtiFrGOtUJYeZVWYFpU6E=@vger.kernel.org X-Gm-Message-State: AOJu0YzjgfAIoAK11043NTPAP9SWNnfL5D7bcbliKWmU9Jc1K1YiMWNT x2w3+FiRYekMNqCoVugMjkat2YUD7rcA7efI6WmH9Yl/G+cUVvv5xnVo X-Gm-Gg: AeBDiesHUB1K2FutreR8aaD7m81saPO/UTIl0+vF7PRuI4vMH9WkDLtpuakmwONg51n q6ms4Uvf5+gRjs5oXSVHKLAYbzl6R0Hi8iTHJAPqe2KNqNr9XwrlmuhlGDT3uo47tmZ2KzCbdGR e0cCwq/1CuS047W+sKMxxpdnfNig+JYCcXDzaEEk/M2iVRI1rmQXVlwxBM3ZgDFCFzccOFuY9CF VsaRJ0ILUVvH23Jnu6XEMHtjCvnU9+6BzOEH7Sqs5XqDxIxV+5xPMnM+MOgbIORMaKzkORm0TQq Ir9oWMBnCTf6efg79eVldzMsqY4ghmVB953zu6S4+rukXsfuFigDsyI0EICI6nRb0SKbYK5erke TWXa+Mx9tibt1emSlqi12dVMnPewwtKlcQXCCC2APAB6iWyjLkD746Ew6ctdsTXK1rH/RBzRWh/ Zty5ICp4MrCg+ySiukpY/FByybyPKa3z+Eqz92xihj/16h2XuLqzs4ITn21GvAfPh8iBvMW+J5P jbviEp7kM+AVhgxtug+L4Zsem92T6JvYfqwuwqATsciUGnHUjkw+Dcqf4ejX59IY2DX7TO4rDxX X-Received: by 2002:a05:6512:690:b0:5a4:1133:c305 with SMTP id 2adb3069b0e04-5a8631bb6famr73694e87.26.1777664250869; Fri, 01 May 2026 12:37:30 -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-5a85c22ded5sm733229e87.17.2026.05.01.12.37.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 May 2026 12:37:28 -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 v2] libceph: reject monitor replies with oversized data segment Date: Fri, 1 May 2026 23:37:22 +0400 Message-ID: <20260501193722.25194-1-mishra.dhiraj95@gmail.com> X-Mailer: git-send-email 2.54.0 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 --- 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 | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/net/ceph/mon_client.c b/net/ceph/mon_client.c index d2cdc8ee3155..7f2293122bba 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,16 @@ 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 (!req->reply) { + pr_warn("%s tid %llu missing reply buffer, skipping\n", + __func__, tid); + *skip =3D 1; + m =3D NULL; + } else if (data_len > req->reply->data_length) { + pr_warn("%s tid %llu data %u > preallocated %zu, skipping\n", + __func__, 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 +1510,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; @@ -1544,6 +1556,15 @@ static struct ceph_msg *mon_alloc_msg(struct ceph_co= nnection *con, ceph_msg_put(m); m =3D ceph_msg_new(type, front_len, GFP_NOFS, false); } + if (m && data_len > m->data_length) { + pr_warn("%s data %u > prealloc %zu (%u#%llu), skipping\n", + __func__, 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.49.0