pull request (net): ipsec 2018-01-24
Subsystems (3)
Steffen Klassert
maintainer1) Only offloads SAs after they are fully initialized. Otherwise a NIC may receive packets on a SA we can not yet handle in the stack.
From Yossi Kuperman.
2) Fix negative refcount in case of a failing offload. From Aviad Yehezkel.
3) Fix inner IP ptoro version when decapsulating
from interaddress family tunnels.
From Yossi Kuperman.
4) Use true or false for boolean variables instead of an integer value in xfrm_get_type_offload.
From Gustavo A. R. Silva.
Please pull or let me know if there are problems.
Thanks!
The following changes since commit ad9294dbc227cbc8e173b3b963e7dd9af5314f77:
bpf: fix cls_bpf on filter replace (2018-01-17 17:14:06 -0500)
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 545d8ae7affff7fb4f8bfd327c7c7790056535c4:
xfrm: fix boolean assignment in xfrm_get_type_offload (2018-01-23 10:56:36 +0100)
----------------------------------------------------------------
Aviad Yehezkel (1):
xfrm: fix error flow in case of add state fails
Gustavo A. R. Silva (1):
xfrm: fix boolean assignment in xfrm_get_type_offload
Yossi Kuperman (2):
xfrm: Add SA to hardware at the end of xfrm_state_construct()
xfrm: Fix eth_hdr(skb)->h_proto to reflect inner IP version
net/ipv4/xfrm4_mode_tunnel.c | 1 + net/ipv6/xfrm6_mode_tunnel.c | 1 + net/xfrm/xfrm_device.c | 1 + net/xfrm/xfrm_state.c | 12 ++++++++---- net/xfrm/xfrm_user.c | 18 +++++++++++------- 5 files changed, 22 insertions(+), 11 deletions(-)
Steffen Klassert
maintainerPATCH 1/4 xfrm: Add SA to hardware at the end of xfrm_state_construct()
From: Yossi Kuperman <[email protected]>
Current code configures the hardware with a new SA before the state has been fully initialized. During this time interval, an incoming ESP packet can cause a crash due to a NULL dereference. More specifically, xfrm_input() considers the packet as valid, and yet, anti-replay mechanism is not initialized.
Move hardware configuration to the end of xfrm_state_construct(), and mark the state as valid once the SA is fully initialized.
--- net/xfrm/xfrm_state.c | 10 +++++++--- net/xfrm/xfrm_user.c | 18 +++++++++++------- 2 files changed, 18 insertions(+), 10 deletions(-)
net/xfrm/xfrm_state.c +7 -3
@@ -2272,8 +2272,6 @@ int __xfrm_init_state(struct xfrm_state *x, bool init_replay, bool offload) goto error; } - x->km.state =XFRM_STATE_VALID ; - error:return err; }
@@ -2282,7 +2280,13 @@ EXPORT_SYMBOL(__xfrm_init_state);int xfrm_init_state (struct xfrm_state *x) { -return __xfrm_init_state (x, true, false); +int err; + + err =__xfrm_init_state (x, true, false); +if (!err) + x->km.state =XFRM_STATE_VALID ; + +return err; }EXPORT_SYMBOL (xfrm_init_state);
net/xfrm/xfrm_user.c +11 -7
@@ -598,13 +598,6 @@ static struct xfrm_state *xfrm_state_construct(struct net *net, goto error; } -if (attrs[XFRMA_OFFLOAD_DEV ]) { - err =xfrm_dev_state_add (net, x, -nla_data (attrs[XFRMA_OFFLOAD_DEV ])); -if (err) - goto error; - } -if ((err =xfrm_alloc_replay_state_esn (&x->replay_esn, &x->preplay_esn, attrs[XFRMA_REPLAY_ESN_VAL ]))) goto error;
@@ -620,6 +613,14 @@ static struct xfrm_state *xfrm_state_construct(struct net *net,/* override default values from above */ xfrm_update_ae_params (x, attrs,0 ); +/* configure the hardware if offload is requested */ +if (attrs[XFRMA_OFFLOAD_DEV ]) { + err =xfrm_dev_state_add (net, x, +nla_data (attrs[XFRMA_OFFLOAD_DEV ])); +if (err) + goto error; + } +return x; error:
@@ -662,6 +663,9 @@ static int xfrm_add_sa(struct sk_buff *skb, struct nlmsghdr *nlh, goto out; } +if (x->km.state ==XFRM_STATE_VOID ) + x->km.state =XFRM_STATE_VALID ; + c.seq = nlh->nlmsg_seq; c.portid = nlh->nlmsg_pid; c.event = nlh->nlmsg_type;
Signature · 1 line
2.14.1
Steffen Klassert
maintainerPATCH 2/4 xfrm: fix error flow in case of add state fails
In reply to Steffen KlassertFrom: Aviad Yehezkel <[email protected]>
If add state fails in case of device offload, netdev refcount will be negative since gc task is attempting to dev_free this state. This is fixed by putting NULL in state dev field.
--- net/xfrm/xfrm_device.c | 1 + 1 file changed, 1 insertion(+)
net/xfrm/xfrm_device.c +1 -0
@@ -102,6 +102,7 @@ int xfrm_dev_state_add(struct net *net, struct xfrm_state *x, err = dev->xfrmdev_ops->xdo_dev_state_add (x);if (err) { + xso->dev =NULL ;dev_put (dev);return err; }
Signature · 1 line
2.14.1
Steffen Klassert
maintainerPATCH 3/4 xfrm: Fix eth_hdr(skb)->h_proto to reflect inner IP version
In reply to Steffen KlassertFrom: Yossi Kuperman <[email protected]>
IPSec tunnel mode supports encapsulation of IPv4 over IPv6 and vice-versa.
The outer IP header is stripped and the inner IP inherits the original Ethernet header. Tcpdump fails to properly decode the inner packet in case that h_proto is different than the inner IP version.
Fix h_proto to reflect the inner IP version.
--- net/ipv4/xfrm4_mode_tunnel.c | 1 + net/ipv6/xfrm6_mode_tunnel.c | 1 + 2 files changed, 2 insertions(+)
net/ipv4/xfrm4_mode_tunnel.c +1 -0
@@ -92,6 +92,7 @@ static int xfrm4_mode_tunnel_input(struct xfrm_state *x, struct sk_buff *skb)skb_reset_network_header (skb);skb_mac_header_rebuild (skb); +eth_hdr (skb)->h_proto = skb->protocol; err =0 ;
net/ipv6/xfrm6_mode_tunnel.c +1 -0
@@ -92,6 +92,7 @@ static int xfrm6_mode_tunnel_input(struct xfrm_state *x, struct sk_buff *skb)skb_reset_network_header (skb);skb_mac_header_rebuild (skb); +eth_hdr (skb)->h_proto = skb->protocol; err =0 ;
Signature · 1 line
2.14.1
Steffen Klassert
maintainerPATCH 4/4 xfrm: fix boolean assignment in xfrm_get_type_offload
In reply to Steffen KlassertFrom: "Gustavo A. R. Silva" <[email protected]>
Assign true or false to boolean variables instead of an integer value.
This issue was detected with the help of Coccinelle.
--- net/xfrm/xfrm_state.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/xfrm/xfrm_state.c +1 -1
@@ -317,7 +317,7 @@ xfrm_get_type_offload(u8 proto, unsigned short family, bool try_load)if (!type && try_load) {request_module ("xfrm-offload-%d-%d" , family, proto); - try_load =0 ; + try_load = false; goto retry; }
Signature · 1 line
2.14.1
David Miller
maintainerFrom: Steffen Klassert <[email protected]>
Date: Wed, 24 Jan 2018 10:47:09 +0100
Quoted 12 lines
1) Only offloads SAs after they are fully initialized. Otherwise a NIC may receive packets on a SA we can not yet handle in the stack.
From Yossi Kuperman.2) Fix negative refcount in case of a failing offload. From Aviad Yehezkel.
3) Fix inner IP ptoro version when decapsulating
from interaddress family tunnels.
From Yossi Kuperman.
Quoted 5 lines
4) Use true or false for boolean variables instead of an integer value in
xfrm_get_type_offload.
From Gustavo A. R. Silva.Please pull or let me know if there are problems.
Pulled, thanks.