stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Chuang W <nashuiliang@gmail.com>
To: unlisted-recipients:; (no To-header on input)
Cc: Chuang W <nashuiliang@gmail.com>,
	stable@vger.kernel.org,
	"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: [PATCH] kprobes: Rollback post_handler on failed arm_kprobe()
Date: Tue, 14 Jun 2022 17:06:33 +0800	[thread overview]
Message-ID: <20220614090633.43832-1-nashuiliang@gmail.com> (raw)

In a scenario where livepatch and aggrprobe coexist, if arm_kprobe()
returns an error, ap.post_handler, while has been modified to
p.post_handler, is not rolled back.

When ap.post_handler is not NULL (not rolled back), the caller (e.g.
register_kprobe/enable_kprobe) of arm_kprobe_ftrace() will always fail.

Fixes: 12310e343755 ("kprobes: Propagate error from arm_kprobe_ftrace()")
Signed-off-by: Chuang W <nashuiliang@gmail.com>
Cc: <stable@vger.kernel.org>
---
 kernel/kprobes.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/kernel/kprobes.c b/kernel/kprobes.c
index f214f8c088ed..0610b02a3a05 100644
--- a/kernel/kprobes.c
+++ b/kernel/kprobes.c
@@ -1300,6 +1300,7 @@ static int register_aggr_kprobe(struct kprobe *orig_p, struct kprobe *p)
 {
 	int ret = 0;
 	struct kprobe *ap = orig_p;
+	kprobe_post_handler_t old_post_handler = NULL;
 
 	cpus_read_lock();
 
@@ -1351,6 +1352,9 @@ static int register_aggr_kprobe(struct kprobe *orig_p, struct kprobe *p)
 
 	/* Copy the insn slot of 'p' to 'ap'. */
 	copy_kprobe(ap, p);
+
+	/* save the old post_handler */
+	old_post_handler = ap->post_handler;
 	ret = add_new_kprobe(ap, p);
 
 out:
@@ -1365,6 +1369,7 @@ static int register_aggr_kprobe(struct kprobe *orig_p, struct kprobe *p)
 			ret = arm_kprobe(ap);
 			if (ret) {
 				ap->flags |= KPROBE_FLAG_DISABLED;
+				ap->post_handler = old_post_handler;
 				list_del_rcu(&p->list);
 				synchronize_rcu();
 			}
-- 
2.34.1


             reply	other threads:[~2022-06-14  9:07 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-14  9:06 Chuang W [this message]
2022-06-15  0:34 ` [PATCH] kprobes: Rollback post_handler on failed arm_kprobe() Masami Hiramatsu
2022-06-15  3:09   ` chuang
2022-06-18 16:04     ` 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=20220614090633.43832-1-nashuiliang@gmail.com \
    --to=nashuiliang@gmail.com \
    --cc=anil.s.keshavamurthy@intel.com \
    --cc=davem@davemloft.net \
    --cc=jeyu@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mhiramat@kernel.org \
    --cc=mingo@kernel.org \
    --cc=naveen.n.rao@linux.ibm.com \
    --cc=stable@vger.kernel.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).