From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qt1-f172.google.com (mail-qt1-f172.google.com [209.85.160.172]) (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 F058939B482 for ; Thu, 4 Jun 2026 18:09:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780596554; cv=none; b=W1PM9E2swJbOiI7vWW05PILCwWX2Raf1hY3AB0cha0FQRIccj6yepARLsqFeqKP+Suuo5hmix4HM4Zyb2LAyAcch4Q+YPA5d1smB861Q8fIg0ZOLIVy3uvkeLa+mwH8D+DBWDr+e+tPNH5tQDZavBF7WiWOsgUu2q05/nrl1ck4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780596554; c=relaxed/simple; bh=PO3iejuBlnRzIOMTIRC7gUF+lvmQGa01DfODjyBXwno=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=M97tlzrpD6vYTsojBYYafNXwP2CRtBpqRDNe6wlevbk4G16C2eppEoukvORy6tLkBB1oPSyJE8bKBJRbzSSRPhnX0LrLCoam91/q3OizIe2i51Nkhm+fmcR5gUjau7W5eUoig5v55/5wR+xJgHWMWxbMHQMH8PrM9ja2LqhgY5k= 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=a3mCZt/d; arc=none smtp.client-ip=209.85.160.172 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="a3mCZt/d" Received: by mail-qt1-f172.google.com with SMTP id d75a77b69052e-5174a1d78f8so9009951cf.2 for ; Thu, 04 Jun 2026 11:09:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1780596552; x=1781201352; 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=qc3UhhffxGWia37/F9UtpFEHW30fe749qB/+Usg5z+c=; b=a3mCZt/dZCd+Vf9j43EAWOSb6Qjxt1sMcE6Vv6KeNx+kuIEx0tprIB1UiEUpIobOpg CgpefpuCvHxY8AHXAZJqXBJxFG74WtzTLypzfS8LZJ7SmoEnMJ1M8BlgfG/rvTnNzqlQ VmSU/O3+7YEvwpLdmOa+ZngYEmeZ827dy/wpRpHP5WdRr4Tan8KPYRkiQcD+WMtAhiBL o94cRNT3FxLwXZWZrocxsqYgxiDFbV1FenHP+apqSC6ZbeWesazgFvmZ+TWjuzXuv3zv V65lTLN8yjI6l3YKrnebw1Q4dq8wC4sHxDqbi7+NIWpOdYLQKPdiA60BWz58wogK/hzb FSUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780596552; x=1781201352; 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=qc3UhhffxGWia37/F9UtpFEHW30fe749qB/+Usg5z+c=; b=iNECKbDziwk70jL6Bv/G4CVvUtTeV2hcvdcwGJ65wKc4CEY9DtBcgvL8ovqBJ7vjAZ Ntd2oks+RdWMaMuVbw/PkBoKz45AL4mF3++R0LlHAU/FFoWeR8A7LsRuy391TPGqSVvr ikLS5KrCqrIUdEdlYDnZTyq1ZSsLi3a6zn3RTNGVa7v26XGAEV9svEXqlufGQcrR4rEM 9gbxmYwwtwEOFbX8Bt7XgCOxYd/8tS6VlJ5u4G/y/4Pxxut/TNml3sr0WImFzByS4EeL b7RV7+O3d5n/9vPlKuPrc6/pi+a1fNIfutsVJQJZuCiwlu88WkZyR/NQbKiYb++XU3GX 59vQ== X-Forwarded-Encrypted: i=1; AFNElJ/Wu78pUYWF/kUIWUmRu8l9baJJQ+fGjN0w+L+Rthi4lYLXfp+utaBjWw6AaC5tnPlb9pIrlxnbIRwkrIE=@vger.kernel.org X-Gm-Message-State: AOJu0YwMpBuhHtrEXYux3vu5Nt0xwgfIZ0wMD8htdzW/hxY2/jOGAa+b J4o/niXZIMS4QJAyu4LmPPntRp/L3huJKolKRJ8SE01+4u8ujDXn8kj1 X-Gm-Gg: Acq92OHHIKtQch5YypMnxbHWiAQ2kRfkKGie8iDu0/mAttizES6/FlrDUakQfDodliJ Zmsbh8VgD17i/huMZ6oUVoxr7K/cxOqPCZA0/qg4/sWNTP/6kTw7oKR3oNvBjtud0+qMvbA7lRt r4n0OTphjd3e521ZRa3hD7GCeLwrU0Y5vSc9TszAPGerYg/RBqTTrGW8bI00yvExXtKzkfN3gUw Kw/0TsUjJFy+ip2r0TwsJBQonuQLeXJr5qcahwET4HWXabb1Z13LgnUbsyJI2Keo7nTYW/2dcKF udUpJdVyvFQJDyiP29UdESwgcPZMZSgyjaWsULTrgT0VickA1u7p/bLTm5b1U9PbNa/YFgKrrxw MwOBHFMplmRFNN40iou8/a83nq5jm0anQtDONA2qNO7JBD18aVnUFrG431+Jir3XYgNHvw7/3Vz M0GJUmb6qMvwCkVlk3m6ZWv5AbcLjHNeShsIrhY0KLGIdV0PxToYtIryr4KotMaBlq2unckqGtc UB59cU++ygMUqeaWJ3d17neurfLL+Y= X-Received: by 2002:ac8:6f13:0:b0:50f:c109:b78 with SMTP id d75a77b69052e-517787c0e39mr124706901cf.60.1780596551903; Thu, 04 Jun 2026 11:09:11 -0700 (PDT) Received: from server0 (c-68-48-65-54.hsd1.mi.comcast.net. [68.48.65.54]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-51775dbd2c9sm59020961cf.23.2026.06.04.11.09.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jun 2026 11:09:11 -0700 (PDT) From: Michael Bommarito To: Ilya Dryomov , Alex Markuze , Viacheslav Dubeyko Cc: ceph-devel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/4] ceph: bound MDSCapAuth path and fs_name decode in handle_session() Date: Thu, 4 Jun 2026 14:08:58 -0400 Message-ID: <54eb585e03930ade4d11d9a103eff5f737d65251.1780596023.git.michael.bommarito@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 7bit handle_session() decodes the MDSCapAuth records carried by a CEPH_SESSION_OPEN message (msg_version >= 6). For each record the match.path and match.fs_name byte strings are read by first decoding a 32-bit length and then copying that many bytes with the bare ceph_decode_copy(). Unlike the surrounding fields, which all use the _safe decode variants, these two copies are not preceded by a ceph_decode_need() bounds check, and the enclosing MDSCapAuth and MDSCapMatch struct_len fields are skipped rather than enforced as an upper bound. A length larger than the bytes remaining in the message front makes ceph_decode_copy() read past the end of the front buffer. The message front is a dedicated allocation (ceph_msg_new2() -> kvmalloc), so the over-read runs off that object. A malicious or compromised MDS can trigger this with the first post-connect message on mount, with no client-side user interaction; under KASAN it is reported as a slab-out-of-bounds read in handle_session(). Impact: a malicious MDS can force the kernel client to read up to 4 GiB past the message front allocation during session setup, crashing the client (out-of-bounds read). Switch both copies to ceph_decode_copy_safe(), which performs the ceph_decode_need() bounds check before the copy and branches to the existing bad label, matching the rest of the decoder and the error path that frees the partially decoded cap_auths array. Fixes: 1d17de9534cb ("ceph: save cap_auths in MDS client when session is opened") Cc: stable@vger.kernel.org Signed-off-by: Michael Bommarito Assisted-by: Claude:claude-opus-4-8 --- fs/ceph/mds_client.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/fs/ceph/mds_client.c b/fs/ceph/mds_client.c index ed17e0023705e..4f36ac73305dc 100644 --- a/fs/ceph/mds_client.c +++ b/fs/ceph/mds_client.c @@ -4318,7 +4318,9 @@ static void handle_session(struct ceph_mds_session *session, pr_err_client(cl, "No memory for path\n"); goto fail; } - ceph_decode_copy(&p, cap_auths[i].match.path, _len); + ceph_decode_copy_safe(&p, end, + cap_auths[i].match.path, + _len, bad); /* Remove the tailing '/' */ while (_len && cap_auths[i].match.path[_len - 1] == '/') { @@ -4335,7 +4337,9 @@ static void handle_session(struct ceph_mds_session *session, pr_err_client(cl, "No memory for fs_name\n"); goto fail; } - ceph_decode_copy(&p, cap_auths[i].match.fs_name, _len); + ceph_decode_copy_safe(&p, end, + cap_auths[i].match.fs_name, + _len, bad); } ceph_decode_8_safe(&p, end, cap_auths[i].match.root_squash, bad); -- 2.53.0