mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Masami Hiramatsu (Google) <mhiramat@kernel.org>
To: Chuang <nashuiliang@gmail.com>
Cc: stable@vger.kernel.org, Jingren Zhou <zhoujingren@didiglobal.com>,
	"Naveen N. Rao" <naveen.n.rao@linux.ibm.com>,
	Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com>,
	"David S. Miller" <davem@davemloft.net>,
	Masami Hiramatsu <mhiramat@kernel.org>,
	Ingo Molnar <mingo@kernel.org>, Jessica Yu <jeyu@kernel.org>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] kprobes: Rollback kprobe flags on failed arm_kprobe
Date: Sun, 12 Jun 2022 21:31:56 +0900	[thread overview]
Message-ID: <20220612213156.1323776351ee1be3cabc7fcc@kernel.org> (raw)
In-Reply-To: <20220610150933.37770-1-nashuiliang@gmail.com>

On Fri, 10 Jun 2022 23:09:33 +0800
Chuang <nashuiliang@gmail.com> wrote:

> From: Chuang Wang <nashuiliang@gmail.com>
> 
> In aggrprobe scenes, if arm_kprobe() returns an error(e.g. livepatch and
> kprobe are using the same function X), kprobe flags, while has been
> modified to ~KPROBE_FLAG_DISABLED, is not rollled back.
> 
> Then, __disable_kprobe() will be failed in __unregister_kprobe_top(),
> the kprobe list will be not removed from aggrprobe, memory leaks or
> illegal pointers will be caused.
> 
> WARN disarm_kprobe:
>  Failed to disarm kprobe-ftrace at 00000000c729fdbc (-2)
>  RIP: 0010:disarm_kprobe+0xcc/0x110
>  Call Trace:
>   __disable_kprobe+0x78/0x90
>   __unregister_kprobe_top+0x13/0x1b0
>   ? _cond_resched+0x15/0x30
>   unregister_kprobes+0x32/0x80
>   unregister_kprobe+0x1a/0x20
> 
> Illegal Pointers:
>  BUG: unable to handle kernel paging request at 0000000000656369
>  RIP: 0010:__get_valid_kprobe+0x69/0x90
>  Call Trace:
>   register_kprobe+0x30/0x60
>   __register_trace_kprobe.part.7+0x8b/0xc0
>   create_local_trace_kprobe+0xd2/0x130
>   perf_kprobe_init+0x83/0xd0
> 

This looks good to me.

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

Thanks for update!

> Fixes: 12310e343755 ("kprobes: Propagate error from arm_kprobe_ftrace()")
> Signed-off-by: Chuang Wang <nashuiliang@gmail.com>
> Cc: <stable@vger.kernel.org>
> Signed-off-by: Jingren Zhou <zhoujingren@didiglobal.com>
> ---
> v1->v2:
> - Supplement commit information: fixline, Cc stable
> 
>  kernel/kprobes.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/kernel/kprobes.c b/kernel/kprobes.c
> index f214f8c088ed..c11c79e05a4c 100644
> --- a/kernel/kprobes.c
> +++ b/kernel/kprobes.c
> @@ -2422,8 +2422,11 @@ int enable_kprobe(struct kprobe *kp)
>  	if (!kprobes_all_disarmed && kprobe_disabled(p)) {
>  		p->flags &= ~KPROBE_FLAG_DISABLED;
>  		ret = arm_kprobe(p);
> -		if (ret)
> +		if (ret) {
>  			p->flags |= KPROBE_FLAG_DISABLED;
> +			if (p != kp)
> +				kp->flags |= KPROBE_FLAG_DISABLED;
> +		}
>  	}
>  out:
>  	mutex_unlock(&kprobe_mutex);
> -- 
> 2.34.1
> 


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

  reply	other threads:[~2022-06-12 12:32 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-10 15:09 Chuang
2022-06-12 12:31 ` Masami Hiramatsu [this message]
  -- strict thread matches above, loose matches on Subject: below --
2022-06-08  2:12 Chuang

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=20220612213156.1323776351ee1be3cabc7fcc@kernel.org \
    --to=mhiramat@kernel.org \
    --cc=anil.s.keshavamurthy@intel.com \
    --cc=davem@davemloft.net \
    --cc=jeyu@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=nashuiliang@gmail.com \
    --cc=naveen.n.rao@linux.ibm.com \
    --cc=stable@vger.kernel.org \
    --cc=zhoujingren@didiglobal.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

all inboxes | Powered by JetHome®