From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qv1-f47.google.com (mail-qv1-f47.google.com [209.85.219.47]) (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 E690C43CEC1 for ; Tue, 7 Jul 2026 18:06:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.47 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783447575; cv=none; b=WSF31Zip/7Q4NKniGO+XTwTlSjPq+3H6fyN5yGpP1S2aiAHd4tZoVSpXixNlrAHcUK1F7j2GTDxmeGFnuotJ1okuvTbwoHcXxw/XNw5FpfNIlru2GHW5JSM4/+f/2KoXWQGwcnqEb2xmIybDdZ3szVpEPFKMS2eHyNxhMbgN7QM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783447575; c=relaxed/simple; bh=DxXt3Q2DiIRmApvRKGH+cQ6dSbHwjJX6ntYdiXVePC0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=it0Sj4NqX4HBGMklG3Jt67HdbHjDAIBIaD6Jee4bLHhMRJKupX7HAoutWtc5AAhSSBaTCc5TlTOQcAHK51W3SYEIBF2p0t573GMIX3auDsm7NR+RFdrJW/YCL9xWvR8GBQU2Hp37XBym+r5wLMIQAFGl8KmQhGyfd2o50+dLozI= 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=pEJe3G/K; arc=none smtp.client-ip=209.85.219.47 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="pEJe3G/K" Received: by mail-qv1-f47.google.com with SMTP id 6a1803df08f44-8f256eaedf8so46455436d6.2 for ; Tue, 07 Jul 2026 11:06:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1783447573; x=1784052373; 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:content-type; bh=g90IJcGT+wQTcmQ/mehdTMw0WPxAuOtQnbadl+b23dk=; b=pEJe3G/Kvb6uUWc5WtG6Zs9rra+0hNM0hw0yvwsHOtFM5LE3o6S54LtqS3rBLFE+8M gnxQFD2yb/rpEoFyysw9mhQv2zhdEDHFlCm2EtWc1xLmhHN6P7SGcUcYUj+rcDnelglp Yf74IqKkzXh2m6aDACCZYGFVWDS1JqpzSdTF/lw2Vlow44szIarfQRGna4AZltv6mKC6 uchj9RrIsaJzZ6Q2pX259GR3+J+vCI5nWgV1d/xjRjj7kfJu2UNJgO7n5ZhLo3/xpzRW 5wcZFDfonS0JbH5eS9vFAM6CUV78mO3mepLfsm/+In0tTS8gz7X5NrwSV4Fa+Rto+QLX gQaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783447573; x=1784052373; 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:content-type; bh=g90IJcGT+wQTcmQ/mehdTMw0WPxAuOtQnbadl+b23dk=; b=qbk9LNOlMzC4aM0rPgMx0qJ3T2X1kIf3pJUHibu+A4M6dvbxS2iqs6fssvPyvRzcjB GNvBw/ZBG3bziuTxxFmqKc7S34VpGzvYQFyLyQSwgxGoORlBBY1/8URJQgzNhStZdpeV xvgHeTPQ2FT/Od9DtJZtKGv37MfpmGf2NJHzo3SKj3xH6AMbUMnkgR7KNlCd9s0lUFOo izAByjJJvF/ru+pDn+dkUwlbuYRUv6iGrTerwlsMxH1Q4r+sFAnMskUXxCGwhUt4oPJ1 4z5/sFjATJABNOqzbwlBdkiXERgabbtvVpmiQ2vNea8fDREgUV8B8xtnCegKDVNXINWq Zl/A== X-Forwarded-Encrypted: i=1; AHgh+RpdP9MT3ow0xxOVJ2tw89ECajeeE29qjzB2AbULoQv10adcgYF+xFSrkivGd8rn1ch/rylJPfa4HLG0Vys=@vger.kernel.org X-Gm-Message-State: AOJu0YwF78DvpCbVSTHwC+GFKyUsRvdgo4yT71XTIiEOtCati0aa1tPC A/Nni7f0vEL7yxkSXXVjHBbYBwigVTD8bL43sP01vJ1iOb1HbJHohYLIc1B6y2tCT/E= X-Gm-Gg: AfdE7cm/hOfLo2yzrV52TE85an3xfbBk77ZhKWpBT7eOzhQMqxHwGTtBk0OyoS5nq+G Q46HaXnBv/tO1TPrb0tR8aoL/V8/bKyf9g1AH/tQYOY2S0ok5ufdiIpn72cmo/gunkCR2qPZues r/qeKZG/QbkXHwIHqFwTViYjcn8pqyOSraJifFvdL0GOanQ/7vt3J9aFFKuORTj1vjtyK/zzCKM raChzdCeKrgJmeImuSKXY0cRmkDO/ZA0KnxJ4TZWY49rOXBV+ziWZnlLMfnnlUGPK3YSoKv+kMN WxLK2sSNJoY2Yt2F+lSCARWaPoHBsBfJLOb9g6RhvcpYhHDtLeJaeQtsL2D+TiqfvUcTfeta61T lIopBIu5cPpqG+QBw95YLn0ZTlFDdmnb/nSUmnECpXKYhUcq2fp6SgwjMEMdF0Qc/9suYxMIPdw 0kTbYKYXNSZi8AO9hJsx+1KFjwPT5jvY6kvFO3mccI5BbWjfyuFweYMN43pK04AI4DGOvXFN9f0 SNx3CqfFK6I0afO0dqNt7IZLu/YrkWe X-Received: by 2002:a05:6214:4e08:b0:8fe:2b7f:2a78 with SMTP id 6a1803df08f44-8fe2b7f3e0cmr13922306d6.53.1783447572745; Tue, 07 Jul 2026 11:06:12 -0700 (PDT) Received: from server0.tail6e7dd.ts.net (c-68-48-65-54.hsd1.mi.comcast.net. [68.48.65.54]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-8f471de87e3sm166404376d6.35.2026.07.07.11.06.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jul 2026 11:06:12 -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 v3 2/4] ceph: bound MDSCapAuth path and fs_name decode in handle_session() Date: Tue, 7 Jul 2026 14:05:58 -0400 Message-ID: <8a59da434c232933be009872b0223a5b907d12c1.1783447231.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 Assisted-by: Claude:claude-opus-4-8 Signed-off-by: Michael Bommarito Reviewed-by: Viacheslav Dubeyko --- 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 18be36c2e9e87..94f76e9fe4ead 100644 --- a/fs/ceph/mds_client.c +++ b/fs/ceph/mds_client.c @@ -4434,7 +4434,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] == '/') { @@ -4451,7 +4453,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