All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sasha Levin <Alexander.Levin@microsoft.com>
To: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"stable@vger.kernel.org" <stable@vger.kernel.org>
Cc: Lorenzo Colitti <lorenzo@google.com>,
	Steffen Klassert <steffen.klassert@secunet.com>,
	Sasha Levin <Alexander.Levin@microsoft.com>
Subject: [PATCH AUTOSEL for 4.14 22/84] net: xfrm: allow clearing socket xfrm policies.
Date: Sat, 3 Mar 2018 22:26:12 +0000	[thread overview]
Message-ID: <20180303222518.26271-22-alexander.levin@microsoft.com> (raw)
In-Reply-To: <20180303222518.26271-1-alexander.levin@microsoft.com>

From: Lorenzo Colitti <lorenzo@google.com>

[ 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>
---
 net/xfrm/xfrm_policy.c | 2 +-
 net/xfrm/xfrm_state.c  | 7 +++++++
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
index 22f5da66357b..7d17c207fc8a 100644
--- a/net/xfrm/xfrm_policy.c
+++ b/net/xfrm/xfrm_policy.c
@@ -1257,7 +1257,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
diff --git a/net/xfrm/xfrm_state.c b/net/xfrm/xfrm_state.c
index 58be0e7f4c7d..bab20c626943 100644
--- a/net/xfrm/xfrm_state.c
+++ b/net/xfrm/xfrm_state.c
@@ -2050,6 +2050,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;
 
-- 
2.14.1

  parent reply	other threads:[~2018-03-04  0:24 UTC|newest]

Thread overview: 84+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-03 22:26 [PATCH AUTOSEL for 4.14 01/84] drm/edid: set ELD connector type in drm_edid_to_eld() Sasha Levin
2018-03-03 22:26 ` [PATCH AUTOSEL for 4.14 03/84] video/hdmi: Allow "empty" HDMI infoframes Sasha Levin
2018-03-03 22:26 ` [PATCH AUTOSEL for 4.14 02/84] dma-buf/fence: Fix lock inversion within dma-fence-array Sasha Levin
2018-03-03 22:26 ` [PATCH AUTOSEL for 4.14 05/84] HID: elo: clear BTN_LEFT mapping Sasha Levin
2018-03-03 22:26 ` [PATCH AUTOSEL for 4.14 04/84] HID: multitouch: Only look at non touch fields in first packet of a frame Sasha Levin
2018-03-03 22:26 ` [PATCH AUTOSEL for 4.14 06/84] iwlwifi: mvm: rs: don't override the rate history in the search cycle Sasha Levin
2018-03-03 22:26 ` [PATCH AUTOSEL for 4.14 08/84] clk: meson: gxbb: fix wrong clock for SARADC/SANA Sasha Levin
2018-03-03 22:26 ` [PATCH AUTOSEL for 4.14 07/84] ARM: dts: koelsch: Move cec_clock to root node Sasha Levin
2018-03-03 22:26 ` [PATCH AUTOSEL for 4.14 09/84] ARM: dts: exynos: Correct Trats2 panel reset line Sasha Levin
2018-03-03 22:26 ` [PATCH AUTOSEL for 4.14 10/84] drm/amdgpu: fix get_max_engine_clock_in_mhz Sasha Levin
2018-03-03 22:26 ` [PATCH AUTOSEL for 4.14 12/84] typec: tcpm: fusb302: Resolve out of order messaging events Sasha Levin
2018-03-03 22:26 ` [PATCH AUTOSEL for 4.14 11/84] staging: rtl8822be: fix missing null check on dev_alloc_skb return Sasha Levin
2018-03-03 22:26 ` [PATCH AUTOSEL for 4.14 13/84] USB: ledtrig-usbport: fix of-node leak Sasha Levin
2018-03-03 22:26 ` [PATCH AUTOSEL for 4.14 15/84] sched: Stop resched_cpu() from sending IPIs to offline CPUs Sasha Levin
2018-03-03 22:26 ` [PATCH AUTOSEL for 4.14 14/84] sched: Stop switched_to_rt() " Sasha Levin
2018-03-03 22:26 ` [PATCH AUTOSEL for 4.14 17/84] crypto: cavium - fix memory leak on info Sasha Levin
2018-03-03 22:26 ` [PATCH AUTOSEL for 4.14 16/84] crypto: ecc - Fix NULL pointer deref. on no default_rng Sasha Levin
2018-03-03 22:26 ` [PATCH AUTOSEL for 4.14 18/84] test_firmware: fix setting old custom fw path back on exit Sasha Levin
2018-03-03 22:26 ` [PATCH AUTOSEL for 4.14 20/84] net: ieee802154: adf7242: Fix bug if defined DEBUG Sasha Levin
2018-03-03 22:26 ` [PATCH AUTOSEL for 4.14 19/84] ASoC: fsl_ssi: only enable proper channel slots in AC'97 mode Sasha Levin
2018-03-03 22:26 ` Sasha Levin [this message]
2018-03-03 22:26 ` [PATCH AUTOSEL for 4.14 21/84] rtc: brcmstb-waketimer: fix error handling in brcmstb_waketmr_probe() Sasha Levin
2018-03-03 22:26 ` [PATCH AUTOSEL for 4.14 23/84] mtd: nand: fix interpretation of NAND_CMD_NONE in nand_command[_lp]() Sasha Levin
2018-03-03 22:26 ` [PATCH AUTOSEL for 4.14 24/84] net: thunderx: Set max queue count taking XDP_TX into account Sasha Levin
2018-03-03 22:26 ` [PATCH AUTOSEL for 4.14 25/84] ARM: dts: am335x-pepper: Fix the audio CODEC's reset pin Sasha Levin
2018-03-03 22:26 ` [PATCH AUTOSEL for 4.14 26/84] ARM: dts: omap3-n900: " Sasha Levin
2018-03-03 22:26 ` [PATCH AUTOSEL for 4.14 27/84] mtd: nand: ifc: update bufnum mask for ver >= 2.0.0 Sasha Levin
2018-03-03 22:26 ` [PATCH AUTOSEL for 4.14 29/84] xfrm: Fix xfrm_replay_overflow_offload_esn Sasha Levin
2018-03-03 22:26 ` [PATCH AUTOSEL for 4.14 28/84] userns: Don't fail follow_automount based on s_user_ns Sasha Levin
2018-03-03 22:26 ` [PATCH AUTOSEL for 4.14 30/84] leds: pm8058: Silence pointer to integer size warning Sasha Levin
2018-03-03 22:26 ` [PATCH AUTOSEL for 4.14 31/84] clk: ti: clkctrl: add support for retrying failed init Sasha Levin
2018-03-03 22:26 ` [PATCH AUTOSEL for 4.14 32/84] ASoC: tlv320aic31xx: Handle inverted BCLK in non-DSP modes Sasha Levin
2018-03-03 22:26 ` [PATCH AUTOSEL for 4.14 34/84] power: supply: ab8500_charger: Bail out in case of error in 'ab8500_charger_init_hw_registers()' Sasha Levin
2018-03-03 22:26 ` [PATCH AUTOSEL for 4.14 33/84] power: supply: ab8500_charger: Fix an error handling path Sasha Levin
2018-03-03 22:26 ` [PATCH AUTOSEL for 4.14 36/84] iio: adc: ina2xx: Shift bus voltage register to mask flag bits Sasha Levin
2018-03-03 22:26 ` [PATCH AUTOSEL for 4.14 35/84] drm/etnaviv: make THERMAL selectable Sasha Levin
2018-03-03 22:26 ` [PATCH AUTOSEL for 4.14 37/84] iio: health: max30102: Add power enable parameter to get_temp function Sasha Levin
2018-03-03 22:26 ` [PATCH AUTOSEL for 4.14 38/84] ath10k: update tdls teardown state to target Sasha Levin
2018-03-03 22:26 ` [PATCH AUTOSEL for 4.14 39/84] cpufreq: Fix governor module removal race Sasha Levin
2018-03-03 22:26 ` [PATCH AUTOSEL for 4.14 40/84] dmaengine: bcm2835-dma: Use vchan_terminate_vdesc() instead of desc_free Sasha Levin
2018-03-03 22:26 ` [PATCH AUTOSEL for 4.14 41/84] dmaengine: amba-pl08x: " Sasha Levin
2018-03-03 22:26 ` [PATCH AUTOSEL for 4.14 42/84] drm/amdgpu:fix random missing of FLR NOTIFY Sasha Levin
2018-03-03 22:26 ` [PATCH AUTOSEL for 4.14 43/84] scsi: ses: don't ask for diagnostic pages repeatedly during probe Sasha Levin
2018-03-03 22:26 ` [PATCH AUTOSEL for 4.14 44/84] pwm: stmpe: Fix wrong register offset for hwpwm=2 case Sasha Levin
2018-03-03 22:26 ` [PATCH AUTOSEL for 4.14 45/84] drm/sun4i: Fix format mask in DE2 driver Sasha Levin
2018-03-03 22:26 ` [PATCH AUTOSEL for 4.14 46/84] pinctrl: sh-pfc: r8a7791: Add can_clk function Sasha Levin
2018-03-03 22:26 ` [PATCH AUTOSEL for 4.14 47/84] pinctrl: sh-pfc: r8a7795-es1: Fix MOD_SEL1 bit[25:24] to 0x3 when using STP_ISEN_1_D Sasha Levin
2018-03-03 22:26 ` [PATCH AUTOSEL for 4.14 48/84] perf annotate: Fix unnecessary memory allocation for s390x Sasha Levin
2018-03-03 22:26 ` [PATCH AUTOSEL for 4.14 49/84] perf annotate: Fix objdump comment parsing for Intel mov dissassembly Sasha Levin
2018-03-03 22:26 ` [PATCH AUTOSEL for 4.14 50/84] iwlwifi: mvm: avoid dumping assert log when device is stopped Sasha Levin
2018-03-03 22:26 ` [PATCH AUTOSEL for 4.14 51/84] drm/amdgpu:fix virtual dce bug Sasha Levin
2018-03-03 22:26 ` [PATCH AUTOSEL for 4.14 53/84] mwifiex: cfg80211: do not change virtual interface during scan processing Sasha Levin
2018-03-03 22:26 ` [PATCH AUTOSEL for 4.14 52/84] clk: qcom: msm8916: fix mnd_width for codec_digcodec Sasha Levin
2018-03-03 22:26 ` [PATCH AUTOSEL for 4.14 54/84] ath10k: fix invalid STS_CAP_OFFSET_MASK Sasha Levin
2018-03-03 22:26 ` [PATCH AUTOSEL for 4.14 56/84] spi: sun6i: disable/unprepare clocks on remove Sasha Levin
2018-03-03 22:26 ` [PATCH AUTOSEL for 4.14 55/84] tools/usbip: fixes build with musl libc toolchain Sasha Levin
2018-03-03 22:26 ` [PATCH AUTOSEL for 4.14 57/84] bnxt_en: Don't print "Link speed -1 no longer supported" messages Sasha Levin
2018-03-03 22:26 ` [PATCH AUTOSEL for 4.14 58/84] scsi: core: scsi_get_device_flags_keyed(): Always return device flags Sasha Levin
2018-03-03 22:26 ` [PATCH AUTOSEL for 4.14 59/84] scsi: devinfo: apply to HP XP the same flags as Hitachi VSP Sasha Levin
2018-03-03 22:26 ` [PATCH AUTOSEL for 4.14 61/84] media: vsp1: Prevent suspending and resuming DRM pipelines Sasha Levin
2018-03-03 22:26 ` [PATCH AUTOSEL for 4.14 60/84] scsi: dh: add new rdac devices Sasha Levin
2018-03-03 22:26 ` [PATCH AUTOSEL for 4.14 62/84] dm raid: fix raid set size revalidation Sasha Levin
2018-03-03 22:26 ` [PATCH AUTOSEL for 4.14 63/84] media: cpia2: Fix a couple off by one bugs Sasha Levin
2018-03-03 22:26 ` [PATCH AUTOSEL for 4.14 64/84] media: davinci: vpif_capture: add NULL check on devm_kzalloc return value Sasha Levin
2018-03-03 22:26 ` [PATCH AUTOSEL for 4.14 66/84] net: sched: drop qdisc_reset from dev_graft_qdisc Sasha Levin
2018-03-03 22:26 ` [PATCH AUTOSEL for 4.14 65/84] virtio_net: Disable interrupts if napi_complete_done rescheduled napi Sasha Levin
2018-03-03 22:26 ` [PATCH AUTOSEL for 4.14 67/84] veth: set peer GSO values Sasha Levin
2018-03-03 22:26 ` [PATCH AUTOSEL for 4.14 69/84] powerpc/modules: Don't try to restore r2 after a sibling call Sasha Levin
2018-03-03 22:26 ` [PATCH AUTOSEL for 4.14 68/84] drm/amdkfd: Fix memory leaks in kfd topology Sasha Levin
2018-03-03 22:26 ` [PATCH AUTOSEL for 4.14 70/84] powerpc/64: Don't trace irqs-off at interrupt return to soft-disabled context Sasha Levin
2018-03-03 22:26 ` [PATCH AUTOSEL for 4.14 71/84] arm64: dts: renesas: salvator-common: Add EthernetAVB PHY reset Sasha Levin
2018-03-03 22:26 ` [PATCH AUTOSEL for 4.14 72/84] agp/intel: Flush all chipset writes after updating the GGTT Sasha Levin
2018-03-03 22:26 ` [PATCH AUTOSEL for 4.14 74/84] mac80211: remove BUG() when interface type is invalid Sasha Levin
2018-03-03 22:26 ` [PATCH AUTOSEL for 4.14 73/84] mac80211_hwsim: enforce PS_MANUAL_POLL to be set after PS_ENABLED Sasha Levin
2018-03-03 22:26 ` [PATCH AUTOSEL for 4.14 75/84] crypto: caam/qi - use correct print specifier for size_t Sasha Levin
2018-03-03 22:26 ` [PATCH AUTOSEL for 4.14 76/84] ASoC: nuc900: Fix a loop timeout test Sasha Levin
2018-03-03 22:26 ` [PATCH AUTOSEL for 4.14 77/84] mmc: mmc_test: Ensure command queue is disabled for testing Sasha Levin
2018-03-03 22:26 ` [PATCH AUTOSEL for 4.14 78/84] Fix misannotated out-of-line _copy_to_user() Sasha Levin
2018-03-03 22:26 ` [PATCH AUTOSEL for 4.14 79/84] ipvlan: add L2 check for packets arriving via virtual devices Sasha Levin
2018-03-03 22:26 ` [PATCH AUTOSEL for 4.14 80/84] rcutorture/configinit: Fix build directory error message Sasha Levin
2018-03-03 22:26 ` [PATCH AUTOSEL for 4.14 81/84] locking/locktorture: Fix num reader/writer corner cases Sasha Levin
2018-03-03 22:26 ` [PATCH AUTOSEL for 4.14 82/84] ima: relax requiring a file signature for new files with zero length Sasha Levin
2018-03-03 22:26 ` [PATCH AUTOSEL for 4.14 83/84] IB/mlx5: revisit -Wmaybe-uninitialized warning Sasha Levin
2018-03-03 22:26 ` [PATCH AUTOSEL for 4.14 84/84] dmaengine: qcom_hidma: check pending interrupts Sasha Levin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180303222518.26271-22-alexander.levin@microsoft.com \
    --to=alexander.levin@microsoft.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lorenzo@google.com \
    --cc=stable@vger.kernel.org \
    --cc=steffen.klassert@secunet.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.