Skip to content

Commit

Permalink
bpf: program: Refuse non-O_RDWR flags in BPF_OBJ_GET
Browse files Browse the repository at this point in the history
As for bpf_link, refuse creating a non-O_RDWR fd. Since program fds
currently don't allow modifications this is a precaution, not a
straight up bug fix.

Signed-off-by: Lorenz Bauer <[email protected]>
Signed-off-by: Alexei Starovoitov <[email protected]>
Acked-by: Andrii Nakryiko <[email protected]>
Acked-by: Daniel Borkmann <[email protected]>
Link: https://lore.kernel.org/bpf/[email protected]
  • Loading branch information
lmb authored and Alexei Starovoitov committed Apr 1, 2021
1 parent 25fc94b commit d37300e
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion kernel/bpf/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ int bpf_obj_get_user(const char __user *pathname, int flags)
return PTR_ERR(raw);

if (type == BPF_TYPE_PROG)
ret = bpf_prog_new_fd(raw);
ret = (f_flags != O_RDWR) ? -EINVAL : bpf_prog_new_fd(raw);
else if (type == BPF_TYPE_MAP)
ret = bpf_map_new_fd(raw, f_flags);
else if (type == BPF_TYPE_LINK)
Expand Down

0 comments on commit d37300e

Please sign in to comment.