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=-8.6 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_PASS,USER_AGENT_MUTT 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 238BFC43381 for ; Sun, 3 Mar 2019 16:38:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DE8AE20835 for ; Sun, 3 Mar 2019 16:38:38 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="XhMNqgmq" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726382AbfCCQii (ORCPT ); Sun, 3 Mar 2019 11:38:38 -0500 Received: from mail-ed1-f65.google.com ([209.85.208.65]:46400 "EHLO mail-ed1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726293AbfCCQii (ORCPT ); Sun, 3 Mar 2019 11:38:38 -0500 Received: by mail-ed1-f65.google.com with SMTP id f2so2251052edy.13 for ; Sun, 03 Mar 2019 08:38:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=OO9Se5yiW/0fT7xe3cOtadGSCyW8gl+/MeWQT1ETwfk=; b=XhMNqgmqy6qMGfahNfsZQU01IUrEDRHUH0Mdte/vQ3bgycIgKIxeDLxD+mUgbaStd2 uuueV5WR9BH/ALKZco7lz8PZsc98WWn+jY7NRn6ObN+As/kXxMieGj+1AlpMPAVLqR+i 34IbKN4N8sfniJaXNr/d2bCdwN5WyAQSlCzoCGe1I8fOzYqkQMrWBbV6EQoHZMDXNOzR Pnw/QZaLDKj9v7QL+2RTMPD69w4nW3BRr3oWS909Z8qvlaJvsJ2hDQMpdxj1uKs3T5Hy 2HuDKri0k6wiN7SHhFtjnwLwWycmgcKlPhy3ctW0BUoSN1FgjIX1IwTWw8emxdwjxqol csew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=OO9Se5yiW/0fT7xe3cOtadGSCyW8gl+/MeWQT1ETwfk=; b=mbT4vf0X/y7Ncad/iXv2guUwHdvGoHEwpxikauplQhqv4YDC6C9OyATmt+gcUzoeIQ ThiGP5NzDLsieBpCuDF31jVh5t+OsuOdzfbFz2nuRFAVgIEwnvKkXZ4NHq4J6mcaxtq5 rAL5WTqP7EZjL5aI4qFoaXZlc3A+5BdgZzff6AGSXnE66z0Z8WRiAaWcf9OecLuX9+UO 1FEuLF6sCji2moqzbF9/SY0Q6iVvOxnSipRmgysPXNg9KLQ1DcpL2qFe9WdsjFL+4YCp X/WpyOINPUs7HH5w7AusUdaptJ/nwxrtx1V/aL7yPs+5y50bBtCpJuxHZYvp2ftfRFP8 /2GQ== X-Gm-Message-State: APjAAAXF2dq44RFzUi4TlErXCIt1Fq0EpcNpe22mDSwBqWOYscmevPbI DOFuamW1W1CnyL6m/SnjxEQ= X-Google-Smtp-Source: APXvYqzEAJlNjiM3Unrc/EAPztiY82OISGklLiLuTlq4ou7IULGpbA2dTKqVJAK0kq1U6ilGkWIRXA== X-Received: by 2002:a17:906:f101:: with SMTP id gv1mr2397065ejb.73.1551631115693; Sun, 03 Mar 2019 08:38:35 -0800 (PST) Received: from archlinux-ryzen ([2a01:4f9:2a:1fae::2]) by smtp.gmail.com with ESMTPSA id k23sm727428eja.60.2019.03.03.08.38.34 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Sun, 03 Mar 2019 08:38:34 -0800 (PST) Date: Sun, 3 Mar 2019 09:38:33 -0700 From: Nathan Chancellor To: Maxim Zhukov Cc: Greg Kroah-Hartman , Andy Lutomirski , Borislav Petkov , Linus Torvalds , Peter Zijlstra , Brian Gerst , Josh Poimboeuf , Denys Vlasenko , stable@vger.kernel.org Subject: Re: [PATCH v4.9] x86/uaccess: Don't leak the AC flag into __put_user() value evaluation Message-ID: <20190303163833.GA5546@archlinux-ryzen> References: <20190303162724.30155-1-mussitantesmortem@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190303162724.30155-1-mussitantesmortem@gmail.com> User-Agent: Mutt/1.11.3 (2019-02-01) Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org On Sun, Mar 03, 2019 at 07:27:24PM +0300, Maxim Zhukov wrote: > From: Andy Lutomirski > > 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 a8d85a687cf4..39bbc225558c 100644 > --- a/arch/x86/include/asm/uaccess.h > +++ b/arch/x86/include/asm/uaccess.h > @@ -292,7 +292,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: \ > @@ -427,8 +427,10 @@ do { \ > #define __put_user_nocheck(x, ptr, size) \ > ({ \ > int __pu_err; \ > + __typeof__(*(ptr)) __pu_val; \ > __uaccess_begin(); \ > - __put_user_size((x), (ptr), (size), __pu_err, -EFAULT); \ > + __pu_val = x; \ This is incorrect, __pu_val's assignment should be before __uaccess_begin like in the original patch (which is the point of the patch in the first place). Cheers, Nathan > + __put_user_size(__pu_val, (ptr), (size), __pu_err, -EFAULT); \ > __uaccess_end(); \ > __builtin_expect(__pu_err, 0); \ > }) > -- > 2.21.0 >