From nobody Sat Sep 26 19:34:28 2026 Received: from out30-131.freemail.mail.aliyun.com (out30-131.freemail.mail.aliyun.com [115.124.30.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 64D923B42CB for ; Mon, 31 Aug 2026 06:28:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788157743; cv=none; b=BZyGAzpAd3PFwS4l0tpxcWWYOWAfK57NNnrpKqVquvOv7eo1TlKRxUiyntONQdB7y1if6GiOtPyWWrnVaVnKYlDFDwjthOgoKmF0CM5pYbD8qCyCTyrS+6TpaH8QjgV7wo0rNtMiizl0qgVS6oH3q0S2SKZWXLLKdWK7DQrR6RU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788157743; c=relaxed/simple; bh=V7FvtSugKhjNT2ZmWlU7OmLNr1hyuaMhvDtV1+/b48s=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=KBJx4zSaV0Gi3+6Zi787R6PDaD18wySdHFJxAlUSDrckCH5KcdgzTgmpJNc8mJ4yPVWUiI9/5h2yzKJtS8Tv+TNnP+Q6hrWzfZAsbxgTi4Iq2Qt43ylZXvrsq/9HwhlaP+6A8p7TQsmiUeyp8OGlhB3xy8ZXveUHvtyydyXtxeU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=rVYnNnuD; arc=none smtp.client-ip=115.124.30.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="rVYnNnuD" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1788157731; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=Y9iAOgav5Xi3RArqDRUmlMz4FJeOv/RfbeIABxvvgig=; b=rVYnNnuDTEYxEfCuD0EEAfNO0+fTWUPD5AE0hMTT11AwDRE0KAcIPOCiG6gWtPshxlQbXMi9hfsc0k38MzxZT5njh8xj/vMT7ACpi47O6ngNrvNrEuuThOGp6oW5RFwjpz+/BRpOiUupxh+9DLWT2iVPJlRktAXmuQmpZ396stQ= X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R271e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033037009110;MF=joseph.qi@linux.alibaba.com;NM=1;PH=DS;RN=6;SR=0;TI=SMTPD_---0X9tzGou_1788157730; Received: from localhost(mailfrom:joseph.qi@linux.alibaba.com fp:SMTPD_---0X9tzGou_1788157730 cluster:ay36) by smtp.aliyun-inc.com; Mon, 31 Aug 2026 14:28:50 +0800 From: Joseph Qi To: Andrew Morton , Heming Zhao Cc: Mark Fasheh , Joel Becker , ocfs2-devel@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH 1/4] ocfs2: restrict OCFS2_INVALID_SLOT suballoc slot to system inodes Date: Mon, 31 Aug 2026 14:28:45 +0800 Message-Id: <20260831062848.2743436-2-joseph.qi@linux.alibaba.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20260831062848.2743436-1-joseph.qi@linux.alibaba.com> References: <20260831062848.2743436-1-joseph.qi@linux.alibaba.com> 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" ocfs2_validate_inode_block() currently permits i_suballoc_slot to be OCFS2_INVALID_SLOT for any dinode. Only system inodes created by mkfs.ocfs2 are allocated from the global allocator and thus legitimately carry this value; regular inodes are always allocated from a per-slot suballocator and hence must have a valid slot. If a corrupted regular inode with OCFS2_INVALID_SLOT is accepted, ocfs2_remove_inode() will pass the slot to ocfs2_get_system_file_inode() and get_local_system_inode() will hit BUG_ON(slot =3D=3D OCFS2_INVALID_SLOT) when the inode is deleted. This can be triggered by an unprivileged user unlinking such a corrupted file. Reject OCFS2_INVALID_SLOT for non-system dinodes during validation, while still accepting it for system inodes. Fixes: fe7a283b3916 ("ocfs2: add suballoc slot check in ocfs2_validate_inod= e_block()") Cc: stable@vger.kernel.org Signed-off-by: Joseph Qi Reviewed-by: Heming Zhao --- fs/ocfs2/inode.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/fs/ocfs2/inode.c b/fs/ocfs2/inode.c index 180107a11046..eda50f13ffb5 100644 --- a/fs/ocfs2/inode.c +++ b/fs/ocfs2/inode.c @@ -1520,8 +1520,23 @@ int ocfs2_validate_inode_block(struct super_block *s= b, goto bail; } =20 - if (le16_to_cpu(di->i_suballoc_slot) !=3D (u16)OCFS2_INVALID_SLOT && - (u32)le16_to_cpu(di->i_suballoc_slot) > OCFS2_SB(sb)->max_slots - 1) { + /* + * Only system inodes created by mkfs.ocfs2 are allocated from the + * global allocator and thus legitimately carry OCFS2_INVALID_SLOT. + * Regular inodes are always allocated from a per-slot suballocator. + * If a regular inode with OCFS2_INVALID_SLOT was accepted here, + * deleting it would pass the slot to get_local_system_inode() via + * ocfs2_remove_inode() and trigger BUG_ON(slot =3D=3D OCFS2_INVALID_SLOT= ). + */ + if (le16_to_cpu(di->i_suballoc_slot) =3D=3D (u16)OCFS2_INVALID_SLOT) { + if (!(le32_to_cpu(di->i_flags) & OCFS2_SYSTEM_FL)) { + rc =3D ocfs2_error(sb, + "Invalid dinode %llu: suballoc slot %u for non-system inode\n", + (unsigned long long)bh->b_blocknr, + le16_to_cpu(di->i_suballoc_slot)); + goto bail; + } + } else if ((u32)le16_to_cpu(di->i_suballoc_slot) > OCFS2_SB(sb)->max_slot= s - 1) { rc =3D ocfs2_error(sb, "Invalid dinode %llu: suballoc slot %u\n", (unsigned long long)bh->b_blocknr, le16_to_cpu(di->i_suballoc_slot)); --=20 2.39.3 From nobody Sat Sep 26 19:34:28 2026 Received: from out30-100.freemail.mail.aliyun.com (out30-100.freemail.mail.aliyun.com [115.124.30.100]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C6A693B3C10 for ; Mon, 31 Aug 2026 06:28:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.100 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788157737; cv=none; b=lZ1dkql5EO+qjk2FyVm/KC5ZbdRKppZW4MuQIMt6E4v8H8Nf4mE3eb2t56pSXMCyX9arm5imgsETwFR0DsaUw0WSOZVEi4HIXkifs4bnDjxl0EeE7N7fo0ok6tw8eEhtZJsfDzsMhIu11MgiRwX96ttgLtbvbep6Ks/FHQcMA4I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788157737; c=relaxed/simple; bh=Qc6//zvKyYbs/q4ZER4nHHDlM7Dqw4HoOprRDo9bSlA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=FMUN4Kw/p4TNxkt7261kS7aw5WiADixKw1XsJptwV2IkhS9doFUpp9/Ojvux8oGkrUhKScxGW7d/4a5RZ9ke8OPuqFHEz1VhMOESWVo6R/Pr8fOe9w1hIrkqAkyO4LuU95+w3z99SotAKNWaZ1j2rXT4yPRgtT9iV1NoTR5QkCk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=GX5a63F0; arc=none smtp.client-ip=115.124.30.100 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="GX5a63F0" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1788157731; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=ji+uhXnF7fLJN74nMTMZN1P6m4lN+gQDKKUil0g/KF0=; b=GX5a63F0wwUh3kfZyq4qGGe4FEcz6xMYCf4euv6e9KvZcAFtiF+0sbnfmsGDyvVOpjca684jbIS14zxpD5wsK6rbIcl3/ohktfJybcPwCQCov7Wl5OuPwdSIHMXbpnErWO8p36UeGJLHO/NRUCPpAFLtUl2bONwH/pbLF+HKCI0= X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R581e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033045098064;MF=joseph.qi@linux.alibaba.com;NM=1;PH=DS;RN=6;SR=0;TI=SMTPD_---0X9tzGpB_1788157730; Received: from localhost(mailfrom:joseph.qi@linux.alibaba.com fp:SMTPD_---0X9tzGpB_1788157730 cluster:ay36) by smtp.aliyun-inc.com; Mon, 31 Aug 2026 14:28:51 +0800 From: Joseph Qi To: Andrew Morton , Heming Zhao Cc: Mark Fasheh , Joel Becker , ocfs2-devel@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH 2/4] ocfs2: validate suballoc bit during inode read Date: Mon, 31 Aug 2026 14:28:46 +0800 Message-Id: <20260831062848.2743436-3-joseph.qi@linux.alibaba.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20260831062848.2743436-1-joseph.qi@linux.alibaba.com> References: <20260831062848.2743436-1-joseph.qi@linux.alibaba.com> 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" i_suballoc_bit of a dinode is currently not validated at all. A corrupted dinode can carry an abnormally large i_suballoc_bit, which bypasses ocfs2_validate_inode_block(). When the inode is deleted, ocfs2_remove_inode() calls ocfs2_free_dinode(), which passes the unvalidated bit to _ocfs2_free_suballoc_bits() and triggers BUG_ON((count + start_bit) > ocfs2_bits_per_group(cl)). Since suballocator block group bitmaps are contained in a single block, a valid suballoc bit must be smaller than the number of bits per block. Reject oversized i_suballoc_bit values during dinode validation. Signed-off-by: Joseph Qi Reviewed-by: Heming Zhao --- fs/ocfs2/inode.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/fs/ocfs2/inode.c b/fs/ocfs2/inode.c index eda50f13ffb5..a982c99a9678 100644 --- a/fs/ocfs2/inode.c +++ b/fs/ocfs2/inode.c @@ -1543,6 +1543,20 @@ int ocfs2_validate_inode_block(struct super_block *s= b, goto bail; } =20 + /* + * A suballocator block group bitmap is contained in a single block, + * so a valid suballoc bit can never exceed the number of bits per + * block. Otherwise deleting the inode will pass the oversized bit + * to _ocfs2_free_suballoc_bits() via ocfs2_free_dinode() and trigger + * BUG_ON((count + start_bit) > ocfs2_bits_per_group(cl)). + */ + if (le16_to_cpu(di->i_suballoc_bit) >=3D sb->s_blocksize * 8) { + rc =3D ocfs2_error(sb, "Invalid dinode %llu: suballoc bit %u\n", + (unsigned long long)bh->b_blocknr, + le16_to_cpu(di->i_suballoc_bit)); + goto bail; + } + if ((le32_to_cpu(di->i_flags) & OCFS2_ORPHANED_FL) && le16_to_cpu(di->i_orphaned_slot) >=3D OCFS2_SB(sb)->max_slots) { rc =3D ocfs2_error(sb, "Invalid dinode %llu: orphaned slot %u\n", --=20 2.39.3 From nobody Sat Sep 26 19:34:28 2026 Received: from out30-118.freemail.mail.aliyun.com (out30-118.freemail.mail.aliyun.com [115.124.30.118]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7CACD3AC0D9 for ; Mon, 31 Aug 2026 06:34:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.118 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788158050; cv=none; b=HT9g4Nq4piUovu8LZZnhPLz2f9TZCSyRS4gY6j2BF2QrKy9uvSx5q7al5LHAFzZcA7Y0jZ9+ii2/iQuEHMHOXZKy0ndxERM/4cAaA6PP3Z6cBvqrj8p5Jm5mTjhxGXCdv9LOW7U95jYT/iUW4zNBCJbVuG0bNieFGwY2qSFhrxo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788158050; c=relaxed/simple; bh=eGEpIjWJqdf8UYbb2QkQk0bxAPkQ7us4f4toxIOYLMQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=MbXi/4Vnlsx04L9g2cWOiiKSJvRdWKZZ+aMdupNkTNcCeX3Djcf2C1hEqWm2d0vCx6raa74Uorl/YQIeDaticc3y4PGyqE+7mFKHN+BNifMcGsZkj4j2sXpDnpVkSOZDsvlf7oQGGfCgeQn+AIPUikiDmkSIjQMs9+BZLdkk/1E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=FpTlJB3h; arc=none smtp.client-ip=115.124.30.118 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="FpTlJB3h" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1788158044; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=EIZTiLjzMsj8zvXrmlEKp70ozCBmN/0RJICpv67UVnE=; b=FpTlJB3hUBqD6bYwIwwDWXuQ0hx48NXuSeHfx60GrEq5qLp7K/oGGCXeyHqe/EeqGfRWUywuSrv69DfFNnQB6zH8axsVzeLySa4+MCr9MNT7kuj+U7cevtv6hVKJpxuLZsa8XW2syeMwSxaL3taxZQ9lVp4xF7glktN6pV0QOLM= X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R171e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033032089153;MF=joseph.qi@linux.alibaba.com;NM=1;PH=DS;RN=6;SR=0;TI=SMTPD_---0X9tzGpc_1788157731; Received: from localhost(mailfrom:joseph.qi@linux.alibaba.com fp:SMTPD_---0X9tzGpc_1788157731 cluster:ay36) by smtp.aliyun-inc.com; Mon, 31 Aug 2026 14:28:52 +0800 From: Joseph Qi To: Andrew Morton , Heming Zhao Cc: Mark Fasheh , Joel Becker , ocfs2-devel@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH 3/4] ocfs2: validate suballoc slot of xattr and dir index blocks Date: Mon, 31 Aug 2026 14:28:47 +0800 Message-Id: <20260831062848.2743436-4-joseph.qi@linux.alibaba.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20260831062848.2743436-1-joseph.qi@linux.alibaba.com> References: <20260831062848.2743436-1-joseph.qi@linux.alibaba.com> 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" ocfs2_validate_xattr_block() and ocfs2_validate_dx_root() do not validate xb_suballoc_slot and dr_suballoc_slot against the mounted filesystem's slot range. Since xattr blocks and dir index root blocks are allocated from a per-slot suballocator at runtime, their suballoc slots must be within range. Otherwise a corrupted image can carry an out-of-range slot. When the xattr block or dir index is removed, ocfs2_xattr_block_remove() or ocfs2_dx_dir_remove_index() passes the unvalidated slot to ocfs2_get_system_file_inode() and get_local_system_inode() will either hit BUG_ON(slot =3D=3D OCFS2_INVALID_SLOT) or compute an out-of-bounds index into the local_system_inodes array. Reject out-of-range suballoc slots during validation. Signed-off-by: Joseph Qi Reviewed-by: Heming Zhao --- fs/ocfs2/dir.c | 14 ++++++++++++++ fs/ocfs2/xattr.c | 13 +++++++++++++ 2 files changed, 27 insertions(+) diff --git a/fs/ocfs2/dir.c b/fs/ocfs2/dir.c index 0075e1624310..eb9850610ba3 100644 --- a/fs/ocfs2/dir.c +++ b/fs/ocfs2/dir.c @@ -605,6 +605,20 @@ static int ocfs2_validate_dx_root(struct super_block *= sb, goto bail; } =20 + /* + * Dir index root blocks are allocated from a per-slot suballocator, + * so the slot must be in range. Otherwise removing the index passes + * it to get_local_system_inode(), which hits BUG_ON() for + * OCFS2_INVALID_SLOT or computes an out-of-bounds index otherwise. + */ + if ((u32)le16_to_cpu(dx_root->dr_suballoc_slot) >=3D OCFS2_SB(sb)->max_sl= ots) { + ret =3D ocfs2_error(sb, + "Dir Index Root # %llu has invalid dr_suballoc_slot %u\n", + (unsigned long long)le64_to_cpu(dx_root->dr_blkno), + le16_to_cpu(dx_root->dr_suballoc_slot)); + goto bail; + } + if (!(dx_root->dr_flags & OCFS2_DX_FLAG_INLINE)) { struct ocfs2_extent_list *el =3D &dx_root->dr_list; =20 diff --git a/fs/ocfs2/xattr.c b/fs/ocfs2/xattr.c index 0062cbeb1e8b..5acc8091d06f 100644 --- a/fs/ocfs2/xattr.c +++ b/fs/ocfs2/xattr.c @@ -517,6 +517,19 @@ static int ocfs2_validate_xattr_block(struct super_blo= ck *sb, le32_to_cpu(xb->xb_fs_generation)); } =20 + /* + * Xattr blocks are allocated from a per-slot suballocator, so the + * slot must be in range. Otherwise freeing the block passes it to + * get_local_system_inode(), which hits BUG_ON() for + * OCFS2_INVALID_SLOT or computes an out-of-bounds index otherwise. + */ + if ((u32)le16_to_cpu(xb->xb_suballoc_slot) >=3D OCFS2_SB(sb)->max_slots) { + return ocfs2_error(sb, + "Extended attribute block #%llu has an invalid xb_suballoc_slot of = %u\n", + (unsigned long long)bh->b_blocknr, + le16_to_cpu(xb->xb_suballoc_slot)); + } + if (!(le16_to_cpu(xb->xb_flags) & OCFS2_XATTR_INDEXED)) { size_t region_offset =3D offsetof(struct ocfs2_xattr_block, xb_attrs.xb_header); --=20 2.39.3 From nobody Sat Sep 26 19:34:28 2026 Received: from out30-119.freemail.mail.aliyun.com (out30-119.freemail.mail.aliyun.com [115.124.30.119]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 84FCA3B47C4 for ; Mon, 31 Aug 2026 06:28:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.119 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788157738; cv=none; b=kiBLrGM9NIvnSXbz1oPtEjn+KUAlK2bZcZb6QEQnYg2fZIF+ajO2UY0Qk03Nfw31JdQDGFYfKvDxPG8NyNAGinDUCsmPeAbCW1fbPb6KBsDYwM54Z+zvr4ijanOcpOM7niB7JNjnFwcgNE0saWZVfB6J7ylpUOEV8Wa67u3mh6I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788157738; c=relaxed/simple; bh=sz1qtavqVpjumr11ifp5nSRRLPo5NpbwtYYTBvJ5pJU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=BzvwH5vAG+2yAoMLJStwHO5+AIUlscXsj7MDsOZoNoH3vKZG6q1Xzum2m1sKNJTHC2TpvNdhIZYCQ6wZuVIqBNb5SFI4wXeg8urz3laXa/YwfgDTotEDnjfwvufHudoNX3CxjiXVy+qRdwCmTZTTmmpB6CFe7Usv7CfpWRbM0tQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=cjCKn6kM; arc=none smtp.client-ip=115.124.30.119 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="cjCKn6kM" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1788157733; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=+3WI6Z3MQlNOMD6y8+KdeslGPCDGj3g1sR9InW0B9K8=; b=cjCKn6kM2WJVi1MxQN4GzZSbtqzUHukpOVZsMXDDxEGjAgEPI+u5GRskIXBSVlpc28GdNNUb3Qil/k/D3JF5DA6/2pf5CQpRRcyr4rxtQIw41biJ8J1np4h2LHYC7mk34EWcPX04ndHw1gWzndbzV/FhK17kU64v4Xek89Qa5Xw= X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R111e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033037033178;MF=joseph.qi@linux.alibaba.com;NM=1;PH=DS;RN=6;SR=0;TI=SMTPD_---0X9tzGq5_1788157732; Received: from localhost(mailfrom:joseph.qi@linux.alibaba.com fp:SMTPD_---0X9tzGq5_1788157732 cluster:ay36) by smtp.aliyun-inc.com; Mon, 31 Aug 2026 14:28:53 +0800 From: Joseph Qi To: Andrew Morton , Heming Zhao Cc: Mark Fasheh , Joel Becker , ocfs2-devel@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH 4/4] ocfs2: validate suballoc slot of extent blocks Date: Mon, 31 Aug 2026 14:28:48 +0800 Message-Id: <20260831062848.2743436-5-joseph.qi@linux.alibaba.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20260831062848.2743436-1-joseph.qi@linux.alibaba.com> References: <20260831062848.2743436-1-joseph.qi@linux.alibaba.com> 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" ocfs2_validate_extent_block() does not validate h_suballoc_slot against the mounted filesystem's slot range. Since extent blocks are allocated from a per-slot suballocator at runtime, their suballoc slot must be within range. Otherwise a corrupted image can carry an out-of-range slot. When the extent block is freed, ocfs2_cache_extent_block_free() caches it and ocfs2_free_cached_blocks() later passes the unvalidated slot to ocfs2_get_system_file_inode(), so get_local_system_inode() will either hit BUG_ON(slot =3D=3D OCFS2_INVALID_SLOT) or compute an out-of-bounds index into the local_system_inodes array. Reject out-of-range suballoc slots during validation. Signed-off-by: Joseph Qi Reviewed-by: Heming Zhao --- fs/ocfs2/alloc.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/fs/ocfs2/alloc.c b/fs/ocfs2/alloc.c index be09e766ac1f..2abd242a438f 100644 --- a/fs/ocfs2/alloc.c +++ b/fs/ocfs2/alloc.c @@ -925,6 +925,20 @@ static int ocfs2_validate_extent_block(struct super_bl= ock *sb, goto bail; } =20 + /* + * Extent blocks are allocated from a per-slot suballocator, so the + * slot must be in range. Otherwise freeing the block passes it to + * get_local_system_inode(), which hits BUG_ON() for + * OCFS2_INVALID_SLOT or computes an out-of-bounds index otherwise. + */ + if ((u32)le16_to_cpu(eb->h_suballoc_slot) >=3D OCFS2_SB(sb)->max_slots) { + rc =3D ocfs2_error(sb, + "Extent block #%llu has an invalid h_suballoc_slot of %u\n", + (unsigned long long)bh->b_blocknr, + le16_to_cpu(eb->h_suballoc_slot)); + goto bail; + } + if (le16_to_cpu(eb->h_list.l_count) !=3D ocfs2_extent_recs_per_eb(sb)) { rc =3D ocfs2_error(sb, "Extent block #%llu has invalid l_count %u (expected %u)\n", --=20 2.39.3