pull request (net): ipsec 2017-05-23
Subsystems (3)
Steffen Klassert
maintainer1) Fix wrong header offset for esp4 udpencap packets.
2) Fix a stack access out of bounds when creating a bundle with sub policies. From Sabrina Dubroca.
3) Fix slab-out-of-bounds in pfkey due to an incorrect sadb_x_sec_len calculation.
4) We checked the wrong feature flags when taking down an interface with IPsec offload enabled. Fix from Ilan Tayari.
5) Copy the anti replay sequence numbers when doing a state migration, otherwise we get out of sync with the sequence numbers. Fix from Antony Antony.
Please pull or let me know if there are problems.
Thanks!
The following changes since commit f411af6822182f84834c4881b825dd40534e7fe8:
Merge branch 'ibmvnic-Updated-reset-handler-andcode-fixes' (2017-05-03 11:33:06 -0400)
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 a486cd23661c9387fb076c3f6ae8b2aa9d20d54a:
xfrm: fix state migration copy replay sequence numbers (2017-05-19 12:49:13 +0200)
----------------------------------------------------------------
Antony Antony (1):
xfrm: fix state migration copy replay sequence numbers
Ilan Tayari (1):
xfrm: Fix NETDEV_DOWN with IPSec offload
Sabrina Dubroca (1):
xfrm: fix stack access out of bounds with CONFIG_XFRM_SUB_POLICY
Steffen Klassert (2):
esp4: Fix udpencap for local TCP packets.
af_key: Fix slab-out-of-bounds in pfkey_compile_policy.
include/net/xfrm.h | 10 ---------- net/ipv4/esp4.c | 5 ++++- net/key/af_key.c | 2 +- net/xfrm/xfrm_device.c | 2 +- net/xfrm/xfrm_policy.c | 47 ----------------------------------------------- net/xfrm/xfrm_state.c | 2 ++ 6 files changed, 8 insertions(+), 60 deletions(-)
Steffen Klassert
maintainerPATCH 1/5 esp4: Fix udpencap for local TCP packets.
Locally generated TCP packets are usually cloned, so we do skb_cow_data() on this packets. After that we need to reload the pointer to the esp header. On udpencap this header has an offset to skb_transport_header, so take this offset into account.
--- net/ipv4/esp4.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
net/ipv4/esp4.c +4 -1
@@ -248,6 +248,7 @@ int esp_output_head(struct xfrm_state *x, struct sk_buff *skb, struct esp_info *u8 *tail;u8 *vaddr;int nfrags; +int esph_offset;struct page *page;struct sk_buff *trailer;int tailen = esp->tailen;
@@ -313,11 +314,13 @@ int esp_output_head(struct xfrm_state *x, struct sk_buff *skb, struct esp_info * } cow: + esph_offset = (unsigned char *)esp->esph -skb_transport_header (skb); + nfrags =skb_cow_data (skb, tailen, &trailer);if (nfrags <0 ) goto out; tail =skb_tail_pointer (trailer); - esp->esph =ip_esp_hdr (skb); + esp->esph = (struct ip_esp_hdr *)(skb_transport_header (skb) + esph_offset); skip_cow:esp_output_fill_trailer (tail, esp->tfclen, esp->plen, esp->proto);
Signature · 1 line
2.7.4
Steffen Klassert
maintainerPATCH 3/5 af_key: Fix slab-out-of-bounds in pfkey_compile_policy.
In reply to Steffen KlassertThe sadb_x_sec_len is stored in the unit 'byte divided by eight'. So we have to multiply this value by eight before we can do size checks. Otherwise we may get a slab-out-of-bounds when we memcpy the user sec_ctx.
--- net/key/af_key.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/key/af_key.c +1 -1
@@ -3285,7 +3285,7 @@ static struct xfrm_policy *pfkey_compile_policy(struct sock *sk, int opt, p += pol->sadb_x_policy_len*8 ; sec_ctx = (struct sadb_x_sec_ctx *)p;if (len < pol->sadb_x_policy_len*8 + - sec_ctx->sadb_x_sec_len) { + sec_ctx->sadb_x_sec_len*8 ) { *dir = -EINVAL ; goto out; }
Signature · 1 line
2.7.4
Steffen Klassert
maintainerPATCH 2/5 xfrm: fix stack access out of bounds with CONFIG_XFRM_SUB_POLICY
In reply to Steffen KlassertFrom: Sabrina Dubroca <[email protected]>
When CONFIG_XFRM_SUB_POLICY=y, xfrm_dst stores a copy of the flowi for that dst. Unfortunately, the code that allocates and fills this copy doesn't care about what type of flowi (flowi, flowi4, flowi6) gets passed. In multiple code paths (from raw_sendmsg, from TCP when replying to a FIN, in vxlan, geneve, and gre), the flowi that gets passed to xfrm is actually an on-stack flowi4, so we end up reading stuff from the stack past the end of the flowi4 struct.
Since xfrm_dst->origin isn't used anywhere following commit ca116922afa8 ("xfrm: Eliminate "fl" and "pol" args to xfrm_bundle_ok()."), just get rid of it. xfrm_dst->partner isn't used either, so get rid of that too.
--- include/net/xfrm.h | 10 ---------- net/xfrm/xfrm_policy.c | 47 ----------------------------------------------- 2 files changed, 57 deletions(-)
include/net/xfrm.h +0 -10
@@ -979,10 +979,6 @@ struct xfrm_dst {struct flow_cache_object flo;struct xfrm_policy *pols[XFRM_POLICY_TYPE_MAX ];int num_pols, num_xfrms; -#ifdef CONFIG_XFRM_SUB_POLICY -struct flowi *origin; -struct xfrm_selector *partner; -#endif u32 xfrm_genid;u32 policy_genid;u32 route_mtu_cached;
@@ -998,12 +994,6 @@ static inline void xfrm_dst_destroy(struct xfrm_dst *xdst)dst_release (xdst->route);if (likely (xdst->u.dst.xfrm)) xfrm_state_put(xdst->u.dst.xfrm); -#ifdef CONFIG_XFRM_SUB_POLICY -kfree (xdst->origin); - xdst->origin =NULL ; -kfree (xdst->partner); - xdst->partner =NULL ; -#endif }#endif
net/xfrm/xfrm_policy.c +0 -47
59 lines not on this page · raw message
Signature · 1 line
2.7.4
Steffen Klassert
maintainerPATCH 4/5 xfrm: Fix NETDEV_DOWN with IPSec offload
In reply to Steffen KlassertFrom: Ilan Tayari <[email protected]>
Upon NETDEV_DOWN event, all xfrm_state objects which are bound to the device are flushed.
The condition for this is wrong, though, testing dev->hw_features instead of dev->features. If a device has non-user-modifiable NETIF_F_HW_ESP, then its xfrm_state objects are not flushed, causing a crash later on after the device is deleted.
Check dev->features instead of dev->hw_features.
--- net/xfrm/xfrm_device.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/xfrm/xfrm_device.c +1 -1
@@ -170,7 +170,7 @@ static int xfrm_dev_feat_change(struct net_device *dev)static int xfrm_dev_down (struct net_device *dev) { -if (dev->hw_features &NETIF_F_HW_ESP ) +if (dev->features &NETIF_F_HW_ESP )xfrm_dev_state_flush (dev_net (dev), dev, true);xfrm_garbage_collect (dev_net (dev));
Signature · 1 line
2.7.4
Steffen Klassert
maintainerPATCH 5/5 xfrm: fix state migration copy replay sequence numbers
In reply to Steffen KlassertFrom: Antony Antony <[email protected]>
During xfrm migration copy replay and preplay sequence numbers from the previous state.
Here is a tcpdump output showing the problem. 10.0.10.46 is running vanilla kernel, is the IKE/IPsec responder. After the migration it sent wrong sequence number, reset to 1. The migration is from 10.0.0.52 to 10.0.0.53.
IP 10.0.0.52.4500 > 10.0.10.46.4500: UDP-encap: ESP(spi=0x43ef462d,seq=0x7cf), length 136 IP 10.0.10.46.4500 > 10.0.0.52.4500: UDP-encap: ESP(spi=0xca1c282d,seq=0x7cf), length 136 IP 10.0.0.52.4500 > 10.0.10.46.4500: UDP-encap: ESP(spi=0x43ef462d,seq=0x7d0), length 136 IP 10.0.10.46.4500 > 10.0.0.52.4500: UDP-encap: ESP(spi=0xca1c282d,seq=0x7d0), length 136
IP 10.0.0.53.4500 > 10.0.10.46.4500: NONESP-encap: isakmp: child_sa inf2[I] IP 10.0.10.46.4500 > 10.0.0.53.4500: NONESP-encap: isakmp: child_sa inf2[R] IP 10.0.0.53.4500 > 10.0.10.46.4500: NONESP-encap: isakmp: child_sa inf2[I] IP 10.0.10.46.4500 > 10.0.0.53.4500: NONESP-encap: isakmp: child_sa inf2[R]
IP 10.0.0.53.4500 > 10.0.10.46.4500: UDP-encap: ESP(spi=0x43ef462d,seq=0x7d1), length 136
NOTE: next sequence is wrong 0x1
IP 10.0.10.46.4500 > 10.0.0.53.4500: UDP-encap: ESP(spi=0xca1c282d,seq=0x1), length 136 IP 10.0.0.53.4500 > 10.0.10.46.4500: UDP-encap: ESP(spi=0x43ef462d,seq=0x7d2), length 136 IP 10.0.10.46.4500 > 10.0.0.53.4500: UDP-encap: ESP(spi=0xca1c282d,seq=0x2), length 136
--- net/xfrm/xfrm_state.c | 2 ++ 1 file changed, 2 insertions(+)
net/xfrm/xfrm_state.c +2 -0
@@ -1383,6 +1383,8 @@ static struct xfrm_state *xfrm_state_clone(struct xfrm_state *orig) x->curlft.add_time = orig->curlft.add_time; x->km.state = orig->km.state; x->km.seq = orig->km.seq; + x->replay = orig->replay; + x->preplay = orig->preplay;return x;
Signature · 1 line
2.7.4
David Miller
maintainerFrom: Steffen Klassert <[email protected]>
Date: Tue, 23 May 2017 07:33:39 +0200
Quoted 12 lines
1) Fix wrong header offset for esp4 udpencap packets.
2) Fix a stack access out of bounds when creating a bundle with sub policies. From Sabrina Dubroca.
3) Fix slab-out-of-bounds in pfkey due to an incorrect
sadb_x_sec_lencalculation.4) We checked the wrong feature flags when taking down an interface with IPsec offload enabled. Fix from Ilan Tayari.
Quoted 5 lines
5) Copy the anti replay sequence numbers when doing a state migration, otherwise we get out of sync with the sequence numbers. Fix from Antony Antony.
Please pull or let me know if there are problems.
Pulled, thank you.