]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commitdiff
net: xfrm: allow clearing socket xfrm policies.
authorLorenzo Colitti <lorenzo@google.com>
Mon, 20 Nov 2017 10:26:02 +0000 (19:26 +0900)
committerThadeu Lima de Souza Cascardo <cascardo@canonical.com>
Mon, 19 Mar 2018 23:41:18 +0000 (20:41 -0300)
BugLink: http://bugs.launchpad.net/bugs/1756978
[ Upstream commit be8f8284cd897af2482d4e54fbc2bdfc15557259 ]

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
Signed-off-by: Lorenzo Colitti <lorenzo@google.com>
Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
Signed-off-by: Sasha Levin <alexander.levin@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Thadeu Lima de Souza Cascardo <cascardo@canonical.com>
net/xfrm/xfrm_policy.c
net/xfrm/xfrm_state.c

index bd6b0e7a0ee41f246ea15c57353b1a8d86054f4c..c135ed9bc8c4f68e0fc7c1aac99cc63116600c05 100644 (file)
@@ -1256,7 +1256,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
index a3785f538018dc8a777f7768752d8f5f7cedb1e1..54e21f19d722c43d0b1fd102777a3467cee5b009 100644 (file)
@@ -2056,6 +2056,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;