public inbox for linux-arm-kernel@lists.infradead.org
 help / color / mirror / Atom feed
From: Mark Rutland <mark.rutland@arm.com>
To: Ard Biesheuvel <ardb@kernel.org>
Cc: Linus Walleij <linus.walleij@linaro.org>,
	Clement LE GOFFIC <clement.legoffic@foss.st.com>,
	Russell King <linux@armlinux.org.uk>,
	"Russell King (Oracle)" <rmk+kernel@armlinux.org.uk>,
	Kees Cook <kees@kernel.org>,
	AngeloGioacchino Del Regno
	<angelogioacchino.delregno@collabora.com>,
	Mark Brown <broonie@kernel.org>,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org,
	linux-stm32@st-md-mailman.stormreply.com,
	Antonio Borneo <antonio.borneo@foss.st.com>
Subject: Re: Crash on armv7-a using KASAN
Date: Wed, 16 Oct 2024 09:55:38 +0100	[thread overview]
Message-ID: <Zw9_imsl2KLf7_GY@J2N7QTR9R3> (raw)
In-Reply-To: <CAMj1kXGGmsWs2XpM7zLURjKp67Uz2ePi1pSV1=rPCMgviLVUgw@mail.gmail.com>

On Tue, Oct 15, 2024 at 07:28:06PM +0200, Ard Biesheuvel wrote:
> On Tue, 15 Oct 2024 at 18:27, Mark Rutland <mark.rutland@arm.com> wrote:
> >
> > On Tue, Oct 15, 2024 at 06:07:00PM +0200, Ard Biesheuvel wrote:
> > > On Tue, 15 Oct 2024 at 17:26, Mark Rutland <mark.rutland@arm.com> wrote:
> > > > Looking some more, I don't see how VMAP_STACK guarantees that the
> > > > old/active stack is mapped in the new mm when switching from the old mm
> > > > to the new mm (which happens before __switch_to()).
> > > >
> > > > Either I'm missing something, or we have a latent bug. Maybe we have
> > > > some explicit copying/prefaulting elsewhere I'm missing?
> > >
> > > We bump the vmalloc_seq counter for that. Given that the top-level
> > > page table can only gain entries covering the kernel space, this
> > > should be sufficient for the old task's stack to be mapped in the new
> > > task's page tables.
> >
> > Ah, yep -- I had missed that. Thanks for the pointer!
> >
> > From a superficial look, it sounds like it should be possible to extend
> > that to also handle the KASAN shadow of the vmalloc area (which
> > __check_vmalloc_seq() currently doesn't copy), but I'm not sure of
> > exactly when we initialise the shadow for a vmalloc allocation relative
> > to updating vmalloc_seq.
> >
> 
> Indeed. It appears both vmalloc_seq() and arch_sync_kernel_mappings()
> need to take the vmalloc shadow into account specifically. And we may
> also need the dummy read from the stack's shadow in __switch_to - I am
> pretty sure I added that for a reason.

I believe that's necessary for the lazy TLB switch, at least for SMP:

	// CPU 0			// CPU 1

	<< switches to task X's mm >>

					<< creates kthread task Y >>
					<< maps task Y's new stack >>
					<< maps task Y's new shadow >>

					// Y switched out
					context_switch(..., Y, ..., ...);

	// Switch from X to Y
	context_switch(..., X, Y, ...) {
		// prev = X
		// next = Y

		if (!next->mm) { 
			// Y has no mm
			// No switch_mm() here
			// ... so no check_vmalloc_seq()
		} else {
			// not taken
		}

		...

		// X's mm still lacks Y's stack + shadow here

		switch_to(prev, next, prev);
	}

... so probably worth a comment that we're faulting in the new
stack+shadow for for lazy tlb when switching to a task with no mm?

In the lazy tlb case the current/old mappings don't disappear from the
active mm, and so we don't need to go add those to the new mm, which is what
we need check_vmalloc_seq() for.

Mark.


  parent reply	other threads:[~2024-10-16  9:00 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-14 13:19 Crash on armv7-a using KASAN Clement LE GOFFIC
2024-10-15  7:55 ` Linus Walleij
2024-10-15 10:35   ` Clement LE GOFFIC
2024-10-15 10:28 ` Mark Rutland
2024-10-15 13:51   ` Linus Walleij
2024-10-15 14:00     ` Mark Rutland
2024-10-15 14:22       ` Ard Biesheuvel
2024-10-15 14:35         ` Mark Rutland
2024-10-15 14:44           ` Ard Biesheuvel
2024-10-15 14:55             ` Linus Walleij
2024-10-15 15:26             ` Mark Rutland
2024-10-15 16:07               ` Ard Biesheuvel
2024-10-15 16:27                 ` Mark Rutland
2024-10-15 17:28                   ` Ard Biesheuvel
2024-10-15 20:55                     ` Linus Walleij
2024-10-15 21:24                       ` Linus Walleij
2024-10-16  8:55                     ` Mark Rutland [this message]
2024-10-16 19:00                       ` Linus Walleij
2024-10-17 10:09                         ` Mark Rutland
2024-10-17 10:31                           ` Ard Biesheuvel
2024-10-15 14:40       ` Linus Walleij

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=Zw9_imsl2KLf7_GY@J2N7QTR9R3 \
    --to=mark.rutland@arm.com \
    --cc=angelogioacchino.delregno@collabora.com \
    --cc=antonio.borneo@foss.st.com \
    --cc=ardb@kernel.org \
    --cc=broonie@kernel.org \
    --cc=clement.legoffic@foss.st.com \
    --cc=kees@kernel.org \
    --cc=linus.walleij@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-stm32@st-md-mailman.stormreply.com \
    --cc=linux@armlinux.org.uk \
    --cc=rmk+kernel@armlinux.org.uk \
    /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