Browse Source

bpf_dbg: always close socket in bpf_runnable

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>
Daniel Borkmann 11 years ago
parent
commit
8b138da62f
1 changed files with 1 additions and 1 deletions
  1. 1 1
      tools/net/bpf_dbg.c

+ 1 - 1
tools/net/bpf_dbg.c

@@ -512,11 +512,11 @@ static bool bpf_runnable(struct sock_filter *f, unsigned int len)
 		return false;
 		return false;
 	}
 	}
 	ret = setsockopt(sock, SOL_SOCKET, SO_ATTACH_FILTER, &bpf, sizeof(bpf));
 	ret = setsockopt(sock, SOL_SOCKET, SO_ATTACH_FILTER, &bpf, sizeof(bpf));
+	close(sock);
 	if (ret < 0) {
 	if (ret < 0) {
 		rl_printf("program not allowed to run by kernel!\n");
 		rl_printf("program not allowed to run by kernel!\n");
 		return false;
 		return false;
 	}
 	}
-	close(sock);
 	for (i = 0; i < len; i++) {
 	for (i = 0; i < len; i++) {
 		if (BPF_CLASS(f[i].code) == BPF_LD &&
 		if (BPF_CLASS(f[i].code) == BPF_LD &&
 		    f[i].k > SKF_AD_OFF) {
 		    f[i].k > SKF_AD_OFF) {