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=-10.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS 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 AD879C43460 for ; Tue, 6 Apr 2021 19:24:53 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id EF3C261040 for ; Tue, 6 Apr 2021 19:24:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EF3C261040 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=alien8.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 672246B007E; Tue, 6 Apr 2021 15:24:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 649A36B0080; Tue, 6 Apr 2021 15:24:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5119A6B0081; Tue, 6 Apr 2021 15:24:52 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0067.hostedemail.com [216.40.44.67]) by kanga.kvack.org (Postfix) with ESMTP id 331976B007E for ; Tue, 6 Apr 2021 15:24:52 -0400 (EDT) Received: from smtpin22.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id E530963E6 for ; Tue, 6 Apr 2021 19:24:51 +0000 (UTC) X-FDA: 78002919582.22.8E5337D Received: from mail.skyhub.de (mail.skyhub.de [5.9.137.197]) by imf27.hostedemail.com (Postfix) with ESMTP id 015FC80192C0 for ; Tue, 6 Apr 2021 19:24:44 +0000 (UTC) Received: from zn.tnic (p200300ec2f0a0d0098c8242cdcf6564d.dip0.t-ipconnect.de [IPv6:2003:ec:2f0a:d00:98c8:242c:dcf6:564d]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.skyhub.de (SuperMail on ZX Spectrum 128k) with ESMTPSA id DA8F81EC01A9; Tue, 6 Apr 2021 21:24:47 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=dkim; t=1617737088; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:in-reply-to:in-reply-to: references:references; bh=VEKpYltx5cUrSdL3AGy4C4Fkwk89IILt63r/FqJJAGg=; b=d6bQzbhq7INBekNgate3k8Cy6LV/vsnBXwFo20OOZteEHuNijbpqu54Ecy2sEfh4WIF17Y q5KdAnrL+UH7sROIh+fxRT4E7Z964CnDa90L4Hf6XwCsTDpIv4QiaeY6N3ARty5+I5kDKy cOHtF4SOUM97aejllgU1RtNuzNo61nk= Date: Tue, 6 Apr 2021 21:24:46 +0200 From: Borislav Petkov To: Tony Luck Cc: x86@kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Andy Lutomirski , Aili Yao , HORIGUCHI =?utf-8?B?TkFPWUEoIOWggOWPo+OAgOebtOS5nyk=?= Subject: Re: [PATCH 1/4] x86/mce: Fix copyin code to return -EFAULT on machine check. Message-ID: <20210406192446.GP17806@zn.tnic> References: <20210326000235.370514-1-tony.luck@intel.com> <20210326000235.370514-2-tony.luck@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20210326000235.370514-2-tony.luck@intel.com> X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 015FC80192C0 X-Stat-Signature: 9nm9b1dps8k5n4nt3an7dz1mhf3hmwqo Received-SPF: none (alien8.de>: No applicable sender policy available) receiver=imf27; identity=mailfrom; envelope-from=""; helo=mail.skyhub.de; client-ip=5.9.137.197 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1617737084-606371 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Thu, Mar 25, 2021 at 05:02:32PM -0700, Tony Luck wrote: > When copy from user fails due to a machine check on poison reading > user data it should return an error code. > > --- > > Separate patch just now, but likely needs to be combined with patches > to iteration code for bisection safety. > --- > arch/x86/lib/copy_user_64.S | 18 +++++++++++------- > 1 file changed, 11 insertions(+), 7 deletions(-) > > diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S > index 77b9b2a3b5c8..2987118c541a 100644 > --- a/arch/x86/lib/copy_user_64.S > +++ b/arch/x86/lib/copy_user_64.S > @@ -14,6 +14,7 @@ > #include > #include > #include > +#include > #include > #include > > @@ -237,18 +238,21 @@ SYM_CODE_START_LOCAL(.Lcopy_user_handle_tail) > cmp $X86_TRAP_MC,%eax /* check if X86_TRAP_MC */ > je 3f > 1: rep movsb > -2: mov %ecx,%eax > + mov %ecx,%eax > + ASM_CLAC > + ret > + > +2: > + cmp $X86_TRAP_MC,%eax > + je 3f > + mov %ecx,%eax > ASM_CLAC > ret > > /* > - * Return zero to pretend that this copy succeeded. This > - * is counter-intuitive, but needed to prevent the code > - * in lib/iov_iter.c from retrying and running back into > - * the poison cache line again. The machine check handler > - * will ensure that a SIGBUS is sent to the task. > + * Return -EFAULT for the machine check cases > */ > -3: xorl %eax,%eax > +3: movl $-EFAULT,%eax > ASM_CLAC > ret Right, looks ok after swapping all that fault-handlers-rerouting-based-on-labels thing back in. You'd need to update the blubber in the comment above it that we're returning -EFAULT now too. Also, you might wanna converge the exit paths to a single "out" label if the unconditional JMPs are not that big of a deal (pasting the whole thing and not as a diff because diff is unreadable): SYM_CODE_START_LOCAL(.Lcopy_user_handle_tail) movl %edx,%ecx cmp $X86_TRAP_MC,%eax /* check if X86_TRAP_MC */ je 3f 1: rep movsb mov %ecx,%eax jmp out 2: cmp $X86_TRAP_MC,%eax je 3f mov %ecx,%eax jmp out /* Return -EFAULT for the machine check cases */ 3: movl $-EFAULT,%eax out: ASM_CLAC ret _ASM_EXTABLE_CPY(1b, 2b) SYM_CODE_END(.Lcopy_user_handle_tail) Thx. -- Regards/Gruss, Boris. https://people.kernel.org/tglx/notes-about-netiquette