linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Masami Hiramatsu <masami.hiramatsu@gmail.com>
To: Vamshi K Sthambamkadi <vamshi.k.sthambamkadi@gmail.com>
Cc: rostedt@goodmis.org, mingo@redhat.com, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] tracing/probe: fix memleak in fetch_op_data operations
Date: Tue, 16 Jun 2020 17:41:06 +0900	[thread overview]
Message-ID: <20200616174106.8b61410d50ce20e010ad6f4e@gmail.com> (raw)
In-Reply-To: <20200615143034.GA1734@cosmos>

On Mon, 15 Jun 2020 20:00:38 +0530
Vamshi K Sthambamkadi <vamshi.k.sthambamkadi@gmail.com> wrote:

> kmemleak report:
>     [<57dcc2ca>] __kmalloc_track_caller+0x139/0x2b0
>     [<f1c45d0f>] kstrndup+0x37/0x80
>     [<f9761eb0>] parse_probe_arg.isra.7+0x3cc/0x630
>     [<055bf2ba>] traceprobe_parse_probe_arg+0x2f5/0x810
>     [<655a7766>] trace_kprobe_create+0x2ca/0x950
>     [<4fc6a02a>] create_or_delete_trace_kprobe+0xf/0x30
>     [<6d1c8a52>] trace_run_command+0x67/0x80
>     [<be812cc0>] trace_parse_run_command+0xa7/0x140
>     [<aecfe401>] probes_write+0x10/0x20
>     [<2027641c>] __vfs_write+0x30/0x1e0
>     [<6a4aeee1>] vfs_write+0x96/0x1b0
>     [<3517fb7d>] ksys_write+0x53/0xc0
>     [<dad91db7>] __ia32_sys_write+0x15/0x20
>     [<da347f64>] do_syscall_32_irqs_on+0x3d/0x260
>     [<fd0b7e7d>] do_fast_syscall_32+0x39/0xb0
>     [<ea5ae810>] entry_SYSENTER_32+0xaf/0x102
> 
> Post parse_probe_arg(), the FETCH_OP_DATA operation type is overwritten
> to FETCH_OP_ST_STRING, as a result memory is never freed since
> traceprobe_free_probe_arg() iterates only over SYMBOL and DATA op types
> 
> Setup fetch string operation correctly after fetch_op_data operation.
> 

Oops, Good catch! (I've commented it but not coded...)

Acked-by: Masami Hiramatsu <mhiramat@kernel.org>

And,

Fixes: a42e3c4de964 ("tracing/probe: Add immediate string parameter support")
Cc: stable@vger.kernel.org

Thank you!

> Signed-off-by: Vamshi K Sthambamkadi <vamshi.k.sthambamkadi@gmail.com>
> ---
>  kernel/trace/trace_probe.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/kernel/trace/trace_probe.c b/kernel/trace/trace_probe.c
> index b8a928e..d2867cc 100644
> --- a/kernel/trace/trace_probe.c
> +++ b/kernel/trace/trace_probe.c
> @@ -639,8 +639,8 @@ static int traceprobe_parse_probe_arg_body(char *arg, ssize_t *size,
>  			ret = -EINVAL;
>  			goto fail;
>  		}
> -		if ((code->op == FETCH_OP_IMM || code->op == FETCH_OP_COMM) ||
> -		     parg->count) {
> +		if ((code->op == FETCH_OP_IMM || code->op == FETCH_OP_COMM ||
> +		     code->op == FETCH_OP_DATA) || parg->count) {
>  			/*
>  			 * IMM, DATA and COMM is pointing actual address, those
>  			 * must be kept, and if parg->count != 0, this is an
> -- 
> 2.7.4
> 


-- 
Masami Hiramatsu

  parent reply	other threads:[~2020-06-16  8:41 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-15 14:30 [PATCH] tracing/probe: fix memleak in fetch_op_data operations Vamshi K Sthambamkadi
2020-06-15 21:13 ` Steven Rostedt
2020-06-16  8:46   ` Masami Hiramatsu
2020-06-16 14:19     ` Oleg Nesterov
2020-06-16 16:21       ` Srikar Dronamraju
2020-06-16  8:41 ` Masami Hiramatsu [this message]
2020-06-15 15:10 Markus Elfring

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=20200616174106.8b61410d50ce20e010ad6f4e@gmail.com \
    --to=masami.hiramatsu@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=rostedt@goodmis.org \
    --cc=vamshi.k.sthambamkadi@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;
as well as URLs for NNTP newsgroup(s).