Skip to content

Commit a19d48f

Browse files
JiangJiaskees
authored andcommitted
pstore/platform: 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: 563ca40 ("pstore/platform: Switch pstore_info::name to const") Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn> Link: https://lore.kernel.org/r/20230623022706.32125-1-jiasheng@iscas.ac.cn Signed-off-by: Kees Cook <keescook@chromium.org>
1 parent 5ee1a43 commit a19d48f

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

fs/pstore/platform.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,8 @@ static int pstore_write_user_compat(struct pstore_record *record,
464464
*/
465465
int pstore_register(struct pstore_info *psi)
466466
{
467+
char *new_backend;
468+
467469
if (backend && strcmp(backend, psi->name)) {
468470
pr_warn("backend '%s' already in use: ignoring '%s'\n",
469471
backend, psi->name);
@@ -484,11 +486,16 @@ int pstore_register(struct pstore_info *psi)
484486
return -EINVAL;
485487
}
486488

489+
new_backend = kstrdup(psi->name, GFP_KERNEL);
490+
if (!new_backend)
491+
return -ENOMEM;
492+
487493
mutex_lock(&psinfo_lock);
488494
if (psinfo) {
489495
pr_warn("backend '%s' already loaded: ignoring '%s'\n",
490496
psinfo->name, psi->name);
491497
mutex_unlock(&psinfo_lock);
498+
kfree(new_backend);
492499
return -EBUSY;
493500
}
494501

@@ -521,7 +528,7 @@ int pstore_register(struct pstore_info *psi)
521528
* Update the module parameter backend, so it is visible
522529
* through /sys/module/pstore/parameters/backend
523530
*/
524-
backend = kstrdup(psi->name, GFP_KERNEL);
531+
backend = new_backend;
525532

526533
pr_info("Registered %s as persistent store backend\n", psi->name);
527534

0 commit comments

Comments
 (0)