pull request (net): ipsec 2013-08-28
Subsystems (4)
Steffen Klassert
maintainerThis pull request fixes some issues that arise when 6in4 or 4in6 tunnels are used in combination with IPsec, all from Hannes Frederic Sowa and a null pointer dereference when queueing packets to the policy hold queue.
1) We might access the local error handler of the wrong address family if 6in4 or 4in6 tunnel is protected by ipsec. Fix this by addind a pointer to the correct local_error to xfrm_state_afinet.
2) Add a helper function to always refer to the correct interpretation of skb->sk.
3) Call skb_reset_inner_headers to record the position of the inner headers when adding a new one in various ipv6 tunnels. This is needed to identify the addresses where to send back errors in the xfrm layer.
4) Dereference inner ipv6 header if encapsulated to always call the right error handler.
5) Choose protocol family by skb protocol to not call the wrong xfrm{4,6}_local_error handler in case an ipv6 sockets is used in ipv4 mode.
6) Partly revert "xfrm: introduce helper for safe determination of mtu" because this introduced pmtu discovery problems.
7) Set skb->protocol on tcp, raw and ip6_append_data genereated skbs. We need this to get the correct mtu informations in xfrm.
8) Fix null pointer dereference in xdst_queue_output.
Please pull or let me know if there are problems.
Thanks!
The following changes since commit d9bf5f130946695063469749bfd190087b7fad39:
tun: compare with 0 instead of total_len (2013-08-13 19:29:08 -0700)
are available in the git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/klassert/ipsec.git master
for you to fetch changes up to 302a50bc941010d7a67f288fd0db31981e4d722d:
xfrm: Fix potential null pointer dereference in xdst_queue_output (2013-08-28 08:47:14 +0200)
----------------------------------------------------------------
Hannes Frederic Sowa (7):
xfrm: make local error reporting more robust
xfrm: introduce helper for safe determination of mtu
ipv6: wire up skb->encapsulation
ipv6: xfrm: dereference inner ipv6 header if encapsulated
xfrm: choose protocol family by skb protocol
xfrm: revert ipv4 mtu determination to dst_mtu
ipv6: set skb->protocol on tcp, raw and ip6_append_data genereated skbs
Steffen Klassert (1):
xfrm: Fix potential null pointer dereference in xdst_queue_output
include/net/route.h | 8 ++++++++ include/net/xfrm.h | 6 ++++++ net/ipv4/ip_output.c | 8 -------- net/ipv4/xfrm4_output.c | 16 +++++++++++----- net/ipv4/xfrm4_state.c | 1 + net/ipv6/ip6_gre.c | 5 +++++ net/ipv6/ip6_output.c | 3 +++ net/ipv6/ip6_tunnel.c | 6 ++++++ net/ipv6/raw.c | 1 + net/ipv6/sit.c | 5 +++++ net/ipv6/xfrm6_output.c | 21 +++++++++++++++------ net/ipv6/xfrm6_state.c | 1 + net/xfrm/xfrm_output.c | 21 +++++++++++++++++++++ net/xfrm/xfrm_policy.c | 9 +-------- net/xfrm/xfrm_state.c | 7 ++----- 15 files changed, 86 insertions(+), 32 deletions(-)
Steffen Klassert
maintainerPATCH 1/8 xfrm: make local error reporting more robust
From: Hannes Frederic Sowa <[email protected]>
In xfrm4 and xfrm6 we need to take care about sockets of the other address family. This could happen because a 6in4 or 4in6 tunnel could get protected by ipsec.
Because we don't want to have a run-time dependency on ipv6 when only using ipv4 xfrm we have to embed a pointer to the correct local_error function in xfrm_state_afinet and look it up when returning an error depending on the socket address family.
Thanks to vi0ss for the great bug report:
<https://bugzilla.kernel.org/show_bug.cgi?id=58691>
v2:
a) fix two more unsafe interpretations of skb->sk as ipv6 socket (xfrm6_local_dontfrag and __xfrm6_output)
v3:
a) add an EXPORT_SYMBOL_GPL(xfrm_local_error) to fix a link error when building ipv6 as a module (thanks to Steffen Klassert)
--- include/net/xfrm.h | 6 ++++++ net/ipv4/xfrm4_output.c | 12 ++++++++++-- net/ipv4/xfrm4_state.c | 1 + net/ipv6/xfrm6_output.c | 10 ++++++---- net/ipv6/xfrm6_state.c | 1 + net/xfrm/xfrm_output.c | 13 +++++++++++++ net/xfrm/xfrm_state.c | 7 ++----- 7 files changed, 39 insertions(+), 11 deletions(-)
include/net/xfrm.h +6 -0
@@ -341,10 +341,13 @@ struct xfrm_state_afinfo { struct sk_buff *skb);int (*transport_finish)(struct sk_buff *skb,int async); +void (*local_error)(struct sk_buff *skb,u32 mtu); };extern int xfrm_state_register_afinfo (struct xfrm_state_afinfo *afinfo);extern int xfrm_state_unregister_afinfo (struct xfrm_state_afinfo *afinfo); +extern struct xfrm_state_afinfo *xfrm_state_get_afinfo (unsigned int family); +extern void xfrm_state_put_afinfo (struct xfrm_state_afinfo *afinfo);extern void xfrm_state_delete_tunnel (struct xfrm_state *x);
@@ -1477,6 +1480,7 @@ extern int xfrm_input_resume(struct sk_buff *skb, int nexthdr);extern int xfrm_output_resume (struct sk_buff *skb,int err);extern int xfrm_output (struct sk_buff *skb);extern int xfrm_inner_extract_output (struct xfrm_state *x,struct sk_buff *skb); +extern void xfrm_local_error (struct sk_buff *skb,int mtu);extern int xfrm4_extract_header (struct sk_buff *skb);extern int xfrm4_extract_input (struct xfrm_state *x,struct sk_buff *skb); extern int xfrm4_rcv_encap(struct sk_buff *skb, int nexthdr, __be32 spi,
@@ -1497,6 +1501,7 @@ extern int xfrm4_tunnel_register(struct xfrm_tunnel *handler, unsigned short famextern int xfrm4_tunnel_deregister (struct xfrm_tunnel *handler,unsigned short family);extern int xfrm4_mode_tunnel_input_register (struct xfrm_tunnel *handler);extern int xfrm4_mode_tunnel_input_deregister (struct xfrm_tunnel *handler); +extern void xfrm4_local_error (struct sk_buff *skb,u32 mtu);extern int xfrm6_extract_header (struct sk_buff *skb);extern int xfrm6_extract_input (struct xfrm_state *x,struct sk_buff *skb);extern int xfrm6_rcv_spi (struct sk_buff *skb,int nexthdr,__be32 spi);
@@ -1514,6 +1519,7 @@ extern int xfrm6_output(struct sk_buff *skb);extern int xfrm6_output_finish (struct sk_buff *skb);extern int xfrm6_find_1stfragopt (struct xfrm_state *x,struct sk_buff *skb,u8 **prevhdr); +extern void xfrm6_local_error (struct sk_buff *skb,u32 mtu);#ifdef CONFIG_XFRM extern int xfrm4_udp_encap_rcv (struct sock *sk,struct sk_buff *skb);
net/ipv4/xfrm4_output.c +10 -2
@@ -33,8 +33,7 @@ static int xfrm4_tunnel_check_size(struct sk_buff *skb) mtu =dst_mtu (dst);if (skb->len > mtu) {if (skb->sk) -ip_local_error (skb->sk,EMSGSIZE ,ip_hdr (skb)->daddr, -inet_sk (skb->sk)->inet_dport, mtu); +xfrm_local_error (skb, mtu);else icmp_send (skb,ICMP_DEST_UNREACH ,ICMP_FRAG_NEEDED ,htonl (mtu));
@@ -99,3 +98,12 @@ int xfrm4_output(struct sk_buff *skb) x->outer_mode->afinfo->output_finish, !(IPCB(skb)->flags & IPSKB_REROUTED)); } + +void xfrm4_local_error (struct sk_buff *skb,u32 mtu) +{ +struct iphdr *hdr; + + hdr = skb->encapsulation ?inner_ip_hdr (skb) :ip_hdr (skb); +ip_local_error (skb->sk,EMSGSIZE , hdr->daddr, +inet_sk (skb->sk)->inet_dport, mtu); +}
net/ipv4/xfrm4_state.c +1 -0
@@ -83,6 +83,7 @@ static struct xfrm_state_afinfo xfrm4_state_afinfo = { .extract_input = xfrm4_extract_input, .extract_output = xfrm4_extract_output, .transport_finish = xfrm4_transport_finish, + .local_error = xfrm4_local_error, };void __init xfrm4_state_init (void )
net/ipv6/xfrm6_output.c +6 -4
@@ -34,8 +34,10 @@ static int xfrm6_local_dontfrag(struct sk_buff *skb)struct sock *sk = skb->sk;if (sk) { - proto = sk->sk_protocol; +if (sk->sk_family !=AF_INET6 ) +return 0 ; + proto = sk->sk_protocol;if (proto ==IPPROTO_UDP || proto ==IPPROTO_RAW )return inet6_sk (sk)->dontfrag; }
@@ -54,7 +56,7 @@ static void xfrm6_local_rxpmtu(struct sk_buff *skb, u32 mtu)ipv6_local_rxpmtu (sk, &fl6, mtu); } -static void xfrm6_local_error (struct sk_buff *skb,u32 mtu) +void xfrm6_local_error (struct sk_buff *skb,u32 mtu) {struct flowi6 fl6;struct sock *sk = skb->sk;
@@ -80,7 +82,7 @@ static int xfrm6_tunnel_check_size(struct sk_buff *skb)if (xfrm6_local_dontfrag (skb))xfrm6_local_rxpmtu (skb, mtu);else if (skb->sk) -xfrm6_local_error (skb, mtu); +xfrm_local_error (skb, mtu);else icmpv6_send (skb,ICMPV6_PKT_TOOBIG ,0 , mtu); ret = -EMSGSIZE ;
@@ -142,7 +144,7 @@ static int __xfrm6_output(struct sk_buff *skb)xfrm6_local_rxpmtu (skb, mtu);return -EMSGSIZE ; }else if (!skb->local_df && skb->len > mtu && skb->sk) { -xfrm6_local_error (skb, mtu); +xfrm_local_error (skb, mtu);return -EMSGSIZE ; }
net/ipv6/xfrm6_state.c +1 -0
@@ -183,6 +183,7 @@ static struct xfrm_state_afinfo xfrm6_state_afinfo = { .extract_input = xfrm6_extract_input, .extract_output = xfrm6_extract_output, .transport_finish = xfrm6_transport_finish, + .local_error = xfrm6_local_error, };int __init xfrm6_state_init (void )
net/xfrm/xfrm_output.c +13 -0
@@ -214,5 +214,18 @@ int xfrm_inner_extract_output(struct xfrm_state *x, struct sk_buff *skb)return inner_mode->afinfo->extract_output (x, skb); } +void xfrm_local_error (struct sk_buff *skb,int mtu) +{ +struct xfrm_state_afinfo *afinfo; + + afinfo =xfrm_state_get_afinfo (skb->sk->sk_family); +if (!afinfo) +return ; + + afinfo->local_error (skb, mtu); +xfrm_state_put_afinfo (afinfo); +} +EXPORT_SYMBOL_GPL (xfrm_output);EXPORT_SYMBOL_GPL (xfrm_inner_extract_output); +EXPORT_SYMBOL_GPL (xfrm_local_error);
net/xfrm/xfrm_state.c +2 -5
@@ -39,9 +39,6 @@ static DEFINE_SPINLOCK(xfrm_state_lock);static unsigned int xfrm_state_hashmax__read_mostly =1 *1024 *1024 ; -static struct xfrm_state_afinfo *xfrm_state_get_afinfo (unsigned int family); -static void xfrm_state_put_afinfo (struct xfrm_state_afinfo *afinfo); - static inline unsigned int xfrm_dst_hash(struct net *net, const xfrm_address_t *daddr, const xfrm_address_t *saddr,
@@ -1860,7 +1857,7 @@ int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo) }EXPORT_SYMBOL (xfrm_state_unregister_afinfo); -static struct xfrm_state_afinfo *xfrm_state_get_afinfo (unsigned int family) +struct xfrm_state_afinfo *xfrm_state_get_afinfo (unsigned int family) {struct xfrm_state_afinfo *afinfo;if (unlikely (family >=NPROTO ))
@@ -1872,7 +1869,7 @@ static struct xfrm_state_afinfo *xfrm_state_get_afinfo(unsigned int family)return afinfo; } -static void xfrm_state_put_afinfo (struct xfrm_state_afinfo *afinfo) +void xfrm_state_put_afinfo (struct xfrm_state_afinfo *afinfo) {rcu_read_unlock (); }
Signature · 1 line
1.7.9.5
Steffen Klassert
maintainerPATCH 2/8 xfrm: introduce helper for safe determination of mtu
In reply to Steffen KlassertFrom: Hannes Frederic Sowa <[email protected]>
skb->sk socket can be of AF_INET or AF_INET6 address family. Thus we always have to make sure we a referring to the correct interpretation of skb->sk.
We only depend on header defines to query the mtu, so we don't introduce a new dependency to ipv6 by this change.
--- include/net/route.h | 8 ++++++++ include/net/xfrm.h | 12 ++++++++++++ net/ipv4/ip_output.c | 8 -------- net/ipv4/xfrm4_output.c | 4 +--- net/ipv6/xfrm6_output.c | 5 ++++- 5 files changed, 25 insertions(+), 12 deletions(-)
include/net/route.h +8 -0
@@ -317,4 +317,12 @@ static inline int ip4_dst_hoplimit(const struct dst_entry *dst) return hoplimit; } +static inline int ip_skb_dst_mtu (struct sk_buff *skb) +{ +struct inet_sock *inet = skb->sk ?inet_sk (skb->sk) :NULL ; + +return (inet && inet->pmtudisc ==IP_PMTUDISC_PROBE ) ? +skb_dst (skb)->dev->mtu :dst_mtu (skb_dst (skb)); +} +#endif /* _ROUTE_H */
include/net/xfrm.h +12 -0
@@ -20,6 +20,7 @@#include <net/route.h> #include <net/ipv6.h> #include <net/ip6_fib.h> +#include <net/ip6_route.h> #include <net/flow.h> #include <linux/interrupt.h>
@@ -1723,4 +1724,15 @@ static inline int xfrm_mark_put(struct sk_buff *skb, const struct xfrm_mark *m) return ret; } +static inline int xfrm_skb_dst_mtu (struct sk_buff *skb) +{ +struct sock *sk = skb->sk; + +if (sk && sk->sk_family ==AF_INET6 ) +return ip6_skb_dst_mtu (skb); +else if (sk && sk->sk_family ==AF_INET ) +return ip_skb_dst_mtu (skb); +return dst_mtu (skb_dst (skb)); +} +#endif /* _NET_XFRM_H */
net/ipv4/ip_output.c +0 -8
@@ -211,14 +211,6 @@ static inline int ip_finish_output2(struct sk_buff *skb)return -EINVAL ; } -static inline int ip_skb_dst_mtu (struct sk_buff *skb) -{ -struct inet_sock *inet = skb->sk ?inet_sk (skb->sk) :NULL ; - -return (inet && inet->pmtudisc ==IP_PMTUDISC_PROBE ) ? -skb_dst (skb)->dev->mtu :dst_mtu (skb_dst (skb)); -} -static int ip_finish_output (struct sk_buff *skb) {#if defined(CONFIG_NETFILTER ) && defined(CONFIG_XFRM )
net/ipv4/xfrm4_output.c +1 -3
@@ -21,7 +21,6 @@static int xfrm4_tunnel_check_size (struct sk_buff *skb) {int mtu, ret =0 ; -struct dst_entry *dst;if (IPCB (skb)->flags &IPSKB_XFRM_TUNNEL_SIZE ) goto out;
@@ -29,8 +28,7 @@ static int xfrm4_tunnel_check_size(struct sk_buff *skb)if (!(ip_hdr (skb)->frag_off &htons (IP_DF )) || skb->local_df) goto out; - dst =skb_dst (skb); - mtu =dst_mtu (dst); + mtu =xfrm_skb_dst_mtu (skb);if (skb->len > mtu) {if (skb->sk)xfrm_local_error (skb, mtu);
net/ipv6/xfrm6_output.c +4 -1
@@ -138,7 +138,10 @@ static int __xfrm6_output(struct sk_buff *skb) {struct dst_entry *dst =skb_dst (skb);struct xfrm_state *x = dst->xfrm; -int mtu =ip6_skb_dst_mtu (skb); +int mtu =xfrm_skb_dst_mtu (skb); + +if (mtu <IPV6_MIN_MTU ) + mtu =IPV6_MIN_MTU ;if (skb->len > mtu &&xfrm6_local_dontfrag (skb)) {xfrm6_local_rxpmtu (skb, mtu);
Signature · 1 line
1.7.9.5
Steffen Klassert
maintainerPATCH 3/8 ipv6: wire up skb->encapsulation
In reply to Steffen KlassertFrom: Hannes Frederic Sowa <[email protected]>
When pushing a new header before current one call skb_reset_inner_headers to record the position of the inner headers in the various ipv6 tunnel protocols.
We later need this to correctly identify the addresses needed to send back an error in the xfrm layer.
This change is safe, because skb->protocol is always checked before dereferencing data from the inner protocol.
--- net/ipv6/ip6_gre.c | 5 +++++ net/ipv6/ip6_tunnel.c | 6 ++++++ net/ipv6/sit.c | 5 +++++ 3 files changed, 16 insertions(+)
net/ipv6/ip6_gre.c +5 -0
@@ -724,6 +724,11 @@ static netdev_tx_t ip6gre_xmit2(struct sk_buff *skb,ipv6_push_nfrag_opts (skb, &opt.ops, &proto,NULL ); } +if (likely (!skb->encapsulation)) { +skb_reset_inner_headers (skb); + skb->encapsulation =1 ; + } +skb_push (skb, gre_hlen);skb_reset_network_header (skb);skb_set_transport_header (skb,sizeof (*ipv6h));
net/ipv6/ip6_tunnel.c +6 -0
@@ -1027,6 +1027,12 @@ static int ip6_tnl_xmit2(struct sk_buff *skb,init_tel_txopt (&opt, encap_limit);ipv6_push_nfrag_opts (skb, &opt.ops, &proto,NULL ); } + +if (likely (!skb->encapsulation)) { +skb_reset_inner_headers (skb); + skb->encapsulation =1 ; + } +skb_push (skb,sizeof (struct ipv6hdr ));skb_reset_network_header (skb); ipv6h =ipv6_hdr (skb);
net/ipv6/sit.c +5 -0
@@ -888,6 +888,11 @@ static netdev_tx_t ipip6_tunnel_xmit(struct sk_buff *skb, ttl = iph6->hop_limit; tos =INET_ECN_encapsulate (tos,ipv6_get_dsfield (iph6)); +if (likely (!skb->encapsulation)) { +skb_reset_inner_headers (skb); + skb->encapsulation =1 ; + } + err =iptunnel_xmit (dev_net (dev), rt, skb, fl4.saddr, fl4.daddr,IPPROTO_IPV6 , tos, ttl, df);iptunnel_xmit_stats (err, &dev->stats, dev->tstats);
Signature · 1 line
1.7.9.5
Steffen Klassert
maintainerPATCH 4/8 ipv6: xfrm: dereference inner ipv6 header if encapsulated
In reply to Steffen KlassertFrom: Hannes Frederic Sowa <[email protected]>
In xfrm6_local_error use inner_header if the packet was encapsulated.
--- net/ipv6/xfrm6_output.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
net/ipv6/xfrm6_output.c +3 -1
@@ -59,10 +59,12 @@ static void xfrm6_local_rxpmtu(struct sk_buff *skb, u32 mtu)void xfrm6_local_error (struct sk_buff *skb,u32 mtu) {struct flowi6 fl6; +const struct ipv6hdr *hdr;struct sock *sk = skb->sk; + hdr = skb->encapsulation ?inner_ipv6_hdr (skb) :ipv6_hdr (skb); fl6.fl6_dport =inet_sk (sk)->inet_dport; - fl6.daddr =ipv6_hdr (skb)->daddr; + fl6.daddr = hdr->daddr;ipv6_local_error (sk,EMSGSIZE , &fl6, mtu); }
Signature · 1 line
1.7.9.5
Steffen Klassert
maintainerPATCH 5/8 xfrm: choose protocol family by skb protocol
In reply to Steffen KlassertFrom: Hannes Frederic Sowa <[email protected]>
We need to choose the protocol family by skb->protocol. Otherwise we call the wrong xfrm{4,6}_local_error handler in case an ipv6 sockets is used in ipv4 mode, in which case we should call down to xfrm4_local_error (ip6 sockets are a superset of ip4 ones).
We are called before before ip_output functions, so skb->protocol is not reset.
--- include/net/xfrm.h | 4 ++-- net/xfrm/xfrm_output.c | 10 +++++++++- 2 files changed, 11 insertions(+), 3 deletions(-)
include/net/xfrm.h +2 -2
@@ -1728,9 +1728,9 @@ static inline int xfrm_skb_dst_mtu(struct sk_buff *skb) {struct sock *sk = skb->sk; -if (sk && sk->sk_family ==AF_INET6 ) +if (sk && skb->protocol ==htons (ETH_P_IPV6 ))return ip6_skb_dst_mtu (skb); -else if (sk && sk->sk_family ==AF_INET ) +else if (sk && skb->protocol ==htons (ETH_P_IP ))return ip_skb_dst_mtu (skb);return dst_mtu (skb_dst (skb)); }
net/xfrm/xfrm_output.c +9 -1
@@ -216,9 +216,17 @@ int xfrm_inner_extract_output(struct xfrm_state *x, struct sk_buff *skb)void xfrm_local_error (struct sk_buff *skb,int mtu) { +unsigned int proto;struct xfrm_state_afinfo *afinfo; - afinfo =xfrm_state_get_afinfo (skb->sk->sk_family); +if (skb->protocol ==htons (ETH_P_IP )) + proto =AF_INET ; +else if (skb->protocol ==htons (ETH_P_IPV6 )) + proto =AF_INET6 ; +else +return ; + + afinfo =xfrm_state_get_afinfo (proto);if (!afinfo)return ;
Signature · 1 line
1.7.9.5
Steffen Klassert
maintainerPATCH 6/8 xfrm: revert ipv4 mtu determination to dst_mtu
In reply to Steffen KlassertFrom: Hannes Frederic Sowa <[email protected]>
In commit 0ea9d5e3e0e03a63b11392f5613378977dae7eca ("xfrm: introduce helper for safe determination of mtu") I switched the determination of ipv4 mtus from dst_mtu to ip_skb_dst_mtu. This was an error because in case of IP_PMTUDISC_PROBE we fall back to the interface mtu, which is never correct for ipv4 ipsec.
This patch partly reverts 0ea9d5e3e0e03a63b11392f5613378977dae7eca ("xfrm: introduce helper for safe determination of mtu").
--- include/net/xfrm.h | 12 ------------ net/ipv4/xfrm4_output.c | 2 +- net/ipv6/xfrm6_output.c | 8 +++++--- 3 files changed, 6 insertions(+), 16 deletions(-)
include/net/xfrm.h +0 -12
@@ -20,7 +20,6 @@#include <net/route.h> #include <net/ipv6.h> #include <net/ip6_fib.h> -#include <net/ip6_route.h> #include <net/flow.h> #include <linux/interrupt.h>
@@ -1724,15 +1723,4 @@ static inline int xfrm_mark_put(struct sk_buff *skb, const struct xfrm_mark *m) return ret; } -static inline int xfrm_skb_dst_mtu (struct sk_buff *skb) -{ -struct sock *sk = skb->sk; - -if (sk && skb->protocol ==htons (ETH_P_IPV6 )) -return ip6_skb_dst_mtu (skb); -else if (sk && skb->protocol ==htons (ETH_P_IP )) -return ip_skb_dst_mtu (skb); -return dst_mtu (skb_dst (skb)); -} -#endif /* _NET_XFRM_H */
net/ipv4/xfrm4_output.c +1 -1
@@ -28,7 +28,7 @@ static int xfrm4_tunnel_check_size(struct sk_buff *skb)if (!(ip_hdr (skb)->frag_off &htons (IP_DF )) || skb->local_df) goto out; - mtu =xfrm_skb_dst_mtu (skb); + mtu =dst_mtu (skb_dst (skb));if (skb->len > mtu) {if (skb->sk)xfrm_local_error (skb, mtu);
net/ipv6/xfrm6_output.c +5 -3
@@ -140,10 +140,12 @@ static int __xfrm6_output(struct sk_buff *skb) {struct dst_entry *dst =skb_dst (skb);struct xfrm_state *x = dst->xfrm; -int mtu =xfrm_skb_dst_mtu (skb); +int mtu; -if (mtu <IPV6_MIN_MTU ) - mtu =IPV6_MIN_MTU ; +if (skb->protocol ==htons (ETH_P_IPV6 )) + mtu =ip6_skb_dst_mtu (skb); +else + mtu =dst_mtu (skb_dst (skb));if (skb->len > mtu &&xfrm6_local_dontfrag (skb)) {xfrm6_local_rxpmtu (skb, mtu);
Signature · 1 line
1.7.9.5
Steffen Klassert
maintainerPATCH 7/8 ipv6: set skb->protocol on tcp, raw and ip6_append_data genereated skbs
In reply to Steffen KlassertFrom: Hannes Frederic Sowa <[email protected]>
Currently we don't initialize skb->protocol when transmitting data via tcp, raw(with and without inclhdr) or udp+ufo or appending data directly to the socket transmit queue (via ip6_append_data). This needs to be done so that we can get the correct mtu in the xfrm layer.
Setting of skb->protocol happens only in functions where we also have a transmitting socket and a new skb, so we don't overwrite old values.
--- net/ipv6/ip6_output.c | 3 +++ net/ipv6/raw.c | 1 + 2 files changed, 4 insertions(+)
net/ipv6/ip6_output.c +3 -0
@@ -238,6 +238,7 @@ int ip6_xmit(struct sock *sk, struct sk_buff *skb, struct flowi6 *fl6, hdr->saddr = fl6->saddr; hdr->daddr = *first_hop; + skb->protocol =htons (ETH_P_IPV6 ); skb->priority = sk->sk_priority; skb->mark = sk->sk_mark;
@@ -1057,6 +1058,7 @@ static inline int ip6_ufo_append_data(struct sock *sk,/* initialize protocol header pointer */ skb->transport_header = skb->network_header + fragheaderlen; + skb->protocol =htons (ETH_P_IPV6 ); skb->ip_summed =CHECKSUM_PARTIAL ; skb->csum =0 ; }
@@ -1359,6 +1361,7 @@ alloc_new_skb:/* * Fill in the control structures */ + skb->protocol =htons (ETH_P_IPV6 ); skb->ip_summed =CHECKSUM_NONE ; skb->csum =0 ;/* reserve for fragmentation and ipsec header */
net/ipv6/raw.c +1 -0
@@ -628,6 +628,7 @@ static int rawv6_send_hdrinc(struct sock *sk, void *from, int length, goto error;skb_reserve (skb, hlen); + skb->protocol =htons (ETH_P_IPV6 ); skb->priority = sk->sk_priority; skb->mark = sk->sk_mark;skb_dst_set (skb, &rt->dst);
Signature · 1 line
1.7.9.5
Steffen Klassert
maintainerPATCH 8/8 xfrm: Fix potential null pointer dereference in xdst_queue_output
In reply to Steffen KlassertThe net_device might be not set on the skb when we try refcounting. This leads to a null pointer dereference in xdst_queue_output(). It turned out that the refcount to the net_device is not needed after all. The dst_entry has a refcount to the net_device before we queue the skb, so it can't go away. Therefore we can remove the refcount on queueing to fix the null pointer dereference.
--- net/xfrm/xfrm_policy.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-)
net/xfrm/xfrm_policy.c +1 -8
@@ -320,10 +320,8 @@ static void xfrm_queue_purge(struct sk_buff_head *list) {struct sk_buff *skb; -while ((skb =skb_dequeue (list)) !=NULL ) { -dev_put (skb->dev); +while ((skb =skb_dequeue (list)) !=NULL )kfree_skb (skb); - } }/* Rule must be locked. Release descentant resources, announce
@@ -1758,7 +1756,6 @@ static void xfrm_policy_queue_process(unsigned long arg)struct sk_buff *skb;struct sock *sk;struct dst_entry *dst; -struct net_device *dev;struct xfrm_policy *pol = (struct xfrm_policy *)arg;struct xfrm_policy_queue *pq = &pol->polq;struct flowi fl;
@@ -1805,7 +1802,6 @@ static void xfrm_policy_queue_process(unsigned long arg) dst =xfrm_lookup (xp_net (pol),skb_dst (skb)->path, &fl, skb->sk,0 );if (IS_ERR (dst)) { -dev_put (skb->dev);kfree_skb (skb);continue ; }
@@ -1814,9 +1810,7 @@ static void xfrm_policy_queue_process(unsigned long arg)skb_dst_drop (skb);skb_dst_set (skb, dst); - dev = skb->dev; err =dst_output (skb); -dev_put (dev); }return ;
@@ -1839,7 +1833,6 @@ static int xdst_queue_output(struct sk_buff *skb) }skb_dst_force (skb); -dev_hold (skb->dev);spin_lock_bh (&pq->hold_queue.lock);
Signature · 1 line
1.7.9.5
Re: [PATCH 8/8] xfrm: Fix potential null pointer dereference in xdst_queue_output
Quoted 17 lines · Steffen Klassert
The
net_devicemight be not set on the skb when we try refcounting. This leads to a null pointer dereference inxdst_queue_output(). It turned out that the refcount to thenet_deviceis not needed after all. Thedst_entryhas a refcount to thenet_devicebefore we queue the skb, so it can't go away. Therefore we can remove the refcount on queueing to fix the null pointer dereference.Signed-off-by Steffen Klassert <[email protected]>--- net/xfrm/xfrm_policy.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-)net/xfrm/xfrm_policy.c +0
-0
net/xfrm/xfrm_policy.c static void xfrm_queue_purge(struct sk_buff_head *list) · line 326
Quoted 10 lines
net/xfrm/xfrm_policy.c +1
-3@@ -320,10 +320,8 @@ static void xfrm_queue_purge(struct sk_buff_head *list) {struct sk_buff *skb; -while ((skb =skb_dequeue (list)) !=NULL ) { -dev_put (skb->dev); +while ((skb =skb_dequeue (list)) !=NULL )kfree_skb (skb); - } }
xfrm_queue_purge() now looks a lot like skb_queue_purge() ;)
Steffen Klassert
maintainerRe: [PATCH 8/8] xfrm: Fix potential null pointer dereference in xdst_queue_output
Quoted 13 lines · Eric Dumazet
Quoted 12 lines · Steffen Klassert
--- net/xfrm/xfrm_policy.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-)net/xfrm/xfrm_policy.c +0
-0@@ -320,10 +320,8 @@ static void xfrm_queue_purge(struct sk_buff_head *list) {struct sk_buff *skb;
Quoted 10 lines
net/xfrm/xfrm_policy.c static void xfrm_queue_purge(struct sk_buff_head *list) · line 326
Quoted 7 lines
net/xfrm/xfrm_policy.c +1
-3-while ((skb =skb_dequeue (list)) !=NULL ) { -dev_put (skb->dev); +while ((skb =skb_dequeue (list)) !=NULL )kfree_skb (skb); - } }
xfrm_queue_purge()now looks a lot likeskb_queue_purge();)
Oh, indeed. Looks like I was too much focused on fixing this bug to notice that this function looks familiar now ;)
I'll do a followup patch to remove xfrm_queue_purge() in favor of skb_queue_purge() or I generate an updated pull request, depending what David prefers.
David Miller
maintainerFrom: Steffen Klassert <[email protected]>
Date: Wed, 28 Aug 2013 13:04:47 +0200
Quoted 3 lines
This pull request fixes some issues that arise when 6in4 or 4in6 tunnels are used in combination with IPsec, all from Hannes Frederic Sowa and a null pointer dereference when queueing packets to the policy hold queue.
...
Quoted 1 line
Please pull or let me know if there are problems.
Pulled, thanks!