* Re: [PATCH v3] bcachefs: fix shift oob in alloc_lru_idx_fragmentation
2024-10-22 2:26 ` Hongbo Li
@ 2024-10-22 2:38 ` Alan Huang
2024-10-22 3:05 ` Hongbo Li
2024-10-22 4:05 ` Jeongjun Park
2024-10-24 11:30 ` Kent Overstreet
2 siblings, 1 reply; 9+ messages in thread
From: Alan Huang @ 2024-10-22 2:38 UTC (permalink / raw)
To: Hongbo Li
Cc: Jeongjun Park, Kent Overstreet, linux-bcachefs, LKML,
syzbot+7f45fa9805c40db3f108
On Oct 22, 2024, at 10:26, Hongbo Li <lihongbo22@huawei.com> wrote:
>
>
>
> On 2024/10/21 23:43, Jeongjun Park wrote:
>> The size of a.data_type is set abnormally large, causing shift-out-of-bounds.
>> To fix this, we need to add validation on a.data_type in
>> alloc_lru_idx_fragmentation().
>> Reported-by: syzbot+7f45fa9805c40db3f108@syzkaller.appspotmail.com
>> Fixes: 260af1562ec1 ("bcachefs: Kill alloc_v4.fragmentation_lru")
>> Signed-off-by: Jeongjun Park <aha310510@gmail.com>
>> ---
>> fs/bcachefs/alloc_background.h | 3 +++
>> 1 file changed, 3 insertions(+)
>> diff --git a/fs/bcachefs/alloc_background.h b/fs/bcachefs/alloc_background.h
>> index f8e87c6721b1..163a67b97a40 100644
>> --- a/fs/bcachefs/alloc_background.h
>> +++ b/fs/bcachefs/alloc_background.h
>> @@ -168,6 +168,9 @@ static inline bool data_type_movable(enum bch_data_type type)
>> static inline u64 alloc_lru_idx_fragmentation(struct bch_alloc_v4 a,
>> struct bch_dev *ca)
>> {
>> + if (a.data_type >= BCH_DATA_NR)
>> + return 0;
>> +
>
> oh, I found I have done the same thing in [1]("Re: [syzbot] [bcachefs?] UBSAN: shift-out-of-bounds in bch2_alloc_to_text"). But
Your patch there is still triggering the issue.
> in my humble opinion, the validation changes also should be added. And in addition, move the condition about a.data_type into
There is already the validation:
bkey_fsck_err_on(alloc_data_type(a, a.data_type) != a.data_type
And the unknown data type is already printed in bch2_prt_data_type, additional validation doesn’t help much.
> data_type_movable will be better. Just my personal opinion.:)
In my personal opinion, I don’t think so :)
>
> [1] https://www.spinics.net/lists/kernel/msg5412619.html
>
> Thanks,
> Hongbo
>
>> if (!data_type_movable(a.data_type) ||
>> !bch2_bucket_sectors_fragmented(ca, a))
>> return 0;
>> --
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: [PATCH v3] bcachefs: fix shift oob in alloc_lru_idx_fragmentation
2024-10-22 2:38 ` Alan Huang
@ 2024-10-22 3:05 ` Hongbo Li
2024-10-22 3:23 ` Alan Huang
0 siblings, 1 reply; 9+ messages in thread
From: Hongbo Li @ 2024-10-22 3:05 UTC (permalink / raw)
To: Alan Huang
Cc: Jeongjun Park, Kent Overstreet, linux-bcachefs, LKML,
syzbot+7f45fa9805c40db3f108
On 2024/10/22 10:38, Alan Huang wrote:
> On Oct 22, 2024, at 10:26, Hongbo Li <lihongbo22@huawei.com> wrote:
>>
>>
>>
>> On 2024/10/21 23:43, Jeongjun Park wrote:
>>> The size of a.data_type is set abnormally large, causing shift-out-of-bounds.
>>> To fix this, we need to add validation on a.data_type in
>>> alloc_lru_idx_fragmentation().
>>> Reported-by: syzbot+7f45fa9805c40db3f108@syzkaller.appspotmail.com
>>> Fixes: 260af1562ec1 ("bcachefs: Kill alloc_v4.fragmentation_lru")
>>> Signed-off-by: Jeongjun Park <aha310510@gmail.com>
>>> ---
>>> fs/bcachefs/alloc_background.h | 3 +++
>>> 1 file changed, 3 insertions(+)
>>> diff --git a/fs/bcachefs/alloc_background.h b/fs/bcachefs/alloc_background.h
>>> index f8e87c6721b1..163a67b97a40 100644
>>> --- a/fs/bcachefs/alloc_background.h
>>> +++ b/fs/bcachefs/alloc_background.h
>>> @@ -168,6 +168,9 @@ static inline bool data_type_movable(enum bch_data_type type)
>>> static inline u64 alloc_lru_idx_fragmentation(struct bch_alloc_v4 a,
>>> struct bch_dev *ca)
>>> {
>>> + if (a.data_type >= BCH_DATA_NR)
>>> + return 0;
>>> +
>>
>> oh, I found I have done the same thing in [1]("Re: [syzbot] [bcachefs?] UBSAN: shift-out-of-bounds in bch2_alloc_to_text"). But
>
> Your patch there is still triggering the issue.
Yeah, it just notify the issue and not prevent the issue. So I found it
should add a.data_type condition indeed. :)
>
>> in my humble opinion, the validation changes also should be added. And in addition, move the condition about a.data_type into
>
> There is already the validation:
>
> bkey_fsck_err_on(alloc_data_type(a, a.data_type) != a.data_type
This is actually not enough. This only do some transition check. For
example, if a.data_type break when bch2_bucket_sectors_dirty (the data
corruption can lead to various situations occurring) is true, the helper
does noting.
Thanks,
Hongbo
>
> And the unknown data type is already printed in bch2_prt_data_type, additional validation doesn’t help much.
>
>> data_type_movable will be better. Just my personal opinion.:)
>
> In my personal opinion, I don’t think so :)
>
>>
>> [1] https://www.spinics.net/lists/kernel/msg5412619.html
>>
>> Thanks,
>> Hongbo
>>
>>> if (!data_type_movable(a.data_type) ||
>>> !bch2_bucket_sectors_fragmented(ca, a))
>>> return 0;
>>> --
>
>
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: [PATCH v3] bcachefs: fix shift oob in alloc_lru_idx_fragmentation
2024-10-22 3:05 ` Hongbo Li
@ 2024-10-22 3:23 ` Alan Huang
0 siblings, 0 replies; 9+ messages in thread
From: Alan Huang @ 2024-10-22 3:23 UTC (permalink / raw)
To: Hongbo Li
Cc: Jeongjun Park, Kent Overstreet, linux-bcachefs, LKML,
syzbot+7f45fa9805c40db3f108
On Oct 22, 2024, at 11:05, Hongbo Li <lihongbo22@huawei.com> wrote:
>
>
>
> On 2024/10/22 10:38, Alan Huang wrote:
>> On Oct 22, 2024, at 10:26, Hongbo Li <lihongbo22@huawei.com> wrote:
>>>
>>>
>>>
>>> On 2024/10/21 23:43, Jeongjun Park wrote:
>>>> The size of a.data_type is set abnormally large, causing shift-out-of-bounds.
>>>> To fix this, we need to add validation on a.data_type in
>>>> alloc_lru_idx_fragmentation().
>>>> Reported-by: syzbot+7f45fa9805c40db3f108@syzkaller.appspotmail.com
>>>> Fixes: 260af1562ec1 ("bcachefs: Kill alloc_v4.fragmentation_lru")
>>>> Signed-off-by: Jeongjun Park <aha310510@gmail.com>
>>>> ---
>>>> fs/bcachefs/alloc_background.h | 3 +++
>>>> 1 file changed, 3 insertions(+)
>>>> diff --git a/fs/bcachefs/alloc_background.h b/fs/bcachefs/alloc_background.h
>>>> index f8e87c6721b1..163a67b97a40 100644
>>>> --- a/fs/bcachefs/alloc_background.h
>>>> +++ b/fs/bcachefs/alloc_background.h
>>>> @@ -168,6 +168,9 @@ static inline bool data_type_movable(enum bch_data_type type)
>>>> static inline u64 alloc_lru_idx_fragmentation(struct bch_alloc_v4 a,
>>>> struct bch_dev *ca)
>>>> {
>>>> + if (a.data_type >= BCH_DATA_NR)
>>>> + return 0;
>>>> +
>>>
>>> oh, I found I have done the same thing in [1]("Re: [syzbot] [bcachefs?] UBSAN: shift-out-of-bounds in bch2_alloc_to_text"). But
>> Your patch there is still triggering the issue.
> Yeah, it just notify the issue and not prevent the issue. So I found it should add a.data_type condition indeed. :)
>>> in my humble opinion, the validation changes also should be added. And in addition, move the condition about a.data_type into
>> There is already the validation:
>> bkey_fsck_err_on(alloc_data_type(a, a.data_type) != a.data_type
>
> This is actually not enough. This only do some transition check. For example, if a.data_type break when bch2_bucket_sectors_dirty (the data corruption can lead to various situations occurring) is true, the helper does noting.
Make sense.
>
> Thanks,
> Hongbo
>
>> And the unknown data type is already printed in bch2_prt_data_type, additional validation doesn’t help much.
>>> data_type_movable will be better. Just my personal opinion.:)
>> In my personal opinion, I don’t think so :)
>>>
>>> [1] https://www.spinics.net/lists/kernel/msg5412619.html
>>>
>>> Thanks,
>>> Hongbo
>>>
>>>> if (!data_type_movable(a.data_type) ||
>>>> !bch2_bucket_sectors_fragmented(ca, a))
>>>> return 0;
>>>> --
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v3] bcachefs: fix shift oob in alloc_lru_idx_fragmentation
2024-10-22 2:26 ` Hongbo Li
2024-10-22 2:38 ` Alan Huang
@ 2024-10-22 4:05 ` Jeongjun Park
2024-10-23 1:11 ` Hongbo Li
2024-10-24 11:30 ` Kent Overstreet
2 siblings, 1 reply; 9+ messages in thread
From: Jeongjun Park @ 2024-10-22 4:05 UTC (permalink / raw)
To: Hongbo Li
Cc: kent.overstreet, mmpgouride, linux-bcachefs, linux-kernel,
syzbot+7f45fa9805c40db3f108
> Hongbo Li <lihongbo22@huawei.com> wrote:
>
>
>
>> On 2024/10/21 23:43, Jeongjun Park wrote:
>> The size of a.data_type is set abnormally large, causing shift-out-of-bounds.
>> To fix this, we need to add validation on a.data_type in
>> alloc_lru_idx_fragmentation().
>> Reported-by: syzbot+7f45fa9805c40db3f108@syzkaller.appspotmail.com
>> Fixes: 260af1562ec1 ("bcachefs: Kill alloc_v4.fragmentation_lru")
>> Signed-off-by: Jeongjun Park <aha310510@gmail.com>
>> ---
>> fs/bcachefs/alloc_background.h | 3 +++
>> 1 file changed, 3 insertions(+)
>> diff --git a/fs/bcachefs/alloc_background.h b/fs/bcachefs/alloc_background.h
>> index f8e87c6721b1..163a67b97a40 100644
>> --- a/fs/bcachefs/alloc_background.h
>> +++ b/fs/bcachefs/alloc_background.h
>> @@ -168,6 +168,9 @@ static inline bool data_type_movable(enum bch_data_type type)
>> static inline u64 alloc_lru_idx_fragmentation(struct bch_alloc_v4 a,
>> struct bch_dev *ca)
>> {
>> + if (a.data_type >= BCH_DATA_NR)
>> + return 0;
>> +
>
> oh, I found I have done the same thing in [1]("Re: [syzbot] [bcachefs?] UBSAN: shift-out-of-bounds in bch2_alloc_to_text"). But in my humble opinion, the validation changes also should be added. And in addition, move the condition about a.data_type into data_type_movable will be better. Just my personal opinion.:)
>
> [1] https://www.spinics.net/lists/kernel/msg5412619.html
I still disagree with the fix to make data_type_movable() do the validation,
but I think [1] is definitely a patch that needs to be added.
However, [1] is far from preventing the shift oob vulnerability described
in that syzbot report. Therefore, I think [1] should be written as a
standalone patch and committed, rather than as a patch for that
syzbot report.
>
> Thanks,
> Hongbo
>
>> if (!data_type_movable(a.data_type) ||
>> !bch2_bucket_sectors_fragmented(ca, a))
>> return 0;
>> --
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: [PATCH v3] bcachefs: fix shift oob in alloc_lru_idx_fragmentation
2024-10-22 4:05 ` Jeongjun Park
@ 2024-10-23 1:11 ` Hongbo Li
0 siblings, 0 replies; 9+ messages in thread
From: Hongbo Li @ 2024-10-23 1:11 UTC (permalink / raw)
To: Jeongjun Park
Cc: kent.overstreet, mmpgouride, linux-bcachefs, linux-kernel,
syzbot+7f45fa9805c40db3f108
On 2024/10/22 12:05, Jeongjun Park wrote:
>
>
>> Hongbo Li <lihongbo22@huawei.com> wrote:
>>
>>
>>
>>> On 2024/10/21 23:43, Jeongjun Park wrote:
>>> The size of a.data_type is set abnormally large, causing shift-out-of-bounds.
>>> To fix this, we need to add validation on a.data_type in
>>> alloc_lru_idx_fragmentation().
>>> Reported-by: syzbot+7f45fa9805c40db3f108@syzkaller.appspotmail.com
>>> Fixes: 260af1562ec1 ("bcachefs: Kill alloc_v4.fragmentation_lru")
>>> Signed-off-by: Jeongjun Park <aha310510@gmail.com>
>>> ---
>>> fs/bcachefs/alloc_background.h | 3 +++
>>> 1 file changed, 3 insertions(+)
>>> diff --git a/fs/bcachefs/alloc_background.h b/fs/bcachefs/alloc_background.h
>>> index f8e87c6721b1..163a67b97a40 100644
>>> --- a/fs/bcachefs/alloc_background.h
>>> +++ b/fs/bcachefs/alloc_background.h
>>> @@ -168,6 +168,9 @@ static inline bool data_type_movable(enum bch_data_type type)
>>> static inline u64 alloc_lru_idx_fragmentation(struct bch_alloc_v4 a,
>>> struct bch_dev *ca)
>>> {
>>> + if (a.data_type >= BCH_DATA_NR)
>>> + return 0;
>>> +
>>
>> oh, I found I have done the same thing in [1]("Re: [syzbot] [bcachefs?] UBSAN: shift-out-of-bounds in bch2_alloc_to_text"). But in my humble opinion, the validation changes also should be added. And in addition, move the condition about a.data_type into data_type_movable will be better. Just my personal opinion.:)
>>
>> [1] https://www.spinics.net/lists/kernel/msg5412619.html
>
> I still disagree with the fix to make data_type_movable() do the validation,
> but I think [1] is definitely a patch that needs to be added.
>
> However, [1] is far from preventing the shift oob vulnerability described
> in that syzbot report. Therefore, I think [1] should be written as a
> standalone patch and committed, rather than as a patch for that
I'm fine for this.:)
Thanks,
Hongbo
> syzbot report.
>
>>
>> Thanks,
>> Hongbo
>>
>>> if (!data_type_movable(a.data_type) ||
>>> !bch2_bucket_sectors_fragmented(ca, a))
>>> return 0;
>>> --
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v3] bcachefs: fix shift oob in alloc_lru_idx_fragmentation
2024-10-22 2:26 ` Hongbo Li
2024-10-22 2:38 ` Alan Huang
2024-10-22 4:05 ` Jeongjun Park
@ 2024-10-24 11:30 ` Kent Overstreet
2 siblings, 0 replies; 9+ messages in thread
From: Kent Overstreet @ 2024-10-24 11:30 UTC (permalink / raw)
To: Hongbo Li
Cc: Jeongjun Park, mmpgouride, linux-bcachefs, linux-kernel,
syzbot+7f45fa9805c40db3f108
On Tue, Oct 22, 2024 at 10:26:18AM +0800, Hongbo Li wrote:
>
>
> On 2024/10/21 23:43, Jeongjun Park wrote:
> > The size of a.data_type is set abnormally large, causing shift-out-of-bounds.
> > To fix this, we need to add validation on a.data_type in
> > alloc_lru_idx_fragmentation().
> >
> > Reported-by: syzbot+7f45fa9805c40db3f108@syzkaller.appspotmail.com
> > Fixes: 260af1562ec1 ("bcachefs: Kill alloc_v4.fragmentation_lru")
> > Signed-off-by: Jeongjun Park <aha310510@gmail.com>
> > ---
> > fs/bcachefs/alloc_background.h | 3 +++
> > 1 file changed, 3 insertions(+)
> >
> > diff --git a/fs/bcachefs/alloc_background.h b/fs/bcachefs/alloc_background.h
> > index f8e87c6721b1..163a67b97a40 100644
> > --- a/fs/bcachefs/alloc_background.h
> > +++ b/fs/bcachefs/alloc_background.h
> > @@ -168,6 +168,9 @@ static inline bool data_type_movable(enum bch_data_type type)
> > static inline u64 alloc_lru_idx_fragmentation(struct bch_alloc_v4 a,
> > struct bch_dev *ca)
> > {
> > + if (a.data_type >= BCH_DATA_NR)
> > + return 0;
> > +
>
> oh, I found I have done the same thing in [1]("Re: [syzbot] [bcachefs?]
> UBSAN: shift-out-of-bounds in bch2_alloc_to_text"). But in my humble
> opinion, the validation changes also should be added. And in addition, move
> the condition about a.data_type into data_type_movable will be better. Just
> my personal opinion.:)
Unknown data types (and key types, btree IDs, etc.) are allowed for
forwards compatibility - they should just be ignored
^ permalink raw reply [flat|nested] 9+ messages in thread