The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Masami Hiramatsu (Google) <mhiramat@kernel.org>
To: Luigi Rizzo <lrizzo@google.com>
Cc: Naveen N Rao <naveen@kernel.org>,
	Luigi Rizzo <rizzo.unipi@gmail.com>,
	"David S . Miller" <davem@davemloft.net>,
	JP Kobryn <inwardvessel@gmail.com>,
	linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] kprobes: Fix NULL pointer dereference in unregister_kretprobes()
Date: Thu, 6 Aug 2026 09:02:35 +0900	[thread overview]
Message-ID: <20260806090235.e40c75f84f8a01b9a80fd570@kernel.org> (raw)
In-Reply-To: <20260805161221.2428623-1-lrizzo@google.com>

On Wed,  5 Aug 2026 16:12:21 +0000
Luigi Rizzo <lrizzo@google.com> wrote:

> In unregister_kretprobes(), rps[i]->rph can be NULL e.g. when called
> after kretprobe failed registration. Under !CONFIG_KRETPROBE_ON_RETHOOK,
> the unconditional access to rps[i]->rph->rp, causes a kernel panic due
> to NULL pointer dereference.

This is not a bug, since if register_kretprobe(rp) fails, rp must NOT be
passed to unregister_kretprobe(rp). Or, do you find any cases where
register_kretprobe() fails, preventing proper cleanup, and requiring
unregister_kretprobe()? If so, we have to fix that case.

> 
> Add a NULL check for rps[i]->rph before invoking rcu_assign_pointer().
> 

But this could be a kind of protective improvemet for someone
misunderstand that.

Thank you,

> Fixes: d839a656d0f3 ("kprobes: consistent rcu api usage for kretprobe holder")
> Signed-off-by: Luigi Rizzo <lrizzo@google.com>
> ---
>  kernel/kprobes.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/kernel/kprobes.c b/kernel/kprobes.c
> index bfc89083daa93..5dd4786c455de 100644
> --- a/kernel/kprobes.c
> +++ b/kernel/kprobes.c
> @@ -2359,7 +2359,8 @@ void unregister_kretprobes(struct kretprobe **rps, int num)
>  #ifdef CONFIG_KRETPROBE_ON_RETHOOK
>  		rethook_free(rps[i]->rh);
>  #else
> -		rcu_assign_pointer(rps[i]->rph->rp, NULL);
> +		if (rps[i]->rph)
> +			rcu_assign_pointer(rps[i]->rph->rp, NULL);
>  #endif
>  	}
>  
> -- 
> 2.48.1.500.g5897711438-goog
> 
> 


-- 
Masami Hiramatsu (Google) <mhiramat@kernel.org>

  parent reply	other threads:[~2026-08-06  0:02 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-05 16:12 [PATCH] kprobes: Fix NULL pointer dereference in unregister_kretprobes() Luigi Rizzo
2026-08-05 18:40 ` Bradley Morgan
2026-08-05 20:25 ` JP Kobryn
2026-08-06  0:02 ` Masami Hiramatsu [this message]
2026-08-06  7:23   ` Luigi Rizzo
2026-08-06 13:41     ` Masami Hiramatsu

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=20260806090235.e40c75f84f8a01b9a80fd570@kernel.org \
    --to=mhiramat@kernel.org \
    --cc=davem@davemloft.net \
    --cc=inwardvessel@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=lrizzo@google.com \
    --cc=naveen@kernel.org \
    --cc=rizzo.unipi@gmail.com \
    /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