Received: by 10.223.185.116 with SMTP id b49csp1102330wrg; Fri, 23 Feb 2018 12:00:11 -0800 (PST) X-Google-Smtp-Source: AH8x227Ae9Wa7ZSeHiNrGraxHWfGnA5HREbFvR/7f4UGN871e8SYhymLdcbyFBQ7VHMJoZpCJlJr X-Received: by 10.98.108.65 with SMTP id h62mr2876852pfc.32.1519416011493; Fri, 23 Feb 2018 12:00:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519416011; cv=none; d=google.com; s=arc-20160816; b=YNCcJb4zyZ5cFmTmVdw2OMQ2hkt4jEQK4X1tUWFSSwrveLbFMYr2gqOEPI4Y1+mhq8 5EXreMTu4n/xqOnEVK4tIMmmv6CahTZpwal6SAv3u852tiftsEXxekkR+Ia2f19BOiMI izrA33+Na5lmezF8JKp8l/zDscwCwNzYE+I4vom51UIjYPb4X+dju6iZimOquuu+sY6p BOtsVIwIFJbtljZpJsJzKyUckFVmaBjVTAiGkTJQ3SDGIQMYabTjTe6O+A0AE8ByQjvf daFpwhgaoOYvL2Tf629UFHeCt+m9q1TL/wT1jxlQ76WbnUi7lL/u/yNOTcLEbQXNdfkI dEbA== 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=4OZVZuRvOQfUmbDqOCnm6OJfX1ajIcXzs2a/bJyvANM=; b=Bv8YUK321I14kZalH7bLs+hOqOWKksY6bR3mD0oB0R4L7colaklqGYsiNGXyKae16K DsWZofukU6/tUk13wlXgrWOOR3fJwnrnm2NEYAd+BQVlefRU8NGbEVSSBsuxDhGxZH2s Iw/aVB/aop4P4JGi4mhV/FdFLhcIgANqNITXqaIKno6QLgH5+xA0uYy2otemDcZ7sW+1 txf345jyOekTPex0QFGpbuTbBD/Uavfb30HzaonemYaqM0XWaAcJLCkFndXBa/FdJnG6 XINX+8XpTIs05GPk31I2UHIdEYd+PORuD1vfiVg05j3NyZgjSjUVxvxWfJFcEwJ3PVVW wTbA== 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 i70si1904226pgc.264.2018.02.23.11.59.57; Fri, 23 Feb 2018 12:00:11 -0800 (PST) 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 S1755044AbeBWT7C (ORCPT + 99 others); Fri, 23 Feb 2018 14:59:02 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:42412 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933478AbeBWSoB (ORCPT ); Fri, 23 Feb 2018 13:44:01 -0500 Received: from localhost (LFbn-1-12258-90.w90-92.abo.wanadoo.fr [90.92.71.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id AB0901215; Fri, 23 Feb 2018 18:44:00 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot , Steffen Klassert Subject: [PATCH 4.9 007/145] xfrm: Fix stack-out-of-bounds read on socket policy lookup. Date: Fri, 23 Feb 2018 19:25:13 +0100 Message-Id: <20180223170725.656716347@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180223170724.669759283@linuxfoundation.org> References: <20180223170724.669759283@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.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Steffen Klassert commit ddc47e4404b58f03e98345398fb12d38fe291512 upstream. When we do tunnel or beet mode, we pass saddr and daddr from the template to xfrm_state_find(), this is ok. On transport mode, we pass the addresses from the flowi, assuming that the IP addresses (and address family) don't change during transformation. This assumption is wrong in the IPv4 mapped IPv6 case, packet is IPv4 and template is IPv6. Fix this by catching address family missmatches of the policy and the flow already before we do the lookup. Reported-by: syzbot Signed-off-by: Steffen Klassert Signed-off-by: Greg Kroah-Hartman --- net/xfrm/xfrm_policy.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) --- a/net/xfrm/xfrm_policy.c +++ b/net/xfrm/xfrm_policy.c @@ -1257,9 +1257,15 @@ static struct xfrm_policy *xfrm_sk_polic again: pol = rcu_dereference(sk->sk_policy[dir]); if (pol != NULL) { - bool match = xfrm_selector_match(&pol->selector, fl, family); + bool match; int err = 0; + if (pol->family != family) { + pol = NULL; + goto out; + } + + match = xfrm_selector_match(&pol->selector, fl, family); if (match) { if ((sk->sk_mark & pol->mark.m) != pol->mark.v) { pol = NULL;