From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.0 required=3.0 tests=DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 181CBC43381 for ; Sun, 3 Mar 2019 16:14:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CB2BF2075B for ; Sun, 3 Mar 2019 16:14:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=dlink.ru header.i=@dlink.ru header.b="Ihdlcnh4" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726387AbfCCQOE (ORCPT ); Sun, 3 Mar 2019 11:14:04 -0500 Received: from mail.dlink.ru ([178.170.168.18]:41294 "EHLO fd.dlink.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726411AbfCCQOE (ORCPT ); Sun, 3 Mar 2019 11:14:04 -0500 X-Greylist: delayed 390 seconds by postgrey-1.27 at vger.kernel.org; Sun, 03 Mar 2019 11:14:01 EST Received: by fd.dlink.ru (Postfix, from userid 5000) id DB1AB1B20B0D; Sun, 3 Mar 2019 19:07:28 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 fd.dlink.ru DB1AB1B20B0D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dlink.ru; s=mail; t=1551629248; bh=D6zwyr9nL5GT/g1T4vWnB1nfCsKimlMaqOXGfuVEvWI=; h=From:To:Cc:Subject:Date; b=Ihdlcnh42evlC7Y8erirMtZbkjcWqtLygaXQbmKT+GzWtpfFQdYhlKCUkzbidpaVU 3e7ReWhTo5RuKG4XR9J2zT8LfGxDjDDrTrz8XDy2oQADMQGWkzOlJnCCU/7U1KPBcj PpiL4Zw9XmUzkPKSXlBwIrYJq66FTvw3C9ZDFYG8= Received: from mail.rzn.dlink.ru (mail.rzn.dlink.ru [178.170.168.13]) by fd.dlink.ru (Postfix) with ESMTP id 5904B1B2085D; Sun, 3 Mar 2019 19:07:20 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 fd.dlink.ru 5904B1B2085D Received: from mail.rzn.dlink.ru (localhost [127.0.0.1]) by mail.rzn.dlink.ru (Postfix) with ESMTP id 2BA001B2015C; Sun, 3 Mar 2019 19:07:20 +0300 (MSK) Received: from localhost (unknown [176.112.142.79]) by mail.rzn.dlink.ru (Postfix) with ESMTPSA; Sun, 3 Mar 2019 19:07:20 +0300 (MSK) From: Maxim Zhukov To: Greg Kroah-Hartman Cc: Andy Lutomirski , Borislav Petkov , Linus Torvalds , Peter Zijlstra , Brian Gerst , Josh Poimboeuf , Denys Vlasenko , stable@vger.kernel.org, Maxim Zhukov Subject: [PATCH v4.4] x86/uaccess: Don't leak the AC flag into __put_user() value evaluation Date: Sun, 3 Mar 2019 19:07:09 +0300 Message-Id: <20190303160709.19426-1-mussitantesmortem@gmail.com> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org 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: Maxim Zhukov --- 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 d788b0cdc0ad..4f4a9fa61b8a 100644 --- a/arch/x86/include/asm/uaccess.h +++ b/arch/x86/include/asm/uaccess.h @@ -306,7 +306,7 @@ do { \ __put_user_asm(x, ptr, retval, "l", "k", "ir", errret); \ break; \ case 8: \ - __put_user_asm_u64((__typeof__(*ptr))(x), ptr, retval, \ + __put_user_asm_u64(x, ptr, retval, \ errret); \ break; \ default: \ @@ -410,7 +410,9 @@ do { \ #define __put_user_nocheck(x, ptr, size) \ ({ \ int __pu_err; \ - __put_user_size((x), (ptr), (size), __pu_err, -EFAULT); \ + __typeof__(*(ptr)) __pu_val; \ + __pu_val = x; \ + __put_user_size(__pu_val, (ptr), (size), __pu_err, -EFAULT); \ __builtin_expect(__pu_err, 0); \ }) -- 2.21.0