bcachefs: fix shift oob in alloc_lru_idx_fragmentation
PATCH v2 1/1 bcachefs: fix shift oob in alloc_lru_idx_fragmentation
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().
--- fs/bcachefs/alloc_background.h | 3 +++ 1 file changed, 3 insertions(+)
fs/bcachefs/alloc_background.h +3 -0
@@ -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 ; +if (!data_type_movable (a.data_type) || !bch2_bucket_sectors_fragmented (ca, a))return 0 ;
--
Quoted 17 lines · Jeongjun Park
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 [email protected]Fixes 260af1562ec1 ("bcachefs: Kill alloc_v4.fragmentation_lru")Signed-off-by Jeongjun Park <[email protected]>---
fs/bcachefs/alloc_background.h| 3 +++1 file changed, 3 insertions(+)fs/bcachefs/alloc_background.h +0
-0
fs/bcachefs/alloc_background.h static inline bool data_type_movable(enum bch_data_type type) · line 171
Quoted 4 lines
fs/bcachefs/alloc_background.h +1
-0@@ -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 )
This should be >= ?
Quoted 6 lines
fs/bcachefs/alloc_background.h +2
-0+return 0 ; +if (!data_type_movable(a.data_type) ||
!bch2_bucket_sectors_fragmented(ca, a))
return 0;
--
Quoted 14 lines · Alan Huang
Quoted 12 lines · Jeongjun Park
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 [email protected]Fixes 260af1562ec1 ("bcachefs: Kill alloc_v4.fragmentation_lru")Signed-off-by Jeongjun Park <[email protected]>---
fs/bcachefs/alloc_background.h| 3 +++1 file changed, 3 insertions(+)
Quoted 11 lines
fs/bcachefs/alloc_background.h static inline bool data_type_movable(enum bch_data_type type) · line 171
Quoted 9 lines
fs/bcachefs/alloc_background.h +1
-0@@ -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 )This should be >= ?
Oh, that's right. I checked it myself and it's the maximum value + 1, so I think I should use >=.
Thanks for letting me know!
Regards,
Jeongjun Park
Quoted 8 lines
Quoted 7 lines
fs/bcachefs/alloc_background.h +2
-0+return 0 ; +if (!data_type_movable(a.data_type) ||
!bch2_bucket_sectors_fragmented(ca, a))
return 0;
--