Re: [RFC][PATCH 3/4] kprobes: Allow kprobes with CONFIG_MODULES=n

From: Google
Date: Thu Mar 07 2024 - 21:47:44 EST


On Thu, 7 Mar 2024 09:22:07 +0200
Mike Rapoport <rppt@xxxxxxxxxx> wrote:

> On Wed, Mar 06, 2024 at 12:05:10PM -0800, Calvin Owens wrote:
> > If something like this is merged down the road, it can go in at leisure
> > once the module_alloc change is in: it's a one-way dependency.
> >
> > Signed-off-by: Calvin Owens <jcalvinowens@xxxxxxxxx>
> > ---
> > arch/Kconfig | 2 +-
> > kernel/kprobes.c | 22 ++++++++++++++++++++++
> > kernel/trace/trace_kprobe.c | 11 +++++++++++
> > 3 files changed, 34 insertions(+), 1 deletion(-)
>
> When I did this in my last execmem posting, I think I've got slightly less
> ugly ifdery, you may want to take a look at that:
>
> https://lore.kernel.org/all/20230918072955.2507221-13-rppt@xxxxxxxxxx

Good catch, and sorry I missed that series last year.
But it seems your patch seems less ugly.

Calvin, can you follow his patch?

Thank you,

>
> > diff --git a/arch/Kconfig b/arch/Kconfig
> > index cfc24ced16dd..e60ce984d095 100644
> > --- a/arch/Kconfig
> > +++ b/arch/Kconfig
> > @@ -52,8 +52,8 @@ config GENERIC_ENTRY
> >
> > config KPROBES
> > bool "Kprobes"
> > - depends on MODULES
> > depends on HAVE_KPROBES
> > + select MODULE_ALLOC
> > select KALLSYMS
> > select TASKS_RCU if PREEMPTION
> > help
> > diff --git a/kernel/kprobes.c b/kernel/kprobes.c
> > index 9d9095e81792..194270e17d57 100644
> > --- a/kernel/kprobes.c
> > +++ b/kernel/kprobes.c
> > @@ -1556,8 +1556,12 @@ static bool is_cfi_preamble_symbol(unsigned long addr)
> > str_has_prefix("__pfx_", symbuf);
> > }
> >
> > +#if IS_ENABLED(CONFIG_MODULES)
> > static int check_kprobe_address_safe(struct kprobe *p,
> > struct module **probed_mod)
> > +#else
> > +static int check_kprobe_address_safe(struct kprobe *p)
> > +#endif
> > {
> > int ret;
> >
> > @@ -1580,6 +1584,7 @@ static int check_kprobe_address_safe(struct kprobe *p,
> > goto out;
> > }
> >
> > +#if IS_ENABLED(CONFIG_MODULES)
>
> Plain #ifdef will do here and below. IS_ENABLED is for usage withing the
> code, like
>
> if (IS_ENABLED(CONFIG_MODULES))
> ;
>
> > /* Check if 'p' is probing a module. */
> > *probed_mod = __module_text_address((unsigned long) p->addr);
> > if (*probed_mod) {
>
> --
> Sincerely yours,
> Mike.


--
Masami Hiramatsu (Google) <mhiramat@xxxxxxxxxx>