netfilter: nf_log: don't zap all loggers on unregister
Subsystems (3)
Pablo Neira Ayuso
maintainerPATCH 1/1 netfilter: nf_log: don't zap all loggers on unregister
From: Florian Westphal <[email protected]>
[ upstream commit 205ee117d4dc4a11ac3bd9638bb9b2e839f4de9a ]
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 1/1 netfilter: nft_compat: fix module refcount underflow
[ upstream commit 520aa7414bb590f39d0d1591b06018e60cbc7cf4 ]
Feb 12 18:20:42 nfdev kernel: ------------[ cut here ]------------ Feb 12 18:20:42 nfdev kernel: WARNING: CPU: 4 PID: 4359 at kernel/module.c:963 module_put+0x9b/0xba() Feb 12 18:20:42 nfdev kernel: CPU: 4 PID: 4359 Comm: ebtables-compat Tainted: G W 3.19.0-rc6+ #43 [...] Feb 12 18:20:42 nfdev kernel: Call Trace: Feb 12 18:20:42 nfdev kernel: [<ffffffff815fd911>] dump_stack+0x4c/0x65 Feb 12 18:20:42 nfdev kernel: [<ffffffff8103e6f7>] warn_slowpath_common+0x9c/0xb6 Feb 12 18:20:42 nfdev kernel: [<ffffffff8109919f>] ? module_put+0x9b/0xba Feb 12 18:20:42 nfdev kernel: [<ffffffff8103e726>] warn_slowpath_null+0x15/0x17 Feb 12 18:20:42 nfdev kernel: [<ffffffff8109919f>] module_put+0x9b/0xba Feb 12 18:20:42 nfdev kernel: [<ffffffff813ecf7c>] nft_match_destroy+0x45/0x4c Feb 12 18:20:42 nfdev kernel: [<ffffffff813e683f>] nf_tables_rule_destroy+0x28/0x70
---
Already in 3.14.x. Please, push this to 3.18 too. Thanks!
net/netfilter/nft_compat.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
net/netfilter/nft_compat.c +10 -2
@@ -578,8 +578,12 @@ nft_match_select_ops(const struct nft_ctx *ctx,struct xt_match *match = nft_match->ops.data;if (strcmp (match->name, mt_name) ==0 && - match->revision == rev && match->family == family) + match->revision == rev && match->family == family) { +if (!try_module_get (match->me)) +return ERR_PTR (-ENOENT ); +return &nft_match->ops; + } } match =xt_request_find_match (family, mt_name, rev);
@@ -648,8 +652,12 @@ nft_target_select_ops(const struct nft_ctx *ctx,struct xt_target *target = nft_target->ops.data;if (strcmp (target->name, tg_name) ==0 && - target->revision == rev && target->family == family) + target->revision == rev && target->family == family) { +if (!try_module_get (target->me)) +return ERR_PTR (-ENOENT ); +return &nft_target->ops; + } } target =xt_request_find_target (family, tg_name, rev);
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 1/1 netfilter: ipt_rpfilter: remove the nh_scope test in rpfilter_lookup_reverse
In reply to Pablo Neira AyusoFrom: lucien <[email protected]>
[ upstream commit cc4998febd567d1c671684abce5595344bd4e8b2 ]
--accept-local option works for res.type == RTN_LOCAL, which should be from the local table, but there, the fib_info's nh->nh_scope = RT_SCOPE_NOWHERE ( > RT_SCOPE_HOST). in fib_create_info().
if (cfg->fc_scope == RT_SCOPE_HOST) {
struct fib_nh *nh = fi->fib_nh;
/* Local address is added. */
if (nhs != 1 || nh->nh_gw)
goto err_inval;
nh->nh_scope = RT_SCOPE_NOWHERE; <===
nh->nh_dev = dev_get_by_index(net, fi->fib_nh->nh_oif);
err = -ENODEV;
if (!nh->nh_dev)
goto failure;but in our rpfilter_lookup_reverse():
if (dev_match || flags & XT_RPFILTER_LOOSE) return FIB_RES_NH(res).nh_scope <= RT_SCOPE_HOST;
if nh->nh_scope > RT_SCOPE_HOST, it will fail. --accept-local option will never be passed.
it seems the test is bogus and can be removed to fix this issue.
if (dev_match || flags & XT_RPFILTER_LOOSE) return FIB_RES_NH(res).nh_scope <= RT_SCOPE_HOST;
ipv6 does not have this issue.
--- net/ipv4/netfilter/ipt_rpfilter.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
net/ipv4/netfilter/ipt_rpfilter.c +1 -3
@@ -61,9 +61,7 @@ static bool rpfilter_lookup_reverse(struct flowi4 *fl4,if (FIB_RES_DEV (res) == dev) dev_match = true;#endif -if (dev_match || flags &XT_RPFILTER_LOOSE ) -return FIB_RES_NH (res).nh_scope <=RT_SCOPE_HOST ; -return dev_match; +return dev_match || flags &XT_RPFILTER_LOOSE ; }static bool rpfilter_is_local (const struct sk_buff *skb)
Signature · 1 line
2.1.4
Re: [PATCH -stable] netfilter: ipt_rpfilter: remove the nh_scope test in rpfilter_lookup_reverse
Quoted 33 lines · Pablo Neira Ayuso
From: lucien <[email protected]>
[ upstream commit
cc4998febd567d1c671684abce5595344bd4e8b2]--accept-local option works for res.type ==
RTN_LOCAL, which should be from the local table, but there, the fib_info'snh->nh_scope=RT_SCOPE_NOWHERE( >RT_SCOPE_HOST). infib_create_info().if (cfg->fc_scope == RT_SCOPE_HOST) { struct fib_nh *nh = fi->fib_nh; /* Local address is added. */ if (nhs != 1 || nh->nh_gw) goto err_inval; nh->nh_scope = RT_SCOPE_NOWHERE; <=== nh->nh_dev = dev_get_by_index(net, fi->fib_nh->nh_oif); err = -ENODEV; if (!nh->nh_dev) goto failure;but in our
rpfilter_lookup_reverse():if (dev_match || flags & XT_RPFILTER_LOOSE) return FIB_RES_NH(res).nh_scope <= RT_SCOPE_HOST;if
nh->nh_scope>RT_SCOPE_HOST, it will fail. --accept-local option will never be passed.it seems the test is bogus and can be removed to fix this issue.
if (dev_match || flags & XT_RPFILTER_LOOSE) return FIB_RES_NH(res).nh_scope <= RT_SCOPE_HOST;
Quoted 6 lines
ipv6 does not have this issue.
Cc <[email protected]> # 3.14.xCc <[email protected]> # 3.18.xCc <[email protected]> # 4.1.xCc <[email protected]> # 4.2.x
Thanks, I'm queuing this one and the next 2 to the 3.16 kernel as well (some of the other patches had already been included).
Cheers,
--
Luís
Quoted 29 lines
Signed-off-by Xin Long <[email protected]>Acked-by Florian Westphal <[email protected]>Signed-off-by Pablo Neira Ayuso <[email protected]>--- net/ipv4/netfilter/ipt_rpfilter.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)net/ipv4/netfilter/ipt_rpfilter.c +1
-3@@ -61,9 +61,7 @@ static bool rpfilter_lookup_reverse(struct flowi4 *fl4,if (FIB_RES_DEV (res) == dev) dev_match = true;#endif -if (dev_match || flags &XT_RPFILTER_LOOSE ) -return FIB_RES_NH (res).nh_scope <=RT_SCOPE_HOST ; -return dev_match; +return dev_match || flags &XT_RPFILTER_LOOSE ; }static bool rpfilter_is_local (const struct sk_buff *skb)Signature · 6 lines
2.1.4 -- To unsubscribe from this list: send the line "unsubscribe stable" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Pablo Neira Ayuso
maintainerPATCH 1/1 netfilter: nft_compat: skip family comparison in case of NFPROTO_UNSPEC
In reply to Pablo Neira Ayuso[ upstream commit ba378ca9c04a5fc1b2cf0f0274a9d02eb3d1bad9 ]
Fix 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 1/1 netfilter: nf_tables: fix bogus warning in nft_data_uninit()
In reply to Pablo Neira AyusoFrom: Mirek Kratochvil <[email protected]>
[ upstream commit 960bd2c26421d321e890f1936938196ead41976f ]
The values 0x00000000-0xfffffeff are reserved for userspace datatype. When, deleting set elements with maps, a bogus warning is triggered.
WARNING: CPU: 0 PID: 11133 at net/netfilter/nf_tables_api.c:4481 nft_data_uninit+0x35/0x40 [nf_tables]()
This fixes the check accordingly to enum definition in include/linux/netfilter/nf_tables.h
--- net/netfilter/nf_tables_api.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/netfilter/nf_tables_api.c +2 -2
@@ -4472,9 +4472,9 @@ EXPORT_SYMBOL_GPL(nft_data_init);*/ void nft_data_uninit (const struct nft_data *data,enum nft_data_types type) { -switch (type) { -case NFT_DATA_VALUE : +if (type <NFT_DATA_VERDICT )return ; +switch (type) {case NFT_DATA_VERDICT :return nft_verdict_uninit (data);default :
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerPATCH 1/1 netfilter: ip6t_SYNPROXY: fix NULL pointer dereference
In reply to Pablo Neira AyusoFrom: Phil Sutter <[email protected]>
[ upstream commit 96fffb4f23f124f297d51dedc9cf51d19eb88ee1 ]
This happens when networking namespaces are enabled.
--- net/ipv6/netfilter/ip6t_SYNPROXY.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-)
net/ipv6/netfilter/ip6t_SYNPROXY.c +10 -8
@@ -37,12 +37,13 @@ synproxy_build_ip(struct sk_buff *skb, const struct in6_addr *saddr, }static void -synproxy_send_tcp (const struct sk_buff *skb,struct sk_buff *nskb, +synproxy_send_tcp (const struct synproxy_net *snet, +const struct sk_buff *skb,struct sk_buff *nskb,struct nf_conntrack *nfct,enum ip_conntrack_info ctinfo,struct ipv6hdr *niph,struct tcphdr *nth,unsigned int tcp_hdr_size) { -struct net *net =nf_ct_net ((struct nf_conn *)nfct); +struct net *net =nf_ct_net (snet->tmpl);struct dst_entry *dst;struct flowi6 fl6;
@@ -83,7 +84,8 @@ free_nskb: }static void -synproxy_send_client_synack (const struct sk_buff *skb,const struct tcphdr *th, +synproxy_send_client_synack (const struct synproxy_net *snet, +const struct sk_buff *skb,const struct tcphdr *th,const struct synproxy_options *opts) {struct sk_buff *nskb;
@@ -119,7 +121,7 @@ synproxy_send_client_synack(const struct sk_buff *skb, const struct tcphdr *th,synproxy_build_options (nth, opts); -synproxy_send_tcp (skb, nskb, skb->nfct,IP_CT_ESTABLISHED_REPLY , +synproxy_send_tcp (snet, skb, nskb, skb->nfct,IP_CT_ESTABLISHED_REPLY , niph, nth, tcp_hdr_size); }
@@ -163,7 +165,7 @@ synproxy_send_server_syn(const struct synproxy_net *snet,synproxy_build_options (nth, opts); -synproxy_send_tcp (skb, nskb, &snet->tmpl->ct_general,IP_CT_NEW , +synproxy_send_tcp (snet, skb, nskb, &snet->tmpl->ct_general,IP_CT_NEW , niph, nth, tcp_hdr_size); }
@@ -203,7 +205,7 @@ synproxy_send_server_ack(const struct synproxy_net *snet,synproxy_build_options (nth, opts); -synproxy_send_tcp (skb, nskb,NULL ,0 , niph, nth, tcp_hdr_size); +synproxy_send_tcp (snet, skb, nskb,NULL ,0 , niph, nth, tcp_hdr_size); } static void
@@ -241,7 +243,7 @@ synproxy_send_client_ack(const struct synproxy_net *snet,synproxy_build_options (nth, opts); -synproxy_send_tcp (skb, nskb,NULL ,0 , niph, nth, tcp_hdr_size); +synproxy_send_tcp (snet, skb, nskb,NULL ,0 , niph, nth, tcp_hdr_size); } static bool
@@ -301,7 +303,7 @@ synproxy_tg6(struct sk_buff *skb, const struct xt_action_param *par)XT_SYNPROXY_OPT_SACK_PERM | XT_SYNPROXY_OPT_ECN); -synproxy_send_client_synack (skb, th, &opts); +synproxy_send_client_synack (snet, skb, th, &opts);return NF_DROP ; }else if (th->ack && !(th->fin || th->rst || th->syn)) {
Signature · 1 line
2.1.4