summaryrefslogtreecommitdiffstats
path: root/fs/pstore
diff options
context:
space:
mode:
authorJiasheng Jiang <jiasheng@iscas.ac.cn>2023-06-23 04:27:06 +0200
committerKees Cook <keescook@chromium.org>2023-10-12 18:47:01 +0200
commita19d48f7c5d57c0f0405a7d4334d1d38fe9d3c1c (patch)
tree7eb86705f475fdfb2f5dbb6f0f5000ad470897ec /fs/pstore
parentdocs: pstore-blk.rst: fix typo, s/console/ftrace (diff)
downloadlinux-a19d48f7c5d57c0f0405a7d4334d1d38fe9d3c1c.tar.xz
linux-a19d48f7c5d57c0f0405a7d4334d1d38fe9d3c1c.zip
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: 563ca40ddf40 ("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>
Diffstat (limited to 'fs/pstore')
-rw-r--r--fs/pstore/platform.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/fs/pstore/platform.c b/fs/pstore/platform.c
index e5bca9a004cc..03425928d2fb 100644
--- a/fs/pstore/platform.c
+++ b/fs/pstore/platform.c
@@ -464,6 +464,8 @@ out:
*/
int pstore_register(struct pstore_info *psi)
{
+ char *new_backend;
+
if (backend && strcmp(backend, psi->name)) {
pr_warn("backend '%s' already in use: ignoring '%s'\n",
backend, psi->name);
@@ -484,11 +486,16 @@ int pstore_register(struct pstore_info *psi)
return -EINVAL;
}
+ new_backend = kstrdup(psi->name, GFP_KERNEL);
+ if (!new_backend)
+ return -ENOMEM;
+
mutex_lock(&psinfo_lock);
if (psinfo) {
pr_warn("backend '%s' already loaded: ignoring '%s'\n",
psinfo->name, psi->name);
mutex_unlock(&psinfo_lock);
+ kfree(new_backend);
return -EBUSY;
}
@@ -521,7 +528,7 @@ int pstore_register(struct pstore_info *psi)
* Update the module parameter backend, so it is visible
* through /sys/module/pstore/parameters/backend
*/
- backend = kstrdup(psi->name, GFP_KERNEL);
+ backend = new_backend;
pr_info("Registered %s as persistent store backend\n", psi->name);