Skip to content

Commit

Permalink
pstore/ram: Add check for kstrdup
Browse files Browse the repository at this point in the history
Add check for the return value of kstrdup() and return the error
if it fails in order to avoid NULL pointer dereference.

Fixes: e163fdb ("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
  • Loading branch information
Jiasheng Jiang authored and Kees Cook committed Jun 14, 2023
1 parent 48f2c68 commit d97038d
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions fs/pstore/ram_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit d97038d

Please sign in to comment.