History

kprobes: Do not use local variable when creating debugfs file

debugfs_create_file() takes a pointer argument that can be used during file operation callbacks (accessible via i_private in the inode structure). An obvious requirement is for the pointer to refer to valid memory when used. When creating the debugfs file to dynamically enable / disable kprobes, a pointer to local variable is passed to debugfs_create_file(); which will go out of scope when the init function returns. The reason this hasn't triggered random memory corruption is because the pointer is not accessed during the debugfs file callbacks. Since the enabled state is managed by the kprobes_all_disabled global variable, the local variable is not needed. Fix the incorrect (and unnecessary) usage of local variable during debugfs_file_create() by passing NULL instead. Link: https://lkml.kernel.org/r/163163031686.489837.4476867635937014973.stgit@devnote2

Punit Agrawal committed 5 years ago

Commit 8f7262c1 parent 5816b3e1 file · +1 −2Browse files

Unified · Split

kernel/kprobes.c+1−2
@@ -2809,13 +2809,12 @@ static const struct file_operations fops_kp = { · 2808 unmodified lines
2809static int __init debugfs_kprobe_init(void)2809static int __init debugfs_kprobe_init(void)
2810{2810{
2811 struct dentry *dir;2811 struct dentry *dir;
2812 unsigned int value = 1;
2813 2812
2814 dir = debugfs_create_dir("kprobes", NULL);2813 dir = debugfs_create_dir("kprobes", NULL);
2815 2814
2816 debugfs_create_file("list", 0400, dir, NULL, &kprobes_fops);2815 debugfs_create_file("list", 0400, dir, NULL, &kprobes_fops);
2817 2816
2818 debugfs_create_file("enabled", 0600, dir, &value, &fops_kp);2817 debugfs_create_file("enabled", 0600, dir, NULL, &fops_kp);
2819 2818
2820 debugfs_create_file("blacklist", 0400, dir, NULL,2819 debugfs_create_file("blacklist", 0400, dir, NULL,
2821 &kprobe_blacklist_fops);2820 &kprobe_blacklist_fops);