Received: by 10.213.65.68 with SMTP id h4csp484057imn; Fri, 16 Mar 2018 09:07:58 -0700 (PDT) X-Google-Smtp-Source: AG47ELuEDh2t3D2zd5pChzpZDPV6rnUMT2GQ985tQYV6EDarD9fOKmXlZ7hz5J4MaJz0Ccx4+CHU X-Received: by 2002:a17:902:481:: with SMTP id e1-v6mr2680675ple.377.1521216478163; Fri, 16 Mar 2018 09:07:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521216478; cv=none; d=google.com; s=arc-20160816; b=SZE9MeUfYdUc9FgyFu8Bvi4lxmIFxhUmQihmodwC1sjdcj02WRV84PwfbdiQXWgqE2 sxmQ4AVnAhhuMWRnDrHGiL4hEZZpytGgcTkGaxG6m+/fs86vMQqVzm2iR+l4y9Fv6dfY oH/byWGgjMicKykgLHjQrJIgp+Y+S3UvJG+Mp4wiHRb3/SLRV43JA28/a2lm7WOCPP/t zi6hHXaM/C0s98yoA7/7Gy1ot8Rnp13LRhZgsYYADEYWWzi0CFA8u3AZZDA0AyF6LB03 LdFrViQ1AHt6ic7c8Zq/lFsUrnLFQesZwW8QFtUT8tvqkV/RD/T+sIZE2qm38ImciwbX gP3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=hMfcw88TKNYXHsZNdiDJ47ntVnZKETechUiaVomQWRI=; b=zKMjcN/YDvsHLc/KGNTdaYEhSMoQ71uB+4sapw46GCrw7GKBnMj9h3XOdUEPdRW8Cc wP0T8kbbumJJCtBkALSnmHgmzqyIndQHTz8YFAUvZBEzLgLWBbfuE7v9ZgcfmTDFakE9 THwtnb9q3o8WYeWG6Gc+dUxalC2pYpqkxvlfWCopNWFBcJ11uimCdujUABZmHb/K/Ltu rdc8kWjnMtFrSfs4EKeE3ivdmSxfptqrK2hWlo0LwKjGYAx8YCoXTy0oQSBBQ/OzsZph 3ibhLkaGSJxGTK56oI/QRRm+jMLV/vfzSC6qbST0VPjd/O2pmCvIm3CmzI1TAKnmGSSK 35KA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a100-v6si6497171pli.483.2018.03.16.09.07.44; Fri, 16 Mar 2018 09:07:58 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S964981AbeCPQGq (ORCPT + 99 others); Fri, 16 Mar 2018 12:06:46 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:44078 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754759AbeCPPll (ORCPT ); Fri, 16 Mar 2018 11:41:41 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 4B421F8D; Fri, 16 Mar 2018 15:41:40 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lorenzo Colitti , Steffen Klassert , Sasha Levin Subject: [PATCH 4.15 057/128] net: xfrm: allow clearing socket xfrm policies. Date: Fri, 16 Mar 2018 16:23:18 +0100 Message-Id: <20180316152339.672814818@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180316152336.199007505@linuxfoundation.org> References: <20180316152336.199007505@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Lorenzo Colitti [ 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 Signed-off-by: Steffen Klassert Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- net/xfrm/xfrm_policy.c | 2 +- net/xfrm/xfrm_state.c | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) --- a/net/xfrm/xfrm_policy.c +++ b/net/xfrm/xfrm_policy.c @@ -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 --- a/net/xfrm/xfrm_state.c +++ b/net/xfrm/xfrm_state.c @@ -2056,6 +2056,13 @@ int xfrm_user_policy(struct sock *sk, in 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;