Skip to content

Commit b06e931

Browse files
maninder42mcgrof
authored andcommitted
kallsyms: move kallsyms_show_value() out of kallsyms.c
function kallsyms_show_value() is used by other parts like modules_open(), kprobes_read() etc. which can work in case of !KALLSYMS also. e.g. as of now lsmod do not show module address if KALLSYMS is disabled. since kallsyms_show_value() defination is not present, it returns false in !KALLSYMS. / # lsmod test 12288 0 - Live 0x0000000000000000 (O) So kallsyms_show_value() can be made generic without dependency on KALLSYMS. Thus moving out function to a new file ksyms_common.c. With this patch code is just moved to new file and no functional change. Co-developed-by: Onkarnath <[email protected]> Signed-off-by: Onkarnath <[email protected]> Signed-off-by: Maninder Singh <[email protected]> Reviewed-by: Zhen Lei <[email protected]> Signed-off-by: Luis Chamberlain <[email protected]>
1 parent 4f521ba commit b06e931

File tree

3 files changed

+46
-36
lines changed

3 files changed

+46
-36
lines changed

kernel/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ obj-y = fork.o exec_domain.o panic.o \
1010
extable.o params.o \
1111
kthread.o sys_ni.o nsproxy.o \
1212
notifier.o ksysfs.o cred.o reboot.o \
13-
async.o range.o smpboot.o ucount.o regset.o
13+
async.o range.o smpboot.o ucount.o regset.o ksyms_common.o
1414

1515
obj-$(CONFIG_USERMODE_DRIVER) += usermode_driver.o
1616
obj-$(CONFIG_MULTIUSER) += groups.o

kernel/kallsyms.c

-35
Original file line numberDiff line numberDiff line change
@@ -907,41 +907,6 @@ late_initcall(bpf_ksym_iter_register);
907907

908908
#endif /* CONFIG_BPF_SYSCALL */
909909

910-
static inline int kallsyms_for_perf(void)
911-
{
912-
#ifdef CONFIG_PERF_EVENTS
913-
extern int sysctl_perf_event_paranoid;
914-
if (sysctl_perf_event_paranoid <= 1)
915-
return 1;
916-
#endif
917-
return 0;
918-
}
919-
920-
/*
921-
* We show kallsyms information even to normal users if we've enabled
922-
* kernel profiling and are explicitly not paranoid (so kptr_restrict
923-
* is clear, and sysctl_perf_event_paranoid isn't set).
924-
*
925-
* Otherwise, require CAP_SYSLOG (assuming kptr_restrict isn't set to
926-
* block even that).
927-
*/
928-
bool kallsyms_show_value(const struct cred *cred)
929-
{
930-
switch (kptr_restrict) {
931-
case 0:
932-
if (kallsyms_for_perf())
933-
return true;
934-
fallthrough;
935-
case 1:
936-
if (security_capable(cred, &init_user_ns, CAP_SYSLOG,
937-
CAP_OPT_NOAUDIT) == 0)
938-
return true;
939-
fallthrough;
940-
default:
941-
return false;
942-
}
943-
}
944-
945910
static int kallsyms_open(struct inode *inode, struct file *file)
946911
{
947912
/*

kernel/ksyms_common.c

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// SPDX-License-Identifier: GPL-2.0-only
2+
/*
3+
* ksyms_common.c: A split of kernel/kallsyms.c
4+
* Contains a few generic function definations independent of config KALLSYMS.
5+
*/
6+
#include <linux/kallsyms.h>
7+
#include <linux/security.h>
8+
9+
#ifdef CONFIG_KALLSYMS
10+
static inline int kallsyms_for_perf(void)
11+
{
12+
#ifdef CONFIG_PERF_EVENTS
13+
extern int sysctl_perf_event_paranoid;
14+
15+
if (sysctl_perf_event_paranoid <= 1)
16+
return 1;
17+
#endif
18+
return 0;
19+
}
20+
21+
/*
22+
* We show kallsyms information even to normal users if we've enabled
23+
* kernel profiling and are explicitly not paranoid (so kptr_restrict
24+
* is clear, and sysctl_perf_event_paranoid isn't set).
25+
*
26+
* Otherwise, require CAP_SYSLOG (assuming kptr_restrict isn't set to
27+
* block even that).
28+
*/
29+
bool kallsyms_show_value(const struct cred *cred)
30+
{
31+
switch (kptr_restrict) {
32+
case 0:
33+
if (kallsyms_for_perf())
34+
return true;
35+
fallthrough;
36+
case 1:
37+
if (security_capable(cred, &init_user_ns, CAP_SYSLOG,
38+
CAP_OPT_NOAUDIT) == 0)
39+
return true;
40+
fallthrough;
41+
default:
42+
return false;
43+
}
44+
}
45+
#endif

0 commit comments

Comments
 (0)