From: Kees Cook
stable inclusion
from stable-5.10
category: feature
commit:563ca40ddf400dbf8c6254077f9b6887101d0f08
issue: #I4919J
--------------------------------
In order to more cleanly pass around backend names, make the "name" member
const. This means the module param needs to be dynamic (technically, it
was before, so this actually cleans up a minor memory leak if a backend
was specified and then gets unloaded.)
Link: https://lore.kernel.org/lkml/20200510202436.63222-3-keescook@chromium.org/
Signed-off-by: Kees Cook
(cherry picked from commit 563ca40ddf400dbf8c6254077f9b6887101d0f08)
Signed-off-by: roger
---
fs/pstore/platform.c | 3 ++-
include/linux/pstore.h | 2 +-
2 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/fs/pstore/platform.c b/fs/pstore/platform.c
index 78058359b18e..53d59cedef3d 100644
--- a/fs/pstore/platform.c
+++ b/fs/pstore/platform.c
@@ -652,7 +652,7 @@ int pstore_register(struct pstore_info *psi)
* Update the module parameter backend, so it is visible
* through /sys/module/pstore/parameters/backend
*/
- backend = psi->name;
+ backend = kstrdup(psi->name, GFP_KERNEL);
pr_info("Registered %s as persistent store backend\n", psi->name);
@@ -681,6 +681,7 @@ void pstore_unregister(struct pstore_info *psi)
free_buf_for_compression();
psinfo = NULL;
+ kfree(backend);
backend = NULL;
}
EXPORT_SYMBOL_GPL(pstore_unregister);
diff --git a/include/linux/pstore.h b/include/linux/pstore.h
index c39f8c873df9..a2755fdd260d 100644
--- a/include/linux/pstore.h
+++ b/include/linux/pstore.h
@@ -188,7 +188,7 @@ struct pstore_record {
*/
struct pstore_info {
struct module *owner;
- char *name;
+ const char *name;
struct semaphore buf_lock;
char *buf;
--
2.17.1