From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qt1-f179.google.com (mail-qt1-f179.google.com [209.85.160.179]) (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 EF2303C0A05 for ; Thu, 4 Jun 2026 18:09:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.179 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780596556; cv=none; b=LIFUxUF6SzS6OIqzY/vKF+v0OadOfhoE8c5KF1YxIGDCUJNDvvPKDrBx1D7MQ6Rj+tPzwsT/HsJqLZWA7eyfGjpGBkZX3mqiTYJE82Sx3CPNRd8SWJxl2CgAa1P9yHH1sZAp8b5XxQhNVDzix1DWGZP3pFH2e87NnMkUTA1xSYA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780596556; c=relaxed/simple; bh=iRGl+Zcv8CCCaVj7l7eFQI316DRL7nx4+17jWOdN+ZQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JwWEk9ZMLvM8U0Y9a0OZICMAXmksWVnevhombMwpoNiNjplgOuy6Wwm2DX+wo7y4S043Z4dV/qx+6+M4zISsZ//38D5LjiG9NUlU5OqQxm0mkITb70Caha19+v9FTKn2ky8/Q5kT60FOyAnbPRXM6Tx1HM0q+e+1i3IpSJd3F1U= 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=kiXwoAM8; arc=none smtp.client-ip=209.85.160.179 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="kiXwoAM8" Received: by mail-qt1-f179.google.com with SMTP id d75a77b69052e-51761d27612so10501181cf.3 for ; Thu, 04 Jun 2026 11:09:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1780596554; x=1781201354; 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=MyP4o+dWT8qg11HXzsRqDPlFSQhGfJVHTkPwzcA0P6E=; b=kiXwoAM8Zf0OUn66TNmFK+ONm02GJHbG/GIgTMf14eIh6uH35dJOW9WA6q2UW8gPgy qK5PBwLhydAH8NBt7QRmZS+GE7zSCrWGHNGOdxtdwyXazCRrhSkwaHy0R3jOwuFbJ0ZW BqjFFaiJfy4z64pg0N/LR1kBGAuXGo1myq5qJc8kyAsMv1B4ELmgb9aZdFvwvo7pNh8u s6sWYHkgfQ3bgYqr8im6w1RCiyo5nEtRWYygRWjyeBzansWyVEkgRy7Z/b0gCiSQmzAq zg+Px0tXcI42sh9G5aNwUinzzT7qhpA7ldMMLkaEgwZ4UCP+ny4fvBujQdLS+qvf8FQC X85Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780596554; x=1781201354; 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=MyP4o+dWT8qg11HXzsRqDPlFSQhGfJVHTkPwzcA0P6E=; b=N+Bm42KF6Mf9Jl6wK5cTe3t+ukYAojEQsv9wGEzubvx+e4MBIXHrdqZcyz6RCoKvWL hn0fSJS0PtY7lrLrLcCfyjYsaAvpByMJoaQKtERU5qmGXCz6ukbguTqCIdTGAdONflDp lR7nIdnewsllfQmFrihxKfzfNwmvawhD4TXtcsyS+FUTftrlbCfxISWTQ+wORyeJc7dq eNUbC0OrIBTMYBnWuXul+WDjPqZWPpcAVdDqDcDan0p0BV0xJkh5uyUSr3bPNZQMR7Ie JoRgZ8Z8cl2m6TkvJsPw///DWW3xDrKmjy0bKo2KULls4jgv91dJf8GcvC0YSfe3E6+T AxKg== X-Forwarded-Encrypted: i=1; AFNElJ9JSVmFzz5hUy/XffWkojZr7ic+5A4y0k/FOhHDxURkxVgm5PpUM0W+5CaHfIaylhSVt/LsWDKHKn2FDC0=@vger.kernel.org X-Gm-Message-State: AOJu0YzIQTxc72t636x/h1F0OT5vQfy3dRe+Jc+LpDyUY0YLRI61luN6 rtoPB5IIVVjz81DK8w4db0ilaz3suiTmKyNPp5Z7h2+mUh8kfElS2xY5 X-Gm-Gg: Acq92OEDoEf4qlpdb508M0pSggB8XoUf6Ov5HsycdCD/x2ct1ncyzqupGkJIZFwRECj pFNZjN7bgBo5TV8dOlIdlRNDbfUCsPuvpkBV2dY6N2rFoAi37BtFr72pHnXEIIUDvLmLp6zXZop +BaX9Gcr6Et53SJZFbAwgWTv9v2UaunEoDDhIAr0qhZSzbvxaM7433kpr3Zu4/LzJnvAKmoQ4Ev PiS5QX+FjWauOW8+cUApMcgL3LtXQGdf5uFJ1qM1ujzM9wAJsUHr3uMj/d+udkE9jn8JdZCY2pr P1/m2gdLxAQVq60GtOgkK7yig4nLVwiwfIRCWqA+XFXGHVnc8nKorW5ENudfNvfTGNirUlyeZjt 7oVfKMTzAcrRkEyQvdaZ57II+BzzRAu/68oICRLEp/BoX6HpDakSLxZOPG5Gc1XptjxqfkH7uhn NajD0GshGKpMKeqVrmQSAzOt+/BWmp6cq+RMoDiWW9xbt3ViGoZIpOHQdsaTBEL7apLUOwlSIOr E6soaBGOhLPwHIAC3S1YqCiZtLLeiA= X-Received: by 2002:a05:622a:d17:b0:517:61d5:2f85 with SMTP id d75a77b69052e-517786c8788mr115781731cf.33.1780596553790; Thu, 04 Jun 2026 11:09:13 -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.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jun 2026 11:09: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 3/4] ceph: bound num_export_targets array for mds info v2/v3 Date: Thu, 4 Jun 2026 14:08:59 -0400 Message-ID: <4ac3b57dcf0fba1dc5cc08bfb9a453be55cc465d.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 ceph_mdsmap_decode() in fs/ceph/mdsmap.c reads num_export_targets from each per-mds info record and advances the decode cursor by num_export_targets * sizeof(u32) without first checking that many bytes remain. The only upper-bound check that catches a runaway cursor (*p > info_end) is gated on info_v >= 4, because info_end is left NULL for info_v 2 and 3. When the monitor sends an MDS map whose per-mds info version is 2 or 3 with an oversized num_export_targets, the cursor moves past the message front buffer and the later export-targets loop calls the unchecked ceph_decode_32() on out-of-bounds memory. A kernel client processes CEPH_MSG_MDS_MAP from its monitor session (net/ceph/mon_client.c dispatches it; fs/ceph/super.c routes it to ceph_mdsc_handle_mdsmap(), which sets end to the front buffer bound and calls ceph_mdsmap_decode()). A malicious or compromised monitor, or an on-path attacker on an unsigned/unencrypted messenger session, can therefore drive an out-of-bounds read in the client kernel; on x86_64 with KASAN it is reported as a slab-out-of-bounds read in ceph_mdsmap_decode(). The decoded values land in the internal info->export_targets[] array, so the consequence is a kernel out-of-bounds read, not an information leak to the attacker. Impact: a malicious or compromised Ceph monitor sending an MDS map with a per-mds info version of 2 or 3 and an oversized num_export_targets field triggers an out-of-bounds read in the CephFS client kernel. Add a ceph_decode_need() for num_export_targets * sizeof(u32) before advancing the cursor, so the bound is enforced for every info_v >= 2, not only info_v >= 4. This mirrors the count-then-need idiom already used for m_data_pg_pools later in the same function. Fixes: d463a43d69f4 ("ceph: CEPH_FEATURE_MDSENC support") Cc: stable@vger.kernel.org Assisted-by: Claude:claude-opus-4-8 Signed-off-by: Michael Bommarito --- fs/ceph/mdsmap.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fs/ceph/mdsmap.c b/fs/ceph/mdsmap.c index d8e46eb7e5eb5..7cb65f9f4783c 100644 --- a/fs/ceph/mdsmap.c +++ b/fs/ceph/mdsmap.c @@ -224,6 +224,8 @@ struct ceph_mdsmap *ceph_mdsmap_decode(struct ceph_mds_client *mdsc, void **p, *p += namelen; if (info_v >= 2) { ceph_decode_32_safe(p, end, num_export_targets, bad); + ceph_decode_need(p, end, + num_export_targets * sizeof(u32), bad); pexport_targets = *p; *p += num_export_targets * sizeof(u32); } else { -- 2.53.0