Netfilter updates for net-next
Subsystems (3)
Pablo Neira Ayuso
maintainercover Netfilter updates for net-next
Hi David,
The following patchset contains a small batch of Netfilter updates for your net-next tree, they are:
* Three patches that provide more accurate error reporting to user-space, instead of -EPERM, in IPv4/IPv6 netfilter re-routing code and NAT, from Patrick McHardy.
* Update copyright statements in Netfilter filters of Patrick McHardy, from himself.
* Add Kconfig dependency on the raw/mangle tables to the rpfilter, from Florian Westphal.
The following changes since commit 6b0ee8c036ecb3ac92e18e6ca0dca7bff88beaf0:
scm: Stop passing struct cred (2013-04-07 18:58:55 -0400)
are available in the git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf-next.git master
for you to fetch changes up to d37d696804a83479f240b397670a07ccb53a7417:
netfilter: xt_rpfilter: depend on raw or mangle table (2013-04-19 00:22:55 +0200)
----------------------------------------------------------------
Florian Westphal (1):
netfilter: xt_rpfilter: depend on raw or mangle table
Patrick McHardy (4):
netfilter: ipv4: propagate routing errors from ip_route_me_harder()
netfilter: ipv6: propagate routing errors from ip6_route_me_harder()
netfilter: nat: propagate errors from xfrm_me_harder()
netfilter: add my copyright statements
net/ipv4/netfilter.c | 15 ++++++++----- net/ipv4/netfilter/Kconfig | 2 +- net/ipv4/netfilter/arp_tables.c | 1 + net/ipv4/netfilter/ip_tables.c | 1 + net/ipv4/netfilter/ipt_ULOG.c | 1 + net/ipv4/netfilter/iptable_mangle.c | 9 +++++--- net/ipv4/netfilter/iptable_nat.c | 23 +++++++++++++------- net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c | 1 + .../netfilter/nf_conntrack_l3proto_ipv4_compat.c | 1 + net/ipv4/netfilter/nf_conntrack_proto_icmp.c | 1 + net/ipv4/netfilter/nf_nat_h323.c | 1 + net/ipv4/netfilter/nf_nat_pptp.c | 2 ++ net/ipv4/netfilter/nf_nat_proto_gre.c | 2 ++ net/ipv4/netfilter/nf_nat_snmp_basic.c | 2 ++ net/ipv6/netfilter.c | 12 +++++++--- net/ipv6/netfilter/Kconfig | 2 +- net/ipv6/netfilter/ip6_tables.c | 1 + net/ipv6/netfilter/ip6t_REJECT.c | 2 ++ net/ipv6/netfilter/ip6table_mangle.c | 9 +++++--- net/ipv6/netfilter/ip6table_nat.c | 23 +++++++++++++------- net/netfilter/core.c | 1 + net/netfilter/nf_conntrack_amanda.c | 1 + net/netfilter/nf_conntrack_core.c | 1 + net/netfilter/nf_conntrack_ecache.c | 8 ++++--- net/netfilter/nf_conntrack_expect.c | 1 + net/netfilter/nf_conntrack_ftp.c | 1 + net/netfilter/nf_conntrack_h323_main.c | 1 + net/netfilter/nf_conntrack_helper.c | 1 + net/netfilter/nf_conntrack_irc.c | 1 + net/netfilter/nf_conntrack_pptp.c | 2 ++ net/netfilter/nf_conntrack_proto.c | 1 + net/netfilter/nf_conntrack_proto_gre.c | 1 + net/netfilter/nf_conntrack_proto_sctp.c | 3 +++ net/netfilter/nf_conntrack_proto_tcp.c | 2 ++ net/netfilter/nf_conntrack_proto_udp.c | 1 + net/netfilter/nf_conntrack_standalone.c | 1 + net/netfilter/nf_conntrack_tftp.c | 2 +- net/netfilter/nf_nat_amanda.c | 1 + net/netfilter/nf_nat_core.c | 9 ++++---- net/netfilter/nf_nat_helper.c | 1 + net/netfilter/nf_queue.c | 5 +++++ net/netfilter/nfnetlink_log.c | 1 + net/netfilter/x_tables.c | 1 + net/netfilter/xt_TCPMSS.c | 1 + net/netfilter/xt_conntrack.c | 1 + net/netfilter/xt_hashlimit.c | 1 + net/netfilter/xt_limit.c | 1 + 47 files changed, 122 insertions(+), 40 deletions(-)
Pablo Neira Ayuso
maintainerPATCH 1/5 netfilter: ipv4: propagate routing errors from ip_route_me_harder()
From: Patrick McHardy <[email protected]>
Propagate routing errors from ip_route_me_harder() when dropping a packet using NF_DROP_ERR(). This makes userspace get the proper error instead of EPERM for everything.
Example:
# ip r a unreachable default table 100 # ip ru add fwmark 0x1 lookup 100 # iptables -t mangle -A OUTPUT -d 8.8.8.8 -j MARK --set-mark 0x1
Current behaviour:
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
ping: sendmsg: Operation not permitted
ping: sendmsg: Operation not permitted
ping: sendmsg: Operation not permitted
New behaviour:
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
ping: sendmsg: Network is unreachable
ping: sendmsg: Network is unreachable
ping: sendmsg: Network is unreachable
ping: sendmsg: Network is unreachable
--- net/ipv4/netfilter.c | 8 ++++---- net/ipv4/netfilter/iptable_mangle.c | 9 ++++++--- net/ipv4/netfilter/iptable_nat.c | 6 ++++-- 3 files changed, 14 insertions(+), 9 deletions(-)
net/ipv4/netfilter.c +4 -4
@@ -40,14 +40,14 @@ int ip_route_me_harder(struct sk_buff *skb, unsigned int addr_type) fl4.flowi4_flags = flags; rt =ip_route_output_key (net, &fl4);if (IS_ERR (rt)) -return -1 ; +return PTR_ERR (rt);/* Drop old route. */ skb_dst_drop (skb);skb_dst_set (skb, &rt->dst);if (skb_dst (skb)->error) -return -1 ; +return skb_dst (skb)->error;#ifdef CONFIG_XFRM if (!(IPCB(skb)->flags & IPSKB_XFRM_TRANSFORMED) &&
@@ -56,7 +56,7 @@ int ip_route_me_harder(struct sk_buff *skb, unsigned int addr_type)skb_dst_set (skb,NULL ); dst =xfrm_lookup (net, dst,flowi4_to_flowi (&fl4), skb->sk,0 );if (IS_ERR (dst)) -return -1 ; +return PTR_ERR (dst);; skb_dst_set(skb, dst); }#endif
@@ -66,7 +66,7 @@ int ip_route_me_harder(struct sk_buff *skb, unsigned int addr_type)if (skb_headroom (skb) < hh_len &&pskb_expand_head (skb,HH_DATA_ALIGN (hh_len -skb_headroom (skb)),0 ,GFP_ATOMIC )) -return -1 ; +return -ENOMEM ;return 0 ; }
net/ipv4/netfilter/iptable_mangle.c +6 -3
@@ -44,6 +44,7 @@ ipt_mangle_out(struct sk_buff *skb, const struct net_device *out)u_int8_t tos;__be32 saddr, daddr;u_int32_t mark; +int err;/* root is playing with raw sockets. */ if (skb->len < sizeof(struct iphdr) ||
@@ -66,9 +67,11 @@ ipt_mangle_out(struct sk_buff *skb, const struct net_device *out)if (iph->saddr != saddr || iph->daddr != daddr || skb->mark != mark || - iph->tos != tos) -if (ip_route_me_harder (skb,RTN_UNSPEC )) - ret =NF_DROP ; + iph->tos != tos) { + err =ip_route_me_harder (skb,RTN_UNSPEC ); +if (err <0 ) + ret =NF_DROP_ERR (err); + } }return ret;
net/ipv4/netfilter/iptable_nat.c +4 -2
@@ -213,6 +213,7 @@ nf_nat_ipv4_local_fn(unsigned int hooknum,const struct nf_conn *ct;enum ip_conntrack_info ctinfo;unsigned int ret; +int err;/* root is playing with raw sockets. */ if (skb->len < sizeof(struct iphdr) ||
@@ -226,8 +227,9 @@ nf_nat_ipv4_local_fn(unsigned int hooknum,if (ct->tuplehash[dir].tuple.dst.u3.ip != ct->tuplehash[!dir].tuple.src.u3.ip) { -if (ip_route_me_harder (skb,RTN_UNSPEC )) - ret =NF_DROP ; + err =ip_route_me_harder (skb,RTN_UNSPEC ); +if (err <0 ) + ret =NF_DROP_ERR (err); }#ifdef CONFIG_XFRM else if (!(IPCB(skb)->flags & IPSKB_XFRM_TRANSFORMED) &&
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 2/5 netfilter: ipv6: propagate routing errors from ip6_route_me_harder()
In reply to Pablo Neira AyusoFrom: Patrick McHardy <[email protected]>
Propagate routing errors from ip_route_me_harder() when dropping a packet using NF_DROP_ERR(). This makes userspace get the proper error instead of EPERM for everything.
# ip -6 r a unreachable default table 100 # ip -6 ru add fwmark 0x1 lookup 100 # ip6tables -t mangle -A OUTPUT -d 2001:4860:4860::8888 -j MARK --set-mark 0x1
Old behaviour:
PING 2001:4860:4860::8888(2001:4860:4860::8888) 56 data bytes
ping: sendmsg: Operation not permitted
ping: sendmsg: Operation not permitted
ping: sendmsg: Operation not permitted
New behaviour:
PING 2001:4860:4860::8888(2001:4860:4860::8888) 56 data bytes
ping: sendmsg: Network is unreachable
ping: sendmsg: Network is unreachable
ping: sendmsg: Network is unreachable
--- net/ipv6/netfilter.c | 6 +++--- net/ipv6/netfilter/ip6table_mangle.c | 9 ++++++--- net/ipv6/netfilter/ip6table_nat.c | 6 ++++-- 3 files changed, 13 insertions(+), 8 deletions(-)
net/ipv6/netfilter.c +3 -3
@@ -29,7 +29,7 @@ int ip6_route_me_harder(struct sk_buff *skb)IP6_INC_STATS (net,ip6_dst_idev (dst),IPSTATS_MIB_OUTNOROUTES );LIMIT_NETDEBUG (KERN_DEBUG "ip6_route_me_harder: No more route.\n" );dst_release (dst); -return -EINVAL ; +return dst->error; }/* Drop old route. */
@@ -43,7 +43,7 @@ int ip6_route_me_harder(struct sk_buff *skb)skb_dst_set (skb,NULL ); dst =xfrm_lookup (net, dst,flowi6_to_flowi (&fl6), skb->sk,0 );if (IS_ERR (dst)) -return -1 ; +return PTR_ERR (dst); skb_dst_set(skb, dst); }#endif
@@ -53,7 +53,7 @@ int ip6_route_me_harder(struct sk_buff *skb)if (skb_headroom (skb) < hh_len &&pskb_expand_head (skb,HH_DATA_ALIGN (hh_len -skb_headroom (skb)),0 ,GFP_ATOMIC )) -return -1 ; +return -ENOMEM ;return 0 ; }
net/ipv6/netfilter/ip6table_mangle.c +6 -3
@@ -38,7 +38,7 @@ ip6t_mangle_out(struct sk_buff *skb, const struct net_device *out)struct in6_addr saddr, daddr;u_int8_t hop_limit;u_int32_t flowlabel, mark; - +int err;#if 0 /* root is playing with raw sockets. */ if (skb->len < sizeof(struct iphdr) ||
@@ -65,8 +65,11 @@ ip6t_mangle_out(struct sk_buff *skb, const struct net_device *out) !ipv6_addr_equal(&ipv6_hdr(skb)->daddr, &daddr) || skb->mark != mark || ipv6_hdr(skb)->hop_limit != hop_limit || - flowlabel != *((u_int32_t *)ipv6_hdr(skb)))) -return ip6_route_me_harder (skb) ==0 ? ret :NF_DROP ; + flowlabel != *((u_int32_t *)ipv6_hdr(skb)))) { + err =ip6_route_me_harder (skb); +if (err <0 ) + ret =NF_DROP_ERR (err); + }return ret; }
net/ipv6/netfilter/ip6table_nat.c +4 -2
@@ -215,6 +215,7 @@ nf_nat_ipv6_local_fn(unsigned int hooknum,const struct nf_conn *ct;enum ip_conntrack_info ctinfo;unsigned int ret; +int err;/* root is playing with raw sockets. */ if (skb->len <sizeof (struct ipv6hdr ))
@@ -227,8 +228,9 @@ nf_nat_ipv6_local_fn(unsigned int hooknum,if (!nf_inet_addr_cmp (&ct->tuplehash[dir].tuple.dst.u3, &ct->tuplehash[!dir].tuple.src.u3)) { -if (ip6_route_me_harder (skb)) - ret =NF_DROP ; + err =ip6_route_me_harder (skb); +if (err <0 ) + ret =NF_DROP_ERR (err); }#ifdef CONFIG_XFRM else if (!(IP6CB(skb)->flags & IP6SKB_XFRM_TRANSFORMED) &&
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 3/5 netfilter: nat: propagate errors from xfrm_me_harder()
In reply to Pablo Neira AyusoFrom: Patrick McHardy <[email protected]>
Propagate errors from ip_xfrm_me_harder() instead of returning EPERM in all cases.
--- net/ipv4/netfilter/iptable_nat.c | 17 +++++++++++------ net/ipv6/netfilter/ip6table_nat.c | 17 +++++++++++------ net/netfilter/nf_nat_core.c | 9 +++++---- 3 files changed, 27 insertions(+), 16 deletions(-)
net/ipv4/netfilter/iptable_nat.c +11 -6
@@ -176,6 +176,7 @@ nf_nat_ipv4_out(unsigned int hooknum,#ifdef CONFIG_XFRM const struct nf_conn *ct;enum ip_conntrack_info ctinfo; +int err;#endif unsigned int ret;
@@ -195,9 +196,11 @@ nf_nat_ipv4_out(unsigned int hooknum, ct->tuplehash[!dir].tuple.dst.u3.ip) || (ct->tuplehash[dir].tuple.dst.protonum != IPPROTO_ICMP && ct->tuplehash[dir].tuple.src.u.all != - ct->tuplehash[!dir].tuple.dst.u.all)) - if (nf_xfrm_me_harder(skb, AF_INET) < 0) - ret = NF_DROP; + ct->tuplehash[!dir].tuple.dst.u.all)) { + err =nf_xfrm_me_harder (skb,AF_INET ); +if (err <0 ) + ret =NF_DROP_ERR (err); + } }#endif return ret;
@@ -235,9 +238,11 @@ nf_nat_ipv4_local_fn(unsigned int hooknum, else if (!(IPCB(skb)->flags & IPSKB_XFRM_TRANSFORMED) && ct->tuplehash[dir].tuple.dst.protonum != IPPROTO_ICMP && ct->tuplehash[dir].tuple.dst.u.all != - ct->tuplehash[!dir].tuple.src.u.all) -if (nf_xfrm_me_harder (skb,AF_INET ) <0 ) - ret =NF_DROP ; + ct->tuplehash[!dir].tuple.src.u.all) { + err =nf_xfrm_me_harder (skb,AF_INET ); +if (err <0 ) + ret =NF_DROP_ERR (err); + }#endif }return ret;
net/ipv6/netfilter/ip6table_nat.c +11 -6
@@ -179,6 +179,7 @@ nf_nat_ipv6_out(unsigned int hooknum,#ifdef CONFIG_XFRM const struct nf_conn *ct;enum ip_conntrack_info ctinfo; +int err;#endif unsigned int ret;
@@ -197,9 +198,11 @@ nf_nat_ipv6_out(unsigned int hooknum, &ct->tuplehash[!dir].tuple.dst.u3) || (ct->tuplehash[dir].tuple.dst.protonum != IPPROTO_ICMPV6 && ct->tuplehash[dir].tuple.src.u.all != - ct->tuplehash[!dir].tuple.dst.u.all)) - if (nf_xfrm_me_harder(skb, AF_INET6) < 0) - ret = NF_DROP; + ct->tuplehash[!dir].tuple.dst.u.all)) { + err =nf_xfrm_me_harder (skb,AF_INET6 ); +if (err <0 ) + ret =NF_DROP_ERR (err); + } }#endif return ret;
@@ -236,9 +239,11 @@ nf_nat_ipv6_local_fn(unsigned int hooknum, else if (!(IP6CB(skb)->flags & IP6SKB_XFRM_TRANSFORMED) && ct->tuplehash[dir].tuple.dst.protonum != IPPROTO_ICMPV6 && ct->tuplehash[dir].tuple.dst.u.all != - ct->tuplehash[!dir].tuple.src.u.all) -if (nf_xfrm_me_harder (skb,AF_INET6 )) - ret =NF_DROP ; + ct->tuplehash[!dir].tuple.src.u.all) { + err =nf_xfrm_me_harder (skb,AF_INET6 ); +if (err <0 ) + ret =NF_DROP_ERR (err); + }#endif }return ret;
net/netfilter/nf_nat_core.c +5 -4
@@ -87,9 +87,10 @@ int nf_xfrm_me_harder(struct sk_buff *skb, unsigned int family)struct flowi fl;unsigned int hh_len;struct dst_entry *dst; +int err; -if (xfrm_decode_session (skb, &fl, family) <0 ) -return -1 ; + err =xfrm_decode_session (skb, &fl, family); +return err; dst =skb_dst (skb);if (dst->xfrm)
@@ -98,7 +99,7 @@ int nf_xfrm_me_harder(struct sk_buff *skb, unsigned int family) dst =xfrm_lookup (dev_net (dst->dev), dst, &fl, skb->sk,0 );if (IS_ERR (dst)) -return -1 ; +return PTR_ERR (dst);skb_dst_drop (skb);skb_dst_set (skb, dst);
@@ -107,7 +108,7 @@ int nf_xfrm_me_harder(struct sk_buff *skb, unsigned int family) hh_len =skb_dst (skb)->dev->hard_header_len;if (skb_headroom (skb) < hh_len &&pskb_expand_head (skb, hh_len -skb_headroom (skb),0 ,GFP_ATOMIC )) -return -1 ; +return -ENOMEM ;return 0 ; }EXPORT_SYMBOL (nf_xfrm_me_harder);
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 5/5 netfilter: xt_rpfilter: depend on raw or mangle table
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
rpfilter is only valid in raw/mangle PREROUTING, i.e. RPFILTER=y|m is useless without raw or mangle table support.
--- net/ipv4/netfilter/Kconfig | 2 +- net/ipv6/netfilter/Kconfig | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
net/ipv4/netfilter/Kconfig +1 -1
@@ -71,7 +71,7 @@ config IP_NF_MATCH_ECN config IP_NF_MATCH_RPFILTER tristate '"rpfilter" reverse path filter match support' - depends on NETFILTER_ADVANCED + depends on NETFILTER_ADVANCED && (IP_NF_MANGLE || IP_NF_RAW) ---help--- This option allows you to match packets whose replies would go out via the interface the packet came in.
net/ipv6/netfilter/Kconfig +1 -1
@@ -105,7 +105,7 @@ config IP6_NF_MATCH_MH config IP6_NF_MATCH_RPFILTER tristate '"rpfilter" reverse path filter match support' - depends on NETFILTER_ADVANCED + depends on NETFILTER_ADVANCED && (IP6_NF_MANGLE || IP6_NF_RAW) ---help--- This option allows you to match packets whose replies would go out via the interface the packet came in.
Signature · 1 line
1.7.10.4
David Miller
maintainerFrom: Pablo Neira Ayuso <[email protected]>
Date: Fri, 19 Apr 2013 03:23:52 +0200
Quoted 12 lines
The following patchset contains a small batch of Netfilter updates for your net-next tree, they are:
* Three patches that provide more accurate error reporting to user-space, instead of
-EPERM, in IPv4/IPv6 netfilter re-routing code and NAT, from Patrick McHardy.* Update copyright statements in Netfilter filters of Patrick McHardy, from himself.
* Add
Kconfigdependency on the raw/mangle tables to the rpfilter, from Florian Westphal.
...
Quoted 1 line
git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf-next.gitmaster
Pulled, thanks Pablo.