public inbox for linux-btrfs@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] btrfs: cleanups to the sys chunk array checks
@ 2026-02-03 15:39 fdmanana
  2026-02-03 15:39 ` [PATCH 1/2] btrfs: remove duplicate system chunk array max size overflow check fdmanana
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: fdmanana @ 2026-02-03 15:39 UTC (permalink / raw)
  To: linux-btrfs

From: Filipe Manana <fdmanana@suse.com>

Details in the changelogs.

Filipe Manana (2):
  btrfs: remove duplicate system chunk array max size overflow check
  btrfs: move min sys chunk array size check to validate_sys_chunk_array()

 fs/btrfs/disk-io.c | 28 +++++++++-------------------
 1 file changed, 9 insertions(+), 19 deletions(-)

-- 
2.47.2


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/2] btrfs: remove duplicate system chunk array max size overflow check
  2026-02-03 15:39 [PATCH 0/2] btrfs: cleanups to the sys chunk array checks fdmanana
@ 2026-02-03 15:39 ` fdmanana
  2026-02-03 15:39 ` [PATCH 2/2] btrfs: move min sys chunk array size check to validate_sys_chunk_array() fdmanana
  2026-02-03 21:03 ` [PATCH 0/2] btrfs: cleanups to the sys chunk array checks Qu Wenruo
  2 siblings, 0 replies; 4+ messages in thread
From: fdmanana @ 2026-02-03 15:39 UTC (permalink / raw)
  To: linux-btrfs

From: Filipe Manana <fdmanana@suse.com>

We check it twice, once in validate_sys_chunk_array() and then again in
its caller, btrfs_validate_super(), right after it calls
validate_sys_chunk_array(). So remove the duplicated check from
btrfs_validate_super().

Signed-off-by: Filipe Manana <fdmanana@suse.com>
---
 fs/btrfs/disk-io.c | 6 ------
 1 file changed, 6 deletions(-)

diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 20c405a4789d..540ec255b7a4 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -2534,12 +2534,6 @@ int btrfs_validate_super(const struct btrfs_fs_info *fs_info,
 	 * Obvious sys_chunk_array corruptions, it must hold at least one key
 	 * and one chunk
 	 */
-	if (btrfs_super_sys_array_size(sb) > BTRFS_SYSTEM_CHUNK_ARRAY_SIZE) {
-		btrfs_err(fs_info, "system chunk array too big %u > %u",
-			  btrfs_super_sys_array_size(sb),
-			  BTRFS_SYSTEM_CHUNK_ARRAY_SIZE);
-		ret = -EINVAL;
-	}
 	if (btrfs_super_sys_array_size(sb) < sizeof(struct btrfs_disk_key)
 			+ sizeof(struct btrfs_chunk)) {
 		btrfs_err(fs_info, "system chunk array too small %u < %zu",
-- 
2.47.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] btrfs: move min sys chunk array size check to validate_sys_chunk_array()
  2026-02-03 15:39 [PATCH 0/2] btrfs: cleanups to the sys chunk array checks fdmanana
  2026-02-03 15:39 ` [PATCH 1/2] btrfs: remove duplicate system chunk array max size overflow check fdmanana
@ 2026-02-03 15:39 ` fdmanana
  2026-02-03 21:03 ` [PATCH 0/2] btrfs: cleanups to the sys chunk array checks Qu Wenruo
  2 siblings, 0 replies; 4+ messages in thread
From: fdmanana @ 2026-02-03 15:39 UTC (permalink / raw)
  To: linux-btrfs

From: Filipe Manana <fdmanana@suse.com>

We check the minimum size of the sys chunk array in btrfs_validate_super()
but we have a better place for that, the helper validate_sys_chunk_array()
which we use for every other sys chunk array check. So move it there, also
converting the return error from -EINVAL to -EUCLEAN, which is a better
fit and also consistent with the other checks.

Signed-off-by: Filipe Manana <fdmanana@suse.com>
---
 fs/btrfs/disk-io.c | 22 +++++++++-------------
 1 file changed, 9 insertions(+), 13 deletions(-)

diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 540ec255b7a4..069f8017d425 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -2288,6 +2288,15 @@ static int validate_sys_chunk_array(const struct btrfs_fs_info *fs_info,
 		return -EUCLEAN;
 	}
 
+	/* It must hold at least one key and one chunk. */
+	if (unlikely(sys_array_size < sizeof(struct btrfs_disk_key) +
+		     sizeof(struct btrfs_chunk))) {
+		btrfs_err(fs_info, "system chunk array too small %u < %zu",
+			  sys_array_size,
+			  sizeof(struct btrfs_disk_key) + sizeof(struct btrfs_chunk));
+		return -EUCLEAN;
+	}
+
 	while (cur < sys_array_size) {
 		struct btrfs_disk_key *disk_key;
 		struct btrfs_chunk *chunk;
@@ -2530,19 +2539,6 @@ int btrfs_validate_super(const struct btrfs_fs_info *fs_info,
 
 	ret = validate_sys_chunk_array(fs_info, sb);
 
-	/*
-	 * Obvious sys_chunk_array corruptions, it must hold at least one key
-	 * and one chunk
-	 */
-	if (btrfs_super_sys_array_size(sb) < sizeof(struct btrfs_disk_key)
-			+ sizeof(struct btrfs_chunk)) {
-		btrfs_err(fs_info, "system chunk array too small %u < %zu",
-			  btrfs_super_sys_array_size(sb),
-			  sizeof(struct btrfs_disk_key)
-			  + sizeof(struct btrfs_chunk));
-		ret = -EINVAL;
-	}
-
 	/*
 	 * The generation is a global counter, we'll trust it more than the others
 	 * but it's still possible that it's the one that's wrong.
-- 
2.47.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 0/2] btrfs: cleanups to the sys chunk array checks
  2026-02-03 15:39 [PATCH 0/2] btrfs: cleanups to the sys chunk array checks fdmanana
  2026-02-03 15:39 ` [PATCH 1/2] btrfs: remove duplicate system chunk array max size overflow check fdmanana
  2026-02-03 15:39 ` [PATCH 2/2] btrfs: move min sys chunk array size check to validate_sys_chunk_array() fdmanana
@ 2026-02-03 21:03 ` Qu Wenruo
  2 siblings, 0 replies; 4+ messages in thread
From: Qu Wenruo @ 2026-02-03 21:03 UTC (permalink / raw)
  To: fdmanana, linux-btrfs



在 2026/2/4 02:09, fdmanana@kernel.org 写道:
> From: Filipe Manana <fdmanana@suse.com>
> 
> Details in the changelogs.

Reviewed-by: Qu Wenruo <wqu@suse.com>

Thanks,
Qu


> 
> Filipe Manana (2):
>    btrfs: remove duplicate system chunk array max size overflow check
>    btrfs: move min sys chunk array size check to validate_sys_chunk_array()
> 
>   fs/btrfs/disk-io.c | 28 +++++++++-------------------
>   1 file changed, 9 insertions(+), 19 deletions(-)
> 


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-02-03 21:03 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-03 15:39 [PATCH 0/2] btrfs: cleanups to the sys chunk array checks fdmanana
2026-02-03 15:39 ` [PATCH 1/2] btrfs: remove duplicate system chunk array max size overflow check fdmanana
2026-02-03 15:39 ` [PATCH 2/2] btrfs: move min sys chunk array size check to validate_sys_chunk_array() fdmanana
2026-02-03 21:03 ` [PATCH 0/2] btrfs: cleanups to the sys chunk array checks Qu Wenruo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox