[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <62a857230cd1bf17105fb7d3858b3c22098573d3.1730274320.git.xiaopei01@kylinos.cn>
Date: Wed, 30 Oct 2024 15:48:01 +0800
From: Pei Xiao <xiaopei01@...inos.cn>
To: kent.overstreet@...ux.dev,
linux-bcachefs@...r.kernel.org,
linux-kernel@...r.kernel.org
Cc: xiaopeitux@...mail.com,
Pei Xiao <xiaopei01@...inos.cn>
Subject: [PATCH] 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@...inos.cn>
Fixes: ac10a9611d87 ("bcachefs: Some fixes for building in userspace")
---
fs/bcachefs/errcode.h | 1 +
fs/bcachefs/journal_io.c | 2 ++
2 files changed, 3 insertions(+)
diff --git a/fs/bcachefs/errcode.h b/fs/bcachefs/errcode.h
index f2736e830007..ae75cb0a842c 100644
--- a/fs/bcachefs/errcode.h
+++ b/fs/bcachefs/errcode.h
@@ -83,6 +83,7 @@
x(ENOMEM, ENOMEM_fs_other_alloc) \
x(ENOMEM, ENOMEM_dev_alloc) \
x(ENOMEM, ENOMEM_disk_accounting) \
+ x(ENOMEM, ENOMEM_journal_read_bucket) \
x(ENOSPC, ENOSPC_disk_reservation) \
x(ENOSPC, ENOSPC_bucket_alloc) \
x(ENOSPC, ENOSPC_disk_label_add) \
diff --git a/fs/bcachefs/journal_io.c b/fs/bcachefs/journal_io.c
index fcb68f111079..667a2bb9e20b 100644
--- a/fs/bcachefs/journal_io.c
+++ b/fs/bcachefs/journal_io.c
@@ -1014,6 +1014,8 @@ static int journal_read_bucket(struct bch_dev *ca,
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;
--
2.34.1
Powered by blists - more mailing lists