]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
dm era: fix NULL pointer dereference in metadata_open()
authorCao Guanghui <caoguanghui@kylinos.cn>
Wed, 17 Jun 2026 06:00:52 +0000 (14:00 +0800)
committerMikulas Patocka <mpatocka@redhat.com>
Wed, 8 Jul 2026 20:33:35 +0000 (22:33 +0200)
metadata_open() returns NULL when kzalloc_obj() fails, but the
caller era_ctr() only checks IS_ERR(md).  Since IS_ERR(NULL)
returns false, the NULL pointer is treated as a valid result
and later assigned to era->md, leading to a NULL pointer
dereference when the metadata is accessed.

Fix this by returning ERR_PTR(-ENOMEM) on allocation failure,
consistent with dm-cache-metadata.c, dm-thin-metadata.c, and
dm-clone-metadata.c which all use ERR_PTR(-ENOMEM) for the
same pattern.

Fixes: eec40579d848 ("dm: add era target")
Signed-off-by: Cao Guanghui <caoguanghui@kylinos.cn>
Reviewed-by: Su Yue <glass.su@suse.com>
Reviewed-by: Ming-Hung Tsai <mtsai@redhat.com>
Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
drivers/md/dm-era-target.c

index 18aed0e2a508e0e1db45caff146b115d09257aa9..cef2881948043492e7b3c1e0c4b7d00fa98c6cee 100644 (file)
@@ -810,8 +810,10 @@ static struct era_metadata *metadata_open(struct block_device *bdev,
        int r;
        struct era_metadata *md = kzalloc_obj(*md);
 
-       if (!md)
-               return NULL;
+       if (!md) {
+               DMERR("could not allocate metadata struct");
+               return ERR_PTR(-ENOMEM);
+       }
 
        md->bdev = bdev;
        md->block_size = block_size;