pstore/ram: Add check for kstrdup

[ Upstream commit d97038d5ec ]

Add check for the return value of kstrdup() and return the error
if it fails in order to avoid NULL pointer dereference.

Fixes: e163fdb3f7 ("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>
This commit is contained in:
Jiasheng Jiang 2023-06-14 17:37:33 +08:00 committed by Greg Kroah-Hartman
parent d1225affc6
commit 2a764a2fac
1 changed files with 2 additions and 0 deletions

View File

@ -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)