Skip to contentSkip to conversation

bpf: Check link_create parameter for multi_kprobe

PATCH Applied Tao Chen 2 participants 3 messages Apr 7, 2025 – Apr 9, 2025

Subsystems (4)
lore
Share & tools
lore

Tao Chen

author
#0 lore raw

PATCH v2 1/2 bpf: Check link_create parameter for multi_kprobe

The flags in link_create no used in multi_kprobe, return -EINVAL if they assigned, keep it same as other link attach apis. Perhaps due to their usage habits, users may set the target_fd to -1. Therefore, no check is carried out here, and it is kept consistent with the multi_uprobe.

Fixes 0dcac2725406 ("bpf: Add multi kprobe link")
---
 kernel/trace/bpf_trace.c | 6 ++++++
 1 file changed, 6 insertions(+)

Change list:
- v1 -> v2:
- remove target_fd check suggested by jiri.
- v1:

    https://lore.kernel.org/bpf/[email protected]/
kernel/trace/bpf_trace.c +6 -0
index 13bef2462..5cd0af80f 100644
@@ -2992,6 +2992,12 @@ int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr
 	/* no support for 32bit archs yet */
 	if (sizeof(u64) != sizeof(void *))
 		return -EOPNOTSUPP;
+	/*
+	 * Perhaps due to their usage habits, users may set the target_fd to -1. Therefore,
+	 * no check is carried out here, and it is kept consistent with the multi_uprobe.
+	 */
+	if (attr->link_create.flags)
+		return -EINVAL;
 
 	if (!is_kprobe_multi(prog))
 		return -EINVAL;
Signature · 1 line
2.43.0
author
#1 lore raw

PATCH v2 2/2 bpf: Check link_create parameter for multi_uprobe

The flags in link_create no used in multi_uprobe, return -EINVAL if they assigned, keep it same as other link attach apis. And the target_fd sometimes will be initialized -1 such as probe_uprobe_multi_link in libbpf, so do not check it at the current stage suggested by jiri.

Fixes 89ae89f53d20 ("bpf: Add multi uprobe link")
---
 kernel/trace/bpf_trace.c | 7 +++++++
 1 file changed, 7 insertions(+)
kernel/trace/bpf_trace.c +7 -0
index 5cd0af80f..0f4085e8d 100644
@@ -3387,6 +3387,13 @@ int bpf_uprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr
 	/* no support for 32bit archs yet */
 	if (sizeof(u64) != sizeof(void *))
 		return -EOPNOTSUPP;
+	/*
+	 * The target_fd sometimes will be initialized -1 such as
+	 * probe_uprobe_multi_link in libbpf, so do not check it at the
+	 * current stage suggested by jiri.
+	 */
+	if (attr->link_create.flags)
+		return -EINVAL;
 
 	if (!is_uprobe_multi(prog))
 		return -EINVAL;
Signature · 1 line
2.43.0
#2 lore raw
In reply to Tao Chen
This series was applied to bpf/bpf-next.git (master) by Andrii Nakryiko <[email protected]>:

Hello:

This series was applied to bpf/bpf-next.git (master) by Andrii Nakryiko <[email protected]>:

Quoted 9 lines · On Mon, 7 Apr 2025 11:57:51 +0800 you wrote:

The flags in link_create no used in multi_kprobe, return -EINVAL if they assigned, keep it same as other link attach apis. Perhaps due to their usage habits, users may set the target_fd to -1. Therefore, no check is carried out here, and it is kept consistent with the multi_uprobe.

Fixes 0dcac2725406 ("bpf: Add multi kprobe link")

[...]

Here is the summary with links:
- [bpf-next,v2,1/2] bpf: Check link_create parameter for multi_kprobe

    https://git.kernel.org/bpf/bpf-next/c/243911982aa9
  - [bpf-next,v2,2/2] bpf: Check link_create parameter for multi_uprobe
    https://git.kernel.org/bpf/bpf-next/c/a76116f422c4

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html