Received: by 2002:ac0:b08d:0:0:0:0:0 with SMTP id l13csp4745965imc; Mon, 25 Feb 2019 10:11:57 -0800 (PST) X-Google-Smtp-Source: AHgI3Ia4uHrhiVp80PQ6WvIovQ9ie5uLfG18lXIX0anK7z4/8GZV7FIYo1M5Bt71ndnKKA73CrQD X-Received: by 2002:a17:902:ba8c:: with SMTP id k12mr2188215pls.193.1551118317172; Mon, 25 Feb 2019 10:11:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551118317; cv=none; d=google.com; s=arc-20160816; b=IfDVM4+YODh6ATfLNv2ukWACVqqOYM1LkmnVbBVOaGZAuy4sBvSwh0qXleD7DnvD1e F9HkMvbPXvOeY6jvdQJnh/H+2/G/1OVYAvpXtN7duVJuDkChz3NjhIu7Luny0JlzJHiX GR7weiB2QSTpzbLjNkMZRsDloeQlskTc1XEG4v0+Lar6L0UwsAFaxJkT0bwaj0YZ9Rdf GKIILvjZr/cEKw7XBjyXyhMaEgeiMbehvxFl2zQWcbOUMZHDIggkTzIoSIpt6KlpBCvs uJGEOtFKmIeODS7ywZd1LEs/MjJl4dycIPnhnxATIzC2ZL5g5865wJdrDx1Dtt3b3M59 SyHA== 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=X33IUJSVfUSZKXewPflWrtNhrNThPa+uigVnCdo9vLg=; b=NIt7dnu1qwjZhncEkljQRBBMt+FkmVnNitsxLUY2pEqQuJAyb9wmJqADGyEOGWqEef XfP6BlGe4FRmJqCcjDuVmjSinGbW+vPES1KhbMl6XyDjsFbH56lf2MVDzho/KQneou1M MuGTTKjlPBBTspP+sUukw6+Y+R5OXxkKlhKBqloRdfcMFHQcwVYqqg9VsvIQRoh9SuLv lM1/RZrNXvnhOXVZpax57+EvaZii/okctnOOORIzU+AnUYOJ65BGwMCa0HHmNMD1sGYn AnKRXR/0AawNgq0e/eZo7DgWarbXXsPVBdKrdA+TSGAYyW+d4EGf2d30S9PpZbFKQkey LY/Q== 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 h6si9753809pll.326.2019.02.25.10.11.40; Mon, 25 Feb 2019 10:11:57 -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 S1728804AbfBYSLN (ORCPT + 99 others); Mon, 25 Feb 2019 13:11:13 -0500 Received: from terminus.zytor.com ([198.137.202.136]:56419 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726921AbfBYSLN (ORCPT ); Mon, 25 Feb 2019 13:11:13 -0500 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTPS id x1PIAlgr1803965 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Mon, 25 Feb 2019 10:10:47 -0800 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id x1PIAkLw1803962; Mon, 25 Feb 2019 10:10:46 -0800 Date: Mon, 25 Feb 2019 10:10:46 -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: mingo@kernel.org, hpa@zytor.com, brgerst@gmail.com, peterz@infradead.org, luto@kernel.org, dvlasenk@redhat.com, linux-kernel@vger.kernel.org, bp@suse.de, tglx@linutronix.de, jpoimboe@redhat.com, torvalds@linux-foundation.org Reply-To: bp@suse.de, linux-kernel@vger.kernel.org, peterz@infradead.org, tglx@linutronix.de, brgerst@gmail.com, dvlasenk@redhat.com, mingo@kernel.org, hpa@zytor.com, jpoimboe@redhat.com, torvalds@linux-foundation.org, luto@kernel.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: 1ee2bd5e09195d5476daefec5c64ba597a0a9920 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: 1ee2bd5e09195d5476daefec5c64ba597a0a9920 Gitweb: https://git.kernel.org/tip/1ee2bd5e09195d5476daefec5c64ba597a0a9920 Author: Andy Lutomirski AuthorDate: Fri, 22 Feb 2019 17:17:04 -0800 Committer: Borislav Petkov CommitDate: Mon, 25 Feb 2019 18:55:04 +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. ] Fixes: 11f1a4b9755f ("x86: reorganize SMAP handling in user space accesses") Signed-off-by: Andy Lutomirski Signed-off-by: Borislav Petkov Cc: Peter Zijlstra Cc: Linus Torvalds 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..d7688efacf29 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(); \