netfilter updates for net-next (batch 3)
Subsystems (3)
[email protected]
maintainercover netfilter updates for net-next (batch 3)
From: Pablo Neira Ayuso <[email protected]>
Hi David,
The following patchset provides fixes for issues that were recently introduced by my new cthelper infrastructure. They have been spotted by Randy Dunlap, Andrew Morton and Dan Carpenter.
The patches provide:
* compilation fixes if CONFIG_NF_CONNTRACK is disabled: I moved all the conntrack code from nfnetlink_queue.c to nfnetlink_queue_ct.c to avoid peppering the entire code with lots of ifdefs. I needed to rename nfnetlink_queue.c to nfnetlink_queue_core.c to get it working with the Makefile tweaks I've added.
* fix NULL pointer dereference via ctnetlink while trying to change the helper for an existing conntrack entry. I don't find any reasonable use case for changing the helper from one to another in run-time. Thus, now ctnetlink returns -EOPNOTSUPP for this operation.
* fix possible out-of-bound zeroing of the conntrack extension area due to the helper automatic assignation routine.
You can pull these changes from:
git://1984.lsi.us.es/nf-next master
Thanks!
Pablo Neira Ayuso (4):
netfilter: ctnetlink: fix NULL dereference while trying to change helper
netfilter: nf_ct_helper: disable automatic helper re-assignment of different type
netfilter: fix compilation of the nfnl_cthelper if NF_CONNTRACK is unset
netfilter: nfnetlink_queue: fix compilation with NF_CONNTRACK disabled
include/net/netfilter/nfnetlink_queue.h | 43 +++++++++
net/netfilter/Kconfig | 29 ++++--
net/netfilter/Makefile | 4 +-
net/netfilter/nf_conntrack_helper.c | 8 +-
net/netfilter/nf_conntrack_netlink.c | 24 ++---
.../{nfnetlink_queue.c => nfnetlink_queue_core.c} | 49 ++--------
net/netfilter/nfnetlink_queue_ct.c | 97 ++++++++++++++++++++
7 files changed, 187 insertions(+), 67 deletions(-)
create mode 100644 include/net/netfilter/nfnetlink_queue.h
rename net/netfilter/{nfnetlink_queue.c => nfnetlink_queue_core.c} (95%)
create mode 100644 net/netfilter/nfnetlink_queue_ct.cSignature · 1 line
1.7.10
[email protected]
maintainerPATCH 1/4 netfilter: ctnetlink: fix NULL dereference while trying to change helper
From: Pablo Neira Ayuso <[email protected]>
The patch 1afc56794e03: "netfilter: nf_ct_helper: implement variable length helper private data" from Jun 7, 2012, leads to the following Smatch complaint:
net/netfilter/nf_conntrack_netlink.c:1231 ctnetlink_change_helper()
error: we previously assumed 'help->helper' could be null (see line 1228)
This NULL dereference can be triggered with the following sequence:
1) attach the helper for first time when the conntrack is created.
2) remove the helper module or detach the helper from the conntrack via ctnetlink.
3) attach helper again (the same or different one, no matter) to the that existing conntrack again via ctnetlink.
This patch fixes the problem by removing the use case that allows you to re-assign again a helper for one conntrack entry via ctnetlink since I cannot find any practical use for it.
--- net/netfilter/nf_conntrack_netlink.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-)
net/netfilter/nf_conntrack_netlink.c +3 -10
@@ -1224,19 +1224,12 @@ ctnetlink_change_helper(struct nf_conn *ct, const struct nlattr * const cda[])if (helper->from_nlattr && helpinfo) helper->from_nlattr (helpinfo, ct);return 0 ; - } -if (help->helper) + }else return -EBUSY ; -/* need to zero data of old helper */ -memset (help->data,0 , help->helper->data_len); - }else { -/* we cannot set a helper for an existing conntrack */ -return -EOPNOTSUPP ; } -rcu_assign_pointer (help->helper, helper); - -return 0 ; +/* we cannot set a helper for an existing conntrack */ +return -EOPNOTSUPP ; } static inline int
Signature · 1 line
1.7.10
[email protected]
maintainerPATCH 2/4 netfilter: nf_ct_helper: disable automatic helper re-assignment of different type
In reply to [email protected]From: Pablo Neira Ayuso <[email protected]>
This patch modifies __nf_ct_try_assign_helper in a way that invalidates support for the following scenario:
1) attach the helper A for first time when the conntrack is created
2) attach new (different) helper B due to changes the reply tuple caused by NAT
eg. port redirection from TCP/21 to TCP/5060 with both FTP and SIP helpers loaded, which seems to be a quite unorthodox scenario.
I can provide a more elaborated patch to support this scenario but explicit helper attachment provides a better solution for this since now the use can attach the helpers consistently, without relying on the automatic helper lookup magic.
This patch fixes a possible out of bound zeroing of the conntrack helper extension if the helper B uses more memory for its private data than helper A.
--- net/netfilter/nf_conntrack_helper.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
net/netfilter/nf_conntrack_helper.c +7 -1
@@ -229,7 +229,13 @@ int __nf_ct_try_assign_helper(struct nf_conn *ct, struct nf_conn *tmpl, goto out; } }else { -memset (help->data,0 , helper->data_len); +/* We only allow helper re-assignment of the same sort since +* we cannot reallocate the helper extension area. +*/ +if (help->helper != helper) { +RCU_INIT_POINTER (help->helper,NULL ); + goto out; + } }rcu_assign_pointer (help->helper, helper);
Signature · 1 line
1.7.10
[email protected]
maintainerPATCH 3/4 netfilter: fix compilation of the nfnl_cthelper if NF_CONNTRACK is unset
In reply to [email protected]From: Pablo Neira Ayuso <[email protected]>
This patch fixes the compilation of net/netfilter/nfnetlink_cthelper.c if CONFIG_NF_CONNTRACK is not set.
This patch also moves the definition of the cthelper infrastructure to the scope of NF_CONNTRACK things.
I have also renamed NETFILTER_NETLINK_CTHELPER by NF_CT_NETLINK_HELPER, to use similar names to other nf_conntrack_netlink extensions. Better now that this has been only for two days in David's tree.
Two new dependencies have been added:
* NF_CT_NETLINK
* NETFILTER_NETLINK_QUEUE
Since these infrastructure requires both ctnetlink and nfqueue.
--- net/netfilter/Kconfig | 20 ++++++++++++-------- net/netfilter/Makefile | 2 +- 2 files changed, 13 insertions(+), 9 deletions(-)
net/netfilter/Kconfig +12 -8
@@ -12,14 +12,6 @@ tristate "Netfilter NFACCT over NFNETLINK interface" If this option is enabled, the kernel will include support for extended accounting via NFNETLINK. -config NETFILTER_NETLINK_CTHELPER -tristate "Netfilter CTHELPER over NFNETLINK interface" - depends on NETFILTER_ADVANCED - select NETFILTER_NETLINK - help - If this option is enabled, the kernel will include support - for user-space connection tracking helpers via NFNETLINK. - config NETFILTER_NETLINK_QUEUE tristate "Netfilter NFQUEUE over NFNETLINK interface" depends on NETFILTER_ADVANCED
@@ -343,6 +335,18 @@ config NF_CT_NETLINK_TIMEOUT If unsure, say `N'. +config NF_CT_NETLINK_HELPER + tristate 'Connection tracking helpers in user-space via Netlink' + select NETFILTER_NETLINK + depends on NF_CT_NETLINK + depends on NETFILTER_NETLINK_QUEUE + depends on NETFILTER_ADVANCED + help + This option enables the user-space connection tracking helpers + infrastructure. + + If unsure, say `N'. + endif # NF_CONNTRACK # transparent proxy support
net/netfilter/Makefile +1 -1
@@ -9,7 +9,6 @@ obj-$(CONFIG_NETFILTER) = netfilter.o obj-$(CONFIG_NETFILTER_NETLINK) += nfnetlink.o obj-$(CONFIG_NETFILTER_NETLINK_ACCT) += nfnetlink_acct.o -obj-$(CONFIG_NETFILTER_NETLINK_CTHELPER) += nfnetlink_cthelper.o obj-$(CONFIG_NETFILTER_NETLINK_QUEUE) += nfnetlink_queue.o obj-$(CONFIG_NETFILTER_NETLINK_LOG) += nfnetlink_log.o
@@ -25,6 +24,7 @@ obj-$(CONFIG_NF_CT_PROTO_UDPLITE) += nf_conntrack_proto_udplite.o # netlink interface for nf_conntrack obj-$(CONFIG_NF_CT_NETLINK) += nf_conntrack_netlink.o obj-$(CONFIG_NF_CT_NETLINK_TIMEOUT) += nfnetlink_cttimeout.o +obj-$(CONFIG_NF_CT_NETLINK_HELPER) += nfnetlink_cthelper.o # connection tracking helpers nf_conntrack_h323-objs := nf_conntrack_h323_main.o nf_conntrack_h323_asn1.o
Signature · 1 line
1.7.10
[email protected]
maintainerPATCH 4/4 netfilter: nfnetlink_queue: fix compilation with NF_CONNTRACK disabled
In reply to [email protected]From: Pablo Neira Ayuso <[email protected]>
In "9cb0176 netfilter: add glue code to integrate nfnetlink_queue and ctnetlink" the compilation with NF_CONNTRACK disabled is broken. This patch fixes this issue.
I have moved the conntrack part into nfnetlink_queue_ct.c to avoid peppering the entire nfnetlink_queue.c code with ifdefs.
I also needed to rename nfnetlink_queue.c to nfnetlink_queue_pkt.c to update the net/netfilter/Makefile to support conditional compilation of the conntrack integration.
This patch also adds CONFIG_NETFILTER_QUEUE_CT in case you want to explicitly disable the integration between nf_conntrack and nfnetlink_queue.
---
include/net/netfilter/nfnetlink_queue.h | 43 +++++++++
net/netfilter/Kconfig | 9 ++
net/netfilter/Makefile | 2 +
net/netfilter/nf_conntrack_netlink.c | 11 +--
.../{nfnetlink_queue.c => nfnetlink_queue_core.c} | 49 ++--------
net/netfilter/nfnetlink_queue_ct.c | 97 ++++++++++++++++++++
6 files changed, 164 insertions(+), 47 deletions(-)
create mode 100644 include/net/netfilter/nfnetlink_queue.h
rename net/netfilter/{nfnetlink_queue.c => nfnetlink_queue_core.c} (95%)
create mode 100644 net/netfilter/nfnetlink_queue_ct.cinclude/net/netfilter/nfnetlink_queue.h new file +43 -0
@@ -0,0 +1,43 @@ +#ifndef _NET_NFNL_QUEUE_H_ +#define _NET_NFNL_QUEUE_H_ + +#include <linux/netfilter/nf_conntrack_common.h> + +struct nf_conn ; + +#if defined(CONFIG_NF_CONNTRACK ) || defined(CONFIG_NF_CONNTRACK_MODULE ) +struct nf_conn *nfqnl_ct_get (struct sk_buff *entskb,size_t *size, +enum ip_conntrack_info *ctinfo); +struct nf_conn *nfqnl_ct_parse (const struct sk_buff *skb, +const struct nlattr *attr, +enum ip_conntrack_info *ctinfo); +int nfqnl_ct_put (struct sk_buff *skb,struct nf_conn *ct, +enum ip_conntrack_info ctinfo); +void nfqnl_ct_seq_adjust (struct sk_buff *skb,struct nf_conn *ct, +enum ip_conntrack_info ctinfo,int diff); +#else +inline struct nf_conn * +nfqnl_ct_get (struct sk_buff *entskb,size_t *size,enum ip_conntrack_info *ctinfo) +{ +return NULL ; +} + +inline struct nf_conn *nfqnl_ct_parse (const struct sk_buff *skb, +const struct nlattr *attr, +enum ip_conntrack_info *ctinfo) +{ +return NULL ; +} + +inline int +nfqnl_ct_put (struct sk_buff *skb,struct nf_conn *ct,enum ip_conntrack_info ctinfo) +{ +return 0 ; +} + +inline void nfqnl_ct_seq_adjust (struct sk_buff *skb,struct nf_conn *ct, +enum ip_conntrack_info ctinfo,int diff) +{ +} +#endif /* NF_CONNTRACK */ +#endif
net/netfilter/Kconfig +9 -0
@@ -340,6 +340,7 @@ config NF_CT_NETLINK_HELPER select NETFILTER_NETLINK depends on NF_CT_NETLINK depends on NETFILTER_NETLINK_QUEUE + depends on NETFILTER_NETLINK_QUEUE_CT depends on NETFILTER_ADVANCED help This option enables the user-space connection tracking helpers
@@ -347,6 +348,14 @@ config NF_CT_NETLINK_HELPER If unsure, say `N'. +config NETFILTER_NETLINK_QUEUE_CT + bool "NFQUEUE integration with Connection Tracking" + default n + depends on NETFILTER_NETLINK_QUEUE + help + If this option is enabled, NFQUEUE can include Connection Tracking + information together with the packet is the enqueued via NFNETLINK. + endif # NF_CONNTRACK # transparent proxy support
net/netfilter/Makefile +2 -0
@@ -9,6 +9,8 @@ obj-$(CONFIG_NETFILTER) = netfilter.o obj-$(CONFIG_NETFILTER_NETLINK) += nfnetlink.o obj-$(CONFIG_NETFILTER_NETLINK_ACCT) += nfnetlink_acct.o +nfnetlink_queue-y := nfnetlink_queue_core.o +nfnetlink_queue-$(CONFIG_NETFILTER_NETLINK_QUEUE_CT) += nfnetlink_queue_ct.o obj-$(CONFIG_NETFILTER_NETLINK_QUEUE) += nfnetlink_queue.o obj-$(CONFIG_NETFILTER_NETLINK_LOG) += nfnetlink_log.o
net/netfilter/nf_conntrack_netlink.c +4 -7
@@ -1627,8 +1627,7 @@ ctnetlink_new_conntrack(struct sock *ctnl, struct sk_buff *skb,return err; } -#if defined(CONFIG_NETFILTER_NETLINK_QUEUE ) || \ - defined(CONFIG_NETFILTER_NETLINK_QUEUE_MODULE ) +#ifdef CONFIG_NETFILTER_NETLINK_QUEUE_CT static size_t ctnetlink_nfqueue_build_size (const struct nf_conn *ct) {
@@ -1762,7 +1761,7 @@ static struct nfq_ct_hook ctnetlink_nfqueue_hook = { .seq_adjust = nf_nat_tcp_seq_adjust, #endif }; -#endif /* CONFIG_NETFILTER_NETLINK_QUEUE */ +#endif /* CONFIG_NETFILTER_NETLINK_QUEUE_CT */ /*********************************************************************** * EXPECT
@@ -2568,8 +2567,7 @@ static int __init ctnetlink_init(void)pr_err ("ctnetlink_init: cannot register pernet operations\n" ); goto err_unreg_exp_subsys; } -#if defined(CONFIG_NETFILTER_NETLINK_QUEUE ) || \ - defined(CONFIG_NETFILTER_NETLINK_QUEUE_MODULE ) +#ifdef CONFIG_NETFILTER_NETLINK_QUEUE_CT /* setup interaction between nf_queue and nf_conntrack_netlink. */ RCU_INIT_POINTER (nfq_ct_hook, &ctnetlink_nfqueue_hook);#endif
@@ -2590,8 +2588,7 @@ static void __exit ctnetlink_exit(void)unregister_pernet_subsys (&ctnetlink_net_ops);nfnetlink_subsys_unregister (&ctnl_exp_subsys);nfnetlink_subsys_unregister (&ctnl_subsys); -#if defined(CONFIG_NETFILTER_NETLINK_QUEUE ) || \ - defined(CONFIG_NETFILTER_NETLINK_QUEUE_MODULE ) +#ifdef CONFIG_NETFILTER_NETLINK_QUEUE_CT RCU_INIT_POINTER (nfq_ct_hook,NULL );#endif }
net/netfilter/nfnetlink_queue_core.c renamed from net/netfilter/nfnetlink_queue.c +9 -40
91 lines not on this page · raw message
net/netfilter/nfnetlink_queue_ct.c new file +97 -0
97 lines not on this page · raw message
Signature · 1 line
1.7.10
David Miller
maintainerFrom: [email protected]
Date: Tue, 19 Jun 2012 05:16:25 +0200
Quoted 13 lines
The patches provide:
* compilation fixes if
CONFIG_NF_CONNTRACKis disabled: I moved all the conntrack code fromnfnetlink_queue.ctonfnetlink_queue_ct.cto avoid peppering the entire code with lots of ifdefs. I needed to renamenfnetlink_queue.ctonfnetlink_queue_core.cto get it working with theMakefiletweaks I've added.* fix NULL pointer dereference via ctnetlink while trying to change the helper for an existing conntrack entry. I don't find any reasonable use case for changing the helper from one to another in run-time. Thus, now ctnetlink returns
-EOPNOTSUPPfor this operation.
Quoted 6 lines
* fix possible out-of-bound zeroing of the conntrack extension area due to the helper automatic assignation routine.
You can pull these changes from:
git://1984.lsi.us.es/nf-nextmaster
Pulled, thanks.
Pablo Neira Ayuso
maintainerOn Tue, Jun 19, 2012 at 05:16:25AM +0200, [email protected] wrote:
[...]
Quoted 3 lines
You can pull these changes from:
git://1984.lsi.us.es/nf-nextmaster
Please, also take the small patch attached after this 4 patch series. It fixes one linking issue.
Sorry, I'll put more care next time testing compilation options more extensively.
Quoted 1 line
From
af6b248c22759fb7448668bbe495f1cbe0a9109dMon Sep 17 00:00:00 2001
From: Pablo Neira Ayuso <[email protected]>
Date: Tue, 19 Jun 2012 05:25:46 +0200
Subject: [PATCH] netfilter: fix missing symbols if
CONFIG_NETFILTER_NETLINK_QUEUE_CT unset
ERROR: "nfqnl_ct_parse" [net/netfilter/nfnetlink_queue.ko] undefined!
ERROR: "nfqnl_ct_seq_adjust" [net/netfilter/nfnetlink_queue.ko] undefined!
ERROR: "nfqnl_ct_put" [net/netfilter/nfnetlink_queue.ko] undefined!
ERROR: "nfqnl_ct_get" [net/netfilter/nfnetlink_queue.ko] undefined!
We have to use CONFIG_NETFILTER_NETLINK_QUEUE_CT in include/net/netfilter/nfnetlink_queue.h, not CONFIG_NF_CONNTRACK.
--- include/net/netfilter/nfnetlink_queue.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/net/netfilter/nfnetlink_queue.h +1 -1
@@ -5,7 +5,7 @@struct nf_conn ; -#if defined(CONFIG_NF_CONNTRACK ) || defined(CONFIG_NF_CONNTRACK_MODULE ) +#ifdef CONFIG_NETFILTER_NETLINK_QUEUE_CT struct nf_conn *nfqnl_ct_get (struct sk_buff *entskb,size_t *size,enum ip_conntrack_info *ctinfo); struct nf_conn *nfqnl_ct_parse(const struct sk_buff *skb,
Signature · 1 line
1.7.10
David Miller
maintainerFrom: Pablo Neira Ayuso <[email protected]>
Date: Tue, 19 Jun 2012 05:37:45 +0200
Quoted 11 lines · On Tue, Jun 19, 2012 at 05:16:25AM +0200, [email protected] wrote:
[...]
Quoted 3 lines
You can pull these changes from:
git://1984.lsi.us.es/nf-nextmasterPlease, also take the small patch attached after this 4 patch series. It fixes one linking issue.
Sorry, I'll put more care next time testing compilation options more extensively.
Done.