bcachefs: Don't allocate too-big bios
authorKent Overstreet <kent.overstreet@gmail.com>
Wed, 13 Oct 2021 17:45:46 +0000 (13:45 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:09:13 +0000 (17:09 -0400)
This fixes a null ptr deref in bio_alloc_bioset() -> biovec_slab()

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
fs/bcachefs/io.c

index 002fd35e6bfea65bcf86046e77e6cd79a6db83cd..ea2adcc213d08f577a565be2ff9fb8d697b2689e 100644 (file)
@@ -782,6 +782,8 @@ static struct bio *bch2_write_bio_alloc(struct bch_fs *c,
                                       ? ((unsigned long) buf & (PAGE_SIZE - 1))
                                       : 0), PAGE_SIZE);
 
+       pages = min(pages, BIO_MAX_VECS);
+
        bio = bio_alloc_bioset(NULL, pages, 0,
                               GFP_NOIO, &c->bio_write);
        wbio                    = wbio_init(bio);