Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp2453260imd; Fri, 2 Nov 2018 11:39:43 -0700 (PDT) X-Google-Smtp-Source: AJdET5eMzsXudS4S5EK7Znw2v+LG/IuYnAlvNd8Otn/CE+BAnCYZVosImXlnt74rOZnnK8X9php0 X-Received: by 2002:a17:902:d708:: with SMTP id w8-v6mr5062597ply.72.1541183983769; Fri, 02 Nov 2018 11:39:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1541183983; cv=none; d=google.com; s=arc-20160816; b=03wI3JwLcOkw1UGtBQHn9hsOy+NPyrbBWchjKcGhicQ1RHi+lgKweo1Zm7+/lEgRfx dCQXYJrPVXd21h6At9K5GwEvyQ3jdQiBXIw52CE6wqxT4fozNQdtnjDgMXS8rz7dlDDp rMAUt4q5H/qMLG7pcUp2lbRDPbEjlu8GEHJR9a1+jR8GMjA0s87L4WjDuim+K+VoA3Ma lhfJkXhg56Wfa7adU9Gacko3bD4+1AYimroqtT+Fbv+akoY/u6mrjSYimfvq7MdgCGQV 0hTmkJnaGMyQ78P8emT4lO3I6zgoE+tD3PoAmwfX2gClcSN53mRIK7+mUbc9GYJnqkP8 NLNA== 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=vJM1+4i2rdKUskdT0TFoS5Q53mLExHB4KGS36/iN8D0=; b=mkU8w80UQCRtLq1LFYMOl8LkiAKlntQxLwHfGMO5ehHDUE8hoWouhXHu9+2Hxzf8cW NdcoQU2cXyt4yaFly91MFFR/nI9e5QMdbeRKPgSpMa7pNXnfInkT8uAB/pH6lE6OtZCT jXvM8jyE8VnaU3iI1nyv1/b0p59l0oq6Fhd/iWKYjD9VyB6+5lN/9uAjRFqpMyTV5yDY unvpWGf7xYNjyrv1SUI9pc1xvnKG/7Fl+tc5xAqrGzrFUtHCSokwrd0TMOhNGWLfK8bL S2AYyf1RBC57UHs6QDToB/gVJU05/LRvBgNjAEBSjDWZeZp6zFUYcm/JRMUdWcfuUMM5 wwtw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ym4AFEk5; 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 i25-v6si34117757pgi.426.2018.11.02.11.39.29; Fri, 02 Nov 2018 11:39:43 -0700 (PDT) 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=ym4AFEk5; 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 S1728803AbeKCDq2 (ORCPT + 99 others); Fri, 2 Nov 2018 23:46:28 -0400 Received: from mail.kernel.org ([198.145.29.99]:40212 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727556AbeKCDq1 (ORCPT ); Fri, 2 Nov 2018 23:46:27 -0400 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (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 E424E20837; Fri, 2 Nov 2018 18:38:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541183896; bh=HGgNrH7+euDADOk6sHOP5mn2riDL/TufRNugsrrirXE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ym4AFEk5CadtZ+mcEzF8UzKxRVUYxKfltq+ksvgIrLCvEyzzKqzGG9OE9yAXeAHNv SEu+ugb+QoNdShjDl/oXJLOa7g+RQVUR9d+9LQjPWye6Brq7dmAAdfOtAm5D/rGT+S NncrInFrIIhgXvbC7ZlczEY8CwACqSY799WhLv5A= 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 4.18 013/150] xfrm: validate template mode Date: Fri, 2 Nov 2018 19:32:55 +0100 Message-Id: <20181102182903.646700065@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181102182902.250560510@linuxfoundation.org> References: <20181102182902.250560510@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 4.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 5151b3ebf068..d0672c400c2f 100644 --- a/net/xfrm/xfrm_user.c +++ b/net/xfrm/xfrm_user.c @@ -1455,6 +1455,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