summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJiasheng Jiang <jiasheng@iscas.ac.cn>2023-06-14 12:37:33 +0300
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2023-07-19 17:21:03 +0300
commitf57ba91a46d3fc52bfdac9cca5cf5572ec7afd6d (patch)
treeca4e624888cfa1b7e6ad36fc3948c1f09539ee32
parent2672144b86a162f274320ae0e48bdf6f67497978 (diff)
downloadlinux-f57ba91a46d3fc52bfdac9cca5cf5572ec7afd6d.tar.xz
pstore/ram: Add check for kstrdup
[ Upstream commit d97038d5ec2062733c1e016caf9baaf68cf64ea1 ] 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 <jiasheng@iscas.ac.cn> Signed-off-by: Kees Cook <keescook@chromium.org> Link: https://lore.kernel.org/r/20230614093733.36048-1-jiasheng@iscas.ac.cn Signed-off-by: Sasha Levin <sashal@kernel.org>
-rw-r--r--fs/pstore/ram_core.c2
1 files changed, 2 insertions, 0 deletions
diff --git a/fs/pstore/ram_core.c b/fs/pstore/ram_core.c
index 8bf09886e7e6..2384de1c2d18 100644
--- a/fs/pstore/ram_core.c
+++ b/fs/pstore/ram_core.c
@@ -591,6 +591,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)