Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp8416202ybi; Thu, 6 Jun 2019 11:58:32 -0700 (PDT) X-Google-Smtp-Source: APXvYqzPzaiAB0mXEMVXmhBvm5datA9psU8Zd0Szi6yDHXfZQWtvotg34C2zLU0z9yYRa1NV8VMU X-Received: by 2002:a17:90a:62c6:: with SMTP id k6mr1290414pjs.7.1559847511925; Thu, 06 Jun 2019 11:58:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559847511; cv=none; d=google.com; s=arc-20160816; b=KZNlPREUN4uDyszMjAhgv9K4n5QOFzTpZVoLrvkrv//uyNaoSzdeecBz8ZfP9lNTrf SBP8LAl5SAHyErsomlDS5Qr1g/0anemt492NwCDS9qx5fzzICM41kKAOPvwFIpKQoKa7 kiSFPVbLk5b0wzIlo8oRHiW4dzUXh0bb5wHWTha01ug6scpNxP5qAFAXO4xP+BEd8glC LJDkN6YvgYOcjxGSp5P/CdVAnFPO77ZwzIJu9pA/s9Ys71OPNUcpafbLsEMTeLwEdeJU hCvv6HlhM0II+cy7vUhI6PihQlhFrx+fDFAc+lEuDUHcIArwEfB7yneUWumpMbK9BsRO ty2A== 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:dkim-signature:dkim-filter; bh=m4AlyVwXpZA6r6w7UbdCGAzUMcLMnUoq15ImttvhGn8=; b=jHeT7ZP9JUsrZUbqOCw8YbV+9uQNgNAbexfpAAKktQxtRuwGnF0UzPR89T5JtKEvq2 5vO9TtItDsaWHJMRERJ/R42Hl57U0SC+bRS8a6P4eiJJ3Os8kRHUT3jXqxWUM/cgrBhn OVAjakZMffuEAeHzCXabjqB7nWLPVsI3Wu9AkVDxLoz3PkTBqq0vFg92jqJP+PjJoLkX DV2PH5pl01YD9A7cLI5ma1PtPVYR0ZIiEghlCPtDxbhFlib7nSulF4BHf1v+ZJUlyLix ALBTBR0TX1M430xWUFgaRH99o6sW9X1H+mLq3wiObOa1SaXYI3Mk2jrxXmH4afZrxSnN MHVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@zytor.com header.s=2019051801 header.b=lE5PJjM0; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zytor.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m10si2509822pgq.420.2019.06.06.11.58.16; Thu, 06 Jun 2019 11:58:31 -0700 (PDT) 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; dkim=pass header.i=@zytor.com header.s=2019051801 header.b=lE5PJjM0; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zytor.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730140AbfFFR0V (ORCPT + 99 others); Thu, 6 Jun 2019 13:26:21 -0400 Received: from terminus.zytor.com ([198.137.202.136]:49491 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730055AbfFFR0U (ORCPT ); Thu, 6 Jun 2019 13:26:20 -0400 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTPS id x56HPK5g2066843 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Thu, 6 Jun 2019 10:25:20 -0700 DKIM-Filter: OpenDKIM Filter v2.11.0 terminus.zytor.com x56HPK5g2066843 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zytor.com; s=2019051801; t=1559841921; bh=m4AlyVwXpZA6r6w7UbdCGAzUMcLMnUoq15ImttvhGn8=; h=Date:From:Cc:Reply-To:In-Reply-To:References:To:Subject:From; b=lE5PJjM03xymRMzb4SFs9dmPHVkLeLDwE8aU2fwwzRIRovPRyqCcriJesZ8sJEsPs QLNoteQwH1Oqj3o7hebpAnA3PqZlO3iyvsCiGarHCZx31hdvv59JghyVIYw+OsqHY+ dfbtCRm16POpRwZyHLw/nqkxzExkhLZ8/XQnh9k55P/5iqh1g/wwtCgaROYqvk1xQ9 wObSupDEoL6bpJfkkOmHCvNF6XObZ3eDm0bMPF5vzB9tX9upaXgS9NhU3K/sdGnn3W sQGMp5dBlDB/QRW59jfQblAdj6HFFFlKniwwqUND12hdAcGViBGVlgJvjfFBVruwQ+ 3dofqJyVe0kHg== Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id x56HPI5t2066840; Thu, 6 Jun 2019 10:25:18 -0700 Date: Thu, 6 Jun 2019 10:25:18 -0700 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for Hugh Dickins Message-ID: Cc: akpm@linux-foundation.org, pavel@ucw.cz, jannh@google.com, hughd@google.com, dave.hansen@linux.intel.com, x86@kernel.org, mingo@redhat.com, rppt@linux.ibm.com, tglx@linutronix.de, linux-mm@kvack.org, bp@suse.de, mingo@kernel.org, chris@chris-wilson.co.uk, linux-kernel@vger.kernel.org, riel@surriel.com, hpa@zytor.com, bigeasy@linutronix.de, aarcange@redhat.com Reply-To: hughd@google.com, jannh@google.com, pavel@ucw.cz, akpm@linux-foundation.org, mingo@redhat.com, dave.hansen@linux.intel.com, x86@kernel.org, chris@chris-wilson.co.uk, mingo@kernel.org, bp@suse.de, tglx@linutronix.de, rppt@linux.ibm.com, linux-mm@kvack.org, bigeasy@linutronix.de, aarcange@redhat.com, hpa@zytor.com, riel@surriel.com, linux-kernel@vger.kernel.org In-Reply-To: <1557844195-18882-1-git-send-email-rppt@linux.ibm.com> References: <20190529072540.g46j4kfeae37a3iu@linutronix.de> <1557844195-18882-1-git-send-email-rppt@linux.ibm.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:x86/urgent] x86/fpu: Use fault_in_pages_writeable() for pre-faulting Git-Commit-ID: b81ff1013eb8eef2934ca7e8cf53d553c1029e84 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=-3.1 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, T_DATE_IN_FUTURE_96_Q autolearn=ham autolearn_force=no version=3.4.2 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: b81ff1013eb8eef2934ca7e8cf53d553c1029e84 Gitweb: https://git.kernel.org/tip/b81ff1013eb8eef2934ca7e8cf53d553c1029e84 Author: Hugh Dickins AuthorDate: Wed, 29 May 2019 09:25:40 +0200 Committer: Borislav Petkov CommitDate: Thu, 6 Jun 2019 19:15:17 +0200 x86/fpu: Use fault_in_pages_writeable() for pre-faulting Since commit d9c9ce34ed5c8 ("x86/fpu: Fault-in user stack if copy_fpstate_to_sigframe() fails") get_user_pages_unlocked() pre-faults user's memory if a write generates a page fault while the handler is disabled. This works in general and uncovered a bug as reported by Mike Rapoport¹. It has been pointed out that this function may be fragile and a simple pre-fault as in fault_in_pages_writeable() would be a better solution. Better as in taste and simplicity: that write (as performed by the alternative function) performs exactly the same faulting of memory as before. This was suggested by Hugh Dickins and Andrew Morton. Use fault_in_pages_writeable() for pre-faulting user's stack. [ bigeasy: Write commit message. ] [ bp: Massage some. ] ¹ https://lkml.kernel.org/r/1557844195-18882-1-git-send-email-rppt@linux.ibm.com Fixes: d9c9ce34ed5c8 ("x86/fpu: Fault-in user stack if copy_fpstate_to_sigframe() fails") Suggested-by: Andrew Morton Signed-off-by: Hugh Dickins Signed-off-by: Sebastian Andrzej Siewior Signed-off-by: Borislav Petkov Tested-by: Chris Wilson Cc: Andrea Arcangeli Cc: Andrew Morton Cc: Dave Hansen Cc: "H. Peter Anvin" Cc: Ingo Molnar Cc: Jann Horn Cc: linux-mm Cc: Mike Rapoport Cc: Pavel Machek Cc: Rik van Riel Cc: Thomas Gleixner Cc: x86-ml Link: https://lkml.kernel.org/r/20190529072540.g46j4kfeae37a3iu@linutronix.de Link: https://lkml.kernel.org/r/1557844195-18882-1-git-send-email-rppt@linux.ibm.com --- arch/x86/kernel/fpu/signal.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/arch/x86/kernel/fpu/signal.c b/arch/x86/kernel/fpu/signal.c index 5a8d118bc423..060d6188b453 100644 --- a/arch/x86/kernel/fpu/signal.c +++ b/arch/x86/kernel/fpu/signal.c @@ -5,6 +5,7 @@ #include #include +#include #include #include @@ -189,15 +190,7 @@ retry: fpregs_unlock(); if (ret) { - int aligned_size; - int nr_pages; - - aligned_size = offset_in_page(buf_fx) + fpu_user_xstate_size; - nr_pages = DIV_ROUND_UP(aligned_size, PAGE_SIZE); - - ret = get_user_pages_unlocked((unsigned long)buf_fx, nr_pages, - NULL, FOLL_WRITE); - if (ret == nr_pages) + if (!fault_in_pages_writeable(buf_fx, fpu_user_xstate_size)) goto retry; return -EFAULT; }