Skip to content

Commit ca959e3

Browse files
gscuiKent Overstreet
authored andcommitted
bcachefs: fix possible null-ptr-deref in __bch2_ec_stripe_head_get()
The function ec_new_stripe_head_alloc() returns nullptr if kzalloc() fails. It is crucial to verify its return value before dereferencing it to avoid a potential nullptr dereference. Fixes: 035d72f ("bcachefs: bch2_ec_stripe_head_get() now checks for change in rw devices") Signed-off-by: Gaosheng Cui <[email protected]> Signed-off-by: Kent Overstreet <[email protected]>
1 parent 778ac32 commit ca959e3

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

fs/bcachefs/ec.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1870,6 +1870,10 @@ __bch2_ec_stripe_head_get(struct btree_trans *trans,
18701870
}
18711871

18721872
h = ec_new_stripe_head_alloc(c, disk_label, algo, redundancy, watermark);
1873+
if (!h) {
1874+
h = ERR_PTR(-BCH_ERR_ENOMEM_stripe_head_alloc);
1875+
goto err;
1876+
}
18731877
found:
18741878
if (h->rw_devs_change_count != c->rw_devs_change_count)
18751879
ec_stripe_head_devs_update(c, h);

fs/bcachefs/errcode.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
x(ENOMEM, ENOMEM_fs_other_alloc) \
8484
x(ENOMEM, ENOMEM_dev_alloc) \
8585
x(ENOMEM, ENOMEM_disk_accounting) \
86+
x(ENOMEM, ENOMEM_stripe_head_alloc) \
8687
x(ENOSPC, ENOSPC_disk_reservation) \
8788
x(ENOSPC, ENOSPC_bucket_alloc) \
8889
x(ENOSPC, ENOSPC_disk_label_add) \

0 commit comments

Comments
 (0)