mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-09-29 22:02:02 +00:00
pstore/platform: Add check for kstrdup
[ Upstream commita19d48f7c5
] Add check for the return value of kstrdup() and return the error if it fails in order to avoid NULL pointer dereference. Fixes:563ca40ddf
("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> Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
parent
d15950c490
commit
1c426da79f
1 changed files with 8 additions and 1 deletions
|
@ -573,6 +573,8 @@ static int pstore_write_user_compat(struct pstore_record *record,
|
||||||
*/
|
*/
|
||||||
int pstore_register(struct pstore_info *psi)
|
int pstore_register(struct pstore_info *psi)
|
||||||
{
|
{
|
||||||
|
char *new_backend;
|
||||||
|
|
||||||
if (backend && strcmp(backend, psi->name)) {
|
if (backend && strcmp(backend, psi->name)) {
|
||||||
pr_warn("backend '%s' already in use: ignoring '%s'\n",
|
pr_warn("backend '%s' already in use: ignoring '%s'\n",
|
||||||
backend, psi->name);
|
backend, psi->name);
|
||||||
|
@ -593,11 +595,16 @@ int pstore_register(struct pstore_info *psi)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
new_backend = kstrdup(psi->name, GFP_KERNEL);
|
||||||
|
if (!new_backend)
|
||||||
|
return -ENOMEM;
|
||||||
|
|
||||||
mutex_lock(&psinfo_lock);
|
mutex_lock(&psinfo_lock);
|
||||||
if (psinfo) {
|
if (psinfo) {
|
||||||
pr_warn("backend '%s' already loaded: ignoring '%s'\n",
|
pr_warn("backend '%s' already loaded: ignoring '%s'\n",
|
||||||
psinfo->name, psi->name);
|
psinfo->name, psi->name);
|
||||||
mutex_unlock(&psinfo_lock);
|
mutex_unlock(&psinfo_lock);
|
||||||
|
kfree(new_backend);
|
||||||
return -EBUSY;
|
return -EBUSY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -630,7 +637,7 @@ int pstore_register(struct pstore_info *psi)
|
||||||
* Update the module parameter backend, so it is visible
|
* Update the module parameter backend, so it is visible
|
||||||
* through /sys/module/pstore/parameters/backend
|
* 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);
|
pr_info("Registered %s as persistent store backend\n", psi->name);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue