Skip to contentSkip to conversation

pull request (net-next): ipsec-next 2017-12-15

PATCH New Steffen Klassert 2 participants 7 messages Dec 15, 2017

Subsystems (4)
lore
Share & tools
lore

Steffen Klassert

author maintainer
#0 lore raw

1) Currently we can add or update socket policies, but not clear them. Support clearing of socket policies too. From Lorenzo Colitti.

2) Add documentation for the xfrm device offload api. From Shannon Nelson.

3) Fix IPsec extended sequence numbers (ESN) for
IPsec offloading. From Yossef Efraim.

4) xfrm_dev_state_add function returns success even for unsupported options, fix this to fail in such cases. From Yossef Efraim.

5) Remove a redundant xfrm_state assignment.
From Aviv Heller.

Please pull or let me know if there are problems.

Thanks!

The following changes since commit b9151761021e25c024a6670df4e7c43ffbab0e1d:

Merge tag 'nfsd-4.15-1' of git://linux-nfs.org/~bfields/linux (2017-11-29 14:49:26 -0800)

are available in the git repository at:

git://git.kernel.org/pub/scm/linux/kernel/git/klassert/ipsec-next.git master

for you to fetch changes up to 9b7e14dba0c087e950fc024b486e8f729c1ee672:

xfrm: Remove redundant state assignment in xfrm_input() (2017-12-01 07:41:48 +0100)

----------------------------------------------------------------
Aviv Heller (1):
xfrm: Remove redundant state assignment in xfrm_input()

Lorenzo Colitti (1):
net: xfrm: allow clearing socket xfrm policies.

Shannon Nelson (1):
xfrm: add documentation for xfrm device offload api

Yossef Efraim (2):
xfrm: Fix xfrm_replay_overflow_offload_esn
xfrm: Fix xfrm_dev_state_add to fail for unsupported HW SA option

 Documentation/networking/00-INDEX        |   2 +
 Documentation/networking/xfrm_device.txt | 132 +++++++++++++++++++++++++++++++
 net/xfrm/xfrm_device.c                   |   2 +-
 net/xfrm/xfrm_input.c                    |   1 -
 net/xfrm/xfrm_policy.c                   |   2 +-
 net/xfrm/xfrm_replay.c                   |   3 +-
 net/xfrm/xfrm_state.c                    |   7 ++
 7 files changed, 144 insertions(+), 5 deletions(-)
 create mode 100644 Documentation/networking/xfrm_device.txt
author maintainer
#1 lore raw

PATCH 1/5 net: xfrm: allow clearing socket xfrm policies.

From: Lorenzo Colitti <[email protected]>

Currently it is possible to add or update socket policies, but not clear them. Therefore, once a socket policy has been applied, the socket cannot be used for unencrypted traffic.

This patch allows (privileged) users to clear socket policies by passing in a NULL pointer and zero length argument to the {IP,IPV6}_{IPSEC,XFRM}_POLICY setsockopts. This results in both the incoming and outgoing policies being cleared.

The simple approach taken in this patch cannot clear socket policies in only one direction. If desired this could be added in the future, for example by continuing to pass in a length of zero (which currently is guaranteed to return EMSGSIZE) and making the policy be a pointer to an integer that contains one of the XFRM_POLICY_{IN,OUT} enum values.

An alternative would have been to interpret the length as a signed integer and use XFRM_POLICY_IN (i.e., 0) to clear the input policy and -XFRM_POLICY_OUT (i.e., -1) to clear the output policy.

Tested: https://android-review.googlesource.com/539816

---
 net/xfrm/xfrm_policy.c | 2 +-
 net/xfrm/xfrm_state.c  | 7 +++++++
 2 files changed, 8 insertions(+), 1 deletion(-)
net/xfrm/xfrm_policy.c +1 -1
index 9542975eb2f9..3263662fb20a 100644
@@ -1251,7 +1251,7 @@ EXPORT_SYMBOL(xfrm_policy_delete);
 
 int xfrm_sk_policy_insert(struct sock *sk, int dir, struct xfrm_policy *pol)
 {
-	struct net *net = xp_net(pol);
+	struct net *net = sock_net(sk);
 	struct xfrm_policy *old_pol;
 
 #ifdef CONFIG_XFRM_SUB_POLICY
net/xfrm/xfrm_state.c +7 -0
index 065d89606888..1b7856be3eeb 100644
@@ -2048,6 +2048,13 @@ int xfrm_user_policy(struct sock *sk, int optname, u8 __user *optval, int optlen
 	struct xfrm_mgr *km;
 	struct xfrm_policy *pol = NULL;
 
+	if (!optval && !optlen) {
+		xfrm_sk_policy_insert(sk, XFRM_POLICY_IN, NULL);
+		xfrm_sk_policy_insert(sk, XFRM_POLICY_OUT, NULL);
+		__sk_dst_reset(sk);
+		return 0;
+	}
+
 	if (optlen <= 0 || optlen > PAGE_SIZE)
 		return -EMSGSIZE;
 
Signature · 1 line
2.14.1
author maintainer
#2 lore raw

PATCH 2/5 xfrm: add documentation for xfrm device offload api

In reply to Steffen Klassert

From: Shannon Nelson <[email protected]>

Add a writeup on how to use the XFRM device offload API, and mention this new file in the index.

---
 Documentation/networking/00-INDEX        |   2 +
 Documentation/networking/xfrm_device.txt | 132 +++++++++++++++++++++++++++++++
 2 files changed, 134 insertions(+)
 create mode 100644 Documentation/networking/xfrm_device.txt
Documentation/networking/00-INDEX +2 -0
index 7a79b3587dd3..f5d642c01dd3 100644
@@ -228,6 +228,8 @@ x25.txt
 	- general info on X.25 development.
 x25-iface.txt
 	- description of the X.25 Packet Layer to LAPB device interface.
+xfrm_device.txt
+	- description of XFRM offload API
 xfrm_proc.txt
 	- description of the statistics package for XFRM.
 xfrm_sync.txt
Documentation/networking/xfrm_device.txt new file +132 -0

132 lines not on this page · raw message

Signature · 1 line
2.14.1
author maintainer
#3 lore raw

PATCH 3/5 xfrm: Fix xfrm_replay_overflow_offload_esn

In reply to Steffen Klassert

From: Yossef Efraim <[email protected]>

In case of wrap around, replay_esn->oseq_hi is not updated before it is tested for it's actual value, leading function to fail with overflow indication and packets being dropped.

This patch updates replay_esn->oseq_hi in the right place.

Fixes d7dbefc45cf5 ("xfrm: Add xfrm_replay_overflow functions for offloading")
---
 net/xfrm/xfrm_replay.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
net/xfrm/xfrm_replay.c +1 -2
index 8b23c5bcf8e8..02501817227b 100644
@@ -666,7 +666,7 @@ static int xfrm_replay_overflow_offload_esn(struct xfrm_state *x, struct sk_buff
 		if (unlikely(oseq < replay_esn->oseq)) {
 			XFRM_SKB_CB(skb)->seq.output.hi = ++oseq_hi;
 			xo->seq.hi = oseq_hi;
-
+			replay_esn->oseq_hi = oseq_hi;
 			if (replay_esn->oseq_hi == 0) {
 				replay_esn->oseq--;
 				replay_esn->oseq_hi--;
@@ -678,7 +678,6 @@ static int xfrm_replay_overflow_offload_esn(struct xfrm_state *x, struct sk_buff
 		}
 
 		replay_esn->oseq = oseq;
-		replay_esn->oseq_hi = oseq_hi;
 
 		if (xfrm_aevent_is_on(net))
 			x->repl->notify(x, XFRM_REPLAY_UPDATE);
Signature · 1 line
2.14.1
author maintainer
#4 lore raw

PATCH 4/5 xfrm: Fix xfrm_dev_state_add to fail for unsupported HW SA option

In reply to Steffen Klassert

From: Yossef Efraim <[email protected]>

xfrm_dev_state_add function returns success for unsupported HW SA options. Resulting the calling function to create SW SA without corrlating HW SA. Desipte IPSec device offloading option was chosen.
These not supported HW SA options are hard coded within xfrm_dev_state_add function.
SW backward compatibility will break if we add any of these option as old HW will fail with new SW.

This patch changes the behaviour to return -EINVAL in case unsupported option is chosen.
Notifying user application regarding failure and not breaking backward compatibility for newly added HW SA options.

---
 net/xfrm/xfrm_device.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/xfrm/xfrm_device.c +1 -1
index 30e5746085b8..dc68d9c1fc8f 100644
@@ -67,7 +67,7 @@ int xfrm_dev_state_add(struct net *net, struct xfrm_state *x,
 
 	/* We don't yet support UDP encapsulation, TFC padding and ESN. */
 	if (x->encap || x->tfcpad || (x->props.flags & XFRM_STATE_ESN))
-		return 0;
+		return -EINVAL;
 
 	dev = dev_get_by_index(net, xuo->ifindex);
 	if (!dev) {
Signature · 1 line
2.14.1
author maintainer
#5 lore raw

PATCH 5/5 xfrm: Remove redundant state assignment in xfrm_input()

In reply to Steffen Klassert

From: Aviv Heller <[email protected]>

x is already initialized to the same value, above.

---
 net/xfrm/xfrm_input.c | 1 -
 1 file changed, 1 deletion(-)
net/xfrm/xfrm_input.c +0 -1
index 347ab31574d5..ac277b97e0d7 100644
@@ -231,7 +231,6 @@ int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type)
 
 		if (xo && (xo->flags & CRYPTO_DONE)) {
 			crypto_done = true;
-			x = xfrm_input_state(skb);
 			family = XFRM_SPI_SKB_CB(skb)->family;
 
 			if (!(xo->status & CRYPTO_SUCCESS)) {
Signature · 1 line
2.14.1
maintainer
#6 lore raw
In reply to Steffen Klassert

From: Steffen Klassert <[email protected]>
Date: Fri, 15 Dec 2017 13:19:47 +0100

Quoted 10 lines

1) Currently we can add or update socket policies, but not clear them. Support clearing of socket policies too. From Lorenzo Colitti.

2) Add documentation for the xfrm device offload api. From Shannon Nelson.

3) Fix IPsec extended sequence numbers (ESN) for
IPsec offloading. From Yossef Efraim.

Quoted 8 lines

4) xfrm_dev_state_add function returns success even for unsupported options, fix this to fail in such cases. From Yossef Efraim.

5) Remove a redundant xfrm_state assignment.
From Aviv Heller.

Please pull or let me know if there are problems.

Pulled, thank you Steffen.