* [PATCH v5 1/2] kallsyms: move kallsyms_show_value() out of kallsyms.c [not found] <CGME20230608033132epcas5p22208020abf46fc8667086c31b6d7c63d@epcas5p2.samsung.com> @ 2023-06-08 3:31 ` Maninder Singh [not found] ` <CGME20230608033140epcas5p1a1a04da5a0c78f888afbf54b00519f1e@epcas5p1.samsung.com> 0 siblings, 1 reply; 3+ messages in thread From: Maninder Singh @ 2023-06-08 3:31 UTC (permalink / raw) To: ast, daniel, john.fastabend, andrii, martin.lau, song, yhs, kpsingh, sdf, haoluo, jolsa, thunder.leizhen, mcgrof, boqun.feng, vincenzopalazzodev, ojeda, jgross, brauner, michael.christie, samitolvanen, glider, peterz, keescook, stephen.s.brennan, alan.maguire, pmladek Cc: linux-kernel, bpf, Maninder Singh, Onkarnath 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 <onkarnath.1@samsung.com> Signed-off-by: Onkarnath <onkarnath.1@samsung.com> Signed-off-by: Maninder Singh <maninder1.s@samsung.com> Reviewed-by: Zhen Lei <thunder.leizhen@huawei.com> --- earlier conversations:(then it has dependancy on other change, but that was stashed from linux-next, now it can be pushed) https://lore.kernel.org/lkml/202205111525.92B1C597@keescook/T/ https://lkml.org/lkml/2022/4/13/47 v1 -> v2: separate out bpf and kallsyms change v2 -> v3: make kallsym changes in2 patches, non functional and functional change v3 -> v4: patch order changed, file name changed form knosyms -> ksyms_common and copyright header modified. v4 -> v5: license changed to kallsyms.c file, and bpf changes are dropped as confirmed from BPF side: https://lore.kernel.org/lkml/CAEf4Bzb4B9FxMnf3t81D22FWkciLOvwDPLY0BbEPGGe7R5QPrg@mail.gmail.com/T/ kernel/Makefile | 2 +- kernel/kallsyms.c | 35 --------------------------------- kernel/ksyms_common.c | 45 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 36 deletions(-) create mode 100644 kernel/ksyms_common.c diff --git a/kernel/Makefile b/kernel/Makefile index f9e3fd9195d9..3947122d618b 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -10,7 +10,7 @@ obj-y = fork.o exec_domain.o panic.o \ extable.o params.o \ kthread.o sys_ni.o nsproxy.o \ notifier.o ksysfs.o cred.o reboot.o \ - async.o range.o smpboot.o ucount.o regset.o + async.o range.o smpboot.o ucount.o regset.o ksyms_common.o obj-$(CONFIG_USERMODE_DRIVER) += usermode_driver.o obj-$(CONFIG_MULTIUSER) += groups.o diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c index 8193e947aa10..0f82c3d5a57d 100644 --- a/kernel/kallsyms.c +++ b/kernel/kallsyms.c @@ -907,41 +907,6 @@ late_initcall(bpf_ksym_iter_register); #endif /* CONFIG_BPF_SYSCALL */ -static inline int kallsyms_for_perf(void) -{ -#ifdef CONFIG_PERF_EVENTS - extern int sysctl_perf_event_paranoid; - if (sysctl_perf_event_paranoid <= 1) - return 1; -#endif - return 0; -} - -/* - * We show kallsyms information even to normal users if we've enabled - * kernel profiling and are explicitly not paranoid (so kptr_restrict - * is clear, and sysctl_perf_event_paranoid isn't set). - * - * Otherwise, require CAP_SYSLOG (assuming kptr_restrict isn't set to - * block even that). - */ -bool kallsyms_show_value(const struct cred *cred) -{ - switch (kptr_restrict) { - case 0: - if (kallsyms_for_perf()) - return true; - fallthrough; - case 1: - if (security_capable(cred, &init_user_ns, CAP_SYSLOG, - CAP_OPT_NOAUDIT) == 0) - return true; - fallthrough; - default: - return false; - } -} - static int kallsyms_open(struct inode *inode, struct file *file) { /* diff --git a/kernel/ksyms_common.c b/kernel/ksyms_common.c new file mode 100644 index 000000000000..3840fa1c9c86 --- /dev/null +++ b/kernel/ksyms_common.c @@ -0,0 +1,45 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * ksyms_common.c: A split of kernel/kallsyms.c + * Contains a few generic function definations independent of config KALLSYMS. + */ +#include <linux/kallsyms.h> +#include <linux/security.h> + +#ifdef CONFIG_KALLSYMS +static inline int kallsyms_for_perf(void) +{ +#ifdef CONFIG_PERF_EVENTS + extern int sysctl_perf_event_paranoid; + + if (sysctl_perf_event_paranoid <= 1) + return 1; +#endif + return 0; +} + +/* + * We show kallsyms information even to normal users if we've enabled + * kernel profiling and are explicitly not paranoid (so kptr_restrict + * is clear, and sysctl_perf_event_paranoid isn't set). + * + * Otherwise, require CAP_SYSLOG (assuming kptr_restrict isn't set to + * block even that). + */ +bool kallsyms_show_value(const struct cred *cred) +{ + switch (kptr_restrict) { + case 0: + if (kallsyms_for_perf()) + return true; + fallthrough; + case 1: + if (security_capable(cred, &init_user_ns, CAP_SYSLOG, + CAP_OPT_NOAUDIT) == 0) + return true; + fallthrough; + default: + return false; + } +} +#endif -- 2.17.1 ^ permalink raw reply related [flat|nested] 3+ messages in thread
[parent not found: <CGME20230608033140epcas5p1a1a04da5a0c78f888afbf54b00519f1e@epcas5p1.samsung.com>]
* [PATCH v5 2/2] kallsyms: make kallsyms_show_value() as generic function [not found] ` <CGME20230608033140epcas5p1a1a04da5a0c78f888afbf54b00519f1e@epcas5p1.samsung.com> @ 2023-06-08 3:31 ` Maninder Singh 2023-06-08 19:28 ` Luis Chamberlain 0 siblings, 1 reply; 3+ messages in thread From: Maninder Singh @ 2023-06-08 3:31 UTC (permalink / raw) To: ast, daniel, john.fastabend, andrii, martin.lau, song, yhs, kpsingh, sdf, haoluo, jolsa, thunder.leizhen, mcgrof, boqun.feng, vincenzopalazzodev, ojeda, jgross, brauner, michael.christie, samitolvanen, glider, peterz, keescook, stephen.s.brennan, alan.maguire, pmladek Cc: linux-kernel, bpf, Maninder Singh, Onkarnath This change makes function kallsyms_show_value() as generic function without dependency on CONFIG_KALLSYMS. Now module address will be displayed with lsmod and /proc/modules. Earlier: ======= / # insmod test.ko / # lsmod test 12288 0 - Live 0x0000000000000000 (O) // No Module Load address / # With change: ========== / # insmod test.ko / # lsmod test 12288 0 - Live 0xffff800000fc0000 (O) // Module address / # cat /proc/modules test 12288 0 - Live 0xffff800000fc0000 (O) Co-developed-by: Onkarnath <onkarnath.1@samsung.com> Signed-off-by: Onkarnath <onkarnath.1@samsung.com> Signed-off-by: Maninder Singh <maninder1.s@samsung.com> Reviewed-by: Zhen Lei <thunder.leizhen@huawei.com> --- include/linux/kallsyms.h | 11 +++-------- kernel/ksyms_common.c | 2 -- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h index 1037f4957caa..c3f075e8f60c 100644 --- a/include/linux/kallsyms.h +++ b/include/linux/kallsyms.h @@ -65,6 +65,9 @@ static inline void *dereference_symbol_descriptor(void *ptr) return ptr; } +/* How and when do we show kallsyms values? */ +extern bool kallsyms_show_value(const struct cred *cred); + #ifdef CONFIG_KALLSYMS unsigned long kallsyms_sym_address(int idx); int kallsyms_on_each_symbol(int (*fn)(void *, const char *, unsigned long), @@ -94,9 +97,6 @@ extern int sprint_backtrace_build_id(char *buffer, unsigned long address); int lookup_symbol_name(unsigned long addr, char *symname); -/* How and when do we show kallsyms values? */ -extern bool kallsyms_show_value(const struct cred *cred); - #else /* !CONFIG_KALLSYMS */ static inline unsigned long kallsyms_lookup_name(const char *name) @@ -154,11 +154,6 @@ static inline int lookup_symbol_name(unsigned long addr, char *symname) return -ERANGE; } -static inline bool kallsyms_show_value(const struct cred *cred) -{ - return false; -} - static inline int kallsyms_on_each_symbol(int (*fn)(void *, const char *, unsigned long), void *data) { diff --git a/kernel/ksyms_common.c b/kernel/ksyms_common.c index 3840fa1c9c86..cf1a73cbf2f6 100644 --- a/kernel/ksyms_common.c +++ b/kernel/ksyms_common.c @@ -6,7 +6,6 @@ #include <linux/kallsyms.h> #include <linux/security.h> -#ifdef CONFIG_KALLSYMS static inline int kallsyms_for_perf(void) { #ifdef CONFIG_PERF_EVENTS @@ -42,4 +41,3 @@ bool kallsyms_show_value(const struct cred *cred) return false; } } -#endif -- 2.17.1 ^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v5 2/2] kallsyms: make kallsyms_show_value() as generic function 2023-06-08 3:31 ` [PATCH v5 2/2] kallsyms: make kallsyms_show_value() as generic function Maninder Singh @ 2023-06-08 19:28 ` Luis Chamberlain 0 siblings, 0 replies; 3+ messages in thread From: Luis Chamberlain @ 2023-06-08 19:28 UTC (permalink / raw) To: Maninder Singh Cc: ast, daniel, john.fastabend, andrii, martin.lau, song, yhs, kpsingh, sdf, haoluo, jolsa, thunder.leizhen, boqun.feng, vincenzopalazzodev, ojeda, jgross, brauner, michael.christie, samitolvanen, glider, peterz, keescook, stephen.s.brennan, alan.maguire, pmladek, linux-kernel, bpf, Onkarnath On Thu, Jun 08, 2023 at 09:01:19AM +0530, Maninder Singh wrote: > This change makes function kallsyms_show_value() as > generic function without dependency on CONFIG_KALLSYMS. > > Now module address will be displayed with lsmod and /proc/modules. > > Earlier: > ======= > / # insmod test.ko > / # lsmod > test 12288 0 - Live 0x0000000000000000 (O) // No Module Load address > / # > > With change: > ========== > / # insmod test.ko > / # lsmod > test 12288 0 - Live 0xffff800000fc0000 (O) // Module address > / # cat /proc/modules > test 12288 0 - Live 0xffff800000fc0000 (O) > > Co-developed-by: Onkarnath <onkarnath.1@samsung.com> > Signed-off-by: Onkarnath <onkarnath.1@samsung.com> > Signed-off-by: Maninder Singh <maninder1.s@samsung.com> > Reviewed-by: Zhen Lei <thunder.leizhen@huawei.com> Thanks! Pushed to modules-next. Luis ^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-06-08 19:28 UTC | newest] Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- [not found] <CGME20230608033132epcas5p22208020abf46fc8667086c31b6d7c63d@epcas5p2.samsung.com> 2023-06-08 3:31 ` [PATCH v5 1/2] kallsyms: move kallsyms_show_value() out of kallsyms.c Maninder Singh [not found] ` <CGME20230608033140epcas5p1a1a04da5a0c78f888afbf54b00519f1e@epcas5p1.samsung.com> 2023-06-08 3:31 ` [PATCH v5 2/2] kallsyms: make kallsyms_show_value() as generic function Maninder Singh 2023-06-08 19:28 ` Luis Chamberlain
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).