linux-trace-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jiri Olsa <olsajiri@gmail.com>
To: "Masami Hiramatsu (Google)" <mhiramat@kernel.org>
Cc: Steven Rostedt <rostedt@goodmis.org>,
	linux-trace-kernel@vger.kernel.org,
	Jiri Olsa <olsajiri@gmail.com>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] fprobe: Fix to allocate entry_data_size buffer with rethook instances
Date: Thu, 29 Feb 2024 22:58:54 +0100	[thread overview]
Message-ID: <ZeD-HkC7bsAn_YgK@krava> (raw)
In-Reply-To: <170920576727.107552.638161246679734051.stgit@devnote2>

On Thu, Feb 29, 2024 at 08:22:47PM +0900, Masami Hiramatsu (Google) wrote:
> From: Masami Hiramatsu (Google) <mhiramat@kernel.org>
> 
> Fix to allocate fprobe::entry_data_size buffer with rethook instances.
> If fprobe doesn't allocate entry_data_size buffer for each rethook instance,
> fprobe entry handler can cause a buffer overrun when storing entry data in
> entry handler.
> 
> Reported-by: Jiri Olsa <olsajiri@gmail.com>

Tested-by: Jiri Olsa <olsajiri@gmail.com>

thanks,
jirka

> Fixes: 4bbd93455659 ("kprobes: kretprobe scalability improvement")
> Cc: stable@vger.kernel.org
> Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
> ---
>  kernel/trace/fprobe.c |   14 ++++++--------
>  1 file changed, 6 insertions(+), 8 deletions(-)
> 
> diff --git a/kernel/trace/fprobe.c b/kernel/trace/fprobe.c
> index 6cd2a4e3afb8..9ff018245840 100644
> --- a/kernel/trace/fprobe.c
> +++ b/kernel/trace/fprobe.c
> @@ -189,9 +189,6 @@ static int fprobe_init_rethook(struct fprobe *fp, int num)
>  {
>  	int size;
>  
> -	if (num <= 0)
> -		return -EINVAL;
> -
>  	if (!fp->exit_handler) {
>  		fp->rethook = NULL;
>  		return 0;
> @@ -199,15 +196,16 @@ static int fprobe_init_rethook(struct fprobe *fp, int num)
>  
>  	/* Initialize rethook if needed */
>  	if (fp->nr_maxactive)
> -		size = fp->nr_maxactive;
> +		num = fp->nr_maxactive;
>  	else
> -		size = num * num_possible_cpus() * 2;
> -	if (size <= 0)
> +		num *= num_possible_cpus() * 2;
> +	if (num <= 0)
>  		return -EINVAL;
>  
> +	size = sizeof(struct fprobe_rethook_node) + fp->entry_data_size;
> +
>  	/* Initialize rethook */
> -	fp->rethook = rethook_alloc((void *)fp, fprobe_exit_handler,
> -				sizeof(struct fprobe_rethook_node), size);
> +	fp->rethook = rethook_alloc((void *)fp, fprobe_exit_handler, size, num);
>  	if (IS_ERR(fp->rethook))
>  		return PTR_ERR(fp->rethook);
>  
> 

  parent reply	other threads:[~2024-02-29 21:58 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-29 11:22 [PATCH] fprobe: Fix to allocate entry_data_size buffer with rethook instances Masami Hiramatsu (Google)
2024-02-29 11:28 ` Masami Hiramatsu
2024-02-29 21:58 ` Jiri Olsa [this message]
2024-02-29 22:50   ` 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=ZeD-HkC7bsAn_YgK@krava \
    --to=olsajiri@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=mhiramat@kernel.org \
    --cc=rostedt@goodmis.org \
    /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;
as well as URLs for NNTP newsgroup(s).