Netfilter updates for net-next
Subsystems (5)
Pablo Neira Ayuso
maintainercover Netfilter updates for net-next
Hi David,
The following patchset contains Netfilter updates for net-next. Basically, more incremental updates for br_netfilter from Florian Westphal, small nf_tables updates (including one fix for rb-tree locking) and small two-liner to add extra validation for the REJECT6 target.
More specifically, they are:
1) Use the conntrack status flags from br_netfilter to know that DNAT is happening. Patch for Florian Westphal.
2) nf_bridge->physoutdev == NULL already indicates that the traffic is bridged, so let's get rid of the BRNF_BRIDGED flag. Also from Florian.
3) Another patch to prepare voidization of seq_printf/seq_puts/seq_putc, from Joe Perches.
4) Consolidation of nf_tables_newtable() error path.
5) Kill nf_bridge_pad used by br_netfilter from ip_fragment(), from Florian Westphal.
6) Access rb-tree root node inside the lock and remove unnecessary locking from the get path (we already hold nfnl_lock there), from Patrick McHardy.
7) You cannot use a NFT_SET_ELEM_INTERVAL_END when the set doesn't support interval, also from Patrick.
8) Enforce IP6T_F_PROTO from ip6t_REJECT to make sure the core is actually restricting matches to TCP.
You can pull these changes from:
git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf-next.git
Thanks!
----------------------------------------------------------------
The following changes since commit 169bf9121b19dd6029e0a354d33513f61bfbe3d3:
tipc: ensure that idle links are deleted when a bearer is disabled (2015-03-10 18:37:36 -0400)
are available in the git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf-next.git master
for you to fetch changes up to e35158e40110270600698f19bda5e21d8ce709d7:
netfilter: ip6t_REJECT: check for IP6T_F_PROTO (2015-03-22 20:02:46 +0100)
----------------------------------------------------------------
Florian Westphal (3):
netfilter: bridge: query conntrack about skb dnat
netfilter: bridge: remove BRNF_STATE_BRIDGED flag
netfilter: bridge: kill nf_bridge_pad
Joe Perches (1):
netfilter: Remove uses of seq_<foo> return values
Pablo Neira Ayuso (2):
netfilter: nf_tables: consolidate error path of nf_tables_newtable()
netfilter: ip6t_REJECT: check for IP6T_F_PROTO
Patrick McHardy (2):
netfilter: nft_rbtree: fix locking
netfilter: nf_tables: reject NFT_SET_ELEM_INTERVAL_END flag for non-interval sets
include/linux/netfilter_bridge.h | 29 ------------ net/bridge/br_netfilter.c | 48 ++++++++++++++++---- net/ipv4/ip_output.c | 5 +- .../netfilter/nf_conntrack_l3proto_ipv4_compat.c | 4 +- net/ipv6/netfilter/ip6t_REJECT.c | 3 +- net/netfilter/nf_conntrack_acct.c | 8 ++-- net/netfilter/nf_conntrack_expect.c | 4 +- net/netfilter/nf_tables_api.c | 23 ++++++---- net/netfilter/nfnetlink_log.c | 12 +++-- net/netfilter/nft_rbtree.c | 6 +-- net/netfilter/xt_physdev.c | 3 +- 11 files changed, 77 insertions(+), 68 deletions(-)
Pablo Neira Ayuso
maintainerPATCH 1/8 netfilter: bridge: query conntrack about skb dnat
From: Florian Westphal <[email protected]>
ask conntrack instead of storing ipv4 address in nf_bridge_info->data.
Ths avoids the need to use ->data during NF_PRE_ROUTING. Only two functions that need ->data remain.
These will be addressed in followup patches.
--- include/linux/netfilter_bridge.h | 6 ------ net/bridge/br_netfilter.c | 27 +++++++++++++++++++++------ 2 files changed, 21 insertions(+), 12 deletions(-)
include/linux/netfilter_bridge.h +0 -6
@@ -54,12 +54,6 @@ static inline unsigned int nf_bridge_pad(const struct sk_buff *skb)return 0 ; } -struct bridge_skb_cb { -union { -__be32 ipv4; - } daddr; -}; -static inline void br_drop_fake_rtable (struct sk_buff *skb) {struct dst_entry *dst =skb_dst (skb);
net/bridge/br_netfilter.c +21 -6
@@ -37,17 +37,16 @@#include <net/route.h> #include <net/netfilter/br_netfilter.h> +#if IS_ENABLED (CONFIG_NF_CONNTRACK ) +#include <net/netfilter/nf_conntrack.h> +#endif +#include <asm/uaccess.h> #include "br_private.h" #ifdef CONFIG_SYSCTL #include <linux/sysctl.h> #endif -#define skb_origaddr (skb) (((struct bridge_skb_cb *) \ - (skb->nf_bridge->data))->daddr.ipv4) -#define store_orig_dstaddr (skb) (skb_origaddr(skb) = ip_hdr(skb)->daddr) -#define dnat_took_place (skb) (skb_origaddr(skb) != ip_hdr(skb)->daddr) -#ifdef CONFIG_SYSCTL static struct ctl_table_header *brnf_sysctl_header;static int brnf_call_iptables__read_mostly =1 ;
@@ -322,6 +321,22 @@ free_skb:return 0 ; } +static bool dnat_took_place (const struct sk_buff *skb) +{ +#if IS_ENABLED (CONFIG_NF_CONNTRACK ) +enum ip_conntrack_info ctinfo; +struct nf_conn *ct; + + ct =nf_ct_get (skb, &ctinfo); +if (!ct ||nf_ct_is_untracked (ct)) +return false; + +return test_bit (IPS_DST_NAT_BIT , &ct->status); +#else +return false; +#endif +} +/* This requires some explaining. If DNAT has taken place, * we will need to fix up the destination Ethernet address. *
@@ -625,7 +640,7 @@ static unsigned int br_nf_pre_routing(const struct nf_hook_ops *ops,return NF_DROP ;if (!setup_pre_routing (skb))return NF_DROP ; -store_orig_dstaddr (skb); + skb->protocol =htons (ETH_P_IP ); NF_HOOK(NFPROTO_IPV4, NF_INET_PRE_ROUTING, skb, skb->dev, NULL,
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 2/8 netfilter: bridge: remove BRNF_STATE_BRIDGED flag
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
Its not needed anymore since 2bf540b73ed5b
([NETFILTER]: bridge-netfilter: remove deferred hooks). Before this it was possible to have physoutdev set for locally generated packets -- this isn't the case anymore:
BRNF_STATE_BRIDGED flag is set when we assign nf_bridge->physoutdev, so physoutdev != NULL means BRNF_STATE_BRIDGED is set.
If physoutdev is NULL, then we are looking at locally-delivered and routed packet.
--- include/linux/netfilter_bridge.h | 1 - net/bridge/br_netfilter.c | 9 ++++++--- net/netfilter/xt_physdev.c | 3 +-- 3 files changed, 7 insertions(+), 6 deletions(-)
include/linux/netfilter_bridge.h +0 -1
@@ -19,7 +19,6 @@ enum nf_br_hook_priorities {#define BRNF_PKT_TYPE 0x01#define BRNF_BRIDGED_DNAT 0x02 -#define BRNF_BRIDGED 0x04#define BRNF_NF_BRIDGE_PREROUTING 0x08#define BRNF_8021Q 0x10#define BRNF_PPPoE 0x20
net/bridge/br_netfilter.c +6 -3
@@ -736,8 +736,6 @@ static unsigned int br_nf_forward_ip(const struct nf_hook_ops *ops,if (pf ==NFPROTO_IPV4 &&br_parse_ip_options (skb))return NF_DROP ; -/* The physdev module checks on this */ - nf_bridge->mask |=BRNF_BRIDGED ; nf_bridge->physoutdev = skb->dev;if (pf ==NFPROTO_IPV4 ) skb->protocol =htons (ETH_P_IP );
@@ -857,7 +855,12 @@ static unsigned int br_nf_post_routing(const struct nf_hook_ops *ops,struct net_device *realoutdev =bridge_parent (skb->dev);u_int8_t pf; -if (!nf_bridge || !(nf_bridge->mask &BRNF_BRIDGED )) +/* if nf_bridge is set, but ->physoutdev is NULL, this packet came in +* on a bridge, but was delivered locally and is now being routed: +* +* POST_ROUTING was already invoked from the ip stack. +*/ +if (!nf_bridge || !nf_bridge->physoutdev)return NF_ACCEPT ;if (!realoutdev)
net/netfilter/xt_physdev.c +1 -2
@@ -56,8 +56,7 @@ physdev_mt(const struct sk_buff *skb, struct xt_action_param *par)/* This only makes sense in the FORWARD and POSTROUTING chains */ if ((info->bitmask &XT_PHYSDEV_OP_BRIDGED ) && - (!!(nf_bridge->mask &BRNF_BRIDGED ) ^ - !(info->invert &XT_PHYSDEV_OP_BRIDGED ))) + (!!nf_bridge->physoutdev ^ !(info->invert &XT_PHYSDEV_OP_BRIDGED )))return false; if ((info->bitmask & XT_PHYSDEV_OP_ISIN &&
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 3/8 netfilter: Remove uses of seq_<foo> return values
In reply to Pablo Neira AyusoFrom: Joe Perches <[email protected]>
The seq_printf/seq_puts/seq_putc return values, because they are frequently misused, will eventually be converted to void.
See: commit 1f33c41c03da ("seq_file: Rename seq_overflow() to
seq_has_overflowed() and make public")
Miscellanea:
o realign arguments
--- net/ipv4/netfilter/nf_conntrack_l3proto_ipv4_compat.c | 4 +++- net/netfilter/nf_conntrack_acct.c | 8 +++++--- net/netfilter/nf_conntrack_expect.c | 4 +++- net/netfilter/nfnetlink_log.c | 12 +++++++----- 4 files changed, 18 insertions(+), 10 deletions(-)
net/ipv4/netfilter/nf_conntrack_l3proto_ipv4_compat.c +3 -1
@@ -300,7 +300,9 @@ static int exp_seq_show(struct seq_file *s, void *v)__nf_ct_l3proto_find (exp->tuple.src.l3num),__nf_ct_l4proto_find (exp->tuple.src.l3num, exp->tuple.dst.protonum)); -return seq_putc (s,'\n' ); +seq_putc (s,'\n' ); + +return 0 ; }static const struct seq_operations exp_seq_ops = {
net/netfilter/nf_conntrack_acct.c +5 -3
@@ -47,9 +47,11 @@ seq_print_acct(struct seq_file *s, const struct nf_conn *ct, int dir)return 0 ; counter = acct->counter; -return seq_printf (s,"packets=%llu bytes=%llu " , - (unsigned long long )atomic64_read (&counter[dir].packets), - (unsigned long long )atomic64_read (&counter[dir].bytes)); +seq_printf (s,"packets=%llu bytes=%llu " , + (unsigned long long )atomic64_read (&counter[dir].packets), + (unsigned long long )atomic64_read (&counter[dir].bytes)); + +return 0 ; };EXPORT_SYMBOL_GPL (seq_print_acct);
net/netfilter/nf_conntrack_expect.c +3 -1
@@ -561,7 +561,9 @@ static int exp_seq_show(struct seq_file *s, void *v) helper->expect_policy[expect->class].name); } -return seq_putc (s,'\n' ); +seq_putc (s,'\n' ); + +return 0 ; }static const struct seq_operations exp_seq_ops = {
net/netfilter/nfnetlink_log.c +7 -5
@@ -998,11 +998,13 @@ static int seq_show(struct seq_file *s, void *v) {const struct nfulnl_instance *inst = v; -return seq_printf (s,"%5d %6d %5d %1d %5d %6d %2d\n" , - inst->group_num, - inst->peer_portid, inst->qlen, - inst->copy_mode, inst->copy_range, - inst->flushtimeout,atomic_read (&inst->use)); +seq_printf (s,"%5d %6d %5d %1d %5d %6d %2d\n" , + inst->group_num, + inst->peer_portid, inst->qlen, + inst->copy_mode, inst->copy_range, + inst->flushtimeout,atomic_read (&inst->use)); + +return 0 ; }static const struct seq_operations nful_seq_ops = {
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 4/8 netfilter: nf_tables: consolidate error path of nf_tables_newtable()
In reply to Pablo Neira Ayuso--- net/netfilter/nf_tables_api.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-)
net/netfilter/nf_tables_api.c +11 -9
@@ -687,11 +687,10 @@ static int nf_tables_newtable(struct sock *nlsk, struct sk_buff *skb,if (!try_module_get (afi->owner))return -EAFNOSUPPORT ; + err = -ENOMEM ; table =kzalloc (sizeof (*table),GFP_KERNEL ); -if (table ==NULL ) { -module_put (afi->owner); -return -ENOMEM ; - } +if (table ==NULL ) + goto err1;nla_strlcpy (table->name, name,NFT_TABLE_MAXNAMELEN );INIT_LIST_HEAD (&table->chains);
@@ -700,13 +699,16 @@ static int nf_tables_newtable(struct sock *nlsk, struct sk_buff *skb,nft_ctx_init (&ctx, skb, nlh, afi, table,NULL , nla); err =nft_trans_table_add (&ctx,NFT_MSG_NEWTABLE ); -if (err <0 ) { -kfree (table); -module_put (afi->owner); -return err; - } +if (err <0 ) + goto err2; +list_add_tail_rcu (&table->list, &afi->tables);return 0 ; +err2: +kfree (table); +err1: +module_put (afi->owner); +return err; }static int nft_flush_table (struct nft_ctx *ctx)
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 6/8 netfilter: nft_rbtree: fix locking
In reply to Pablo Neira AyusoFrom: Patrick McHardy <[email protected]>
Fix a race condition and unnecessary locking:
* the root rb_node must only be accessed under the lock in nft_rbtree_lookup()
* the lock is not needed in lookup functions in netlink context
--- net/netfilter/nft_rbtree.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
net/netfilter/nft_rbtree.c +2 -4
@@ -37,10 +37,11 @@ static bool nft_rbtree_lookup(const struct nft_set *set, {const struct nft_rbtree *priv =nft_set_priv (set);const struct nft_rbtree_elem *rbe, *interval =NULL ; -const struct rb_node *parent = priv->root.rb_node; +const struct rb_node *parent;int d;spin_lock_bh (&nft_rbtree_lock); + parent = priv->root.rb_node;while (parent !=NULL ) { rbe = rb_entry(parent, struct nft_rbtree_elem, node);
@@ -158,7 +159,6 @@ static int nft_rbtree_get(const struct nft_set *set, struct nft_set_elem *elem)struct nft_rbtree_elem *rbe;int d; -spin_lock_bh (&nft_rbtree_lock);while (parent !=NULL ) { rbe = rb_entry(parent, struct nft_rbtree_elem, node);
@@ -173,11 +173,9 @@ static int nft_rbtree_get(const struct nft_set *set, struct nft_set_elem *elem) !(rbe->flags & NFT_SET_ELEM_INTERVAL_END))nft_data_copy (&elem->data, rbe->data); elem->flags = rbe->flags; -spin_unlock_bh (&nft_rbtree_lock);return 0 ; } } -spin_unlock_bh (&nft_rbtree_lock);return -ENOENT ; }
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 7/8 netfilter: nf_tables: reject NFT_SET_ELEM_INTERVAL_END flag for non-interval sets
In reply to Pablo Neira AyusoFrom: Patrick McHardy <[email protected]>
--- net/netfilter/nf_tables_api.c | 3 +++ 1 file changed, 3 insertions(+)
net/netfilter/nf_tables_api.c +3 -0
@@ -3138,6 +3138,9 @@ static int nft_add_set_elem(struct nft_ctx *ctx, struct nft_set *set, elem.flags =ntohl (nla_get_be32 (nla[NFTA_SET_ELEM_FLAGS ]));if (elem.flags & ~NFT_SET_ELEM_INTERVAL_END )return -EINVAL ; +if (!(set->flags &NFT_SET_INTERVAL ) && + elem.flags &NFT_SET_ELEM_INTERVAL_END ) +return -EINVAL ; }if (set->flags &NFT_SET_MAP ) {
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 8/8 netfilter: ip6t_REJECT: check for IP6T_F_PROTO
In reply to Pablo Neira AyusoMake sure IP6T_F_PROTO is set to enforce layer 4 protocol matching from the ip6_tables core.
--- net/ipv6/netfilter/ip6t_REJECT.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
net/ipv6/netfilter/ip6t_REJECT.c +2 -1
@@ -83,7 +83,8 @@ static int reject_tg6_check(const struct xt_tgchk_param *par)return -EINVAL ; }else if (rejinfo->with ==IP6T_TCP_RESET ) {/* Must specify that it's a TCP packet */ -if (e->ipv6.proto !=IPPROTO_TCP || +if (!(e->ipv6.flags &IP6T_F_PROTO ) || + e->ipv6.proto !=IPPROTO_TCP || (e->ipv6.invflags &XT_INV_PROTO )) {pr_info ("TCP_RESET illegal for non-tcp\n" );return -EINVAL ;
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 5/8 netfilter: bridge: kill nf_bridge_pad
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
The br_netfilter frag output function calls skb_cow_head() so in case it needs a larger headroom to e.g. re-add a previously stripped PPPOE or VLAN header things will still work (at cost of reallocation).
We can then move nf_bridge_encap_header_len to br_netfilter.
--- include/linux/netfilter_bridge.h | 22 ---------------------- net/bridge/br_netfilter.c | 12 ++++++++++++ net/ipv4/ip_output.c | 5 +---- 3 files changed, 13 insertions(+), 26 deletions(-)
include/linux/netfilter_bridge.h +0 -22
@@ -23,18 +23,6 @@ enum nf_br_hook_priorities {#define BRNF_8021Q 0x10#define BRNF_PPPoE 0x20 -static inline unsigned int nf_bridge_encap_header_len (const struct sk_buff *skb) -{ -switch (skb->protocol) { -case __cpu_to_be16 (ETH_P_8021Q ): -return VLAN_HLEN ; -case __cpu_to_be16 (ETH_P_PPP_SES ): -return PPPOE_SES_HLEN ; -default : -return 0 ; - } -} -static inline unsigned int nf_bridge_mtu_reduction (const struct sk_buff *skb) {if (unlikely (skb->nf_bridge->mask & BRNF_PPPoE))
@@ -44,15 +32,6 @@ static inline unsigned int nf_bridge_mtu_reduction(const struct sk_buff *skb)int br_handle_frame_finish (struct sk_buff *skb); -/* This is called by the IP fragmenting code and it ensures there is -* enough room for the encapsulating header (if there is one). */ -static inline unsigned int nf_bridge_pad (const struct sk_buff *skb) -{ -if (skb->nf_bridge) -return nf_bridge_encap_header_len (skb); -return 0 ; -} -static inline void br_drop_fake_rtable (struct sk_buff *skb) {struct dst_entry *dst =skb_dst (skb);
@@ -62,7 +41,6 @@ static inline void br_drop_fake_rtable(struct sk_buff *skb) }#else -#define nf_bridge_pad (skb) (0)#define br_drop_fake_rtable (skb) do { } while (0)#endif /* CONFIG_BRIDGE_NETFILTER */
net/bridge/br_netfilter.c +12 -0
@@ -153,6 +153,18 @@ static inline struct nf_bridge_info *nf_bridge_unshare(struct sk_buff *skb)return nf_bridge; } +static unsigned int nf_bridge_encap_header_len (const struct sk_buff *skb) +{ +switch (skb->protocol) { +case __cpu_to_be16 (ETH_P_8021Q ): +return VLAN_HLEN ; +case __cpu_to_be16 (ETH_P_PPP_SES ): +return PPPOE_SES_HLEN ; +default : +return 0 ; + } +} +static inline void nf_bridge_push_encap_header (struct sk_buff *skb) {unsigned int len =nf_bridge_encap_header_len (skb);
net/ipv4/ip_output.c +1 -4
@@ -636,10 +636,7 @@ slow_path: left = skb->len - hlen;/* Space per frame */ ptr = hlen;/* Where to start from */ -/* for bridged IP traffic encapsulated inside f.e. a vlan header, -* we need to make room for the encapsulating header -*/ - ll_rs =LL_RESERVED_SPACE_EXTRA (rt->dst.dev,nf_bridge_pad (skb)); + ll_rs =LL_RESERVED_SPACE (rt->dst.dev);/* * Fragment the datagram.
Signature · 1 line
1.7.10.4
David Miller
maintainerFrom: Pablo Neira Ayuso <[email protected]>
Date: Mon, 23 Mar 2015 12:36:16 +0100
Quoted 7 lines
The following patchset contains Netfilter updates for net-next. Basically, more incremental updates for
br_netfilterfrom Florian Westphal, smallnf_tablesupdates (including one fix for rb-tree locking) and small two-liner to add extra validation for the REJECT6 target.More specifically, they are:
...
Quoted 3 lines
You can pull these changes from:
git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf-next.git
Pulled, thanks a lot Pablo.