Commit ca959e32 authored by Gaosheng Cui's avatar Gaosheng Cui Committed by Kent Overstreet
Browse files

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: 035d72f7 ("bcachefs: bch2_ec_stripe_head_get() now checks for change in rw devices")
Signed-off-by: default avatarGaosheng Cui <cuigaosheng1@huawei.com>
Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent 778ac324
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -1870,6 +1870,10 @@ __bch2_ec_stripe_head_get(struct btree_trans *trans,
		}

	h = ec_new_stripe_head_alloc(c, disk_label, algo, redundancy, watermark);
	if (!h) {
		h = ERR_PTR(-BCH_ERR_ENOMEM_stripe_head_alloc);
		goto err;
	}
found:
	if (h->rw_devs_change_count != c->rw_devs_change_count)
		ec_stripe_head_devs_update(c, h);
+1 −0
Original line number Diff line number Diff line
@@ -83,6 +83,7 @@
	x(ENOMEM,			ENOMEM_fs_other_alloc)			\
	x(ENOMEM,			ENOMEM_dev_alloc)			\
	x(ENOMEM,			ENOMEM_disk_accounting)			\
	x(ENOMEM,			ENOMEM_stripe_head_alloc)		\
	x(ENOSPC,			ENOSPC_disk_reservation)		\
	x(ENOSPC,			ENOSPC_bucket_alloc)			\
	x(ENOSPC,			ENOSPC_disk_label_add)			\