All of lore.kernel.org
 help / color / mirror / Atom feed
From: Erhard Furtner <erhard_f@mailbox.org>
To: Christophe Leroy <christophe.leroy@csgroup.eu>
Cc: Hari Bathini <hbathini@linux.ibm.com>,
	"Christopher M. Riedl" <cmr@bluescreens.de>,
	"linuxppc-dev@lists.ozlabs.org" <linuxppc-dev@lists.ozlabs.org>,
	"maddy@linux.ibm.com" <maddy@linux.ibm.com>
Subject: Re: BUG: KASAN: vmalloc-out-of-bounds in copy_to_kernel_nofault+0xd8/0x1c8 (v6.13-rc6, PowerMac G4)
Date: Sun, 2 Feb 2025 14:25:52 +0100	[thread overview]
Message-ID: <20250202142552.33285e7e@yea> (raw)
In-Reply-To: <66f36cf5-37d5-4edb-a20b-4047dbe6a846@csgroup.eu>

On Sun, 2 Feb 2025 09:44:20 +0100
Christophe Leroy <christophe.leroy@csgroup.eu> wrote:

> This time the problem is a mixture of commit 465cabc97b42 
> ("powerpc/code-patching: introduce patch_instructions()") and commit 
> c28c15b6d28a ("powerpc/code-patching: Use temporary mm for Radix MMU") 
> which is revealed by commit e4137f08816b ("mm, kasan, kmsan: instrument 
> copy_from/to_kernel_nofault")
> 
> Commit c28c15b6d28a is inspired by commit b3fd8e83ada0 
> ("x86/alternatives: Use temporary mm for text poking") but misses the 
> kasan_disable_current() / kasan_enable_current() sequence.
> 
> Was not necessary because __patch_mem() is not instrumented. But commit 
> 465cabc97b42 added use of copy_to_kernel_nofault() which is now 
> instrumented.
> 
> The problem is that commit c28c15b6d28a makes use of a special memory 
> area which is not kernel memory and it doesn't have any matching KASAN 
> shadow area. And because it is located below TASK_SIZE, in addition 
> kasan sees it as user memory.
> 
> Can you try the change below ?
> 
> diff --git a/arch/powerpc/lib/code-patching.c 
> b/arch/powerpc/lib/code-patching.c
> index 8a378fc19074..f84e0337cc02 100644
> --- a/arch/powerpc/lib/code-patching.c
> +++ b/arch/powerpc/lib/code-patching.c
> @@ -493,7 +493,9 @@ static int __do_patch_instructions_mm(u32 *addr, u32 
> *code, size_t len, bool rep
> 
>   	orig_mm = start_using_temp_mm(patching_mm);
> 
> +	kasan_disable_current();
>   	err = __patch_instructions(patch_addr, code, len, repeat_instr);
> +	kasan_enable_current();
> 
>   	/* context synchronisation performed by __patch_instructions */
>   	stop_using_temp_mm(patching_mm, orig_mm);
> 

Thanks! With this patch applied the KASAN hit is gone and I got no further KASAN hits on my Talos II during boot. Applied both patches on top of v6.13.1.

Regards,
Erhard


  reply	other threads:[~2025-02-02 13:26 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-12 12:58 BUG: KASAN: vmalloc-out-of-bounds in copy_to_kernel_nofault+0xd8/0x1c8 (v6.13-rc6, PowerMac G4) Erhard Furtner
2025-01-19 16:36 ` Madhavan Srinivasan
2025-01-20 22:42   ` Erhard Furtner
2025-01-21 21:00   ` Erhard Furtner
2025-01-21 22:07     ` Christophe Leroy
2025-01-21 23:21       ` Erhard Furtner
2025-01-22 15:32         ` Christophe Leroy
2025-01-22 18:23           ` Christophe Leroy
2025-01-23 10:00             ` Erhard Furtner
2025-02-01 14:14             ` Erhard Furtner
2025-02-01 15:14               ` Christophe Leroy
     [not found]                 ` <20250201165416.71e00c43@yea>
2025-02-02  8:44                   ` Christophe Leroy
2025-02-02 13:25                     ` Erhard Furtner [this message]
2025-01-22  0:34     ` Linus Torvalds

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=20250202142552.33285e7e@yea \
    --to=erhard_f@mailbox.org \
    --cc=christophe.leroy@csgroup.eu \
    --cc=cmr@bluescreens.de \
    --cc=hbathini@linux.ibm.com \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=maddy@linux.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.