* [PATCH] btrfs-progs: volumes: check stripe end against device boundary
@ 2020-08-03 7:06 Qu Wenruo
2020-08-03 7:13 ` Qu Wenruo
0 siblings, 1 reply; 2+ messages in thread
From: Qu Wenruo @ 2020-08-03 7:06 UTC (permalink / raw)
To: linux-btrfs
There is a report of kernel generationg READ bio access beyond device
boundary.
To make sure it's not caused by on-disk chunk items, add extra stripe
check against device total_bytes so that btrfs check can detect such
problem early on.
Signed-off-by: Qu Wenruo <wqu@suse.com>
---
volumes.c | 29 +++++++++++++++++++++++++++++
1 file changed, 29 insertions(+)
diff --git a/volumes.c b/volumes.c
index 538f799e7211..0467dd63d5cb 100644
--- a/volumes.c
+++ b/volumes.c
@@ -1843,6 +1843,7 @@ int btrfs_check_chunk_valid(struct btrfs_fs_info *fs_info,
u64 type;
u32 chunk_ondisk_size;
u32 sectorsize = fs_info->sectorsize;
+ int i;
/*
* Basic chunk item size check. Note that btrfs_chunk already contains
@@ -1953,6 +1954,34 @@ int btrfs_check_chunk_valid(struct btrfs_fs_info *fs_info,
return -EIO;
}
+ /*
+ * Stripe check against device boundary
+ */
+ for (i = 0; i < num_stripes; i++) {
+ struct btrfs_device *dev;
+ u64 physical;
+ u64 devid;
+ u64 stripe_len;
+
+ devid = btrfs_stripe_devid_nr(leaf, chunk, i);
+ physical = btrfs_stripe_offset_nr(leaf, chunk, i);
+ stripe_len = calc_stripe_length(type, length, num_stripes);
+ dev = btrfs_find_device(fs_info, devid, NULL, NULL);
+ /*
+ * Device not found? Then we may be in the bootstrap process for
+ * system chunks. Skip.
+ */
+ if (!dev)
+ continue;
+ if (physical + stripe_len > dev->total_bytes) {
+ error(
+"chunk %llu stripe %d is beyond device boundary: devid %llu total_bytes %llu stripe start %llu len %llu",
+ logical, i, devid, dev->total_bytes, physical,
+ stripe_len);
+ return -EUCLEAN;
+ }
+ }
+
return 0;
}
--
2.28.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] btrfs-progs: volumes: check stripe end against device boundary
2020-08-03 7:06 [PATCH] btrfs-progs: volumes: check stripe end against device boundary Qu Wenruo
@ 2020-08-03 7:13 ` Qu Wenruo
0 siblings, 0 replies; 2+ messages in thread
From: Qu Wenruo @ 2020-08-03 7:13 UTC (permalink / raw)
To: linux-btrfs
On 2020/8/3 下午3:06, Qu Wenruo wrote:
> There is a report of kernel generationg READ bio access beyond device
> boundary.
>
> To make sure it's not caused by on-disk chunk items, add extra stripe
> check against device total_bytes so that btrfs check can detect such
> problem early on.
To add more info on this, kernel can already detects such problem at
mount time, by verify_one_dev_extent() on each dev extent read and
compare it against existing chunks.
Thus there is no need to enhance kernel already.
Thanks,
Qu
>
> Signed-off-by: Qu Wenruo <wqu@suse.com>
> ---
> volumes.c | 29 +++++++++++++++++++++++++++++
> 1 file changed, 29 insertions(+)
>
> diff --git a/volumes.c b/volumes.c
> index 538f799e7211..0467dd63d5cb 100644
> --- a/volumes.c
> +++ b/volumes.c
> @@ -1843,6 +1843,7 @@ int btrfs_check_chunk_valid(struct btrfs_fs_info *fs_info,
> u64 type;
> u32 chunk_ondisk_size;
> u32 sectorsize = fs_info->sectorsize;
> + int i;
>
> /*
> * Basic chunk item size check. Note that btrfs_chunk already contains
> @@ -1953,6 +1954,34 @@ int btrfs_check_chunk_valid(struct btrfs_fs_info *fs_info,
> return -EIO;
> }
>
> + /*
> + * Stripe check against device boundary
> + */
> + for (i = 0; i < num_stripes; i++) {
> + struct btrfs_device *dev;
> + u64 physical;
> + u64 devid;
> + u64 stripe_len;
> +
> + devid = btrfs_stripe_devid_nr(leaf, chunk, i);
> + physical = btrfs_stripe_offset_nr(leaf, chunk, i);
> + stripe_len = calc_stripe_length(type, length, num_stripes);
> + dev = btrfs_find_device(fs_info, devid, NULL, NULL);
> + /*
> + * Device not found? Then we may be in the bootstrap process for
> + * system chunks. Skip.
> + */
> + if (!dev)
> + continue;
> + if (physical + stripe_len > dev->total_bytes) {
> + error(
> +"chunk %llu stripe %d is beyond device boundary: devid %llu total_bytes %llu stripe start %llu len %llu",
> + logical, i, devid, dev->total_bytes, physical,
> + stripe_len);
> + return -EUCLEAN;
> + }
> + }
> +
> return 0;
> }
>
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-08-03 7:14 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-08-03 7:06 [PATCH] btrfs-progs: volumes: check stripe end against device boundary Qu Wenruo
2020-08-03 7:13 ` Qu Wenruo
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox