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=-15.2 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 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 AF7C9C4361A for ; Sat, 5 Dec 2020 09:57:34 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id EE13E22D2B for ; Sat, 5 Dec 2020 09:57:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EE13E22D2B Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=csgroup.eu Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 3507B6B0036; Sat, 5 Dec 2020 04:57:33 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 301666B005D; Sat, 5 Dec 2020 04:57:33 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1C7D56B0068; Sat, 5 Dec 2020 04:57:33 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0226.hostedemail.com [216.40.44.226]) by kanga.kvack.org (Postfix) with ESMTP id 043CE6B0036 for ; Sat, 5 Dec 2020 04:57:32 -0500 (EST) Received: from smtpin18.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id A8EFA181AEF23 for ; Sat, 5 Dec 2020 09:57:32 +0000 (UTC) X-FDA: 77558776344.18.size67_3d14290273cc Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin18.hostedemail.com (Postfix) with ESMTP id 7C925100ED3B2 for ; Sat, 5 Dec 2020 09:57:32 +0000 (UTC) X-HE-Tag: size67_3d14290273cc X-Filterd-Recvd-Size: 5239 Received: from pegase1.c-s.fr (pegase1.c-s.fr [93.17.236.30]) by imf39.hostedemail.com (Postfix) with ESMTP for ; Sat, 5 Dec 2020 09:57:31 +0000 (UTC) Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 4Cp4kJ31KPz9txrr; Sat, 5 Dec 2020 10:57:28 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at c-s.fr Received: from pegase1.c-s.fr ([192.168.12.234]) by localhost (pegase1.c-s.fr [192.168.12.234]) (amavisd-new, port 10024) with ESMTP id 5C8p_2D3PaXb; Sat, 5 Dec 2020 10:57:28 +0100 (CET) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase1.c-s.fr (Postfix) with ESMTP id 4Cp4kJ1ry4z9txrq; Sat, 5 Dec 2020 10:57:28 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 5BBF88B77F; Sat, 5 Dec 2020 10:57:29 +0100 (CET) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id OQIUmRAgHQh5; Sat, 5 Dec 2020 10:57:29 +0100 (CET) Received: from [192.168.4.90] (unknown [192.168.4.90]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 9F89A8B75B; Sat, 5 Dec 2020 10:57:28 +0100 (CET) Subject: Re: [PATCH] powerpc/mm: Fix KUAP warning by providing copy_from_kernel_nofault_allowed() To: Christoph Hellwig Cc: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , viro@zeniv.linux.org.uk, akpm@linux-foundation.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-mm@kvack.org, Linus Torvalds References: <20201205084804.GA25452@lst.de> From: Christophe Leroy Message-ID: <0ede82c3-d4e9-6ce6-0590-6254272c3ae2@csgroup.eu> Date: Sat, 5 Dec 2020 10:56:56 +0100 User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.5.1 MIME-Version: 1.0 In-Reply-To: <20201205084804.GA25452@lst.de> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: fr Content-Transfer-Encoding: quoted-printable 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: Le 05/12/2020 =C3=A0 09:48, Christoph Hellwig a =C3=A9crit=C2=A0: > On Sat, Dec 05, 2020 at 08:43:06AM +0000, Christophe Leroy wrote: >> Since commit c33165253492 ("powerpc: use non-set_fs based maccess >> routines"), userspace access is not granted anymore when using >> copy_from_kernel_nofault() >> >> However, kthread_probe_data() uses copy_from_kernel_nofault() >> to check validity of pointers. When the pointer is NULL, >> it points to userspace, leading to a KUAP fault and triggering >> the following big hammer warning many times when you request >> a sysrq "show task": >=20 >=20 >=20 >> To avoid that, copy_from_kernel_nofault_allowed() is used to check >> whether the address is a valid kernel address. But the default >> version of it returns true for any address. >> >> Provide a powerpc version of copy_from_kernel_nofault_allowed() >> that returns false when the address is below TASK_USER_MAX, >> so that copy_from_kernel_nofault() will return -ERANGE. >=20 > Looks good. I wonder if we should just default to the TASK_SIZE_MAX > check in copy_from_kernel_nofault_allowed for architectures that selec= t > CONFIG_ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE? Yes maybe that would be better. Can you cook a patch an get it into 5.10 ? Christophe >=20 >> >> Reported-by: Qian Cai >> Fixes: c33165253492 ("powerpc: use non-set_fs based maccess routines") >> Cc: Christoph Hellwig >> Cc: Al Viro >> Signed-off-by: Christophe Leroy >> --- >> This issue was introduced in 5.10. I didn't mark it for stable, hoppin= g it will go into 5.10-rc7 >> --- >> arch/powerpc/mm/Makefile | 2 +- >> arch/powerpc/mm/maccess.c | 9 +++++++++ >> 2 files changed, 10 insertions(+), 1 deletion(-) >> create mode 100644 arch/powerpc/mm/maccess.c >> >> diff --git a/arch/powerpc/mm/Makefile b/arch/powerpc/mm/Makefile >> index 5e147986400d..55b4a8bd408a 100644 >> --- a/arch/powerpc/mm/Makefile >> +++ b/arch/powerpc/mm/Makefile >> @@ -5,7 +5,7 @@ >> =20 >> ccflags-$(CONFIG_PPC64) :=3D $(NO_MINIMAL_TOC) >> =20 >> -obj-y :=3D fault.o mem.o pgtable.o mmap.o \ >> +obj-y :=3D fault.o mem.o pgtable.o mmap.o maccess.o \ >> init_$(BITS).o pgtable_$(BITS).o \ >> pgtable-frag.o ioremap.o ioremap_$(BITS).o \ >> init-common.o mmu_context.o drmem.o >> diff --git a/arch/powerpc/mm/maccess.c b/arch/powerpc/mm/maccess.c >> new file mode 100644 >> index 000000000000..56e97c0fb233 >> --- /dev/null >> +++ b/arch/powerpc/mm/maccess.c >> @@ -0,0 +1,9 @@ >> +// SPDX-License-Identifier: GPL-2.0-only >> + >> +#include >> +#include >> + >> +bool copy_from_kernel_nofault_allowed(const void *unsafe_src, size_t = size) >> +{ >> + return (unsigned long)unsafe_src >=3D TASK_SIZE_MAX; >> +} >> --=20 >> 2.25.0 > ---end quoted text--- >=20