From: Jiasheng Jiang Date: Wed, 14 Jun 2023 09:37:33 +0000 (+0800) Subject: pstore/ram: Add check for kstrdup X-Git-Tag: v6.6.17~4571^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d97038d5ec2062733c1e016caf9baaf68cf64ea1;p=platform%2Fkernel%2Flinux-rpi.git pstore/ram: Add check for kstrdup Add check for the return value of kstrdup() and return the error if it fails in order to avoid NULL pointer dereference. Fixes: e163fdb3f7f8 ("pstore/ram: Regularize prz label allocation lifetime") Signed-off-by: Jiasheng Jiang Signed-off-by: Kees Cook Link: https://lore.kernel.org/r/20230614093733.36048-1-jiasheng@iscas.ac.cn --- diff --git a/fs/pstore/ram_core.c b/fs/pstore/ram_core.c index 966191d..85aaf0fc 100644 --- a/fs/pstore/ram_core.c +++ b/fs/pstore/ram_core.c @@ -599,6 +599,8 @@ struct persistent_ram_zone *persistent_ram_new(phys_addr_t start, size_t size, raw_spin_lock_init(&prz->buffer_lock); prz->flags = flags; prz->label = kstrdup(label, GFP_KERNEL); + if (!prz->label) + goto err; ret = persistent_ram_buffer_map(start, size, prz, memtype); if (ret)