Received: by 2002:ac0:b08d:0:0:0:0:0 with SMTP id l13csp4826342imc; Mon, 25 Feb 2019 11:46:59 -0800 (PST) X-Google-Smtp-Source: AHgI3IZmMtFa8v5EV+MT91uX9wG9vaykD16IFbiIVdVahjiltFJLITJKH9NCOkzgOGI2NalNVrzK X-Received: by 2002:a65:4b83:: with SMTP id t3mr20476921pgq.417.1551124019228; Mon, 25 Feb 2019 11:46:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551124019; cv=none; d=google.com; s=arc-20160816; b=tU7DBF5D/km9VTe3uoxdgRnPZjF5EYvArQ0+QiIagFUGaLnCONe0aL9utrV8StNR+7 AebU1EwaHk0p/ZTi5NoC4dxj8U0GQb0YZ4CIMstoiZYMzcledFlG/u0KsA725vhcA+lu LfbGTqnubVmK0PMLLl/R2ZdBR3XgTaQWNDTZZnNAvG3JobM6lio1dcHfsYcF1uj8MNPe G5vvyN+6BJKWAZ32+xPOjj+ltkkoI/LfsifM2FcsZ9sYGeYzMpp9zdLTeI0+ko4wKtae fp/+1v9XmVGeC+0K16T74itT4KTwOHytJHhcFgxkOoGGHJET+NN1BNZokkcmTWfNZ3q+ nzfQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:mime-version:robot-unsubscribe:robot-id :git-commit-id:subject:to:references:in-reply-to:reply-to:cc :message-id:from:date; bh=zGHv67IbAq82NqKY0MK7S2KpACx6YmBvTrGfSTAT558=; b=kEMEEF+vwlodjcoRTGlRQ9JtnIzxQFoozzKcfaTPaeYiln1+7cY/33AqI26YpwuqO4 raWH57EPxIMRPGYSfyryjxi44fcfzRh6huKwQ/+daoa0ejfan1h7ynYrkJ0Akjm075AF nW/fRYuSZklbISOMpNoSVokeyzHtlWk4QTstk3Av7HfAeejzLEQeXQD/CycOQ9rhj4wv ZZnOfejzE/tOY36sXb1CDSXSwBRB68j3O/SboY5fYO3FXK7SPxxnwf+LHqhQCXDZ1T3Q oCEs+OYlhkxqZ4rp/UaNU/q6XHPdP+stEXXxx5q00KNbef27kwB/4f6tsyqM4LMDgzW7 pi8Q== 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 z88si10884752pfl.65.2019.02.25.11.46.42; Mon, 25 Feb 2019 11:46:59 -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 S1726958AbfBYTqX (ORCPT + 99 others); Mon, 25 Feb 2019 14:46:23 -0500 Received: from terminus.zytor.com ([198.137.202.136]:37077 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726377AbfBYTqX (ORCPT ); Mon, 25 Feb 2019 14:46:23 -0500 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTPS id x1PJk66I1842431 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Mon, 25 Feb 2019 11:46:06 -0800 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id x1PJk33h1842427; Mon, 25 Feb 2019 11:46:03 -0800 Date: Mon, 25 Feb 2019 11:46:03 -0800 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for Andy Lutomirski Message-ID: Cc: linux-kernel@vger.kernel.org, dvlasenk@redhat.com, bp@suse.de, tglx@linutronix.de, torvalds@linux-foundation.org, brgerst@gmail.com, jpoimboe@redhat.com, mingo@kernel.org, peterz@infradead.org, luto@kernel.org, hpa@zytor.com Reply-To: mingo@kernel.org, bp@suse.de, linux-kernel@vger.kernel.org, tglx@linutronix.de, torvalds@linux-foundation.org, dvlasenk@redhat.com, brgerst@gmail.com, jpoimboe@redhat.com, hpa@zytor.com, luto@kernel.org, peterz@infradead.org In-Reply-To: <20190225125231.845656645@infradead.org> References: <20190225125231.845656645@infradead.org> To: linux-tip-commits@vger.kernel.org Subject: [tip:x86/urgent] x86/uaccess: Don't leak the AC flag into __put_user() value evaluation Git-Commit-ID: 2a418cf3f5f1caf911af288e978d61c9844b0695 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline X-Spam-Status: No, score=1.2 required=5.0 tests=ALL_TRUSTED,BAYES_00, DATE_IN_FUTURE_24_48,FREEMAIL_FORGED_REPLYTO autolearn=no autolearn_force=no version=3.4.2 X-Spam-Level: * X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on terminus.zytor.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 2a418cf3f5f1caf911af288e978d61c9844b0695 Gitweb: https://git.kernel.org/tip/2a418cf3f5f1caf911af288e978d61c9844b0695 Author: Andy Lutomirski AuthorDate: Fri, 22 Feb 2019 17:17:04 -0800 Committer: Borislav Petkov CommitDate: Mon, 25 Feb 2019 20:17:05 +0100 x86/uaccess: Don't leak the AC flag into __put_user() value evaluation 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 --- arch/x86/include/asm/uaccess.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h index a77445d1b034..28376aa2d053 100644 --- a/arch/x86/include/asm/uaccess.h +++ b/arch/x86/include/asm/uaccess.h @@ -284,7 +284,7 @@ do { \ __put_user_goto(x, ptr, "l", "k", "ir", label); \ break; \ case 8: \ - __put_user_goto_u64((__typeof__(*ptr))(x), ptr, label); \ + __put_user_goto_u64(x, ptr, label); \ break; \ default: \ __put_user_bad(); \ @@ -431,8 +431,10 @@ do { \ ({ \ __label__ __pu_label; \ int __pu_err = -EFAULT; \ + __typeof__(*(ptr)) __pu_val; \ + __pu_val = x; \ __uaccess_begin(); \ - __put_user_size((x), (ptr), (size), __pu_label); \ + __put_user_size(__pu_val, (ptr), (size), __pu_label); \ __pu_err = 0; \ __pu_label: \ __uaccess_end(); \