linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Ritesh Harjani (IBM) <ritesh.list@gmail.com>
To: Christophe Leroy <christophe.leroy@csgroup.eu>,
	linuxppc-dev@lists.ozlabs.org,
Cc: Michael Ellerman <mpe@ellerman.id.au>,
	Nicholas Piggin <npiggin@gmail.com>,
	Madhavan Srinivasan <maddy@linux.ibm.com>,
	Hari Bathini <hbathini@linux.ibm.com>,
	"Aneesh Kumar K . V" <aneesh.kumar@kernel.org>,
	Donet Tom <donettom@linux.vnet.ibm.com>,
	Pavithra Prakash <pavrampu@linux.vnet.ibm.com>,
	Nirjhar Roy <nirjhar@linux.ibm.com>,
	LKML <linux-kernel@vger.kernel.org>,
	kasan-dev@googlegroups.com, Disha Goel <disgoel@linux.ibm.com>,
	Alexander Potapenko <glider@google.com>
Subject: Re: [RFC v2 02/13] powerpc: mm: Fix kfence page fault reporting
Date: Thu, 19 Sep 2024 11:17:16 +0530	[thread overview]
Message-ID: <87ldzotct7.fsf@gmail.com> (raw)
In-Reply-To: <65664ab8-4250-47c2-be50-d56c112a17fb@csgroup.eu>

Christophe Leroy <christophe.leroy@csgroup.eu> writes:

> Le 19/09/2024 à 04:56, 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().
>
> Searching the exception table is a heavy operation and all has been done 
> in the past to minimise the number of times it is called, see for 
> instance commit cbd7e6ca0210 ("powerpc/fault: Avoid heavy 
> search_exception_tables() verification")

This should not cause latency in user page fault paths. We call
search_exception_tables() only when there is a page fault for kernel
address (which isn't that common right) which otherwise kfence will handle.

>
> Also, by trying to hide false positives you also hide real ones. For 

I believe these should be false negatives. If kernel functions provides an
exception table to handle such a fault, then shouldn't it be handled via
fixup table provided rather then via kfence?

> instance if csum_partial_copy_generic() is using a kfence protected 
> area, it will now go undetected.

I can go and look into usages of csum_partial_copy_generic(). But can
you please expand more here on what you meant? 

... so if a fault occurs for above case, this patch will just let the
fixup table handle that fault rather than kfence reporting it and
returning 0.


The issue we see here is when unmapped kfence addresses get accessed via
*_nofault() variants which causes kfence to report a false negative
(this happens when we use read /proc/kcore or tools like perf read that)

This is because as per my understanding copy_from_kernel_nofault()
should return -EFAULT from it's fixup table if a fault occurs...
whereas with kfence it will report the warning and will return 0 after
kfence handled the fault.

I see other archs too calling fixup_table() in their fault handling
routine before allowing kfence to handle the fault. 

>
> IIUC, here your problem is limited to copy_from_kernel_nofault(). You 
> should handle the root cause, not its effects. For that, you could 
> perform additional verifications in copy_from_kernel_nofault_allowed().

Sorry, why make copy_from_kernel_nofault() as a special case for powerpc?
I don't see any other arch making copy_from_kernel_nofault() as a
special case. Shouldn't Kernel faults be handled via fixup_table(), if
it is supplied, before kfence handling it?
(maybe I am missing something)


-ritesh


  reply	other threads:[~2024-09-19  6:23 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-19  2:55 [RFC v2 00/13] powerpc/kfence: Improve kfence support Ritesh Harjani (IBM)
2024-09-19  2:55 ` [RFC v2 01/13] mm/kfence: Add a new kunit test test_use_after_free_read_nofault() Ritesh Harjani (IBM)
2024-10-03  5:06   ` Ritesh Harjani
2024-09-19  2:56 ` [RFC v2 02/13] powerpc: mm: Fix kfence page fault reporting Ritesh Harjani (IBM)
2024-09-19  5:12   ` Christophe Leroy
2024-09-19  5:47     ` Ritesh Harjani [this message]
2024-09-19  2:56 ` [RFC v2 03/13] book3s64/hash: Remove kfence support temporarily Ritesh Harjani (IBM)
2024-09-19  5:20   ` Christophe Leroy
2024-09-19  6:23     ` Ritesh Harjani
2024-09-19  2:56 ` [RFC v2 04/13] book3s64/hash: Refactor kernel linear map related calls Ritesh Harjani (IBM)
2024-09-19  2:56 ` [RFC v2 05/13] book3s64/hash: Add hash_debug_pagealloc_add_slot() function Ritesh Harjani (IBM)
2024-09-19  2:56 ` [RFC v2 06/13] book3s64/hash: Add hash_debug_pagealloc_alloc_slots() function Ritesh Harjani (IBM)
2024-09-19  2:56 ` [RFC v2 07/13] book3s64/hash: Refactor hash__kernel_map_pages() function Ritesh Harjani (IBM)
2024-09-19  2:56 ` [RFC v2 08/13] book3s64/hash: Make kernel_map_linear_page() generic Ritesh Harjani (IBM)
2024-09-19  2:56 ` [RFC v2 09/13] book3s64/hash: Disable debug_pagealloc if it requires more memory Ritesh Harjani (IBM)
2024-09-19  2:56 ` [RFC v2 10/13] book3s64/hash: Add kfence functionality Ritesh Harjani (IBM)
2024-09-19  2:56 ` [RFC v2 11/13] book3s64/radix: Refactoring common kfence related functions Ritesh Harjani (IBM)
2024-09-19  2:56 ` [RFC v2 12/13] book3s64/hash: Disable kfence if not early init Ritesh Harjani (IBM)
2024-09-19  2:56 ` [RFC v2 13/13] book3s64/hash: Early detect debug_pagealloc size requirement Ritesh Harjani (IBM)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87ldzotct7.fsf@gmail.com \
    --to=ritesh.list@gmail.com \
    --cc=aneesh.kumar@kernel.org \
    --cc=christophe.leroy@csgroup.eu \
    --cc=disgoel@linux.ibm.com \
    --cc=donettom@linux.vnet.ibm.com \
    --cc=glider@google.com \
    --cc=hbathini@linux.ibm.com \
    --cc=kasan-dev@googlegroups.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=maddy@linux.ibm.com \
    --cc=mpe@ellerman.id.au \
    --cc=nirjhar@linux.ibm.com \
    --cc=npiggin@gmail.com \
    --cc=pavrampu@linux.vnet.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).