Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpf: check bpf_map/bpf_program fd validity #6588

Closed

Conversation

kernel-patches-daemon-bpf[bot]
Copy link

Pull request for series with
subject: bpf: check bpf_map/bpf_program fd validity
version: 1
url: https://patchwork.kernel.org/project/netdevbpf/list/?series=836080

@kernel-patches-daemon-bpf
Copy link
Author

Upstream branch: 4c8644f
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=836080
version: 1

@kernel-patches-daemon-bpf
Copy link
Author

Upstream branch: 4c8644f
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=836080
version: 1

@kernel-patches-daemon-bpf
Copy link
Author

Upstream branch: 7f3edd0
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=836080
version: 1

libbpf creates bpf_program/bpf_map structs for each program/map that
user defines, but it allows to disable creating/loading those objects in
kernel, in that case they won't have associated file descriptor
(fd < 0). Such functionality is used for backward compatibility
with some older kernels.

Nothing prevents users from passing these maps or programs with no
kernel counterpart to libbpf APIs. This change introduces explicit
checks for kernel objects existence, aiming to improve visibility of
those edge cases and provide meaningful warnings to users.

Signed-off-by: Mykyta Yatsenko <yatsenko@meta.com>
@kernel-patches-daemon-bpf
Copy link
Author

Upstream branch: 7b30c29
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=836080
version: 1

Pull request is NOT updated. Failed to apply https://patchwork.kernel.org/project/netdevbpf/list/?series=836080
error message:

Cmd('git') failed due to: exit code(128)
  cmdline: git am --3way
  stdout: 'Applying: bpf: check bpf_map/bpf_program fd validity
Using index info to reconstruct a base tree...
M	tools/lib/bpf/libbpf.c
Falling back to patching base and 3-way merge...
Auto-merging tools/lib/bpf/libbpf.c
CONFLICT (content): Merge conflict in tools/lib/bpf/libbpf.c
Patch failed at 0001 bpf: check bpf_map/bpf_program fd validity
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".'
  stderr: 'error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch'

conflict:

diff --cc tools/lib/bpf/libbpf.c
index 3a756d61c120,d1febdb036de..000000000000
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@@ -8573,7 -8573,8 +8573,12 @@@ int bpf_map__pin(struct bpf_map *map, c
  	}
  
  	if (map->fd < 0) {
++<<<<<<< HEAD
 +		pr_warn("map '%s': can't pin BPF map without FD (was it created?)\n", map->name);
++=======
+ 		pr_warn("map '%s': can't pin BPF map without FD (was it created?)\n",
+ 			bpf_map__name(map));
++>>>>>>> bpf: check bpf_map/bpf_program fd validity
  		return libbpf_err(-EINVAL);
  	}
  
@@@ -10439,13 -10440,13 +10444,23 @@@ int bpf_link__update_program(struct bpf
  {
  	int ret;
  	int prog_fd = bpf_program__fd(prog);
++<<<<<<< HEAD
 +
 +	if (prog_fd < 0) {
 +		pr_warn("prog '%s': can't use BPF program without FD (was it loaded?)\n",
 +			prog->name);
 +		return libbpf_err(-EINVAL);
 +	}
 +
++=======
+ 
+ 	if (prog_fd < 0) {
+ 		pr_warn("prog '%s': can't use BPF program without FD (was it created?)\n",
+ 			prog->name);
+ 		return libbpf_err(-EINVAL);
+ 	}
+ 
++>>>>>>> bpf: check bpf_map/bpf_program fd validity
  	ret = bpf_link_update(bpf_link__fd(link), prog_fd, NULL);
  	return libbpf_err_errno(ret);
  }
@@@ -11366,7 -11367,7 +11381,11 @@@ bpf_program__attach_kprobe_multi_opts(c
  
  	prog_fd = bpf_program__fd(prog);
  	if (prog_fd < 0) {
++<<<<<<< HEAD
 +		pr_warn("prog '%s': can't attach BPF program without FD (was it loaded?)\n",
++=======
+ 		pr_warn("prog '%s': can't attach BPF program without FD (was it created?)\n",
++>>>>>>> bpf: check bpf_map/bpf_program fd validity
  			prog->name);
  		return libbpf_err_ptr(-EINVAL);
  	}
@@@ -11795,7 -11796,7 +11814,11 @@@ bpf_program__attach_uprobe_multi(const 
  
  	prog_fd = bpf_program__fd(prog);
  	if (prog_fd < 0) {
++<<<<<<< HEAD
 +		pr_warn("prog '%s': can't attach BPF program without FD (was it loaded?)\n",
++=======
+ 		pr_warn("prog '%s': can't attach BPF program without FD (was it created?)\n",
++>>>>>>> bpf: check bpf_map/bpf_program fd validity
  			prog->name);
  		return libbpf_err_ptr(-EINVAL);
  	}
@@@ -12701,7 -12702,7 +12724,11 @@@ struct bpf_link *bpf_program__attach(co
  		return libbpf_err_ptr(-EOPNOTSUPP);
  
  	if (bpf_program__fd(prog) < 0) {
++<<<<<<< HEAD
 +		pr_warn("prog '%s': can't attach BPF program without FD (was it loaded?)\n",
++=======
+ 		pr_warn("prog '%s': can't attach BPF program w/o FD (did you load it?)\n",
++>>>>>>> bpf: check bpf_map/bpf_program fd validity
  			prog->name);
  		return libbpf_err_ptr(-EINVAL);
  	}
@@@ -12750,7 -12751,7 +12777,11 @@@ struct bpf_link *bpf_map__attach_struct
  		return libbpf_err_ptr(-EINVAL);
  
  	if (map->fd < 0) {
++<<<<<<< HEAD
 +		pr_warn("map '%s': can't attach BPF map without FD (was it created?)\n", map->name);
++=======
+ 		pr_warn("map '%s': can't attach BPF map w/o FD (did you load it?)\n", map->name);
++>>>>>>> bpf: check bpf_map/bpf_program fd validity
  		return libbpf_err_ptr(-EINVAL);
  	}
  
@@@ -12804,7 -12805,7 +12835,11 @@@ int bpf_link__update_map(struct bpf_lin
  		return -EINVAL;
  
  	if (map->fd < 0) {
++<<<<<<< HEAD
 +		pr_warn("map '%s': can't use BPF map without FD (was it created?)\n", map->name);
++=======
+ 		pr_warn("map '%s': can't use BPF map w/o FD (did you load it?)\n", map->name);
++>>>>>>> bpf: check bpf_map/bpf_program fd validity
  		return -EINVAL;
  	}
  

@kernel-patches-daemon-bpf
Copy link
Author

At least one diff in series https://patchwork.kernel.org/project/netdevbpf/list/?series=836080 irrelevant now. Closing PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant