Received: by 2002:ac0:aed5:0:0:0:0:0 with SMTP id t21csp2279829imb; Mon, 4 Mar 2019 00:37:28 -0800 (PST) X-Google-Smtp-Source: APXvYqxZVTQ7bVijWXg1d/jOP5vkTDnVaMpVeg7qCETfFBb2oFun629rRai2CvsXc5eh0mITQCJG X-Received: by 2002:a63:ef05:: with SMTP id u5mr17579262pgh.177.1551688648695; Mon, 04 Mar 2019 00:37:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551688648; cv=none; d=google.com; s=arc-20160816; b=afnSSTebkd2Qyze+RZ48Ll2ONKVUUbdzS+SG7QQw2xwuJoffL3AT/R7bma1bOEJlmP V475TnxWo8Kq2PjBDR9sV2EnQ6JsPXBDB6lVBzGw/FXTYsAlfNaiJ9RcHEGlOAZuTW/e gXQt0EyhdM17pnXBBmn9RRZjbCjYRivR/5VnikiozBgafnI73TF8VP2Jk5F4NBElCdnc gDTCoDl228EdasFu0kQNm11NvHpkIlgTVZfIBEpG988CdpCErScrCdMYwqH5QE2HMilH HNGpyQ4Mciz9x0agviNSEjT+v7I31lPwWkA1jwxUxyf4t1lcSQcb0gcoS9VVyJnT6Ce7 fgHQ== 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=+y0IROz4eCQADXhEP0bQocBf99yGM8bQIkPeHtU/HCw=; b=cpUfJPjO+EO++yzoLo9BWM7c3/7a9MSpl78MSIT46XhJ4ZQKmGg4PgNuKL/kHgH3PO 4UFftLWI5ny57t9xaQbn7SFwQYB1Fy/bdn67VofkL6YPgWzzfrrr2kwIVtvL0xs5wlLd +Hlp/M2W8J5B8uG5VNeX2YUq7NdJPy2RA8q5RssX+c4vTEV0z0dnn9tk2zqqvEmKMinP xJMoJzQVKAXRwm5V6c2FPS5hnYXEI4RwoqSd95JD8MgJAtpVn5whAITTJmuUQPXd2vFO zZC/RBIoOsgCWV6WuL90R9e+dUIeaoPtg35m4lBu8Sie4XEct3amauyLc7ObFMAgqrvZ snQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="cx5WK/pV"; 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 o24si4747642pgh.114.2019.03.04.00.37.11; Mon, 04 Mar 2019 00:37:28 -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="cx5WK/pV"; 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 S1728730AbfCDIgr (ORCPT + 99 others); Mon, 4 Mar 2019 03:36:47 -0500 Received: from mail.kernel.org ([198.145.29.99]:46774 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728708AbfCDIgl (ORCPT ); Mon, 4 Mar 2019 03:36:41 -0500 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 17C30208E4; Mon, 4 Mar 2019 08:36:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1551688600; bh=L2f2rrBPA1R8LUwfmPMEwa6x7Dz+3AgKfbuXi95KKU4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cx5WK/pVimDkTlV1dp0Kn0BqL5fZoa7iOlskaRAXKa7N92HDqRjFp4yYMdd/fkqk/ ITeIlpchmrmqvw8uWcNP+iTFGDyzIBbwy67MYAz5DIOYHABKK6rgYb/7/KKAVn18Fz Rg4JgS1/mzTUD5yOqKGIWChLoGB1D/LmccAGWsAU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Andy Lutomirski , Borislav Petkov , Linus Torvalds , Peter Zijlstra , Brian Gerst , Josh Poimboeuf , Denys Vlasenko Subject: [PATCH 4.20 88/88] x86/uaccess: Dont leak the AC flag into __put_user() value evaluation Date: Mon, 4 Mar 2019 09:23:11 +0100 Message-Id: <20190304081634.180902760@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190304081630.610632175@linuxfoundation.org> References: <20190304081630.610632175@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore 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.20-stable review patch. If anyone has any objections, please let me know. ------------------ From: Andy Lutomirski commit 2a418cf3f5f1caf911af288e978d61c9844b0695 upstream. When calling __put_user(foo(), ptr), the __put_user() macro would call foo() in between __uaccess_begin() and __uaccess_end(). If that code were buggy, then those bugs would be run without SMAP protection. Fortunately, there seem to be few instances of the problem in the kernel. Nevertheless, __put_user() should be fixed to avoid doing this. Therefore, evaluate __put_user()'s argument before setting AC. This issue was noticed when an objtool hack by Peter Zijlstra complained about genregs_get() and I compared the assembly output to the C source. [ bp: Massage commit message and fixed up whitespace. ] Fixes: 11f1a4b9755f ("x86: reorganize SMAP handling in user space accesses") Signed-off-by: Andy Lutomirski Signed-off-by: Borislav Petkov Acked-by: Linus Torvalds Cc: Peter Zijlstra Cc: Brian Gerst Cc: Josh Poimboeuf Cc: Denys Vlasenko Cc: stable@vger.kernel.org Link: http://lkml.kernel.org/r/20190225125231.845656645@infradead.org Signed-off-by: Greg Kroah-Hartman --- arch/x86/include/asm/uaccess.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) --- a/arch/x86/include/asm/uaccess.h +++ b/arch/x86/include/asm/uaccess.h @@ -293,8 +293,7 @@ do { \ __put_user_asm(x, ptr, retval, "l", "k", "ir", errret); \ break; \ case 8: \ - __put_user_asm_u64((__typeof__(*ptr))(x), ptr, retval, \ - errret); \ + __put_user_asm_u64(x, ptr, retval, errret); \ break; \ default: \ __put_user_bad(); \ @@ -440,8 +439,10 @@ do { \ #define __put_user_nocheck(x, ptr, size) \ ({ \ int __pu_err; \ + __typeof__(*(ptr)) __pu_val; \ + __pu_val = x; \ __uaccess_begin(); \ - __put_user_size((x), (ptr), (size), __pu_err, -EFAULT); \ + __put_user_size(__pu_val, (ptr), (size), __pu_err, -EFAULT);\ __uaccess_end(); \ __builtin_expect(__pu_err, 0); \ })