Skip to content

Commit 93d53f1

Browse files
Pei XiaoKent Overstreet
authored andcommitted
bcachefs: add check NULL return of bio_kmalloc in journal_read_bucket
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: ac10a96 ("bcachefs: Some fixes for building in userspace") Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
1 parent ef4f6c3 commit 93d53f1

File tree

2 files changed

+3
-0
lines changed

2 files changed

+3
-0
lines changed

fs/bcachefs/errcode.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
8484
x(ENOMEM, ENOMEM_dev_alloc) \
8585
x(ENOMEM, ENOMEM_disk_accounting) \
8686
x(ENOMEM, ENOMEM_stripe_head_alloc) \
87+
x(ENOMEM, ENOMEM_journal_read_bucket) \
8788
x(ENOSPC, ENOSPC_disk_reservation) \
8889
x(ENOSPC, ENOSPC_bucket_alloc) \
8990
x(ENOSPC, ENOSPC_disk_label_add) \

fs/bcachefs/journal_io.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,6 +1012,8 @@ static int journal_read_bucket(struct bch_dev *ca,
10121012
nr_bvecs = buf_pages(buf->data, sectors_read << 9);
10131013

10141014
bio = bio_kmalloc(nr_bvecs, GFP_KERNEL);
1015+
if (!bio)
1016+
return -BCH_ERR_ENOMEM_journal_read_bucket;
10151017
bio_init(bio, ca->disk_sb.bdev, bio->bi_inline_vecs, nr_bvecs, REQ_OP_READ);
10161018

10171019
bio->bi_iter.bi_sector = offset;

0 commit comments

Comments
 (0)