From: Daniel Mack <daniel@zonque.org>
To: pablo@netfilter.org
Cc: daniel@iogearbox.net, netfilter-devel@vger.kernel.org,
netdev@vger.kernel.org, fw@strlen.de,
balazs.scheidler@balabit.com, Daniel Mack <daniel@zonque.org>
Subject: [PATCH RFC 2/3] netfilter: nft_meta: mark skbs for postponed filter processing
Date: Wed, 16 Sep 2015 17:42:59 +0200 [thread overview]
Message-ID: <1442418180-14322-3-git-send-email-daniel@zonque.org> (raw)
In-Reply-To: <1442418180-14322-1-git-send-email-daniel@zonque.org>
When the cgroup matching code in nft_meta is called without a socket to
look at, it currently bails out and lets the packet pass. This is bad,
because the reason for skb->sk being NULL is simply that the packet was
directed to a socket that hasn't been looked up yet by early demux.
This patch does two things:
a) it uses the newly introduced pkt->sk pointer rather than skb->sk
to check for the net class ID. This allows us to look at the socket
the user passed into nf_hook().
b) in case the socket can't be accessed, it marks the skb as
'nf_postponed', so that later dispatchers have a chance to
re-iterate the chain for such packets, after a full demux was
conducted.
Note that the added flag in 'struct skb' does not increase the size
of the struct, as it fits in the 'flags1' bitfield.
Signed-off-by: Daniel Mack <daniel@zonque.org>
---
include/linux/skbuff.h | 3 ++-
net/netfilter/nft_meta.c | 9 ++++++---
2 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
index 2738d35..3590101 100644
--- a/include/linux/skbuff.h
+++ b/include/linux/skbuff.h
@@ -584,7 +584,8 @@ struct sk_buff {
fclone:2,
peeked:1,
head_frag:1,
- xmit_more:1;
+ xmit_more:1,
+ nf_postponed:1;
/* one bit hole */
kmemcheck_bitfield_end(flags1);
diff --git a/net/netfilter/nft_meta.c b/net/netfilter/nft_meta.c
index cb2f13e..33b8d23 100644
--- a/net/netfilter/nft_meta.c
+++ b/net/netfilter/nft_meta.c
@@ -29,8 +29,9 @@ void nft_meta_get_eval(const struct nft_expr *expr,
const struct nft_pktinfo *pkt)
{
const struct nft_meta *priv = nft_expr_priv(expr);
- const struct sk_buff *skb = pkt->skb;
const struct net_device *in = pkt->in, *out = pkt->out;
+ struct sk_buff *skb = pkt->skb;
+ struct sock *sk = pkt->sk;
u32 *dest = ®s->data[priv->dreg];
switch (priv->key) {
@@ -168,9 +169,11 @@ void nft_meta_get_eval(const struct nft_expr *expr,
break;
#ifdef CONFIG_CGROUP_NET_CLASSID
case NFT_META_CGROUP:
- if (skb->sk == NULL || !sk_fullsock(skb->sk))
+ if (sk == NULL || !sk_fullsock(sk)) {
+ skb->nf_postponed = 1;
goto err;
- *dest = skb->sk->sk_classid;
+ }
+ *dest = sk->sk_classid;
break;
#endif
default:
--
2.5.0
next prev parent reply other threads:[~2015-09-16 15:50 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-09-16 15:42 [PATCH RFC 0/3] Allow postponed netfilter handling for socket matches Daniel Mack
2015-09-16 15:42 ` [PATCH RFC 1/3] netfilter: add socket to struct nft_pktinfo Daniel Mack
2015-09-16 15:42 ` Daniel Mack [this message]
2015-09-16 15:43 ` [PATCH RFC 3/3] net: tcp_ipv4: re-run netfilter chains for marked skbs Daniel Mack
2015-09-16 21:21 ` [PATCH RFC 0/3] Allow postponed netfilter handling for socket matches Florian Westphal
2015-09-17 10:04 ` Daniel Mack
2015-09-17 16:00 ` Florian Westphal
2015-09-21 16:52 ` Daniel Mack
2015-09-21 19:05 ` Florian Westphal
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=1442418180-14322-3-git-send-email-daniel@zonque.org \
--to=daniel@zonque.org \
--cc=balazs.scheidler@balabit.com \
--cc=daniel@iogearbox.net \
--cc=fw@strlen.de \
--cc=netdev@vger.kernel.org \
--cc=netfilter-devel@vger.kernel.org \
--cc=pablo@netfilter.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).