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 contains small updates for net-next, more relevantly:
* One fix for potential NULL dereference in xt_HMARK by Dan Carpenter.
* Conversion to use _ALL macro in xt_hashlimit as you suggested by Florian Westphal.
* One fix for timeout overflow from Jozsef Kadlecsik.
* Replace usage of modulus for hash calculation in xt_HMARK as you suggested from myself.
You can pull these changes from:
git://1984.lsi.us.es/net-next master
Thanks!
Dan Carpenter (1):
netfilter: xt_HMARK: potential NULL dereference in get_inner_hdr()
Eldad Zack (1):
netfilter: xt_CT: remove redundant header include
Florian Westphal (1):
netfilter: xt_hashlimit: use _ALL macro to reject unknown flag bits
Jozsef Kadlecsik (1):
netfilter: ipset: fix timeout value overflow bug
Pablo Neira Ayuso (3):
netfilter: xt_HMARK: modulus is expensive for hash calculation
netfilter: nf_ct_tcp: extend log message for invalid ignored packets
netfilter: nf_ct_h323: fix usage of MODULE_ALIAS_NFCT_HELPER
include/linux/netfilter/ipset/ip_set_timeout.h | 4 ++++ include/linux/netfilter/xt_hashlimit.h | 6 ++++-- net/netfilter/nf_conntrack_h323_main.c | 4 +++- net/netfilter/nf_conntrack_proto_tcp.c | 3 ++- net/netfilter/xt_CT.c | 1 - net/netfilter/xt_HMARK.c | 4 ++-- net/netfilter/xt_hashlimit.c | 2 +- net/netfilter/xt_set.c | 15 +++++++++++++-- 8 files changed, 29 insertions(+), 10 deletions(-)
Signature · 1 line
1.7.10
[email protected]
maintainerPATCH 1/7 netfilter: xt_hashlimit: use _ALL macro to reject unknown flag bits
From: Florian Westphal <[email protected]>
David Miller says:
The canonical way to validate if the set bits are in a valid range is to have a "_ALL" macro, and test:
if (val & ~XT_HASHLIMIT_ALL)
goto err;"
make it so.
--- include/linux/netfilter/xt_hashlimit.h | 6 ++++-- net/netfilter/xt_hashlimit.c | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-)
include/linux/netfilter/xt_hashlimit.h +4 -2
@@ -22,10 +22,12 @@ enum {XT_HASHLIMIT_HASH_SPT =1 <<3 ,XT_HASHLIMIT_INVERT =1 <<4 , XT_HASHLIMIT_BYTES = 1 << 5, +};#ifdef __KERNEL__ - XT_HASHLIMIT_MAX = 1 << 6, +#define XT_HASHLIMIT_ALL (XT_HASHLIMIT_HASH_DIP | XT_HASHLIMIT_HASH_DPT | \ + XT_HASHLIMIT_HASH_SIP | XT_HASHLIMIT_HASH_SPT | \ + XT_HASHLIMIT_INVERT | XT_HASHLIMIT_BYTES)#endif -}; struct hashlimit_cfg { __u32 mode; /* bitmask of XT_HASHLIMIT_HASH_* */
net/netfilter/xt_hashlimit.c +1 -1
@@ -647,7 +647,7 @@ static int hashlimit_mt_check(const struct xt_mtchk_param *par)return -EINVAL ; } -if (info->cfg.mode >=XT_HASHLIMIT_MAX ) { +if (info->cfg.mode & ~XT_HASHLIMIT_ALL ) {pr_info ("Unknown mode mask %X, kernel too old?\n" , info->cfg.mode);return -EINVAL ;
Signature · 1 line
1.7.10
[email protected]
maintainerPATCH 2/7 netfilter: xt_HMARK: potential NULL dereference in get_inner_hdr()
In reply to [email protected]From: Dan Carpenter <[email protected]>
There is a typo in the error checking and "&&" was used instead of "||". If skb_header_pointer() returns NULL then it leads to a NULL dereference.
--- net/netfilter/xt_HMARK.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/xt_HMARK.c +1 -1
@@ -223,7 +223,7 @@ static int get_inner_hdr(const struct sk_buff *skb, int iphsz, int *nhoff)/* Not enough header? */ icmph =skb_header_pointer (skb, *nhoff + iphsz,sizeof (_ih), &_ih); -if (icmph ==NULL && icmph->type >NR_ICMP_TYPES ) +if (icmph ==NULL || icmph->type >NR_ICMP_TYPES )return 0 ;/* Error message? */
Signature · 1 line
1.7.10
[email protected]
maintainerPATCH 3/7 netfilter: xt_HMARK: modulus is expensive for hash calculation
In reply to [email protected]From: Pablo Neira Ayuso <[email protected]>
Use:
((u64)(HASH_VAL * HASH_SIZE)) >> 32
as suggested by David S. Miller.
--- net/netfilter/xt_HMARK.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/xt_HMARK.c +1 -1
@@ -109,7 +109,7 @@ hmark_hash(struct hmark_tuple *t, const struct xt_hmark_info *info) hash =jhash_3words (t->src, t->dst, t->uports.v32, info->hashrnd); hash = hash ^ (t->proto & info->proto_mask); -return (hash % info->hmodulus) + info->hoffset; +return (((u64 )hash * info->hmodulus) >>32 ) + info->hoffset; } static void
Signature · 1 line
1.7.10
[email protected]
maintainerPATCH 4/7 netfilter: nf_ct_tcp: extend log message for invalid ignored packets
In reply to [email protected]From: Pablo Neira Ayuso <[email protected]>
Extend log message if packets are ignored to include the TCP state, ie. replace:
[ 3968.070196] nf_ct_tcp: invalid packet ignored IN= OUT= SRC=...
by:
[ 3968.070196] nf_ct_tcp: invalid packet ignored in state ESTABLISHED IN= OUT= SRC=...
This information is useful to know in what state we were while ignoring the packet.
--- net/netfilter/nf_conntrack_proto_tcp.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
net/netfilter/nf_conntrack_proto_tcp.c +2 -1
@@ -952,7 +952,8 @@ static int tcp_packet(struct nf_conn *ct,spin_unlock_bh (&ct->lock);if (LOG_INVALID (net,IPPROTO_TCP ))nf_log_packet (pf,0 , skb,NULL ,NULL ,NULL , -"nf_ct_tcp: invalid packet ignored " ); +"nf_ct_tcp: invalid packet ignored in " +"state %s " , tcp_conntrack_names[old_state]);return NF_ACCEPT ;case TCP_CONNTRACK_MAX :/* Invalid packet */
Signature · 1 line
1.7.10
[email protected]
maintainerPATCH 5/7 netfilter: ipset: fix timeout value overflow bug
In reply to [email protected]From: Jozsef Kadlecsik <[email protected]>
Large timeout parameters could result wrong timeout values due to an overflow at msec to jiffies conversion (reported by Andreas Herz)
[ This patch was mangled by Pablo Neira Ayuso since David Laight and
Eric Dumazet noticed that we were using hardcoded 1000 instead of MSEC_PER_SEC to calculate the timeout ]
--- include/linux/netfilter/ipset/ip_set_timeout.h | 4 ++++ net/netfilter/xt_set.c | 15 +++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-)
include/linux/netfilter/ipset/ip_set_timeout.h +4 -0
@@ -30,6 +30,10 @@ ip_set_timeout_uget(struct nlattr *tb) {unsigned int timeout =ip_set_get_h32 (tb); +/* Normalize to fit into jiffies */ +if (timeout >UINT_MAX /MSEC_PER_SEC ) + timeout =UINT_MAX /MSEC_PER_SEC ; +/* Userspace supplied TIMEOUT parameter: adjust crazy size */ return timeout ==IPSET_NO_TIMEOUT ?IPSET_NO_TIMEOUT -1 : timeout; }
net/netfilter/xt_set.c +13 -2
@@ -44,6 +44,14 @@ const struct ip_set_adt_opt n = { \ .cmdflags = cfs, \ .timeout = t, \ } +#define ADT_MOPT (n, f, d, fs, cfs, t) \ +struct ip_set_adt_opt n = { \ + .family = f, \ + .dim = d, \ + .flags = fs, \ + .cmdflags = cfs, \ + .timeout = t, \ +}/* Revision 0 interface: backward compatible with netfilter/iptables */
@@ -296,11 +304,14 @@ static unsigned int set_target_v2(struct sk_buff *skb, const struct xt_action_param *par) { const struct xt_set_info_target_v2 *info = par->targinfo; -ADT_OPT (add_opt, par->family, info->add_set.dim, - info->add_set.flags, info->flags, info->timeout); +ADT_MOPT (add_opt, par->family, info->add_set.dim, + info->add_set.flags, info->flags, info->timeout);ADT_OPT (del_opt, par->family, info->del_set.dim, info->del_set.flags,0 ,UINT_MAX ); +/* Normalize to fit into jiffies */ +if (add_opt.timeout >UINT_MAX /MSEC_PER_SEC ) + add_opt.timeout =UINT_MAX /MSEC_PER_SEC ;if (info->add_set.index !=IPSET_INVALID_ID )ip_set_add (info->add_set.index, skb, par, &add_opt);if (info->del_set.index !=IPSET_INVALID_ID )
Signature · 1 line
1.7.10
[email protected]
maintainerPATCH 6/7 netfilter: xt_CT: remove redundant header include
In reply to [email protected]From: Eldad Zack <[email protected]>
nf_conntrack_l4proto.h is included twice.
--- net/netfilter/xt_CT.c | 1 - 1 file changed, 1 deletion(-)
net/netfilter/xt_CT.c +0 -1
@@ -17,7 +17,6 @@#include <net/netfilter/nf_conntrack_l4proto.h> #include <net/netfilter/nf_conntrack_helper.h> #include <net/netfilter/nf_conntrack_ecache.h> -#include <net/netfilter/nf_conntrack_l4proto.h> #include <net/netfilter/nf_conntrack_timeout.h> #include <net/netfilter/nf_conntrack_zones.h>
Signature · 1 line
1.7.10
[email protected]
maintainerPATCH 7/7 netfilter: nf_ct_h323: fix usage of MODULE_ALIAS_NFCT_HELPER
In reply to [email protected]From: Pablo Neira Ayuso <[email protected]>
ctnetlink uses the aliases that are created by MODULE_ALIAS_NFCT_HELPER to auto-load the module based on the helper name. Thus, we have to use RAS, Q.931 and H.245, not H.323.
--- net/netfilter/nf_conntrack_h323_main.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
net/netfilter/nf_conntrack_h323_main.c +3 -1
@@ -1830,4 +1830,6 @@ MODULE_AUTHOR("Jing Min Zhao <[email protected]>");MODULE_DESCRIPTION ("H.323 connection tracking helper" );MODULE_LICENSE ("GPL" );MODULE_ALIAS ("ip_conntrack_h323" ); -MODULE_ALIAS_NFCT_HELPER ("h323" ); +MODULE_ALIAS_NFCT_HELPER ("RAS" ); +MODULE_ALIAS_NFCT_HELPER ("Q.931" ); +MODULE_ALIAS_NFCT_HELPER ("H.245" );
Signature · 1 line
1.7.10
David Miller
maintainerFrom: [email protected]
Date: Thu, 17 May 2012 01:06:37 +0200
Quoted 7 lines
The following patchset contains small updates for net-next, more relevantly:
* One fix for potential NULL dereference in
xt_HMARKby Dan Carpenter.* Conversion to use
_ALLmacro inxt_hashlimitas you suggested by Florian Westphal.
Quoted 8 lines
* One fix for timeout overflow from Jozsef Kadlecsik.
* Replace usage of modulus for hash calculation in
xt_HMARKas you suggested from myself.You can pull these changes from:
git://1984.lsi.us.es/net-nextmaster
Pulled, thanks a lot!
RE: [PATCH 3/7] netfilter: xt_HMARK: modulus is expensive for hash calculation
In reply to [email protected]Quoted 8 lines
From: Pablo Neira Ayuso <[email protected]>
Use:
((u64)(HASH_VAL *
HASH_SIZE)) >> 32as suggested by David S. Miller.
That (u64) cast is very unlikely to have any effect. If you want a 64 bit result from the product of two 32 bit values, you have to cast one of the 32 bit values prior to the multiply - as in the patch below.
David
Quoted 29 lines
Signed-off-by Pablo Neira Ayuso <[email protected]>--- net/netfilter/xt_HMARK.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)net/netfilter/xt_HMARK.c +1
-1@@ -109,7 +109,7 @@ hmark_hash(struct hmark_tuple *t, const struct xt_hmark_info *info) hash =jhash_3words (t->src, t->dst, t->uports.v32, info->hashrnd); hash = hash ^ (t->proto & info->proto_mask); -return (hash % info->hmodulus) + info->hoffset; +return (((u64 )hash * info->hmodulus) >>32 ) + info->hoffset; }static void
Signature · 6 lines
1.7.10 -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
RE: [PATCH 3/7] netfilter: xt_HMARK: modulus is expensive for hash calculation
Quoted 4 lines · David Laight
Quoted 4 lines
From: Pablo Neira Ayuso <[email protected]>
Use:
Quoted 8 lines
Quoted 3 lines
((u64)(HASH_VAL *
HASH_SIZE)) >> 32as suggested by David S. Miller.
That (u64) cast is very unlikely to have any effect. If you want a 64 bit result from the product of two 32 bit values, you have to cast one of the 32 bit values prior to the multiply - as in the patch below.
Hey, Changelog is a bit wrong (for several reasons) but code is correct.
return (((u64)hash * info->hmodulus) >> 32) + info->hoffset;
Pablo Neira Ayuso
maintainerRe: [PATCH 3/7] netfilter: xt_HMARK: modulus is expensive for hash calculation
Quoted 9 lines · Eric Dumazet
Quoted 8 lines · David Laight
Quoted 7 lines
From: Pablo Neira Ayuso <[email protected]>
Use:
((u64)(HASH_VAL *
HASH_SIZE)) >> 32as suggested by David S. Miller.
Quoted 8 lines
Quoted 4 lines
That (u64) cast is very unlikely to have any effect. If you want a 64 bit result from the product of two 32 bit values, you have to cast one of the 32 bit values prior to the multiply - as in the patch below.
Hey, Changelog is a bit wrong (for several reasons) but code is correct.
return (((u64)hash *
info->hmodulus) >> 32) +info->hoffset;
Sorry, for the mistake in the changelog. I copied & pasted it from the mailing list discussion.