Skip to content

Commit

Permalink
bpf_dbg: always close socket in bpf_runnable
Browse files Browse the repository at this point in the history
We must not leave the socket intact in bpf_runnable(). The socket
is used to test if the filter code is being accepted by the kernel
or not. So right after we do the setsockopt(2), we need to close
it again.

Signed-off-by: Daniel Borkmann <dborkman@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Daniel Borkmann authored and David S. Miller committed Dec 17, 2013
1 parent 5c509a2 commit 8b138da
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion tools/net/bpf_dbg.c
Original file line number Diff line number Diff line change
Expand Up @@ -512,11 +512,11 @@ static bool bpf_runnable(struct sock_filter *f, unsigned int len)
return false;
}
ret = setsockopt(sock, SOL_SOCKET, SO_ATTACH_FILTER, &bpf, sizeof(bpf));
close(sock);
if (ret < 0) {
rl_printf("program not allowed to run by kernel!\n");
return false;
}
close(sock);
for (i = 0; i < len; i++) {
if (BPF_CLASS(f[i].code) == BPF_LD &&
f[i].k > SKF_AD_OFF) {
Expand Down

0 comments on commit 8b138da

Please sign in to comment.