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 1D6933A5E6C for ; Thu, 4 Jun 2026 18:09:16 +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=1780596557; cv=none; b=mfZ6uvUY+D+rGhWYIOREN7g06bxXDKIPP8zbPecRujaPRS/FWHubet7kFouCJsYnqcOtJv1HURkqKjdr8yXPsVZ+YRDbDMRagqh7IZhgmlxPAKPr1ze7SuepervQu7yyqN60KxWuKURxvfzu0iw7I6u3E7T2/yC5zO++fxTLw+g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780596557; c=relaxed/simple; bh=fX7fFsPfEFC3JMips9J8bHVCCgmHkm5jA9KcnfjY+8A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Kls92d91qUWo7v6QCEFwlHEkaOoor7hy/Lbv25PnBL55xYxHSavCGOqX3pHgBC8Ody+jwkdB0No7agH8mFCAmqmSRzYsYZWgisyqy0vqlJoDfi1XQPP6oXBfMgJbYPy8zeGWsgH803gsviojzG7dUi0Yu8hXp5jlyHiApBQAmqE= 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=jwCstpsJ; 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="jwCstpsJ" Received: by mail-qt1-f172.google.com with SMTP id d75a77b69052e-51775f2473aso7641171cf.0 for ; Thu, 04 Jun 2026 11:09:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1780596555; x=1781201355; 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=BX4HzXJ3JGZjJL5r8tJ9uzkaLb8khgmN8CTpb058st8=; b=jwCstpsJWJ2drukiVKXlyhm02GTMHoz/lPbmvi0p96clarOMmkDLIJE+pIgpGviwIo uPk0m4WHDzMa2i1nY+hQ2HSL3yvnmgiVRruhlTOxr7Fdk6IVDq8sDVOsHfKJNcEiGLcK KcYqc20zaGvwsJ5KiQe0iSgRYARAeDFzJreZjTmPPOpd0CDe9GpxSgqZek7E3qmoZxKs utKAjX86hvcSHUEIAY6mlEVm69djfFLqDPn+9jMGflvKUjr2p1yUnIjXbPH6bc/LsQQM TKA7hLjQmjV5o3Bu74Q2ASWIRtqh5THhNz4C/a14kQAXrH2ia7NU2nPo9G55TXWmEd2o +pJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780596555; x=1781201355; 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=BX4HzXJ3JGZjJL5r8tJ9uzkaLb8khgmN8CTpb058st8=; b=OFxcuUoiNZCAqKKImoEd0ABA+tVD7XR4a9JuNXwe3awJpsdACMbPl77ie73Fh++lYQ p0RELjb8OyoNWjYMEnN4M3dDiDJ2+hJCT1DM++q8vHVdUZKBzu6TrGaBvT5JMOkXi+kD 9He/rE5qA3PRPxf5dA+FsusNobg2lr25jAYbgU3Wre2UYhqgiM/vtks72400enzn4S4I 6xgMPUOsnkXOq/IUKnIdNIdOErornbk5Wdg5pCi9JQQnNWH5ot7/3skDBY5GMYgzsZNt 24csKb+AV8foA/qOSa8t+wn+1MOYTd5095/JUSeE7RTslnjqE1pmCnkkGMXm6hG7lt/D oC2g== X-Forwarded-Encrypted: i=1; AFNElJ/TItabqkRcF2Ra1/Cml9Fswo5OXj9M1Cq7ImL2ByFUhvJKCeU7YbKEu/8Ra9w8p6AKlfCXB9lyZV8dRhg=@vger.kernel.org X-Gm-Message-State: AOJu0YxC0AoMYCBKmuFpC5dz8RxW3C4RvaeCbHuJty40FqSsfFpq2sV/ zBEtJ3se3LY0guxCHsWW0Wrmx6zxfsnEfdZXUuXnnljgnUlZf/5CQ9X0 X-Gm-Gg: Acq92OHuXts9A9+tJSB5UhV0nRZ+Dqh2JLCHiC+YJN38/4dEJPaVpKIjdBIvphleGJj Y6gpoMIpyynVqbMK75xAY+zsdfDl4wbY0DTmjElxcSctCW5JiekSY4t/wZDuZZLN9af0FQan8M/ 1aWXKyMeUUWtwPUh9TaIabOY1O+sLqy4UDbtSyQjAvzGMEzb1/ruWS7jhK+ORa/MJ5Zar/paMvV YuYpcNW2X3xZwftDHNvcbvHyXHYagp7EQyJBqr0KZDdAmre88HH1EkpwLJmbEbV0O2/Rx75ybmd GCK36pfR6EsCiLoqeeFbKl04PWxLCCU2Tx6VgPjodlRNZRMiH2h81qy+SV3du9efvCSiD2EUDs2 Ovj2UquCFJXF9pIyjGRY98IFwWUyzmizyHqM8OvW4eIynurUTVVFqKH+YT7pDw1Zdd1QYJdXioJ AYQnaC3+mS7K09k17/GD3o69Kaz5mBiEbbJpkRgYU+YM/LTNG/fEdvENWIXL2bcNWa5QXfJ7T+e ExF07BmZM/de07pvyAhsz4GGhSBwRJrB/X4awYrBA== X-Received: by 2002:ac8:5881:0:b0:517:82bd:46ff with SMTP id d75a77b69052e-51782bd4a4fmr96126461cf.26.1780596555207; Thu, 04 Jun 2026 11:09:15 -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.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jun 2026 11:09:14 -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 4/4] ceph: cap delegated inode count in ceph_parse_deleg_inos() Date: Thu, 4 Jun 2026 14:09:00 -0400 Message-ID: <8f25e9ac54cb3c408d061993a5a797186aa50506.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_parse_deleg_inos() decodes interval sets of delegated inode numbers from an MDS create-with-delegation reply. For each set it reads a 64-bit start and a 64-bit len with ceph_decode_64_safe(), which only validates that the eight bytes are present in the message, not the value, and then loops: while (len--) { xa_insert(&s->s_delegated_inos, start++, DELEGATED_INO_AVAILABLE, GFP_KERNEL); ... } len is fully attacker controlled. A malicious or compromised MDS can send a create reply whose interval set declares len near 2^63, driving an effectively unbounded loop that performs a GFP_KERNEL xarray insert on each iteration. This spins a kernel thread in the reply dispatch path and exhausts memory; on a client that has negotiated CEPHFS_FEATURE_DELEG_INO (enabled by default) a single reply is enough to wedge the mount. A legitimate MDS delegates only a small range per set (the userspace MDS prealloc window, mds_client_prealloc_inos, defaults to 1000). Reject any set whose len exceeds CEPH_MAX_DELEG_INOS (1M, far above any legitimate value) by treating the reply as malformed and returning -EIO, consistent with the existing decode error handling. Normal delegations are well under the cap and are unaffected. Fixes: d4846487870897 ("ceph: decode interval_sets for delegated inos") Cc: stable@vger.kernel.org Signed-off-by: Michael Bommarito Assisted-by: Claude:claude-opus-4-8 --- fs/ceph/mds_client.c | 14 ++++++++++++++ fs/ceph/super.h | 9 +++++++++ 2 files changed, 23 insertions(+) diff --git a/fs/ceph/mds_client.c b/fs/ceph/mds_client.c index 4f36ac73305dc..0a084c4f3aae2 100644 --- a/fs/ceph/mds_client.c +++ b/fs/ceph/mds_client.c @@ -633,6 +633,20 @@ static int ceph_parse_deleg_inos(void **p, void *end, start, len); continue; } + + /* + * A legitimate MDS delegates a small range per set. Treat a + * count larger than any plausible delegation window as a + * malformed reply rather than spinning while(len--) and + * inserting unbounded xarray entries. + */ + if (len > CEPH_MAX_DELEG_INOS) { + pr_warn_ratelimited_client(cl, + "rejecting oversized inode range delegation (start=0x%llx len=0x%llx)\n", + start, len); + return -EIO; + } + while (len--) { int err = xa_insert(&s->s_delegated_inos, start++, DELEGATED_INO_AVAILABLE, diff --git a/fs/ceph/super.h b/fs/ceph/super.h index afc89ce91804e..43a9b075f344c 100644 --- a/fs/ceph/super.h +++ b/fs/ceph/super.h @@ -634,6 +634,15 @@ static inline int ceph_ino_compare(struct inode *inode, void *data) #define CEPH_MDS_INO_LOG_OFFSET (2 * CEPH_MAX_MDS) #define CEPH_INO_SYSTEM_BASE ((6*CEPH_MAX_MDS) + (CEPH_MAX_MDS * CEPH_NUM_STRAY)) +/* + * Upper bound on the number of inodes the MDS may delegate to a client in a + * single interval set. The userspace MDS hands out at most a few thousand + * (mds_client_prealloc_inos, default 1000); 1M is far above any legitimate + * value and guards ceph_parse_deleg_inos() against an unbounded loop driven + * by an attacker controlled 64-bit length. + */ +#define CEPH_MAX_DELEG_INOS (1024 * 1024) + static inline bool ceph_vino_is_reserved(const struct ceph_vino vino) { if (vino.ino >= CEPH_INO_SYSTEM_BASE || -- 2.53.0