]> www.infradead.org Git - users/hch/configfs.git/commitdiff
bcachefs: add check NULL return of bio_kmalloc in journal_read_bucket
authorPei Xiao <xiaopei01@kylinos.cn>
Wed, 30 Oct 2024 07:48:01 +0000 (15:48 +0800)
committerKent Overstreet <kent.overstreet@linux.dev>
Thu, 7 Nov 2024 21:48:21 +0000 (16:48 -0500)
bio_kmalloc may return NULL, will cause NULL pointer dereference.
Add check NULL return for bio_kmalloc in journal_read_bucket.

Signed-off-by: Pei Xiao <xiaopei01@kylinos.cn>
Fixes: ac10a9611d87 ("bcachefs: Some fixes for building in userspace")
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/errcode.h
fs/bcachefs/journal_io.c

index a1bc6c7a8ba0e9c687a1a34cfed6f76637bc55b9..9c4fe5cdbfb77d1d9c4135ef0cf0bb3d05f4501d 100644 (file)
@@ -84,6 +84,7 @@
        x(ENOMEM,                       ENOMEM_dev_alloc)                       \
        x(ENOMEM,                       ENOMEM_disk_accounting)                 \
        x(ENOMEM,                       ENOMEM_stripe_head_alloc)               \
+       x(ENOMEM,                       ENOMEM_journal_read_bucket)             \
        x(ENOSPC,                       ENOSPC_disk_reservation)                \
        x(ENOSPC,                       ENOSPC_bucket_alloc)                    \
        x(ENOSPC,                       ENOSPC_disk_label_add)                  \
index 954f6a96e0f4d857ebd12134e80ebe725da30df0..ccaafa90f4f4aebabac245b4f0ae2361ccb85a8d 100644 (file)
@@ -1012,6 +1012,8 @@ reread:
                        nr_bvecs = buf_pages(buf->data, sectors_read << 9);
 
                        bio = bio_kmalloc(nr_bvecs, GFP_KERNEL);
+                       if (!bio)
+                               return -BCH_ERR_ENOMEM_journal_read_bucket;
                        bio_init(bio, ca->disk_sb.bdev, bio->bi_inline_vecs, nr_bvecs, REQ_OP_READ);
 
                        bio->bi_iter.bi_sector = offset;