Netfilter fixes for net
Subsystems (4)
Pablo Neira Ayuso
maintainercover Netfilter fixes for net
Hi David,
The following patchset contains Netfilter fixes for your net tree. This batch mostly comes with patches to address fallout from the previous merge window cycle, they are:
1) Use entry->state.hook_list from nf_queue() instead of the global nf_hooks which is not valid when used from NFPROTO_NETDEV, this should cause no problems though since we have no userspace queueing for that family, but let's fix this now for the sake of correctness. Patch from Eric W. Biederman.
2) Fix compilation breakage in bridge netfilter if CONFIG_NF_DEFRAG_IPV4 is not set, from Bernhard Thaler.
3) Use percpu jumpstack in arptables too, now that there's a single copy of the rule blob we can't store the return address there anymore. Patch from Florian Westphal.
4) Fix a skb leak in the xmit path of bridge netfilter, problem there since 2.6.37 although it should be not possible to hit invalid traffic there, also from Florian.
5) Eric Leblond reports that when loading a large ruleset with many missing modules after a fresh boot, nf_tables can take long time commit it. Fix this by processing the full batch until the end, even on missing modules, then abort only once and restart processing.
6) Add bridge netfilter files to the MAINTAINER files.
7) Fix a net_device refcount leak in the new IPV6 bridge netfilter code, from Julien Grall.
You can pull these changes from:
git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf.git
Thanks!
----------------------------------------------------------------
The following changes since commit 4da3064d1775810f10f7ddc1c34c3f1ff502a654:
Merge tag 'devicetree-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/glikely/linux (2015-07-01 19:40:18 -0700)
are available in the git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf.git master
for you to fetch changes up to 86e8971800381c3a8d8d9327f83b1f97ccb04a4f:
netfilter: bridge: Use __in6_dev_get rather than in6_dev_get in br_validate_ipv6 (2015-07-08 11:02:16 +0200)
----------------------------------------------------------------
Bernhard Thaler (1):
netfilter: bridge: fix CONFIG_NF_DEFRAG_IPV4/6 related warnings/errors
Eric W. Biederman (1):
netfilter: nf_queue: Don't recompute the hook_list head
Florian Westphal (2):
netfilter: arptables: use percpu jumpstack
netfilter: bridge: don't leak skb in error paths
Julien Grall (1):
netfilter: bridge: Use __in6_dev_get rather than in6_dev_get in br_validate_ipv6
Pablo Neira Ayuso (2):
netfilter: nfnetlink: keep going batch handling on missing modules
MAINTAINER: add bridge netfilter
MAINTAINERS | 1 + net/bridge/br_netfilter_hooks.c | 16 +++++++++++----- net/bridge/br_netfilter_ipv6.c | 2 +- net/ipv4/netfilter/arp_tables.c | 25 ++++++++++++++++--------- net/netfilter/nf_queue.c | 2 +- net/netfilter/nfnetlink.c | 38 +++++++++++++++++++++++++------------- 6 files changed, 55 insertions(+), 29 deletions(-)
Pablo Neira Ayuso
maintainerPATCH 4/7 netfilter: bridge: don't leak skb in error paths
From: Florian Westphal <[email protected]>
br_nf_dev_queue_xmit must free skb in its error path. NF_DROP is misleading -- its an okfn, not a netfilter hook.
--- net/bridge/br_netfilter_hooks.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
net/bridge/br_netfilter_hooks.c +8 -4
@@ -744,7 +744,7 @@ static int br_nf_dev_queue_xmit(struct sock *sk, struct sk_buff *skb)struct brnf_frag_data *data;if (br_validate_ipv4 (skb)) -return NF_DROP ; + goto drop;IPCB (skb)->frag_max_size = nf_bridge->frag_max_size;
@@ -769,7 +769,7 @@ static int br_nf_dev_queue_xmit(struct sock *sk, struct sk_buff *skb)struct brnf_frag_data *data;if (br_validate_ipv6 (skb)) -return NF_DROP ; + goto drop;IP6CB (skb)->frag_max_size = nf_bridge->frag_max_size;
@@ -784,12 +784,16 @@ static int br_nf_dev_queue_xmit(struct sock *sk, struct sk_buff *skb)if (v6ops)return v6ops->fragment (sk, skb, br_nf_push_frag_xmit); -else - return -EMSGSIZE; + +kfree_skb (skb); + return -EMSGSIZE; }#endif nf_bridge_info_free (skb);return br_dev_queue_push_xmit (sk, skb); + drop: +kfree_skb (skb); +return 0 ; }/* PF_BRIDGE/POST_ROUTING ********************************************/
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 5/7 netfilter: nfnetlink: keep going batch handling on missing modules
In reply to Pablo Neira AyusoAfter a fresh boot with no modules in place at all and a large rulesets, the existing nfnetlink_rcv_batch() funcion can take long time to commit the ruleset due to the many abort path. This is specifically a problem for the existing client of this code, ie. nf_tables, since it results in several synchronize_rcu() call in a row.
This patch changes the policy to keep full batch processing on missing modules errors so we abort only once.
--- net/netfilter/nfnetlink.c | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-)
net/netfilter/nfnetlink.c +25 -13
@@ -269,6 +269,12 @@ static void nfnl_err_deliver(struct list_head *err_list, struct sk_buff *skb) } } +enum { +NFNL_BATCH_FAILURE = (1 <<0 ), +NFNL_BATCH_DONE = (1 <<1 ), +NFNL_BATCH_REPLAY = (1 <<2 ), +}; +static void nfnetlink_rcv_batch (struct sk_buff *skb,struct nlmsghdr *nlh,u_int16_t subsys_id) {
@@ -276,13 +282,15 @@ static void nfnetlink_rcv_batch(struct sk_buff *skb, struct nlmsghdr *nlh,struct net *net =sock_net (skb->sk);const struct nfnetlink_subsystem *ss;const struct nfnl_callback *nc; -bool success = true, done = false;static LIST_HEAD (err_list); +u32 status;int err;if (subsys_id >=NFNL_SUBSYS_COUNT )return netlink_ack (skb, nlh, -EINVAL ); replay: + status =0 ; + skb =netlink_skb_clone (oskb,GFP_KERNEL );if (!skb)return netlink_ack (oskb, nlh, -ENOMEM );
@@ -336,10 +344,10 @@ replay:if (type ==NFNL_MSG_BATCH_BEGIN ) {/* Malformed: Batch begin twice */ nfnl_err_reset (&err_list); - success = false; + status |=NFNL_BATCH_FAILURE ; goto done; }else if (type ==NFNL_MSG_BATCH_END ) { - done = true; + status |=NFNL_BATCH_DONE ; goto done; }else if (type <NLMSG_MIN_TYPE ) { err = -EINVAL ;
@@ -382,11 +390,8 @@ replay:* original skb. */ if (err == -EAGAIN ) { -nfnl_err_reset (&err_list); - ss->abort (oskb); -nfnl_unlock (subsys_id); -kfree_skb (skb); - goto replay; + status |=NFNL_BATCH_REPLAY ; + goto next; } } ack:
@@ -402,7 +407,7 @@ ack:*/ nfnl_err_reset (&err_list);netlink_ack (skb,nlmsg_hdr (oskb), -ENOMEM ); - success = false; + status |=NFNL_BATCH_FAILURE ; goto done; }/* We don't stop processing the batch on errors, thus,
@@ -410,19 +415,26 @@ ack:* triggers. */ if (err) - success = false; + status |=NFNL_BATCH_FAILURE ; } - +next: msglen =NLMSG_ALIGN (nlh->nlmsg_len);if (msglen > skb->len) msglen = skb->len;skb_pull (skb, msglen); } done: -if (success && done) +if (status &NFNL_BATCH_REPLAY ) { + ss->abort (oskb); +nfnl_err_reset (&err_list); +nfnl_unlock (subsys_id); +kfree_skb (skb); + goto replay; + }else if (status ==NFNL_BATCH_DONE ) { ss->commit (oskb); -else + }else { ss->abort (oskb); + }nfnl_err_deliver (&err_list, oskb);nfnl_unlock (subsys_id);
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 1/7 netfilter: nf_queue: Don't recompute the hook_list head
In reply to Pablo Neira AyusoFrom: "Eric W. Biederman" <[email protected]>
If someone sends packets from one of the netdevice ingress hooks to the a userspace queue, and then userspace later accepts the packet, the netfilter code can enter an infinite loop as the list head will never be found.
Pass in the saved list_head to avoid this.
--- net/netfilter/nf_queue.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/nf_queue.c +1 -1
@@ -213,7 +213,7 @@ void nf_reinject(struct nf_queue_entry *entry, unsigned int verdict)if (verdict ==NF_ACCEPT ) { next_hook: - verdict =nf_iterate (&nf_hooks[entry->state.pf][entry->state.hook], + verdict =nf_iterate (entry->state.hook_list, skb, &entry->state, &elem); }
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 3/7 netfilter: arptables: use percpu jumpstack
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
commit 482cfc318559 ("netfilter: xtables: avoid percpu ruleset duplication")
Unlike ip and ip6tables, arp tables were never converted to use the percpu jump stack.
It still uses the rule blob to store return address, which isn't safe anymore since we now share this blob among all processors.
Because there is no TEE support for arptables, we don't need to cope with reentrancy, so we can use loocal variable to hold stack offset.
--- net/ipv4/netfilter/arp_tables.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-)
net/ipv4/netfilter/arp_tables.c +16 -9
@@ -254,9 +254,10 @@ unsigned int arpt_do_table(struct sk_buff *skb, static const char nulldevname[IFNAMSIZ] __attribute__((aligned(sizeof(long))));unsigned int verdict =NF_DROP ;const struct arphdr *arp; -struct arpt_entry *e, *back; +struct arpt_entry *e, **jumpstack;const char *indev, *outdev;const void *table_base; +unsigned int cpu, stackidx =0 ;const struct xt_table_info *private;struct xt_action_param acpar;unsigned int addend;
@@ -270,15 +271,16 @@ unsigned int arpt_do_table(struct sk_buff *skb,local_bh_disable (); addend =xt_write_recseq_begin (); private = table->private; + cpu =smp_processor_id ();/* * Ensure we load private-> members after we've fetched the base * pointer. */ smp_read_barrier_depends (); table_base = private->entries; + jumpstack = (struct arpt_entry **)private->jumpstack[cpu]; e =get_entry (table_base, private->hook_entry[hook]); - back =get_entry (table_base, private->underflow[hook]); acpar.in = state->in; acpar.out = state->out;
@@ -312,18 +314,23 @@ unsigned int arpt_do_table(struct sk_buff *skb, verdict = (unsigned int )(-v) -1 ;break ; } - e = back; - back =get_entry (table_base, back->comefrom); +if (stackidx ==0 ) { + e =get_entry (table_base, + private->underflow[hook]); + }else { + e = jumpstack[--stackidx]; + e =arpt_next_entry (e); + }continue ; }if (table_base + v !=arpt_next_entry (e)) { -/* Save old back ptr in next entry */ -struct arpt_entry *next =arpt_next_entry (e); - next->comefrom = (void *)back - table_base; -/* set back pointer to next entry */ - back = next; +if (stackidx >= private->stacksize) { + verdict =NF_DROP ; +break ; + } + jumpstack[stackidx++] = e; } e =get_entry (table_base, v);
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 2/7 netfilter: bridge: fix CONFIG_NF_DEFRAG_IPV4/6 related warnings/errors
In reply to Pablo Neira AyusoFrom: Bernhard Thaler <[email protected]>
br_nf_ip_fragment() is not needed when neither CONFIG_NF_DEFRAG_IPV4 nor CONFIG_NF_DEFRAG_IPV6 is set.
struct brnf_frag_data must be available if either CONFIG_NF_DEFRAG_IPV4 or CONFIG_NF_DEFRAG_IPV6 is set.
--- net/bridge/br_netfilter_hooks.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
net/bridge/br_netfilter_hooks.c +3 -1
@@ -111,7 +111,7 @@ static inline __be16 pppoe_proto(const struct sk_buff *skb)/* largest possible L2 header, see br_nf_dev_queue_xmit() */ #define NF_BRIDGE_MAX_MAC_HEADER_LENGTH (PPPOE_SES_HLEN + ETH_HLEN) -#if IS_ENABLED(CONFIG_NF_DEFRAG_IPV4) +#if IS_ENABLED(CONFIG_NF_DEFRAG_IPV4) || IS_ENABLED(CONFIG_NF_DEFRAG_IPV6) struct brnf_frag_data { char mac[NF_BRIDGE_MAX_MAC_HEADER_LENGTH]; u8 encap_size;
@@ -694,6 +694,7 @@ static int br_nf_push_frag_xmit(struct sock *sk, struct sk_buff *skb) }#endif +#if IS_ENABLED (CONFIG_NF_DEFRAG_IPV4 )static int br_nf_ip_fragment (struct sock *sk,struct sk_buff *skb,int (*output)(struct sock *,struct sk_buff *)) {
@@ -712,6 +713,7 @@ static int br_nf_ip_fragment(struct sock *sk, struct sk_buff *skb, return ip_do_fragment(sk, skb, output); } +#endif static unsigned int nf_bridge_mtu_reduction (const struct sk_buff *skb) {
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 6/7 MAINTAINER: add bridge netfilter
In reply to Pablo Neira AyusoSo scripts/get_maintainer.pl shows the Netfilter mailing lists.
--- MAINTAINERS | 1 + 1 file changed, 1 insertion(+)
MAINTAINERS +1 -0
@@ -6996,6 +6996,7 @@ F: include/uapi/linux/netfilter/ F: net/*/netfilter.c F: net/*/netfilter/ F: net/netfilter/ +F: net/bridge/br_netfilter*.c NETLABEL M: Paul Moore <[email protected]>
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 7/7 netfilter: bridge: Use __in6_dev_get rather than in6_dev_get in br_validate_ipv6
In reply to Pablo Neira AyusoFrom: Julien Grall <[email protected]>
The commit efb6de9b4ba0092b2c55f6a52d16294a8a698edd "netfilter: bridge:
forward IPv6 fragmented packets" introduced a new function br_validate_ipv6 which take a reference on the inet6 device. Although, the reference is not released at the end.
This will result to the impossibility to destroy any netdevice using ipv6 and bridge.
It's possible to directly retrieve the inet6 device without taking a reference as all netfilter hooks are protected by rcu_read_lock via nf_hook_slow.
Spotted while trying to destroy a Xen guest on the upstream Linux:
"unregister_netdevice: waiting for vif1.0 to become free. Usage count = 1"
--- net/bridge/br_netfilter_ipv6.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/bridge/br_netfilter_ipv6.c +1 -1
@@ -104,7 +104,7 @@ int br_validate_ipv6(struct sk_buff *skb) {const struct ipv6hdr *hdr;struct net_device *dev = skb->dev; -struct inet6_dev *idev =in6_dev_get (skb->dev); +struct inet6_dev *idev =__in6_dev_get (skb->dev);u32 pkt_len;u8 ip6h_len =sizeof (struct ipv6hdr );
Signature · 1 line
1.7.10.4
David Miller
maintainerFrom: Pablo Neira Ayuso <[email protected]>
Date: Wed, 8 Jul 2015 11:48:13 +0200
Quoted 3 lines
You can pull these changes from:
git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf.git
Pulled, thanks a lot Pablo.