Skip to content

Commit

Permalink
bpf: Allow cgroup sock filters to use get_current_uid_gid helper
Browse files Browse the repository at this point in the history
Allow BPF programs run on sock create to use the get_current_uid_gid
helper. IPv4 and IPv6 sockets are created in a process context so
there is always a valid uid/gid

Signed-off-by: David Ahern <[email protected]>
Acked-by: Alexei Starovoitov <[email protected]>
Acked-by: Daniel Borkmann <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
dsahern authored and davem330 committed Sep 1, 2017
1 parent 482dca9 commit ae2cf1c
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion net/core/filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -3149,6 +3149,20 @@ bpf_base_func_proto(enum bpf_func_id func_id)
}
}

static const struct bpf_func_proto *
sock_filter_func_proto(enum bpf_func_id func_id)
{
switch (func_id) {
/* inet and inet6 sockets are created in a process
* context so there is always a valid uid/gid
*/
case BPF_FUNC_get_current_uid_gid:
return &bpf_get_current_uid_gid_proto;
default:
return bpf_base_func_proto(func_id);
}
}

static const struct bpf_func_proto *
sk_filter_func_proto(enum bpf_func_id func_id)
{
Expand Down Expand Up @@ -4233,7 +4247,7 @@ const struct bpf_verifier_ops lwt_xmit_prog_ops = {
};

const struct bpf_verifier_ops cg_sock_prog_ops = {
.get_func_proto = bpf_base_func_proto,
.get_func_proto = sock_filter_func_proto,
.is_valid_access = sock_filter_is_valid_access,
.convert_ctx_access = sock_filter_convert_ctx_access,
};
Expand Down

0 comments on commit ae2cf1c

Please sign in to comment.