All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Florian Westphal <fw@strlen.de>,
	Steffen Klassert <steffen.klassert@secunet.com>,
	Sasha Levin <sashal@kernel.org>,
	netdev@vger.kernel.org
Subject: [PATCH AUTOSEL 4.9 02/32] xfrm: refine validation of template and selector families
Date: Sat, 23 Feb 2019 16:09:21 -0500	[thread overview]
Message-ID: <20190223210951.202268-2-sashal@kernel.org> (raw)
In-Reply-To: <20190223210951.202268-1-sashal@kernel.org>

From: Florian Westphal <fw@strlen.de>

[ Upstream commit 35e6103861a3a970de6c84688c6e7a1f65b164ca ]

The check assumes that in transport mode, the first templates family
must match the address family of the policy selector.

Syzkaller managed to build a template using MODE_ROUTEOPTIMIZATION,
with ipv4-in-ipv6 chain, leading to following splat:

BUG: KASAN: stack-out-of-bounds in xfrm_state_find+0x1db/0x1854
Read of size 4 at addr ffff888063e57aa0 by task a.out/2050
 xfrm_state_find+0x1db/0x1854
 xfrm_tmpl_resolve+0x100/0x1d0
 xfrm_resolve_and_create_bundle+0x108/0x1000 [..]

Problem is that addresses point into flowi4 struct, but xfrm_state_find
treats them as being ipv6 because it uses templ->encap_family is used
(AF_INET6 in case of reproducer) rather than family (AF_INET).

This patch inverts the logic: Enforce 'template family must match
selector' EXCEPT for tunnel and BEET mode.

In BEET and Tunnel mode, xfrm_tmpl_resolve_one will have remote/local
address pointers changed to point at the addresses found in the template,
rather than the flowi ones, so no oob read will occur.

Reported-by: 3ntr0py1337@gmail.com
Reported-by: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 net/xfrm/xfrm_user.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/net/xfrm/xfrm_user.c b/net/xfrm/xfrm_user.c
index 026770884d46b..f6f91c3b2de02 100644
--- a/net/xfrm/xfrm_user.c
+++ b/net/xfrm/xfrm_user.c
@@ -1408,10 +1408,15 @@ static int validate_tmpl(int nr, struct xfrm_user_tmpl *ut, u16 family)
 		if (!ut[i].family)
 			ut[i].family = family;
 
-		if ((ut[i].mode == XFRM_MODE_TRANSPORT) &&
-		    (ut[i].family != prev_family))
-			return -EINVAL;
-
+		switch (ut[i].mode) {
+		case XFRM_MODE_TUNNEL:
+		case XFRM_MODE_BEET:
+			break;
+		default:
+			if (ut[i].family != prev_family)
+				return -EINVAL;
+			break;
+		}
 		if (ut[i].mode >= XFRM_MODE_MAX)
 			return -EINVAL;
 
-- 
2.19.1


  reply	other threads:[~2019-02-23 21:18 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-23 21:09 [PATCH AUTOSEL 4.9 01/32] vti4: Fix a ipip packet processing bug in 'IPCOMP' virtual tunnel Sasha Levin
2019-02-23 21:09 ` Sasha Levin [this message]
2019-02-23 21:09 ` [PATCH AUTOSEL 4.9 03/32] perf core: Fix perf_proc_update_handler() bug Sasha Levin
2019-02-23 21:09 ` [PATCH AUTOSEL 4.9 04/32] perf tools: Handle TOPOLOGY headers with no CPU Sasha Levin
2019-02-23 21:09 ` [PATCH AUTOSEL 4.9 05/32] IB/{hfi1, qib}: Fix WC.byte_len calculation for UD_SEND_WITH_IMM Sasha Levin
2019-02-23 21:09 ` [PATCH AUTOSEL 4.9 06/32] iommu/amd: Call free_iova_fast with pfn in map_sg Sasha Levin
2019-02-23 21:09 ` [PATCH AUTOSEL 4.9 07/32] iommu/amd: Unmap all mapped pages in error path of map_sg Sasha Levin
2019-02-23 21:09   ` Sasha Levin
2019-02-23 21:09 ` [PATCH AUTOSEL 4.9 08/32] ipvs: Fix signed integer overflow when setsockopt timeout Sasha Levin
2019-02-23 21:09 ` [PATCH AUTOSEL 4.9 09/32] iommu/amd: Fix IOMMU page flush when detach device from a domain Sasha Levin
2019-02-23 21:09   ` Sasha Levin
2019-02-23 21:09 ` [PATCH AUTOSEL 4.9 10/32] xtensa: SMP: fix ccount_timer_shutdown Sasha Levin
2019-02-23 21:09 ` [PATCH AUTOSEL 4.9 11/32] xtensa: SMP: fix secondary CPU initialization Sasha Levin
2019-02-23 21:09 ` [PATCH AUTOSEL 4.9 12/32] xtensa: smp_lx200_defconfig: fix vectors clash Sasha Levin
2019-02-23 21:09 ` [PATCH AUTOSEL 4.9 13/32] xtensa: SMP: mark each possible CPU as present Sasha Levin
2019-02-23 21:09 ` [PATCH AUTOSEL 4.9 14/32] xtensa: SMP: limit number of possible CPUs by NR_CPUS Sasha Levin
2019-02-23 21:09 ` [PATCH AUTOSEL 4.9 15/32] net: altera_tse: fix msgdma_tx_completion on non-zero fill_level case Sasha Levin
2019-02-23 21:09 ` [PATCH AUTOSEL 4.9 16/32] net: hns: Fix for missing of_node_put() after of_parse_phandle() Sasha Levin
2019-02-23 21:09 ` [PATCH AUTOSEL 4.9 17/32] net: hns: Fix wrong read accesses via Clause 45 MDIO protocol Sasha Levin
2019-02-23 21:09 ` [PATCH AUTOSEL 4.9 18/32] net: stmmac: dwmac-rk: fix error handling in rk_gmac_powerup() Sasha Levin
2019-02-23 21:09 ` [PATCH AUTOSEL 4.9 19/32] gpio: vf610: Mask all GPIO interrupts Sasha Levin
2019-02-23 21:09 ` [PATCH AUTOSEL 4.9 20/32] nfs: Fix NULL pointer dereference of dev_name Sasha Levin
2019-02-23 21:09 ` [PATCH AUTOSEL 4.9 21/32] qed: Fix VF probe failure while FLR Sasha Levin
2019-02-23 21:09 ` [PATCH AUTOSEL 4.9 22/32] scsi: libfc: free skb when receiving invalid flogi resp Sasha Levin
2019-02-23 21:09 ` [PATCH AUTOSEL 4.9 23/32] platform/x86: Fix unmet dependency warning for SAMSUNG_Q10 Sasha Levin
2019-02-23 21:09 ` [PATCH AUTOSEL 4.9 24/32] cifs: fix computation for MAX_SMB2_HDR_SIZE Sasha Levin
2019-02-23 21:09 ` [PATCH AUTOSEL 4.9 25/32] arm64: kprobe: Always blacklist the KVM world-switch code Sasha Levin
2019-02-23 21:09 ` [PATCH AUTOSEL 4.9 26/32] x86/kexec: Don't setup EFI info if EFI runtime is not enabled Sasha Levin
2019-02-23 21:09   ` Sasha Levin
2019-02-23 21:09 ` [PATCH AUTOSEL 4.9 27/32] x86_64: increase stack size for KASAN_EXTRA Sasha Levin
2019-02-23 21:09 ` [PATCH AUTOSEL 4.9 28/32] mm, memory_hotplug: is_mem_section_removable do not pass the end of a zone Sasha Levin
2019-02-23 21:09 ` [PATCH AUTOSEL 4.9 29/32] mm, memory_hotplug: test_pages_in_a_zone do not pass the end of zone Sasha Levin
2019-02-23 21:09 ` [PATCH AUTOSEL 4.9 30/32] fs/drop_caches.c: avoid softlockups in drop_pagecache_sb() Sasha Levin
2019-02-23 21:09 ` [PATCH AUTOSEL 4.9 31/32] autofs: drop dentry reference only when it is never used Sasha Levin
2019-02-23 21:09 ` [PATCH AUTOSEL 4.9 32/32] autofs: fix error return in autofs_fill_super() 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=20190223210951.202268-2-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=fw@strlen.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --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.