netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Daniel Borkmann <dborkman@redhat.com>
To: davem@davemloft.net
Cc: netdev@vger.kernel.org
Subject: [PATCH net-next 1/2] bpf_dbg: always close socket in bpf_runnable
Date: Mon, 16 Dec 2013 11:45:00 +0100	[thread overview]
Message-ID: <1387190701-1893-2-git-send-email-dborkman@redhat.com> (raw)
In-Reply-To: <1387190701-1893-1-git-send-email-dborkman@redhat.com>

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>
---
 tools/net/bpf_dbg.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/net/bpf_dbg.c b/tools/net/bpf_dbg.c
index 0fdcb70..65dc757 100644
--- a/tools/net/bpf_dbg.c
+++ b/tools/net/bpf_dbg.c
@@ -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) {
-- 
1.8.3.1

  reply	other threads:[~2013-12-16 10:45 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-16 10:44 [PATCH net-next 0/2] two bpf tools fixes Daniel Borkmann
2013-12-16 10:45 ` Daniel Borkmann [this message]
2013-12-16 10:45 ` [PATCH net-next 2/2] bpf_exp: free duplicated labels at exit time Daniel Borkmann
2013-12-17 22:11 ` [PATCH net-next 0/2] two bpf tools fixes David Miller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1387190701-1893-2-git-send-email-dborkman@redhat.com \
    --to=dborkman@redhat.com \
    --cc=davem@davemloft.net \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).