Netfilter fixes for net
Subsystems (3)
Pablo Neira Ayuso
maintainercover Netfilter fixes for net
Hi David,
The following patch contains Netfilter fixes for your net tree, they are:
1) nf_log_unregister() should only set to NULL the logger that is being unregistered, instead of everything else. Patch from Florian Westphal.
2) Fix a crash when accessing physoutdev from PREROUTING in br_netfilter. This is partially reverting the patch to shrink nf_bridge_info to 32 bytes. Also from Florian.
3) Use existing match/target extensions in the internal nft_compat extension lists when the extension is family unspecific (ie. NFPROTO_UNSPEC).
4) Wait for rcu grace period before leaving nf_log_unregister().
You can pull these changes from:
git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf.git
Thanks!
----------------------------------------------------------------
The following changes since commit e8684c88774c0ddfeefdbed0aa469b25b9962f3e:
irda: ali-ircc: Fix deadlock in ali_ircc_sir_change_speed() (2015-09-11 16:18:33 -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 ad5001cc7cdf9aaee5eb213fdee657e4a3c94776:
netfilter: nf_log: wait for rcu grace after logger unregistration (2015-09-17 13:37:31 +0200)
----------------------------------------------------------------
Florian Westphal (2):
netfilter: nf_log: don't zap all loggers on unregister
netfilter: bridge: fix routing of bridge frames with call-iptables=1
Pablo Neira Ayuso (2):
netfilter: nft_compat: skip family comparison in case of NFPROTO_UNSPEC
netfilter: nf_log: wait for rcu grace after logger unregistration
include/linux/skbuff.h | 6 +++--- net/netfilter/nf_log.c | 9 +++++++-- net/netfilter/nft_compat.c | 24 ++++++++++++++++++------ 3 files changed, 28 insertions(+), 11 deletions(-)
Pablo Neira Ayuso
maintainerPATCH 1/4 netfilter: nf_log: don't zap all loggers on unregister
From: Florian Westphal <[email protected]>
like nf_log_unset, nf_log_unregister must not reset the list of loggers. Otherwise, a call to nf_log_unregister() will render loggers of other nf protocols unusable:
iptables -A INPUT -j LOG
modprobe nf_log_arp ; rmmod nf_log_arp
iptables -A INPUT -j LOG
iptables: No chain/target/match by that name
--- net/netfilter/nf_log.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
net/netfilter/nf_log.c +6 -2
@@ -107,11 +107,15 @@ EXPORT_SYMBOL(nf_log_register);void nf_log_unregister (struct nf_logger *logger) { +const struct nf_logger *log;int i;mutex_lock (&nf_log_mutex); -for (i =0 ; i <NFPROTO_NUMPROTO ; i++) -RCU_INIT_POINTER (loggers[i][logger->type],NULL ); +for (i =0 ; i <NFPROTO_NUMPROTO ; i++) { + log =nft_log_dereference (loggers[i][logger->type]); +if (log == logger) +RCU_INIT_POINTER (loggers[i][logger->type],NULL ); + }mutex_unlock (&nf_log_mutex); }EXPORT_SYMBOL (nf_log_unregister);
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 2/4 netfilter: bridge: fix routing of bridge frames with call-iptables=1
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
We can't re-use the physoutdev storage area.
1. When using NFQUEUE in PREROUTING, we attempt to bump a bogus refcnt since nf_bridge->physoutdev is garbage (ipv4/ipv6 address)
2. for same reason, we crash in physdev match in FORWARD or later if skb is routed instead of bridged.
This increases nf_bridge_info to 40 bytes, but we have no other choice.
--- include/linux/skbuff.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
include/linux/skbuff.h +3 -3
@@ -179,6 +179,9 @@ struct nf_bridge_info { u8 bridged_dnat:1;__u16 frag_max_size;struct net_device *physindev; + +/* always valid & non-NULL from FORWARD on, for physdev match */ +struct net_device *physoutdev;union {/* prerouting: detect dnat in orig/reply direction */ __be32 ipv4_daddr;
@@ -189,9 +192,6 @@ struct nf_bridge_info {* skb is out in neigh layer. */ char neigh_header[8]; - -/* always valid & non-NULL from FORWARD on, for physdev match */ - struct net_device *physoutdev; }; };#endif
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 3/4 netfilter: nft_compat: skip family comparison in case of NFPROTO_UNSPEC
In reply to Pablo Neira AyusoFix lookup of existing match/target structures in the corresponding list by skipping the family check if NFPROTO_UNSPEC is used.
This is resulting in the allocation and insertion of one match/target structure for each use of them. So this not only bloats memory consumption but also severely affects the time to reload the ruleset from the iptables-compat utility.
After this patch, iptables-compat-restore and iptables-compat take almost the same time to reload large rulesets.
--- net/netfilter/nft_compat.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-)
net/netfilter/nft_compat.c +18 -6
@@ -619,6 +619,13 @@ struct nft_xt {static struct nft_expr_type nft_match_type; +static bool nft_match_cmp (const struct xt_match *match, +const char *name,u32 rev,u32 family) +{ +return strcmp (match->name, name) ==0 && match->revision == rev && + (match->family ==NFPROTO_UNSPEC || match->family == family); +} +static const struct nft_expr_ops *nft_match_select_ops (const struct nft_ctx *ctx,const struct nlattr *const tb[])
@@ -626,7 +633,7 @@ nft_match_select_ops(const struct nft_ctx *ctx,struct nft_xt *nft_match;struct xt_match *match;char *mt_name; -__u32 rev, family; +u32 rev, family; if (tb[NFTA_MATCH_NAME] == NULL || tb[NFTA_MATCH_REV] == NULL ||
@@ -641,8 +648,7 @@ nft_match_select_ops(const struct nft_ctx *ctx,list_for_each_entry (nft_match, &nft_match_list, head) {struct xt_match *match = nft_match->ops.data; -if (strcmp (match->name, mt_name) ==0 && - match->revision == rev && match->family == family) { +if (nft_match_cmp (match, mt_name, rev, family)) {if (!try_module_get (match->me))return ERR_PTR (-ENOENT );
@@ -693,6 +699,13 @@ static LIST_HEAD(nft_target_list);static struct nft_expr_type nft_target_type; +static bool nft_target_cmp (const struct xt_target *tg, +const char *name,u32 rev,u32 family) +{ +return strcmp (tg->name, name) ==0 && tg->revision == rev && + (tg->family ==NFPROTO_UNSPEC || tg->family == family); +} +static const struct nft_expr_ops *nft_target_select_ops (const struct nft_ctx *ctx,const struct nlattr *const tb[])
@@ -700,7 +713,7 @@ nft_target_select_ops(const struct nft_ctx *ctx,struct nft_xt *nft_target;struct xt_target *target;char *tg_name; -__u32 rev, family; +u32 rev, family; if (tb[NFTA_TARGET_NAME] == NULL || tb[NFTA_TARGET_REV] == NULL ||
@@ -715,8 +728,7 @@ nft_target_select_ops(const struct nft_ctx *ctx,list_for_each_entry (nft_target, &nft_target_list, head) {struct xt_target *target = nft_target->ops.data; -if (strcmp (target->name, tg_name) ==0 && - target->revision == rev && target->family == family) { +if (nft_target_cmp (target, tg_name, rev, family)) {if (!try_module_get (target->me))return ERR_PTR (-ENOENT );
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 4/4 netfilter: nf_log: wait for rcu grace after logger unregistration
In reply to Pablo Neira AyusoThe nf_log_unregister() function needs to call synchronize_rcu() to make sure that the objects are not dereferenced anymore on module removal.
--- net/netfilter/nf_log.c | 1 + 1 file changed, 1 insertion(+)
net/netfilter/nf_log.c +1 -0
@@ -117,6 +117,7 @@ void nf_log_unregister(struct nf_logger *logger)RCU_INIT_POINTER (loggers[i][logger->type],NULL ); }mutex_unlock (&nf_log_mutex); +synchronize_rcu (); }EXPORT_SYMBOL (nf_log_unregister);
Signature · 1 line
1.7.10.4
David Miller
maintainerFrom: Pablo Neira Ayuso <[email protected]>
Date: Fri, 18 Sep 2015 11:17:52 +0200
Quoted 9 lines
The following patch contains Netfilter fixes for your net tree, they are:
1)
nf_log_unregister()should only set to NULL the logger that is being unregistered, instead of everything else. Patch from Florian Westphal.2) Fix a crash when accessing physoutdev from PREROUTING in
br_netfilter. This is partially reverting the patch to shrinknf_bridge_infoto 32 bytes. Also from Florian.
Quoted 8 lines
3) Use existing match/target extensions in the internal
nft_compatextension lists when the extension is family unspecific (ie.NFPROTO_UNSPEC).4) Wait for rcu grace period before leaving
nf_log_unregister().You can pull these changes from:
git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf.git
Pulled, thanks Pablo.