Skip to contentSkip to conversation

kprobe: reverse kp->flags when arm_kprobe failed

PATCH In review Li Qiang 3 participants 5 messages Sep 2, 2022 – Sep 27, 2022 kprobes

lore
Share & tools
lore

Li Qiang

author
#0 lore raw

PATCH 1/1 kprobe: reverse kp->flags when arm_kprobe failed

In aggregate kprobe case, when arm_kprobe failed, we need set the kp->flags with KPROBE_FLAG_DISABLED again. If not, the 'kp' kprobe will been considered as enabled but it actually not enabled.

---
 kernel/kprobes.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
kernel/kprobes.c +4 -1
index 08350e35a..333454df5 100644
@@ -2424,8 +2424,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);
Signature · 1 line
2.25.1
#1 lore raw

Kindly ping.

Quoted 31 lines · Li Qiang <[email protected]> 于2022年9月3日周六 00:00写道:

In aggregate kprobe case, when arm_kprobe failed, we need set the kp->flags with KPROBE_FLAG_DISABLED again. If not, the 'kp' kprobe will been considered as enabled but it actually not enabled.

---
 kernel/kprobes.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
kernel/kprobes.c +4 -2
index 08350e35a..333454df5 100644
@@ -2424,8 +2424,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.25.1

maintainer Acked-by on v1 1/1
#2 lore raw
In reply to Li Qiang
Quoted 6 lines · On Fri, 2 Sep 2022 08:58:20 -0700 Li Qiang <[email protected]> wrote:

In aggregate kprobe case, when arm_kprobe failed, we need set the kp->flags with KPROBE_FLAG_DISABLED again. If not, the 'kp' kprobe will been considered as enabled but it actually not enabled.

Looks good to me.

Thanks!

Quoted 24 lines
---
 kernel/kprobes.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
kernel/kprobes.c +4 -1
index 08350e35a..333454df5 100644
@@ -2424,8 +2424,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);
Signature · 1 line
2.25.1
Signature · 1 line
Masami Hiramatsu (Google) <[email protected]>
#3 lore raw
Quoted 9 lines · Masami Hiramatsu <[email protected]> 于2022年9月9日周五 21:07写道:
Quoted 5 lines · On Fri, 2 Sep 2022 08:58:20 -0700 Li Qiang <[email protected]> wrote:

In aggregate kprobe case, when arm_kprobe failed, we need set the kp->flags with KPROBE_FLAG_DISABLED again. If not, the 'kp' kprobe will been considered as enabled but it actually not enabled.

Quoted 5 lines
Quoted 1 line

Looks good to me.

Hello Masami,

Who should merge this, you? This issue will crash the kernel before:

0bc11ed5ab60c135aa764a62c02cd5ea68289de4 commit ("kprobes: Allow kprobes coexist with
livepatch") and
8094029330a2f03fb406ecff80671cf27ce28d42 commit("libbpf: Cleanup the legacy kprobe_event on failed add/attach_event()")

Thanks,
Li Qiang

Quoted 31 lines

Thanks!

Quoted 22 lines
---
 kernel/kprobes.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
kernel/kprobes.c +4 -2
index 08350e35a..333454df5 100644
@@ -2424,8 +2424,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);
--
Quoted 2 lines

2.25.1

--
Masami Hiramatsu (Google) <[email protected]>

#4 lore raw
In reply to Li Qiang

Hello all,

What's the status of this patch?

Quoted 31 lines · Li Qiang <[email protected]> 于2022年9月3日周六 00:00写道:

In aggregate kprobe case, when arm_kprobe failed, we need set the kp->flags with KPROBE_FLAG_DISABLED again. If not, the 'kp' kprobe will been considered as enabled but it actually not enabled.

---
 kernel/kprobes.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
kernel/kprobes.c +4 -2
index 08350e35a..333454df5 100644
@@ -2424,8 +2424,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.25.1