linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Christophe Leroy <christophe.leroy@csgroup.eu>
To: Benjamin Gray <bgray@linux.ibm.com>,
	"linuxppc-dev@lists.ozlabs.org" <linuxppc-dev@lists.ozlabs.org>
Cc: "hbathini@linux.ibm.com" <hbathini@linux.ibm.com>
Subject: Re: [PATCH] powerpc/code-patching: Disable KASAN in __patch_instructions()
Date: Mon, 19 Feb 2024 07:47:34 +0000	[thread overview]
Message-ID: <671c06fb-c053-4fbe-b011-6f4b8e8dd618@csgroup.eu> (raw)
In-Reply-To: <20240213043638.168048-1-bgray@linux.ibm.com>



Le 13/02/2024 à 05:36, Benjamin Gray a écrit :
> The memset/memcpy functions are by default instrumented by KASAN, which
> complains about user memory access when using a poking page in
> userspace.
> 
> Using a userspace address is expected though, so don't instrument with
> KASAN for this function.

memcpy/memset should never be used to access user memory, we have 
copy_to_user() and clear_user() for that.

A few weeks age I sent a KASAN report I got from the same function. But 
I got it on PPC32 which doesn't use userspace for that. See 
https://lore.kernel.org/all/2000a30f-214a-4b20-b0b5-348e987d6a0e@csgroup.eu/T/#u

So I have the feeling that your patch may be hidding another problem. 
The PPC32 report for sure will be hidden if your patch gets applied, 
allthough your explanation doesn't fit.

Christophe

> 
> Signed-off-by: Benjamin Gray <bgray@linux.ibm.com>
> 
> ---
> 
> I tried to replace the memsetN calls with __memsetN, but we appear to
> disable the non-instrumented variants of these when KASAN is enabled.
> Christophe might you know more here?
> 
> The cost of just suppressing reports for this section shouldn't be too
> relevant; KASAN detects the access, but exits before it starts preparing
> the report itself. So it's just like any other KASAN instrumented
> function for the most part.
> ---
>   arch/powerpc/lib/code-patching.c | 3 +++
>   1 file changed, 3 insertions(+)
> 
> diff --git a/arch/powerpc/lib/code-patching.c b/arch/powerpc/lib/code-patching.c
> index c6ab46156cda..24989594578a 100644
> --- a/arch/powerpc/lib/code-patching.c
> +++ b/arch/powerpc/lib/code-patching.c
> @@ -3,6 +3,7 @@
>    *  Copyright 2008 Michael Ellerman, IBM Corporation.
>    */
>   
> +#include <linux/kasan.h>
>   #include <linux/kprobes.h>
>   #include <linux/mmu_context.h>
>   #include <linux/random.h>
> @@ -377,6 +378,7 @@ static int __patch_instructions(u32 *patch_addr, u32 *code, size_t len, bool rep
>   	unsigned long start = (unsigned long)patch_addr;
>   
>   	/* Repeat instruction */
> +	kasan_disable_current();
>   	if (repeat_instr) {
>   		ppc_inst_t instr = ppc_inst_read(code);
>   
> @@ -392,6 +394,7 @@ static int __patch_instructions(u32 *patch_addr, u32 *code, size_t len, bool rep
>   	} else {
>   		memcpy(patch_addr, code, len);
>   	}
> +	kasan_enable_current();
>   
>   	smp_wmb();	/* smp write barrier */
>   	flush_icache_range(start, start + len);

      reply	other threads:[~2024-02-19  7:48 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-13  4:36 [PATCH] powerpc/code-patching: Disable KASAN in __patch_instructions() Benjamin Gray
2024-02-19  7:47 ` Christophe Leroy [this message]

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=671c06fb-c053-4fbe-b011-6f4b8e8dd618@csgroup.eu \
    --to=christophe.leroy@csgroup.eu \
    --cc=bgray@linux.ibm.com \
    --cc=hbathini@linux.ibm.com \
    --cc=linuxppc-dev@lists.ozlabs.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;
as well as URLs for NNTP newsgroup(s).