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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4D388D3DEA0 for ; Fri, 18 Oct 2024 17:40:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B96056B00A6; Fri, 18 Oct 2024 13:40:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B1EA46B00A8; Fri, 18 Oct 2024 13:40:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9BFA26B00AA; Fri, 18 Oct 2024 13:40:20 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 7CA2D6B00A6 for ; Fri, 18 Oct 2024 13:40:20 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 0DBBA12025B for ; Fri, 18 Oct 2024 17:40:09 +0000 (UTC) X-FDA: 82687436664.21.5C83E62 Received: from pegase2.c-s.fr (pegase2.c-s.fr [93.17.235.10]) by imf01.hostedemail.com (Postfix) with ESMTP id 8F36440010 for ; Fri, 18 Oct 2024 17:40:08 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=none; spf=pass (imf01.hostedemail.com: domain of christophe.leroy@csgroup.eu designates 93.17.235.10 as permitted sender) smtp.mailfrom=christophe.leroy@csgroup.eu; dmarc=pass (policy=quarantine) header.from=csgroup.eu ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1729273071; h=from:from:sender: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:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=v57rTYxRjrPWie/sbzb55q8HI0oXpri0RSDi3q5sTzg=; b=ZD8GQZD18Lh39oWUvkregoimgpaaKvSJNWDlXRsb6j++N5q3TADVtev+GO8mbcMlE1XT9w clcItTe8SJH8M7d4RkaoCA9GGctXrB259rcfw6bgJ/UFTnM2oHcaZNN0N14UC8xpPIvRUx jmF9Pa73sN5h+WCcg6HqTY3SgwM6exw= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1729273071; a=rsa-sha256; cv=none; b=jqAFYsgw+g2rsCTnZCVhRYFpE2AMB7bKCAuGCb2HqaBEBFZ21MiQ43G63WFHx13NoHmXUS R9wQfrUuvyVNyyxBAdDx3Zuwyh1/COJzhGTJUpLkQ03S1CHD058Tl8jXUila3cKzkotviL beq22DfKa2eRVTlq8ohYqw9EY+1k6Ew= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=none; spf=pass (imf01.hostedemail.com: domain of christophe.leroy@csgroup.eu designates 93.17.235.10 as permitted sender) smtp.mailfrom=christophe.leroy@csgroup.eu; dmarc=pass (policy=quarantine) header.from=csgroup.eu Received: from localhost (mailhub3.si.c-s.fr [172.26.127.67]) by localhost (Postfix) with ESMTP id 4XVX675pLBz9sPd; Fri, 18 Oct 2024 19:40:15 +0200 (CEST) X-Virus-Scanned: amavisd-new at c-s.fr Received: from pegase2.c-s.fr ([172.26.127.65]) by localhost (pegase2.c-s.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id A60ALosMKCjZ; Fri, 18 Oct 2024 19:40:15 +0200 (CEST) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase2.c-s.fr (Postfix) with ESMTP id 4XVX674tplz9rvV; Fri, 18 Oct 2024 19:40:15 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 97B0A8B779; Fri, 18 Oct 2024 19:40:15 +0200 (CEST) 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 ZaNkbIa7WNNO; Fri, 18 Oct 2024 19:40:15 +0200 (CEST) Received: from [192.168.232.18] (unknown [192.168.232.18]) by messagerie.si.c-s.fr (Postfix) with ESMTP id CBDAC8B764; Fri, 18 Oct 2024 19:40:14 +0200 (CEST) Message-ID: <0c81a6cc-2466-4932-805b-056d4e7dec2b@csgroup.eu> Date: Fri, 18 Oct 2024 19:40:14 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3 01/12] powerpc: mm/fault: Fix kfence page fault reporting To: "Ritesh Harjani (IBM)" , linuxppc-dev@lists.ozlabs.org Cc: kasan-dev@googlegroups.com, linux-mm@kvack.org, Marco Elver , Alexander Potapenko , Heiko Carstens , Michael Ellerman , Nicholas Piggin , Madhavan Srinivasan , Hari Bathini , "Aneesh Kumar K . V" , Donet Tom , Pavithra Prakash , LKML , Disha Goel References: Content-Language: fr-FR From: Christophe Leroy In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 8F36440010 X-Stat-Signature: mbzwigqqry7uu5rpmyftpnytxym9yn9y X-HE-Tag: 1729273208-817212 X-HE-Meta: U2FsdGVkX185zQtoHIKYidaRv49iWoCSj93bKQglKnq3nq/sb3NUk1Y2y7siSOCUN2WxNHPx8RQKtg4vmyLahRY+vtFSnU7otLRHVeHXWwJ7PliGC7DGINqQ8oSZ6l7OvEV+LrkEB2A+JSWrl0aVrJ2M7BtTFcXO/4Zeghn/l+JWaYueVUyHA0NTiDJd4wrg2BUKDMfdR/0qEpGp818ZVrcsor5CAzKc4W/bwEf63xGf7D9IcnKTJHczSTymmAvPKlgFao9lfd8lySSWD39Ypa7JJjvsWDrISLcPIBq2XZTfAvA8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Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Le 18/10/2024 à 19:29, Ritesh Harjani (IBM) a écrit : > copy_from_kernel_nofault() can be called when doing read of /proc/kcore. > /proc/kcore can have some unmapped kfence objects which when read via > copy_from_kernel_nofault() can cause page faults. Since *_nofault() > functions define their own fixup table for handling fault, use that > instead of asking kfence to handle such faults. > > Hence we search the exception tables for the nip which generated the > fault. If there is an entry then we let the fixup table handler handle the > page fault by returning an error from within ___do_page_fault(). > > This can be easily triggered if someone tries to do dd from /proc/kcore. > dd if=/proc/kcore of=/dev/null bs=1M > > > =============================== > BUG: KFENCE: invalid read in copy_from_kernel_nofault+0xb0/0x1c8 > Invalid read at 0x000000004f749d2e: > copy_from_kernel_nofault+0xb0/0x1c8 > 0xc0000000057f7950 > read_kcore_iter+0x41c/0x9ac > proc_reg_read_iter+0xe4/0x16c > vfs_read+0x2e4/0x3b0 > ksys_read+0x88/0x154 > system_call_exception+0x124/0x340 > system_call_common+0x160/0x2c4 > > BUG: KFENCE: use-after-free read in copy_from_kernel_nofault+0xb0/0x1c8 > Use-after-free read at 0x000000008fbb08ad (in kfence-#0): > copy_from_kernel_nofault+0xb0/0x1c8 > 0xc0000000057f7950 > read_kcore_iter+0x41c/0x9ac > proc_reg_read_iter+0xe4/0x16c > vfs_read+0x2e4/0x3b0 > ksys_read+0x88/0x154 > system_call_exception+0x124/0x340 > system_call_common+0x160/0x2c4 > > Fixes: 90cbac0e995d ("powerpc: Enable KFENCE for PPC32") > Suggested-by: Christophe Leroy Reviewed-by: Christophe Leroy Nit below. > Reported-by: Disha Goel > Signed-off-by: Ritesh Harjani (IBM) > --- > arch/powerpc/mm/fault.c | 11 +++++++++-- > 1 file changed, 9 insertions(+), 2 deletions(-) > > diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c > index 81c77ddce2e3..316f5162ffc4 100644 > --- a/arch/powerpc/mm/fault.c > +++ b/arch/powerpc/mm/fault.c > @@ -439,10 +439,17 @@ static int ___do_page_fault(struct pt_regs *regs, unsigned long address, > /* > * The kernel should never take an execute fault nor should it > * take a page fault to a kernel address or a page fault to a user > - * address outside of dedicated places > + * address outside of dedicated places. > + * > + * Rather than kfence directly reporting false negatives, search whether > + * the NIP belongs to the fixup table for cases where fault could come > + * from functions like copy_from_kernel_nofault(). > */ > if (unlikely(!is_user && bad_kernel_fault(regs, error_code, address, is_write))) { > - if (kfence_handle_page_fault(address, is_write, regs)) > + Why do you need a blank line here ? > + if (is_kfence_address((void *)address) && > + !search_exception_tables(instruction_pointer(regs)) && > + kfence_handle_page_fault(address, is_write, regs)) > return 0; > > return SIGSEGV; > -- > 2.46.0 >