mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Jinjie Ruan <ruanjinjie@huawei.com>
Cc: tglx@linutronix.de, linux-kernel@vger.kernel.org,
	Christophe Leroy <christophe.leroy@csgroup.eu>,
	Josh Poimboeuf <jpoimboe@kernel.org>
Subject: Re: [PATCH] static_call: Fix a wild-memory-access bug in static_call_del_module()
Date: Fri, 15 Sep 2023 11:01:47 +0200	[thread overview]
Message-ID: <20230915090147.GB6721@noisy.programming.kicks-ass.net> (raw)
In-Reply-To: <20230915082126.4187913-1-ruanjinjie@huawei.com>

On Fri, Sep 15, 2023 at 04:21:25PM +0800, Jinjie Ruan wrote:
> Inject fault while probing btrfs.ko, if the first kzalloc() fails
> in __static_call_init(), key->mods will no be initialized. And then
> in static_call_del_module() the site_mod->mod will cause
> wild-memory-access as below:
> 
> So assign key->mods to NULL in __static_call_init() if it fails
> to fix the issue. And if kzalloc fails, it will just return in init
> func, so it should break if it the key->mods is NULL in exit func.
> 

I don't think we need that full splat.

> 
> Fixes: 8fd4ddda2f49 ("static_call: Don't make __static_call_return0 static")

And that looks wrong, that just moved code around.

> Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
> ---
>  kernel/static_call_inline.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/kernel/static_call_inline.c b/kernel/static_call_inline.c
> index 639397b5491c..e7aa70d33530 100644
> --- a/kernel/static_call_inline.c
> +++ b/kernel/static_call_inline.c
> @@ -256,8 +256,10 @@ static int __static_call_init(struct module *mod,
>  			}
>  
>  			site_mod = kzalloc(sizeof(*site_mod), GFP_KERNEL);
> -			if (!site_mod)
> +			if (!site_mod) {
> +				key->mods = NULL;
>  				return -ENOMEM;
> +			}
>  
>  			/*
>  			 * When the key has a direct sites pointer, extract
> @@ -422,7 +424,7 @@ static void static_call_del_module(struct module *mod)
>  			;
>  
>  		if (!site_mod)
> -			continue;
> +			break;
>  
>  		*prev = site_mod->next;
>  		kfree(site_mod);

The actual patch looks okay.

  reply	other threads:[~2023-09-15  9:03 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-15  8:21 Jinjie Ruan
2023-09-15  9:01 ` Peter Zijlstra [this message]
2024-09-02 12:01 ` Jinjie Ruan
2024-09-02 12:06   ` Christophe Leroy
2024-09-02 12:07     ` Jinjie Ruan
2024-09-02 12:14       ` Christophe Leroy
2024-09-03 20:01   ` Thomas Gleixner
2024-09-03 22:58     ` [PATCH] static_call: Handle module init failure correctly " Thomas Gleixner
2024-09-04  3:32       ` Jinjie Ruan
2024-09-04  7:08         ` Thomas Gleixner
2024-09-04  8:00           ` Thomas Gleixner
2024-09-04  8:17             ` Peter Zijlstra
2024-09-04  9:08               ` [PATCH] static_call: Replace pointless WARN_ON() in static_call_module_notify() Thomas Gleixner
2024-09-06 14:41                 ` [tip: locking/urgent] " tip-bot2 for Thomas Gleixner
2024-09-04  8:03           ` [PATCH] static_call: Handle module init failure correctly in static_call_del_module() Jinjie Ruan
2024-09-04  8:51             ` Thomas Gleixner
2024-09-04  9:50               ` Jinjie Ruan
2024-09-05  3:34               ` Jinjie Ruan
2024-09-05  9:44                 ` Thomas Gleixner
2024-09-06 23:24                   ` Luis Chamberlain
2024-09-19  9:53                     ` Luis Chamberlain
2024-09-24  7:22                       ` Mike Rapoport
2024-11-08  8:12                         ` Christophe Leroy
2024-11-08 15:49                           ` Luis Chamberlain
2024-11-08 16:09                             ` Daniel Gomez
2024-11-08 16:22                               ` Daniel Gomez
2024-09-04  9:09             ` [PATCH v2] " Thomas Gleixner
2024-09-04  9:19               ` Jinjie Ruan
2024-09-06 14:41               ` [tip: locking/urgent] " tip-bot2 for Thomas Gleixner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230915090147.GB6721@noisy.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=christophe.leroy@csgroup.eu \
    --cc=jpoimboe@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ruanjinjie@huawei.com \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome