Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp18516ybl; Tue, 7 Jan 2020 13:13:57 -0800 (PST) X-Google-Smtp-Source: APXvYqztXlNkbSnKvjLMfE+RXc2g5hF8Qfyoosm92Y5ZC+Ps89CD4gzkcik+KDX4RkuMZMqhPupd X-Received: by 2002:aca:a883:: with SMTP id r125mr398733oie.56.1578431637296; Tue, 07 Jan 2020 13:13:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578431637; cv=none; d=google.com; s=arc-20160816; b=CaMF3SMwIr0VKWMJqK/Z/JmMOS0PLCtQ4r5jioLXdYO34bQL1JpUaxvp1VB1z7iHGj JG2+u9jxZXc1BfZapEMSGLY5sQEPrnQjrLNNxfnOlBRVLkDAlwgpT5cgYukl7U54e7lI r2Xh8cdLmrw0kHBjzcAn0JoROHjrqyrOrrI0gY05Ujosh+tvXPvByycz6RmZ0RY9XiWO dHcnr6XoXbWgUIPZkdMTixkDiijwmuEzP9yFOTcXgdmZclD/YBVo/V50nF5nk0GH7T83 XCk3W9vuumxDTgjbxsAeIhP0V9GfwA19Mooz2c3+1REUcGdAcLGeZjLvbnYEJyyhQKeY wO3w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=Emc4gqlHuot5uDXxEXBN5k25anUceEZZBoD6ir7DdJw=; b=Ux8ytuXXAgAH3K44Glviw7r7eJhzdxnJ/gMnVdTUVwjYW0tBwYnIjIVMWJgkAi0by8 h6ugCNjg9hiuzV/YS3GOpWiS0d0vOnDEBzmdOg0V7OmNRzNkgtN52bnhUDFyLVxwNCTr llEA3+Jb8IWYyZ9NmdIL/yaAGfUd4DGZPpsxaeJNYmyDcAmAUWNzGR3mdBmzfklSRe9y Mylp1nLx9pYnyvPDBy83KwF2Uaq8WN8pFiRNrzvyze8eSuHINrSeMWNCtGUto1AIFPmz HUj6V3s+ds4SwE+ZKDdjXggmuOt5nH0Efz+1m9Fa6jXSwoNB7wlW+Gq7mz/38NIdng5b mwmw== 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 h125si551432oia.253.2020.01.07.13.13.44; Tue, 07 Jan 2020 13:13: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 S1730022AbgAGVMC convert rfc822-to-8bit (ORCPT + 99 others); Tue, 7 Jan 2020 16:12:02 -0500 Received: from Galois.linutronix.de ([193.142.43.55]:47030 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730123AbgAGVLg (ORCPT ); Tue, 7 Jan 2020 16:11:36 -0500 Received: from bigeasy by Galois.linutronix.de with local (Exim 4.80) (envelope-from ) id 1iow8U-0000TK-GS; Tue, 07 Jan 2020 22:11:34 +0100 Date: Tue, 7 Jan 2020 22:11:34 +0100 From: Sebastian Andrzej Siewior To: Andy Lutomirski Cc: linux-kernel@vger.kernel.org, linux-tip-commits@vger.kernel.org, Yu-cheng Yu , Borislav Petkov , Andy Lutomirski , Dave Hansen , Fenghua Yu , "H. Peter Anvin" , Ingo Molnar , Jann Horn , Peter Zijlstra , "Ravi V. Shankar" , Rik van Riel , Thomas Gleixner , Tony Luck , x86-ml Subject: Re: [tip: x86/fpu] x86/fpu: Deactivate FPU state after failure during state load Message-ID: <20200107211134.tckhc5knkthmjsj6@linutronix.de> References: <157840155965.30329.313988118654552721.tip-bot2@tip-bot2> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8BIT In-Reply-To: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2020-01-07 10:41:52 [-1000], Andy Lutomirski wrote: > Wow, __fpu__restore_sig is a mess. We have __copy_from... that is > Obviously Incorrect (tm) even though it’s not obviously exploitable. > (It’s wrong because the *wrong pointer* is checked with access_ok().). > We have a fast path that will execute just enough of the time to make > debugging the slow path really annoying. (We should probably delete > the fast path.) There are pagefault_disable() call in there mostly to > confuse people. (So we take a fault and sleep — big deal. We have > temporarily corrupt state, but no one will ever read it. The retry > after sleeping will clobber xstate, but lazy save is long gone and > this should be fine now. The real issue is that, if we’re preempted > after a successful a successful restore, then the new state will get > lost.) There is preempt_disable() as part of FPU locking since we can't change the content of the FPU registers (CPU's or within task's state) and get interrupted by task preemption. With disabled preemption we can't take a page fault. We need to load the page from userland which may fault. The context switch saves _current_ FPU state only if TIF_NEED_FPU_LOAD is cleared. This needs to happen atomic. The fast path may fail if stack is not faulted-in (custom stack, madvise(,, MADV_DONTNEED)) > So either we should delete the fast path or we should make it work > reliably and delete the slow path. And we should get rid of the > __copy. And we should have some test cases. without the fastpath the average case is too slow. People-complained-about-this-slow. That is why we ended up with the fastpath in the last revision of the series. The go people contirbuted a testcase. Maybe I should hack up it up so that we trigger each path and post since it obviously did not happen. Boris, do you remember why we did not include their testcase yet? > BTW, how was the bug in here discovered? It looks like it only > affects signal restore failure, which is usually not survivable unless > the user program is really trying. The glibc test suite. Sebastian