Skip to content

Commit 1c86a18

Browse files
Muchun Songakpm00
authored andcommitted
mm: kfence: fix using kfence_metadata without initialization in show_object()
The variable kfence_metadata is initialized in kfence_init_pool(), then, it is not initialized if kfence is disabled after booting. In this case, kfence_metadata will be used (e.g. ->lock and ->state fields) without initialization when reading /sys/kernel/debug/kfence/objects. There will be a warning if you enable CONFIG_DEBUG_SPINLOCK. Fix it by creating debugfs files when necessary. Link: https://lkml.kernel.org/r/[email protected] Fixes: 0ce20dd ("mm: add Kernel Electric-Fence infrastructure") Signed-off-by: Muchun Song <[email protected]> Tested-by: Marco Elver <[email protected]> Reviewed-by: Marco Elver <[email protected]> Cc: Alexander Potapenko <[email protected]> Cc: Dmitry Vyukov <[email protected]> Cc: Jann Horn <[email protected]> Cc: SeongJae Park <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 13684e9 commit 1c86a18

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

mm/kfence/core.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -726,10 +726,14 @@ static const struct seq_operations objects_sops = {
726726
};
727727
DEFINE_SEQ_ATTRIBUTE(objects);
728728

729-
static int __init kfence_debugfs_init(void)
729+
static int kfence_debugfs_init(void)
730730
{
731-
struct dentry *kfence_dir = debugfs_create_dir("kfence", NULL);
731+
struct dentry *kfence_dir;
732732

733+
if (!READ_ONCE(kfence_enabled))
734+
return 0;
735+
736+
kfence_dir = debugfs_create_dir("kfence", NULL);
733737
debugfs_create_file("stats", 0444, kfence_dir, NULL, &stats_fops);
734738
debugfs_create_file("objects", 0400, kfence_dir, NULL, &objects_fops);
735739
return 0;
@@ -883,6 +887,8 @@ static int kfence_init_late(void)
883887
}
884888

885889
kfence_init_enable();
890+
kfence_debugfs_init();
891+
886892
return 0;
887893
}
888894

0 commit comments

Comments
 (0)