lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20250315123621.GCZ9V0RWGFapbQNL1w@fat_crate.local>
Date: Sat, 15 Mar 2025 13:36:21 +0100
From: Borislav Petkov <bp@...en8.de>
To: Junaid Shahid <junaids@...gle.com>
Cc: Brendan Jackman <jackmanb@...gle.com>, akpm@...ux-foundation.org,
	dave.hansen@...ux.intel.com, yosryahmed@...gle.com,
	kvm@...r.kernel.org, linux-kernel@...r.kernel.org,
	linux-mm@...ck.org, peterz@...radead.org, seanjc@...gle.com,
	tglx@...utronix.de, x86@...nel.org
Subject: Re: [PATCH RFC v2 03/29] mm: asi: Introduce ASI core API

On Fri, Mar 14, 2025 at 06:34:32PM -0700, Junaid Shahid wrote:
> The reason this isn't a problem with the current asi_enter() is because
> there the equivalent of asi_start_critical() happens _before_ the address
> space switch. That ensures that even if an NMI arrives in the middle of
> asi_enter(), the NMI epilog will switch to the restricted address space and
> there is no window where an NMI (or any other interrupt/exception for that
> matter) would result in going into vmenter with an unrestricted address
> space.

Aha.

> So
> 	asi_enter();
> 	asi_start_critical();
> 	vmenter();
> 	asi_end_critical();
> 
> is broken as there is a problematic window between asi_enter() and
> asi_start_critical() as Brendan pointed out.
> 
> However,
> 	asi_start_critical();
> 	asi_enter();
> 	vmenter();
> 	asi_end_critical();
> 
> would work perfectly fine.
> 
> Perhaps that might be the way to refactor the API?

Ok, let's see if I understand the API better now. And I'm using function names
which say what they do:

I guess the flow and needed ingredients should be:

	1. asi_lock() or asi_start() or whatnot which does that atomic switch
	   of asi target. That tells other code like the NMI glue where in the
	   asi context the CPU is so that glue code can know what to do on
	   return

	2. asi_switch_address_space() - the expensive pagetables build and CR3
	   switch

	3. asi_enter_critical_region() - this could be NOP but basically marks
	   the beginning of the CPU executing "unsafe" code

		<... executes unsafe code... >

	4. asi_exit_critical_region() - sets ASI target to NULL, i.e., what
	   asi_relax) does now. This also atomic and tells other code, we're
	   done with executing unsafe code but we're still running in the
	   restricted address space.

	   This here can go back to 3 as often as needed.

	5. asi_switch_address_space() - this goes back to the unrestricted
	   adddress space

	6. asi_unlock()

Close?

Btw, I should probably continue reviewing the rest and then we can circle back
to this as then I'll have a fuller big picture.

Thx.

-- 
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ