Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp60395imu; Thu, 8 Nov 2018 14:48:35 -0800 (PST) X-Google-Smtp-Source: AJdET5fsLsBWJpV1KqMvtWQcLkSNQ6awbDtWz7aVUH39DFGnbpRH71jRpzf6qeQLq9jzdbK/Pi0D X-Received: by 2002:a17:902:7b93:: with SMTP id w19-v6mr6517353pll.80.1541717315903; Thu, 08 Nov 2018 14:48:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541717315; cv=none; d=google.com; s=arc-20160816; b=BpFAnFjTPpnPwdhNSbQkxvQKhI/H0Dpg2g7WZjXaGg0aKvZYyv3A30CUGZ4uKuUkqu vazHjC0WrnhL2E98CjsCAvGlcU1HPCRsQP3TF2cITtiZCDwjVwH6e7bmc2ey0Qb/l3QF aKSrmsAFIcf4R5f1tPhN7C8Jo7JBmPINpPaHISELJn+xdkBEqAVkntrV+wsW+d/Lamk7 A4cLXLCiNghO/v98ARfu8FJAAlWXjwyDJyUPzErlikx0und7nMz39/177KjLUH76cMFB 62bhJCiw6dN+qt3jX7i/HKRRKhZGirMrFU25QmY49RK0MkCoSu1fKSPYOxbrt9AhAYij iCJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=asZBhkCOGnotJruLHBmh2wgQiSnaJ2psbfJ/Eti9Kjk=; b=ymTfN5QYrkMg3xxdp5/nz3rYj2o4cFpTEGZQt7IcDXR3U9YfK3SGZd6PHRvolE7Y5k KqGaS1fgdDwRaniQpiaK4sESsQuGAZYXwGpWD6XVa4mByrBFS4tSovxeXrV5TkwMKLD0 +GdzmRNFkO6eIUJ68qr6/5GY97AFR4DJ4l5KqICnTtq8ovb9rmUpD9ENbvRodWOBTko8 oxijerrcXvlghma5vmG+HN/x95FPogSFKCsUAl3B9oRHx3969R6qDFnMPP2RD6ieYQSI srgmPFuObbr6tS0PjhCJ9p1oQXoWEo5Qax6N3qFjYq9pWtfBuXSVs7oW5yjE6nH01X1x g76A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=twIC7rUk; 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 i128-v6si5593127pfb.256.2018.11.08.14.48.20; Thu, 08 Nov 2018 14:48:35 -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; dkim=pass header.i=@kernel.org header.s=default header.b=twIC7rUk; 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 S1728351AbeKIIY4 (ORCPT + 99 others); Fri, 9 Nov 2018 03:24:56 -0500 Received: from mail.kernel.org ([198.145.29.99]:45930 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725922AbeKIHbV (ORCPT ); Fri, 9 Nov 2018 02:31:21 -0500 Received: from localhost (unknown [208.72.13.198]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id AC0072081C; Thu, 8 Nov 2018 21:53:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541714034; bh=5XXfrz1MIY2VlCu4t1O3VmAZ+v4hd1zvsGwjqiVbHZ0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=twIC7rUk1llUAXh+zrN5JW0df/mtwohVACZxE629Eqy8WVpjKGUufNWHfZSEbUHw3 1jP675f/uJeL3rpimJrcyd2gieqMu6S/p8dNldHOQzMUrEm9c0x+3QhUHWClWiyXNd KrcUUpsVjSw+PjtCR8RcliN2LdgrYKSLbbRUDtCc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Sean Tranchetti , Steffen Klassert , Sasha Levin Subject: [PATCH 3.18 024/144] xfrm: validate template mode Date: Thu, 8 Nov 2018 13:49:55 -0800 Message-Id: <20181108215056.564988299@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181108215054.826084593@linuxfoundation.org> References: <20181108215054.826084593@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.18-stable review patch. If anyone has any objections, please let me know. ------------------ [ Upstream commit 32bf94fb5c2ec4ec842152d0e5937cd4bb6738fa ] XFRM mode parameters passed as part of the user templates in the IP_XFRM_POLICY are never properly validated. Passing values other than valid XFRM modes can cause stack-out-of-bounds reads to occur later in the XFRM processing: [ 140.535608] ================================================================ [ 140.543058] BUG: KASAN: stack-out-of-bounds in xfrm_state_find+0x17e4/0x1cc4 [ 140.550306] Read of size 4 at addr ffffffc0238a7a58 by task repro/5148 [ 140.557369] [ 140.558927] Call trace: [ 140.558936] dump_backtrace+0x0/0x388 [ 140.558940] show_stack+0x24/0x30 [ 140.558946] __dump_stack+0x24/0x2c [ 140.558949] dump_stack+0x8c/0xd0 [ 140.558956] print_address_description+0x74/0x234 [ 140.558960] kasan_report+0x240/0x264 [ 140.558963] __asan_report_load4_noabort+0x2c/0x38 [ 140.558967] xfrm_state_find+0x17e4/0x1cc4 [ 140.558971] xfrm_resolve_and_create_bundle+0x40c/0x1fb8 [ 140.558975] xfrm_lookup+0x238/0x1444 [ 140.558977] xfrm_lookup_route+0x48/0x11c [ 140.558984] ip_route_output_flow+0x88/0xc4 [ 140.558991] raw_sendmsg+0xa74/0x266c [ 140.558996] inet_sendmsg+0x258/0x3b0 [ 140.559002] sock_sendmsg+0xbc/0xec [ 140.559005] SyS_sendto+0x3a8/0x5a8 [ 140.559008] el0_svc_naked+0x34/0x38 [ 140.559009] [ 140.592245] page dumped because: kasan: bad access detected [ 140.597981] page_owner info is not active (free page?) [ 140.603267] [ 140.653503] ================================================================ Signed-off-by: Sean Tranchetti Signed-off-by: Steffen Klassert Signed-off-by: Sasha Levin --- net/xfrm/xfrm_user.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/net/xfrm/xfrm_user.c b/net/xfrm/xfrm_user.c index ca99638b5d5a..017b1c91d58e 100644 --- a/net/xfrm/xfrm_user.c +++ b/net/xfrm/xfrm_user.c @@ -1381,6 +1381,9 @@ static int validate_tmpl(int nr, struct xfrm_user_tmpl *ut, u16 family) (ut[i].family != prev_family)) return -EINVAL; + if (ut[i].mode >= XFRM_MODE_MAX) + return -EINVAL; + prev_family = ut[i].family; switch (ut[i].family) { -- 2.17.1