From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-sn1nam02on0104.outbound.protection.outlook.com ([104.47.36.104]:27338 "EHLO NAM02-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1032509AbeCAPhh (ORCPT ); Thu, 1 Mar 2018 10:37:37 -0500 From: Sasha Levin To: "stable@vger.kernel.org" , "stable-commits@vger.kernel.org" CC: Steffen Klassert , Sasha Levin Subject: [added to the 4.1 stable tree] xfrm: Fix stack-out-of-bounds with misconfigured transport mode policies. Date: Thu, 1 Mar 2018 15:27:00 +0000 Message-ID: <20180301152116.1486-421-alexander.levin@microsoft.com> References: <20180301152116.1486-1-alexander.levin@microsoft.com> In-Reply-To: <20180301152116.1486-1-alexander.levin@microsoft.com> Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org List-ID: From: Steffen Klassert This patch has been added to the 4.1 stable tree. If you have any objections, please let us know. =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D [ Upstream commit 732706afe1cc46ef48493b3d2b69c98f36314ae4 ] On policies with a transport mode template, we pass the addresses from the flowi to xfrm_state_find(), assuming that the IP addresses (and address family) don't change during transformation. Unfortunately our policy template validation is not strict enough. It is possible to configure policies with transport mode template where the address family of the template does not match the selectors address family. This lead to stack-out-of-bound reads because we compare arddesses of the wrong family. Fix this by refusing such a configuration, address family can not change on transport mode. We use the assumption that, on transport mode, the first templates address family must match the address family of the policy selector. Subsequent transport mode templates must mach the address family of the previous template. Signed-off-by: Steffen Klassert Signed-off-by: Sasha Levin --- net/xfrm/xfrm_user.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/net/xfrm/xfrm_user.c b/net/xfrm/xfrm_user.c index 713194a3822f..84541b35629a 100644 --- a/net/xfrm/xfrm_user.c +++ b/net/xfrm/xfrm_user.c @@ -1353,11 +1353,14 @@ static void copy_templates(struct xfrm_policy *xp, = struct xfrm_user_tmpl *ut, =20 static int validate_tmpl(int nr, struct xfrm_user_tmpl *ut, u16 family) { + u16 prev_family; int i; =20 if (nr > XFRM_MAX_DEPTH) return -EINVAL; =20 + prev_family =3D family; + for (i =3D 0; i < nr; i++) { /* We never validated the ut->family value, so many * applications simply leave it at zero. The check was @@ -1369,6 +1372,12 @@ static int validate_tmpl(int nr, struct xfrm_user_tm= pl *ut, u16 family) if (!ut[i].family) ut[i].family =3D family; =20 + if ((ut[i].mode =3D=3D XFRM_MODE_TRANSPORT) && + (ut[i].family !=3D prev_family)) + return -EINVAL; + + prev_family =3D ut[i].family; + switch (ut[i].family) { case AF_INET: break; --=20 2.14.1