diff options
author | Daniel Borkmann <daniel@iogearbox.net> | 2016-06-30 17:24:44 +0200 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2016-07-01 16:00:47 -0400 |
commit | 113214be7f6c98dd6d0435e4765aea8dea91662c (patch) | |
tree | 31d2c41c7af6991401c3aff11e7ade3317b4a614 /net/packet | |
parent | 1aacde3d22c42281236155c1ef6d7a5aa32a826b (diff) | |
download | talos-obmc-linux-113214be7f6c98dd6d0435e4765aea8dea91662c.tar.gz talos-obmc-linux-113214be7f6c98dd6d0435e4765aea8dea91662c.zip |
bpf: refactor bpf_prog_get and type check into helper
Since bpf_prog_get() and program type check is used in a couple of places,
refactor this into a small helper function that we can make use of. Since
the non RO prog->aux part is not used in performance critical paths and a
program destruction via RCU is rather very unlikley when doing the put, we
shouldn't have an issue just doing the bpf_prog_get() + prog->type != type
check, but actually not taking the ref at all (due to being in fdget() /
fdput() section of the bpf fd) is even cleaner and makes the diff smaller
as well, so just go for that. Callsites are changed to make use of the new
helper where possible.
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/packet')
-rw-r--r-- | net/packet/af_packet.c | 6 |
1 files changed, 1 insertions, 5 deletions
diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c index d1f3b9e977e5..48b58957adf4 100644 --- a/net/packet/af_packet.c +++ b/net/packet/af_packet.c @@ -1588,13 +1588,9 @@ static int fanout_set_data_ebpf(struct packet_sock *po, char __user *data, if (copy_from_user(&fd, data, len)) return -EFAULT; - new = bpf_prog_get(fd); + new = bpf_prog_get_type(fd, BPF_PROG_TYPE_SOCKET_FILTER); if (IS_ERR(new)) return PTR_ERR(new); - if (new->type != BPF_PROG_TYPE_SOCKET_FILTER) { - bpf_prog_put(new); - return -EINVAL; - } __fanout_set_data_bpf(po->fanout, new); return 0; |