netfilter/ipvs fixes for net
Subsystems (5)
Pablo Neira Ayuso
maintainercover netfilter/ipvs fixes for net
Hi David,
The following patchset contains fixes for netfilter/ipvs. This round of fixes is larger than usual at this stage, specifically because of the nf_tables bridge reject fixes that I would like to see in 3.18. The patches are:
1) Fix a null-pointer dereference that may occur when logging errors. This problem was introduced by 4a4739d56b0 ("ipvs: Pull out crosses_local_route_boundary logic") in v3.17-rc5.
2) Update hook mask in nft_reject_bridge so we can also filter out packets from there. This fixes 36d2af5 ("netfilter: nf_tables: allow to filter from prerouting and postrouting"), which needs this chunk to work.
3) Two patches to refactor common code to forge the IPv4 and IPv6 reject packets from the bridge. These are required by the nf_tables reject bridge fix.
4) Fix nft_reject_bridge by avoiding the use of the IP stack to reject packets from the bridge. The idea is to forge the reject packets and inject them to the original port via br_deliver() which is now exported for that purpose.
5) Restrict nft_reject_bridge to bridge prerouting and input hooks. the original skbuff may cloned after prerouting when the bridge stack needs to flood it to several bridge ports, it is too late to reject the traffic.
You can pull these changes from:
git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf.git
Thanks!
----------------------------------------------------------------
The following changes since commit 7965ee93719921ea5978f331da653dfa2d7b99f5:
netfilter: nft_compat: fix wrong target lookup in nft_target_select_ops() (2014-10-27 22:17:46 +0100)
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 127917c29a432c3b798e014a1714e9c1af0f87fe:
netfilter: nft_reject_bridge: restrict reject to prerouting and input (2014-10-31 12:50:09 +0100)
----------------------------------------------------------------
Alex Gartrell (1):
ipvs: Avoid null-pointer deref in debug code
Pablo Neira Ayuso (5):
netfilter: nf_tables_bridge: update hook_mask to allow {pre,post}routing
netfilter: nf_reject_ipv4: split nf_send_reset() in smaller functions
netfilter: nf_reject_ipv6: split nf_send_reset6() in smaller functions
netfilter: nft_reject_bridge: don't use IP stack to reject traffic
netfilter: nft_reject_bridge: restrict reject to prerouting and input
include/net/netfilter/ipv4/nf_reject.h | 10 + include/net/netfilter/ipv6/nf_reject.h | 10 + net/bridge/br_forward.c | 1 + net/bridge/netfilter/nf_tables_bridge.c | 6 +- net/bridge/netfilter/nft_reject_bridge.c | 296 ++++++++++++++++++++++++++++-- net/ipv4/netfilter/nf_reject_ipv4.c | 88 ++++++--- net/ipv6/netfilter/nf_reject_ipv6.c | 175 +++++++++++------- net/netfilter/ipvs/ip_vs_xmit.c | 4 +- 8 files changed, 483 insertions(+), 107 deletions(-)
Pablo Neira Ayuso
maintainerPATCH 1/6 ipvs: Avoid null-pointer deref in debug code
From: Alex Gartrell <[email protected]>
Use daddr instead of reaching into dest.
--- net/netfilter/ipvs/ip_vs_xmit.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/netfilter/ipvs/ip_vs_xmit.c +2 -2
@@ -316,7 +316,7 @@ __ip_vs_get_out_rt(int skb_af, struct sk_buff *skb, struct ip_vs_dest *dest,if (unlikely (crosses_local_route_boundary (skb_af, skb, rt_mode, local))) {IP_VS_DBG_RL ("We are crossing local and non-local addresses" -" daddr=%pI4\n" , &dest->addr.ip); +" daddr=%pI4\n" , &daddr); goto err_put; }
@@ -458,7 +458,7 @@ __ip_vs_get_out_rt_v6(int skb_af, struct sk_buff *skb, struct ip_vs_dest *dest,if (unlikely (crosses_local_route_boundary (skb_af, skb, rt_mode, local))) {IP_VS_DBG_RL ("We are crossing local and non-local addresses" -" daddr=%pI6\n" , &dest->addr.in6); +" daddr=%pI6\n" , daddr); goto err_put; }
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 2/6 netfilter: nf_tables_bridge: update hook_mask to allow {pre,post}routing
In reply to Pablo Neira Ayuso--- net/bridge/netfilter/nf_tables_bridge.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
net/bridge/netfilter/nf_tables_bridge.c +4 -2
@@ -75,9 +75,11 @@ static const struct nf_chain_type filter_bridge = { .type = NFT_CHAIN_T_DEFAULT, .family = NFPROTO_BRIDGE, .owner = THIS_MODULE, - .hook_mask = (1 <<NF_BR_LOCAL_IN ) | + .hook_mask = (1 <<NF_BR_PRE_ROUTING ) | + (1 <<NF_BR_LOCAL_IN ) | (1 <<NF_BR_FORWARD ) | - (1 << NF_BR_LOCAL_OUT), + (1 <<NF_BR_LOCAL_OUT ) | + (1 << NF_BR_POST_ROUTING), };static int __init nf_tables_bridge_init (void )
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 3/6 netfilter: nf_reject_ipv4: split nf_send_reset() in smaller functions
In reply to Pablo Neira AyusoThat can be reused by the reject bridge expression to build the reject packet. The new functions are:
* nf_reject_ip_tcphdr_get(): to sanitize and to obtain the TCP header.
* nf_reject_iphdr_put(): to build the IPv4 header.
* nf_reject_ip_tcphdr_put(): to build the TCP header.
--- include/net/netfilter/ipv4/nf_reject.h | 10 ++++ net/ipv4/netfilter/nf_reject_ipv4.c | 88 ++++++++++++++++++++++---------- 2 files changed, 72 insertions(+), 26 deletions(-)
include/net/netfilter/ipv4/nf_reject.h +10 -0
@@ -1,6 +1,8 @@#ifndef _IPV4_NF_REJECT_H#define _IPV4_NF_REJECT_H +#include <linux/skbuff.h> +#include <net/ip.h> #include <net/icmp.h> static inline void nf_send_unreach (struct sk_buff *skb_in,int code)
@@ -10,4 +12,12 @@ static inline void nf_send_unreach(struct sk_buff *skb_in, int code)void nf_send_reset (struct sk_buff *oldskb,int hook); +const struct tcphdr *nf_reject_ip_tcphdr_get (struct sk_buff *oldskb, +struct tcphdr *_oth,int hook); +struct iphdr *nf_reject_iphdr_put (struct sk_buff *nskb, +const struct sk_buff *oldskb, +__be16 protocol,int ttl); +void nf_reject_ip_tcphdr_put (struct sk_buff *nskb,const struct sk_buff *oldskb, +const struct tcphdr *oth); +#endif /* _IPV4_NF_REJECT_H */
net/ipv4/netfilter/nf_reject_ipv4.c +62 -26
140 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 4/6 netfilter: nf_reject_ipv6: split nf_send_reset6() in smaller functions
In reply to Pablo Neira AyusoThat can be reused by the reject bridge expression to build the reject packet. The new functions are:
* nf_reject_ip6_tcphdr_get(): to sanitize and to obtain the TCP header.
* nf_reject_ip6hdr_put(): to build the IPv6 header.
* nf_reject_ip6_tcphdr_put(): to build the TCP header.
--- include/net/netfilter/ipv6/nf_reject.h | 10 ++ net/ipv6/netfilter/nf_reject_ipv6.c | 175 ++++++++++++++++++++------------ 2 files changed, 119 insertions(+), 66 deletions(-)
include/net/netfilter/ipv6/nf_reject.h +10 -0
@@ -15,4 +15,14 @@ nf_send_unreach6(struct net *net, struct sk_buff *skb_in, unsigned char code,void nf_send_reset6 (struct net *net,struct sk_buff *oldskb,int hook); +const struct tcphdr *nf_reject_ip6_tcphdr_get (struct sk_buff *oldskb, +struct tcphdr *otcph, +unsigned int *otcplen,int hook); +struct ipv6hdr *nf_reject_ip6hdr_put (struct sk_buff *nskb, +const struct sk_buff *oldskb, +__be16 protocol,int hoplimit); +void nf_reject_ip6_tcphdr_put (struct sk_buff *nskb, +const struct sk_buff *oldskb, +const struct tcphdr *oth,unsigned int otcplen); +#endif /* _IPV6_NF_REJECT_H */
net/ipv6/netfilter/nf_reject_ipv6.c +109 -66
231 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 5/6 netfilter: nft_reject_bridge: don't use IP stack to reject traffic
In reply to Pablo Neira AyusoIf the packet is received via the bridge stack, this cannot reject packets from the IP stack.
This adds functions to build the reject packet and send it from the bridge stack. Comments and assumptions on this patch:
1) Validate the IPv4 and IPv6 headers before further processing, given that the packet comes from the bridge stack, we cannot assume they are clean. Truncated packets are dropped, we follow similar approach in the existing iptables match/target extensions that need to inspect layer 4 headers that is not available. This also includes packets that are directed to multicast and broadcast ethernet addresses.
2) br_deliver() is exported to inject the reject packet via bridge localout -> postrouting. So the approach is similar to what we already do in the iptables reject target. The reject packet is sent to the bridge port from which we have received the original packet.
3) The reject packet is forged based on the original packet. The TTL is set based on sysctl_ip_default_ttl for IPv4 and per-net ipv6.devconf_all hoplimit for IPv6.
--- net/bridge/br_forward.c | 1 + net/bridge/netfilter/nft_reject_bridge.c | 263 ++++++++++++++++++++++++++++-- 2 files changed, 254 insertions(+), 10 deletions(-)
net/bridge/br_forward.c +1 -0
@@ -112,6 +112,7 @@ void br_deliver(const struct net_bridge_port *to, struct sk_buff *skb)kfree_skb (skb); } +EXPORT_SYMBOL_GPL (br_deliver);/* called with rcu_read_lock */ void br_forward (const struct net_bridge_port *to,struct sk_buff *skb,struct sk_buff *skb0)
net/bridge/netfilter/nft_reject_bridge.c +253 -10
300 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 6/6 netfilter: nft_reject_bridge: restrict reject to prerouting and input
In reply to Pablo Neira AyusoRestrict the reject expression to the prerouting and input bridge hooks. If we allow this to be used from forward or any other later bridge hook, if the frame is flooded to several ports, we'll end up sending several reject packets, one per cloned packet.
--- net/bridge/netfilter/nft_reject_bridge.c | 33 +++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-)
net/bridge/netfilter/nft_reject_bridge.c +32 -1
@@ -18,6 +18,7 @@#include <net/netfilter/ipv6/nf_reject.h> #include <linux/ip.h> #include <net/ip.h> +#include <linux/netfilter_bridge.h> #include "../br_private.h" static void nft_reject_br_push_etherhdr(struct sk_buff *oldskb,
@@ -305,12 +306,34 @@ out: data[NFT_REG_VERDICT ].verdict =NF_DROP ; } +static int nft_reject_bridge_validate_hooks (const struct nft_chain *chain) +{ +struct nft_base_chain *basechain; + +if (chain->flags &NFT_BASE_CHAIN ) { + basechain =nft_base_chain (chain); + +switch (basechain->ops[0 ].hooknum) { +case NF_BR_PRE_ROUTING : +case NF_BR_LOCAL_IN : +break ; +default : +return -EOPNOTSUPP ; + } + } +return 0 ; +} +static int nft_reject_bridge_init (const struct nft_ctx *ctx,const struct nft_expr *expr,const struct nlattr *const tb[]) {struct nft_reject *priv =nft_expr_priv (expr); -int icmp_code; +int icmp_code, err; + + err =nft_reject_bridge_validate_hooks (ctx->chain); +if (err <0 ) +return err;if (tb[NFTA_REJECT_TYPE ] ==NULL )return -EINVAL ;
@@ -359,6 +382,13 @@ nla_put_failure:return -1 ; } +static int nft_reject_bridge_validate (const struct nft_ctx *ctx, +const struct nft_expr *expr, +const struct nft_data **data) +{ +return nft_reject_bridge_validate_hooks (ctx->chain); +} +static struct nft_expr_type nft_reject_bridge_type;static const struct nft_expr_ops nft_reject_bridge_ops = { .type = &nft_reject_bridge_type,
@@ -366,6 +396,7 @@ static const struct nft_expr_ops nft_reject_bridge_ops = { .eval = nft_reject_bridge_eval, .init = nft_reject_bridge_init, .dump = nft_reject_bridge_dump, + .validate = nft_reject_bridge_validate, };static struct nft_expr_type nft_reject_bridge_type__read_mostly = {
Signature · 1 line
1.7.10.4
David Miller
maintainerFrom: Pablo Neira Ayuso <[email protected]>
Date: Fri, 31 Oct 2014 13:18:26 +0100
Quoted 4 lines
The following patchset contains fixes for netfilter/ipvs. This round of fixes is larger than usual at this stage, specifically because of the
nf_tablesbridge reject fixes that I would like to see in 3.18. The patches are:
...
Quoted 3 lines
You can pull these changes from:
git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf.git
Pulled, thanks Pablo.