[PATCH v4 6/9] crash_dump: Improve readability of config_keys_restore_store
From: Coiby Xu
Date: Fri Aug 28 2026 - 04:53:43 EST
config_keys_restore_store currently doesn't validate the user input
before restoring dm-crypt keys. Although it's not necessary for the case
of vmcore dumping, it's better to do it for the sake of consistency and
code readability. Also check the return code of
restore_dm_crypt_keys_to_thread_keyring.
Fixes: 62f17d9df692 ("crash_dump: retrieve dm crypt keys in kdump kernel")
Reviewed-by: Sourabh Jain <sourabhjain@xxxxxxxxxxxxx>
Signed-off-by: Coiby Xu <coiby.xu@xxxxxxxxx>
---
kernel/crash_dump_dm_crypt.c | 20 ++++++++++++++++----
1 file changed, 16 insertions(+), 4 deletions(-)
diff --git a/kernel/crash_dump_dm_crypt.c b/kernel/crash_dump_dm_crypt.c
index 9ccc7b5320a3..e82693df73fb 100644
--- a/kernel/crash_dump_dm_crypt.c
+++ b/kernel/crash_dump_dm_crypt.c
@@ -371,13 +371,25 @@ static ssize_t config_keys_restore_show(struct config_item *item, char *page)
static ssize_t config_keys_restore_store(struct config_item *item,
const char *page, size_t count)
{
- if (!restore)
- restore_dm_crypt_keys_to_thread_keyring();
+ bool val;
+ int r;
- if (kstrtobool(page, &restore))
+ if (kstrtobool(page, &val))
return -EINVAL;
- return count;
+ if (val) {
+ if (restore) {
+ pr_warn("dm-crypt keys already restored!\n");
+ return count;
+ }
+ r = restore_dm_crypt_keys_to_thread_keyring();
+ if (!r) {
+ restore = true;
+ r = count;
+ }
+ }
+
+ return r;
}
CONFIGFS_ATTR(config_keys_, restore);
--
2.55.0