]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
bcachefs: fix shift oob in alloc_lru_idx_fragmentation
authorJeongjun Park <aha310510@gmail.com>
Mon, 21 Oct 2024 15:43:56 +0000 (00:43 +0900)
committerKent Overstreet <kent.overstreet@linux.dev>
Thu, 24 Oct 2024 21:41:43 +0000 (17:41 -0400)
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>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/alloc_background.h

index f8e87c6721b1220864132b96d283336f5ae73416..163a67b97a4094e66c4cdf20beccd4eacab42b04 100644 (file)
@@ -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;