Skip to content

Commit 1b51423

Browse files
lmbAlexei Starovoitov
authored and
Alexei Starovoitov
committed
bpf: flow_dissector: Check value of unused flags to BPF_PROG_ATTACH
Using BPF_PROG_ATTACH on a flow dissector program supports neither target_fd, attach_flags or replace_bpf_fd but accepts any value. Enforce that all of them are zero. This is fine for replace_bpf_fd since its presence is indicated by BPF_F_REPLACE. It's more problematic for target_fd, since zero is a valid fd. Should we want to use the flag later on we'd have to add an exception for fd 0. The alternative is to force a value like -1. This requires more changes to tests. There is also precedent for using 0, since bpf_iter uses this for target_fd as well. Fixes: b27f7bb ("flow_dissector: Move out netns_bpf prog callbacks") Signed-off-by: Lorenz Bauer <[email protected]> Signed-off-by: Alexei Starovoitov <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent 951f38c commit 1b51423

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

kernel/bpf/net_namespace.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,9 @@ int netns_bpf_prog_attach(const union bpf_attr *attr, struct bpf_prog *prog)
209209
struct net *net;
210210
int ret;
211211

212+
if (attr->target_fd || attr->attach_flags || attr->replace_bpf_fd)
213+
return -EINVAL;
214+
212215
type = to_netns_bpf_attach_type(attr->attach_type);
213216
if (type < 0)
214217
return -EINVAL;

0 commit comments

Comments
 (0)