From: Omar Sandoval <osandov@osandov.com>
To: Christophe Leroy <christophe.leroy@csgroup.eu>
Cc: linux-mm@kvack.org, Andrew Morton <akpm@linux-foundation.org>,
Benjamin Gray <bgray@linux.ibm.com>,
"Christopher M. Riedl" <cmr@bluescreens.de>,
Christoph Hellwig <hch@lst.de>,
x86@kernel.org, linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, loongarch@lists.linux.dev,
linux-mips@vger.kernel.org, linux-parisc@vger.kernel.org,
linuxppc-dev@lists.ozlabs.org, linux-um@lists.infradead.org,
kernel-team@fb.com
Subject: Re: [PATCH 2/2] mm: make copy_to_kernel_nofault() not fault on user addresses
Date: Wed, 4 Sep 2024 15:56:04 -0700 [thread overview]
Message-ID: <ZtjlhFbeFZtxzmTb@telecaster.dhcp.thefacebook.com> (raw)
In-Reply-To: <64e74f4d-948d-442e-9810-69907915401c@csgroup.eu>
On Wed, Sep 04, 2024 at 09:50:56AM +0200, Christophe Leroy wrote:
> Hi,
>
> Le 02/09/2024 à 07:31, Omar Sandoval a écrit :
> > [Vous ne recevez pas souvent de courriers de osandov@osandov.com. Découvrez pourquoi ceci est important à https://aka.ms/LearnAboutSenderIdentification ]
> >
> > From: Omar Sandoval <osandov@fb.com>
> >
> > I found that on x86, copy_to_kernel_nofault() still faults on addresses
> > outside of the kernel address range (including NULL):
> >
> > # echo ttyS0 > /sys/module/kgdboc/parameters/kgdboc
> > # echo g > /proc/sysrq-trigger
> > ...
> > [15]kdb> mm 0 1234
> > [ 94.652476] BUG: kernel NULL pointer dereference, address: 0000000000000000
> ...
> >
> > Note that copy_to_kernel_nofault() uses pagefault_disable(), but it
> > still faults. This is because with Supervisor Mode Access Prevention
> > (SMAP) enabled, do_user_addr_fault() Oopses on a fault for a user
> > address from kernel space _before_ checking faulthandler_disabled().
> >
> > copy_from_kernel_nofault() avoids this by checking that the address is
> > in the kernel before doing the actual memory access. Do the same in
> > copy_to_kernel_nofault() so that we get an error as expected:
> >
> > # echo ttyS0 > /sys/module/kgdboc/parameters/kgdboc
> > # echo g > /proc/sysrq-trigger
> > ...
> > [17]kdb> mm 0 1234
> > kdb_putarea_size: Bad address 0x0
> > diag: -21: Invalid address
> >
> > Signed-off-by: Omar Sandoval <osandov@fb.com>
> > ---
> > mm/maccess.c | 3 +++
> > 1 file changed, 3 insertions(+)
> >
> > diff --git a/mm/maccess.c b/mm/maccess.c
> > index 72e9c03ea37f..d67dee51a1cc 100644
> > --- a/mm/maccess.c
> > +++ b/mm/maccess.c
> > @@ -61,6 +61,9 @@ long copy_to_kernel_nofault(void *dst, const void *src, size_t size)
> > if (!IS_ENABLED(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS))
> > align = (unsigned long)dst | (unsigned long)src;
> >
> > + if (!copy_kernel_nofault_allowed(dst, size))
> > + return -ERANGE;
> > +
> > pagefault_disable();
> > if (!(align & 7))
> > copy_to_kernel_nofault_loop(dst, src, size, u64, Efault);
> > --
> > 2.46.0
> >
>
> This patch leads to the following errors on ppc64le_defconfig:
>
> [ 2.423930][ T1] Running code patching self-tests ...
> [ 2.428912][ T1] code-patching: test failed at line 395
> [ 2.429085][ T1] code-patching: test failed at line 398
> [ 2.429561][ T1] code-patching: test failed at line 432
> [ 2.429679][ T1] code-patching: test failed at line 435
>
> This seems to be linked to commit c28c15b6d28a ("powerpc/code-patching: Use
> temporary mm for Radix MMU"), copy_from_kernel_nofault_allowed() returns
> false for the patching area.
Thanks for testing. This patch isn't worth the trouble, so we can drop
it.
Thanks,
Omar
next prev parent reply other threads:[~2024-09-04 22:56 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-02 5:31 [PATCH 0/2] " Omar Sandoval
2024-09-02 5:31 ` [PATCH 1/2] mm: rename copy_from_kernel_nofault_allowed() to copy_kernel_nofault_allowed() Omar Sandoval
2024-09-02 5:31 ` [PATCH 2/2] mm: make copy_to_kernel_nofault() not fault on user addresses Omar Sandoval
2024-09-04 7:50 ` Christophe Leroy
2024-09-04 22:56 ` Omar Sandoval [this message]
2024-09-02 6:19 ` [PATCH 0/2] " Christophe Leroy
2024-09-02 6:31 ` Omar Sandoval
2024-09-02 8:56 ` David Hildenbrand
2024-09-02 15:26 ` Omar Sandoval
2024-09-02 16:39 ` David Hildenbrand
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=ZtjlhFbeFZtxzmTb@telecaster.dhcp.thefacebook.com \
--to=osandov@osandov.com \
--cc=akpm@linux-foundation.org \
--cc=bgray@linux.ibm.com \
--cc=christophe.leroy@csgroup.eu \
--cc=cmr@bluescreens.de \
--cc=hch@lst.de \
--cc=kernel-team@fb.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mips@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-parisc@vger.kernel.org \
--cc=linux-um@lists.infradead.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=loongarch@lists.linux.dev \
--cc=x86@kernel.org \
/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