All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] /proc/modules: honor kptr_restrict even without CONFIG_KALLSYMS
@ 2022-06-05 20:43 Aleksander Mazur
  2023-05-26 22:55 ` Aleksander Mazur
  0 siblings, 1 reply; 4+ messages in thread
From: Aleksander Mazur @ 2022-06-05 20:43 UTC (permalink / raw)
  To: Arnd Bergmann, Sergey Senozhatsky
  Cc: Aleksander Mazur, linux-kernel, Jiri Olsa

Commit e4a8ca3baa55 fixed building without CONFIG_KALLSYMS by providing
dummy kallsyms_show_value(). Unfortunately -- due to hard-coded "false"
being returned -- access to addresses in /proc/modules became permanently
disabled.

My proposal is to change this unconditional "false" to !kptr_restrict.
This re-enables addresses in /proc/modules even without CONFIG_KALLSYSMS
unless restricted by means of sysctl (kernel.kptr_restrict).

Fixes: e4a8ca3baa55 ("/proc/module: fix building without kallsyms")
Signed-off-by: Aleksander Mazur <deweloper@wp.pl>
---
 include/linux/kallsyms.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
index ad39636e0c3f..cf64f9709f46 100644
--- a/include/linux/kallsyms.h
+++ b/include/linux/kallsyms.h
@@ -160,7 +160,7 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
 
 static inline bool kallsyms_show_value(const struct cred *cred)
 {
-	return false;
+	return !kptr_restrict;
 }
 
 static inline int kallsyms_on_each_symbol(int (*fn)(void *, const char *, struct module *,
-- 
2.36.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] /proc/modules: honor kptr_restrict even without CONFIG_KALLSYMS
  2022-06-05 20:43 [PATCH] /proc/modules: honor kptr_restrict even without CONFIG_KALLSYMS Aleksander Mazur
@ 2023-05-26 22:55 ` Aleksander Mazur
  2023-05-27  9:44   ` Arnd Bergmann
  0 siblings, 1 reply; 4+ messages in thread
From: Aleksander Mazur @ 2023-05-26 22:55 UTC (permalink / raw)
  To: Arnd Bergmann, Sergey Senozhatsky; +Cc: linux-kernel, Jiri Olsa

Hi,

Have you had a chance to review my patch?

-- 

Dnia 2022-06-05, o godz. 22:43:47
Aleksander Mazur <deweloper@wp.pl> napisał(a):

> Commit e4a8ca3baa55 fixed building without CONFIG_KALLSYMS by providing
> dummy kallsyms_show_value(). Unfortunately -- due to hard-coded "false"
> being returned -- access to addresses in /proc/modules became permanently
> disabled.
> 
> My proposal is to change this unconditional "false" to !kptr_restrict.
> This re-enables addresses in /proc/modules even without CONFIG_KALLSYSMS
> unless restricted by means of sysctl (kernel.kptr_restrict).
> 
> Fixes: e4a8ca3baa55 ("/proc/module: fix building without kallsyms")
> Signed-off-by: Aleksander Mazur <deweloper@wp.pl>
> ---
>  include/linux/kallsyms.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
> index ad39636e0c3f..cf64f9709f46 100644
> --- a/include/linux/kallsyms.h
> +++ b/include/linux/kallsyms.h
> @@ -160,7 +160,7 @@ static inline int lookup_symbol_attrs(unsigned long addr,
> unsigned long *size, u 
>  static inline bool kallsyms_show_value(const struct cred *cred)
>  {
> -	return false;
> +	return !kptr_restrict;
>  }
>  
>  static inline int kallsyms_on_each_symbol(int (*fn)(void *, const char *,
> struct module *,


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] /proc/modules: honor kptr_restrict even without CONFIG_KALLSYMS
  2023-05-26 22:55 ` Aleksander Mazur
@ 2023-05-27  9:44   ` Arnd Bergmann
  2023-08-21 15:13     ` Aleksander Mazur
  0 siblings, 1 reply; 4+ messages in thread
From: Arnd Bergmann @ 2023-05-27  9:44 UTC (permalink / raw)
  To: Aleksander Mazur, Sergey Senozhatsky; +Cc: linux-kernel, Jiri Olsa

On Sat, May 27, 2023, at 00:55, Aleksander Mazur wrote:
> Have you had a chance to review my patch?

I don't seem to have the original submission from you.

> Dnia 2022-06-05, o godz. 22:43:47
> Aleksander Mazur <deweloper@wp.pl> napisał(a):
>
>> Commit e4a8ca3baa55 fixed building without CONFIG_KALLSYMS by providing
>> dummy kallsyms_show_value(). Unfortunately -- due to hard-coded "false"
>> being returned -- access to addresses in /proc/modules became permanently
>> disabled.
>> 
>> My proposal is to change this unconditional "false" to !kptr_restrict.
>> This re-enables addresses in /proc/modules even without CONFIG_KALLSYSMS
>> unless restricted by means of sysctl (kernel.kptr_restrict).

I just looked at the original 516fb7f2e73dc ("/proc/module: use the
same logic as /proc/kallsyms for address exposure") commit again,
the intention here was to use the same logic for /proc/modules
and /proc/kallsyms.

I agree that this means my patch went too far, but I'm not sure
about yours either. Maybe we can just move kallsyms_show_value()
into a different location that is always built and rename it
accordingly. Then it can be used by both kallsyms and /proc/modules
regardless of which combination of these two is enabled in the
kernel.

     Arnd

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] /proc/modules: honor kptr_restrict even without CONFIG_KALLSYMS
  2023-05-27  9:44   ` Arnd Bergmann
@ 2023-08-21 15:13     ` Aleksander Mazur
  0 siblings, 0 replies; 4+ messages in thread
From: Aleksander Mazur @ 2023-08-21 15:13 UTC (permalink / raw)
  To: Arnd Bergmann; +Cc: Sergey Senozhatsky, linux-kernel, Jiri Olsa

Dnia 2023-05-27, o godz. 11:44:35
"Arnd Bergmann" <arnd@arndb.de> napisał(a):

> > Dnia 2022-06-05, o godz. 22:43:47
> > Aleksander Mazur <deweloper@wp.pl> napisał(a):
> >  
> >> Commit e4a8ca3baa55 fixed building without CONFIG_KALLSYMS by providing
> >> dummy kallsyms_show_value(). Unfortunately -- due to hard-coded "false"
> >> being returned -- access to addresses in /proc/modules became permanently
> >> disabled.
> >> 
> >> My proposal is to change this unconditional "false" to !kptr_restrict.
> >> This re-enables addresses in /proc/modules even without CONFIG_KALLSYSMS
> >> unless restricted by means of sysctl (kernel.kptr_restrict).  
> 
> I just looked at the original 516fb7f2e73dc ("/proc/module: use the
> same logic as /proc/kallsyms for address exposure") commit again,
> the intention here was to use the same logic for /proc/modules
> and /proc/kallsyms.
> 
> I agree that this means my patch went too far, but I'm not sure
> about yours either. Maybe we can just move kallsyms_show_value()
> into a different location that is always built and rename it
> accordingly. Then it can be used by both kallsyms and /proc/modules
> regardless of which combination of these two is enabled in the
> kernel.
> 

I don't see any reason why should I enable both KALLSYMS and PERF_EVENTS just to see addressess inside /proc/modules.
But this is currently required by the kernel, what in my opinion violates the description of kptr_restrict in Documentation/admin-guide/sysctl/kernel.rst.

My patch restores exposing kernel addresses via /proc/modules in the case of kptr_restrict==0 and it doesn't change current behaviour in other cases, especially for kptr_restrict==1; this means that even with my patch applied, the code is still more restrictive than the description of kptr_restrict (because it doesn't make an exception for processes with CAP_SYSLOG). Therefore I cannot agree that my patch goes "too far"; it rather goes just one step in the direction towards compliance with kernel documentation.

Moving kallsyms_show_value() somewhere else and re-using it won't help in my case because that function honors kptr_restrict==0 only if profiling is compiled in and perf_event_paranoid<=1.
BTW. I think this is wrong since according to the docs, perf_event_paranoid "controls use of the performance events system by unprivileged users", while placing restrictions on exposing kernel addresses via /proc should be controlled by kptr_restrict.
Or maybe I'm wrong and /proc/modules silently became a part of "the performance events system"?...

-- 
Aleksander Mazur

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-08-21 15:20 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-05 20:43 [PATCH] /proc/modules: honor kptr_restrict even without CONFIG_KALLSYMS Aleksander Mazur
2023-05-26 22:55 ` Aleksander Mazur
2023-05-27  9:44   ` Arnd Bergmann
2023-08-21 15:13     ` Aleksander Mazur

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.