Commit a19d48f7 authored by Jiasheng Jiang's avatar Jiasheng Jiang Committed by Kees Cook
Browse files

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: 563ca40d ("pstore/platform: Switch pstore_info::name to const")
Signed-off-by: default avatarJiasheng Jiang <jiasheng@iscas.ac.cn>
Link: https://lore.kernel.org/r/20230623022706.32125-1-jiasheng@iscas.ac.cn


Signed-off-by: default avatarKees Cook <keescook@chromium.org>
parent 5ee1a430
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -464,6 +464,8 @@ static int pstore_write_user_compat(struct pstore_record *record,
 */
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);