* [PATCH v3] btrfs: Add chunk type check in read a chunk
@ 2018-07-04 10:16 Gu Jinxiang
2018-07-04 12:42 ` Nikolay Borisov
2018-07-05 14:17 ` David Sterba
0 siblings, 2 replies; 4+ messages in thread
From: Gu Jinxiang @ 2018-07-04 10:16 UTC (permalink / raw)
To: linux-btrfs; +Cc: nborisov, quwenruo.btrfs
Reported in https://bugzilla.kernel.org/show_bug.cgi?id=199839,
which has a invalid chunk, not return error opportunlly.
Add chunk type check in btrfs_check_chunk_valid,
to make error be returned in advance.
Reported-by: Xu Wen <wen.xu@gatech.edu>
Signed-off-by: Gu Jinxiang <gujx@cn.fujitsu.com>
Reviewed-by: Qu Wenruo <wqu@suse.com>
---
changelog:
v3:
deal with comment by Nikolay Borisov, change the error message
more appropriate.
v2:
deal with comment by Qu, add precise check for chunk type.
fs/btrfs/volumes.c | 29 +++++++++++++++++++++++++++++
1 file changed, 29 insertions(+)
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index b33bf29130b6..deea169cc276 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -6401,6 +6401,8 @@ static int btrfs_check_chunk_valid(struct btrfs_fs_info *fs_info,
u16 num_stripes;
u16 sub_stripes;
u64 type;
+ u64 features;
+ int mixed = 0;
length = btrfs_chunk_length(leaf, chunk);
stripe_len = btrfs_chunk_stripe_len(leaf, chunk);
@@ -6439,6 +6441,33 @@ static int btrfs_check_chunk_valid(struct btrfs_fs_info *fs_info,
btrfs_chunk_type(leaf, chunk));
return -EIO;
}
+
+ if (!(type & BTRFS_BLOCK_GROUP_TYPE_MASK)) {
+ btrfs_err(fs_info, "missing chunk type flag: %llu", type);
+ return -EIO;
+ }
+
+ if ((type & BTRFS_BLOCK_GROUP_SYSTEM) &&
+ (type & (BTRFS_BLOCK_GROUP_METADATA | BTRFS_BLOCK_GROUP_DATA))) {
+ btrfs_err(fs_info,
+"system chunk type, meanwhile with metadata or data chunk type flag: %llu",
+ type);
+ return -EIO;
+ }
+
+ features = btrfs_super_incompat_flags(fs_info->super_copy);
+ if (features & BTRFS_FEATURE_INCOMPAT_MIXED_GROUPS)
+ mixed = 1;
+
+ if (!mixed) {
+ if (type &
+ (BTRFS_BLOCK_GROUP_METADATA & BTRFS_BLOCK_GROUP_DATA)) {
+ btrfs_err(fs_info,
+ "mixed chunk type flag in non-mixed mode: %llu", type);
+ return -EIO;
+ }
+ }
+
if ((type & BTRFS_BLOCK_GROUP_RAID10 && sub_stripes != 2) ||
(type & BTRFS_BLOCK_GROUP_RAID1 && num_stripes < 1) ||
(type & BTRFS_BLOCK_GROUP_RAID5 && num_stripes < 2) ||
--
2.17.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v3] btrfs: Add chunk type check in read a chunk
2018-07-04 10:16 [PATCH v3] btrfs: Add chunk type check in read a chunk Gu Jinxiang
@ 2018-07-04 12:42 ` Nikolay Borisov
2018-07-05 14:17 ` David Sterba
2018-07-05 14:17 ` David Sterba
1 sibling, 1 reply; 4+ messages in thread
From: Nikolay Borisov @ 2018-07-04 12:42 UTC (permalink / raw)
To: Gu Jinxiang, linux-btrfs; +Cc: quwenruo.btrfs
On 4.07.2018 13:16, Gu Jinxiang wrote:
> Reported in https://bugzilla.kernel.org/show_bug.cgi?id=199839,
> which has a invalid chunk, not return error opportunlly.
>
> Add chunk type check in btrfs_check_chunk_valid,
> to make error be returned in advance.
>
> Reported-by: Xu Wen <wen.xu@gatech.edu>
> Signed-off-by: Gu Jinxiang <gujx@cn.fujitsu.com>
> Reviewed-by: Qu Wenruo <wqu@suse.com>
> ---
> changelog:
> v3:
> deal with comment by Nikolay Borisov, change the error message
> more appropriate.
>
> v2:
> deal with comment by Qu, add precise check for chunk type.
>
> fs/btrfs/volumes.c | 29 +++++++++++++++++++++++++++++
> 1 file changed, 29 insertions(+)
>
> diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
> index b33bf29130b6..deea169cc276 100644
> --- a/fs/btrfs/volumes.c
> +++ b/fs/btrfs/volumes.c
> @@ -6401,6 +6401,8 @@ static int btrfs_check_chunk_valid(struct btrfs_fs_info *fs_info,
> u16 num_stripes;
> u16 sub_stripes;
> u64 type;
> + u64 features;
> + int mixed = 0;
>
> length = btrfs_chunk_length(leaf, chunk);
> stripe_len = btrfs_chunk_stripe_len(leaf, chunk);
> @@ -6439,6 +6441,33 @@ static int btrfs_check_chunk_valid(struct btrfs_fs_info *fs_info,
> btrfs_chunk_type(leaf, chunk));
> return -EIO;
> }
> +
> + if (!(type & BTRFS_BLOCK_GROUP_TYPE_MASK)) {
> + btrfs_err(fs_info, "missing chunk type flag: %llu", type);
> + return -EIO;
> + }
> +
> + if ((type & BTRFS_BLOCK_GROUP_SYSTEM) &&
> + (type & (BTRFS_BLOCK_GROUP_METADATA | BTRFS_BLOCK_GROUP_DATA))) {
> + btrfs_err(fs_info,
> +"system chunk type, meanwhile with metadata or data chunk type flag: %llu",
> + type);
That's rather cumbersomely worded, why not simply "Invalid chunk type
detected"
> + return -EIO;
> + }
> +
> + features = btrfs_super_incompat_flags(fs_info->super_copy);
> + if (features & BTRFS_FEATURE_INCOMPAT_MIXED_GROUPS)
> + mixed = 1;
> +
> + if (!mixed) {
> + if (type &
> + (BTRFS_BLOCK_GROUP_METADATA & BTRFS_BLOCK_GROUP_DATA)) {
> + btrfs_err(fs_info,
> + "mixed chunk type flag in non-mixed mode: %llu", type);
> + return -EIO;
> + }
> + }
> +
> if ((type & BTRFS_BLOCK_GROUP_RAID10 && sub_stripes != 2) ||
> (type & BTRFS_BLOCK_GROUP_RAID1 && num_stripes < 1) ||
> (type & BTRFS_BLOCK_GROUP_RAID5 && num_stripes < 2) ||
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v3] btrfs: Add chunk type check in read a chunk
2018-07-04 12:42 ` Nikolay Borisov
@ 2018-07-05 14:17 ` David Sterba
0 siblings, 0 replies; 4+ messages in thread
From: David Sterba @ 2018-07-05 14:17 UTC (permalink / raw)
To: Nikolay Borisov; +Cc: Gu Jinxiang, linux-btrfs, quwenruo.btrfs
On Wed, Jul 04, 2018 at 03:42:30PM +0300, Nikolay Borisov wrote:
> On 4.07.2018 13:16, Gu Jinxiang wrote:
> > Reported in https://bugzilla.kernel.org/show_bug.cgi?id=199839,
> > which has a invalid chunk, not return error opportunlly.
> >
> > Add chunk type check in btrfs_check_chunk_valid,
> > to make error be returned in advance.
> >
> > Reported-by: Xu Wen <wen.xu@gatech.edu>
> > Signed-off-by: Gu Jinxiang <gujx@cn.fujitsu.com>
> > Reviewed-by: Qu Wenruo <wqu@suse.com>
> > ---
> > changelog:
> > v3:
> > deal with comment by Nikolay Borisov, change the error message
> > more appropriate.
> >
> > v2:
> > deal with comment by Qu, add precise check for chunk type.
> >
> > fs/btrfs/volumes.c | 29 +++++++++++++++++++++++++++++
> > 1 file changed, 29 insertions(+)
> >
> > diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
> > index b33bf29130b6..deea169cc276 100644
> > --- a/fs/btrfs/volumes.c
> > +++ b/fs/btrfs/volumes.c
> > @@ -6401,6 +6401,8 @@ static int btrfs_check_chunk_valid(struct btrfs_fs_info *fs_info,
> > u16 num_stripes;
> > u16 sub_stripes;
> > u64 type;
> > + u64 features;
> > + int mixed = 0;
> >
> > length = btrfs_chunk_length(leaf, chunk);
> > stripe_len = btrfs_chunk_stripe_len(leaf, chunk);
> > @@ -6439,6 +6441,33 @@ static int btrfs_check_chunk_valid(struct btrfs_fs_info *fs_info,
> > btrfs_chunk_type(leaf, chunk));
> > return -EIO;
> > }
> > +
> > + if (!(type & BTRFS_BLOCK_GROUP_TYPE_MASK)) {
> > + btrfs_err(fs_info, "missing chunk type flag: %llu", type);
> > + return -EIO;
> > + }
> > +
> > + if ((type & BTRFS_BLOCK_GROUP_SYSTEM) &&
> > + (type & (BTRFS_BLOCK_GROUP_METADATA | BTRFS_BLOCK_GROUP_DATA))) {
> > + btrfs_err(fs_info,
> > +"system chunk type, meanwhile with metadata or data chunk type flag: %llu",
> > + type);
>
> That's rather cumbersomely worded, why not simply "Invalid chunk type
> detected"
Updated.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v3] btrfs: Add chunk type check in read a chunk
2018-07-04 10:16 [PATCH v3] btrfs: Add chunk type check in read a chunk Gu Jinxiang
2018-07-04 12:42 ` Nikolay Borisov
@ 2018-07-05 14:17 ` David Sterba
1 sibling, 0 replies; 4+ messages in thread
From: David Sterba @ 2018-07-05 14:17 UTC (permalink / raw)
To: Gu Jinxiang; +Cc: linux-btrfs, nborisov, quwenruo.btrfs
On Wed, Jul 04, 2018 at 06:16:39PM +0800, Gu Jinxiang wrote:
> Reported in https://bugzilla.kernel.org/show_bug.cgi?id=199839,
> which has a invalid chunk, not return error opportunlly.
>
> Add chunk type check in btrfs_check_chunk_valid,
> to make error be returned in advance.
>
> Reported-by: Xu Wen <wen.xu@gatech.edu>
> Signed-off-by: Gu Jinxiang <gujx@cn.fujitsu.com>
> Reviewed-by: Qu Wenruo <wqu@suse.com>
> ---
> changelog:
> v3:
> deal with comment by Nikolay Borisov, change the error message
> more appropriate.
>
> v2:
> deal with comment by Qu, add precise check for chunk type.
Added to misc-next with some updates, thanks.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2018-07-05 14:17 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-07-04 10:16 [PATCH v3] btrfs: Add chunk type check in read a chunk Gu Jinxiang
2018-07-04 12:42 ` Nikolay Borisov
2018-07-05 14:17 ` David Sterba
2018-07-05 14:17 ` David Sterba
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).