public inbox for linuxppc-dev@ozlabs.org 
 help / color / mirror / Atom feed
From: Deepak Gupta <debug@rivosinc•com>
To: Mark Brown <broonie@kernel•org>
Cc: Richard Henderson <richard.henderson@linaro•org>,
	Ivan Kokshaysky <ink@jurassic•park.msu.ru>,
	Matt Turner <mattst88@gmail•com>,
	Vineet Gupta <vgupta@kernel•org>,
	Russell King <linux@armlinux•org.uk>, Guo Ren <guoren@kernel•org>,
	Huacai Chen <chenhuacai@kernel•org>,
	WANG Xuerui <kernel@xen0n•name>,
	"James E.J. Bottomley" <James.Bottomley@hansenpartnership•com>,
	Helge Deller <deller@gmx•de>,
	Michael Ellerman <mpe@ellerman•id.au>,
	Nicholas Piggin <npiggin@gmail•com>,
	Christophe Leroy <christophe.leroy@csgroup•eu>,
	Naveen N Rao <naveen@kernel•org>,
	Alexander Gordeev <agordeev@linux•ibm.com>,
	Gerald Schaefer <gerald.schaefer@linux•ibm.com>,
	Heiko Carstens <hca@linux•ibm.com>,
	Vasily Gorbik <gor@linux•ibm.com>,
	Christian Borntraeger <borntraeger@linux•ibm.com>,
	Sven Schnelle <svens@linux•ibm.com>,
	Yoshinori Sato <ysato@users•sourceforge.jp>,
	Rich Felker <dalias@libc•org>,
	John Paul Adrian Glaubitz <glaubitz@physik•fu-berlin.de>,
	"David S. Miller" <davem@davemloft•net>,
	Andreas Larsson <andreas@gaisler•com>,
	Thomas Gleixner <tglx@linutronix•de>,
	Ingo Molnar <mingo@redhat•com>, Borislav Petkov <bp@alien8•de>,
	Dave Hansen <dave.hansen@linux•intel.com>,
	x86@kernel•org, "H. Peter Anvin" <hpa@zytor•com>,
	Chris Zankel <chris@zankel•net>,
	Max Filippov <jcmvbkbc@gmail•com>,
	Andrew Morton <akpm@linux-foundation•org>,
	"Liam R. Howlett" <Liam.Howlett@oracle•com>,
	Vlastimil Babka <vbabka@suse•cz>,
	Lorenzo Stoakes <lorenzo.stoakes@oracle•com>,
	Catalin Marinas <catalin.marinas@arm•com>,
	Will Deacon <will@kernel•org>,
	linux-arm-kernel@lists•infradead.org,
	linux-alpha@vger•kernel.org, linux-kernel@vger•kernel.org,
	linux-snps-arc@lists•infradead.org, linux-csky@vger•kernel.org,
	loongarch@lists•linux.dev, linux-parisc@vger•kernel.org,
	linuxppc-dev@lists•ozlabs.org, linux-s390@vger•kernel.org,
	linux-sh@vger•kernel.org, sparclinux@vger•kernel.org,
	linux-mm@kvack•org, Rick Edgecombe <rick.p.edgecombe@intel•com>
Subject: Re: [PATCH 3/3] mm: Care about shadow stack guard gap when getting an unmapped area
Date: Wed, 4 Sep 2024 11:51:53 -0700	[thread overview]
Message-ID: <ZtisSerxbnDaWr5l@debug.ba.rivosinc.com> (raw)
In-Reply-To: <20240902-mm-generic-shadow-stack-guard-v1-3-9acda38b3dd3@kernel.org>

On Mon, Sep 02, 2024 at 08:08:15PM +0100, Mark Brown wrote:
>As covered in the commit log for c44357c2e76b ("x86/mm: care about shadow
>stack guard gap during placement") our current mmap() implementation does
>not take care to ensure that a new mapping isn't placed with existing
>mappings inside it's own guard gaps. This is particularly important for
>shadow stacks since if two shadow stacks end up getting placed adjacent to
>each other then they can overflow into each other which weakens the
>protection offered by the feature.
>
>On x86 there is a custom arch_get_unmapped_area() which was updated by the
>above commit to cover this case by specifying a start_gap for allocations
>with VM_SHADOW_STACK. Both arm64 and RISC-V have equivalent features and
>use the generic implementation of arch_get_unmapped_area() so let's make
>the equivalent change there so they also don't get shadow stack pages
>placed without guard pages.
>
>Architectures which do not have this feature will define VM_SHADOW_STACK
>to VM_NONE and hence be unaffected.
>
>Suggested-by: Rick Edgecombe <rick.p.edgecombe@intel•com>
>Signed-off-by: Mark Brown <broonie@kernel•org>
>---
> mm/mmap.c | 10 ++++++++++
> 1 file changed, 10 insertions(+)
>
>diff --git a/mm/mmap.c b/mm/mmap.c
>index b06ba847c96e..902c482b6084 100644
>--- a/mm/mmap.c
>+++ b/mm/mmap.c
>@@ -1753,6 +1753,14 @@ static unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info)
> 	return gap;
> }
>
>+static inline unsigned long stack_guard_placement(vm_flags_t vm_flags)
>+{
>+	if (vm_flags & VM_SHADOW_STACK)
>+		return PAGE_SIZE;
>+
>+	return 0;
>+}
>+
> /*
>  * Search for an unmapped address range.
>  *
>@@ -1814,6 +1822,7 @@ generic_get_unmapped_area(struct file *filp, unsigned long addr,
> 	info.length = len;
> 	info.low_limit = mm->mmap_base;
> 	info.high_limit = mmap_end;
>+	info.start_gap = stack_guard_placement(vm_flags);
> 	return vm_unmapped_area(&info);
> }
>
>@@ -1863,6 +1872,7 @@ generic_get_unmapped_area_topdown(struct file *filp, unsigned long addr,
> 	info.length = len;
> 	info.low_limit = PAGE_SIZE;
> 	info.high_limit = arch_get_mmap_base(addr, mm->mmap_base);
>+	info.start_gap = stack_guard_placement(vm_flags);
> 	addr = vm_unmapped_area(&info);
>
> 	/*
>

lgtm

Reviewed-by: Deepak Gupta <debug@rivosinc•com>

>-- 
>2.39.2
>


      parent reply	other threads:[~2024-09-04 22:33 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-02 19:08 [PATCH 0/3] mm: Care about shadow stack guard gap when getting an unmapped area Mark Brown
2024-09-02 19:08 ` [PATCH 1/3] mm: Make arch_get_unmapped_area() take vm_flags by default Mark Brown
2024-09-03 17:43   ` Lorenzo Stoakes
2024-09-03 19:35   ` Liam R. Howlett
2024-09-03 19:50   ` Helge Deller
2024-09-02 19:08 ` [PATCH 2/3] mm: Pass vm_flags to generic_get_unmapped_area() Mark Brown
2024-09-03 17:44   ` Lorenzo Stoakes
2024-09-03 19:37   ` Liam R. Howlett
2024-09-04  4:13   ` Michael Ellerman
2024-09-04 18:53   ` Deepak Gupta
2024-09-02 19:08 ` [PATCH 3/3] mm: Care about shadow stack guard gap when getting an unmapped area Mark Brown
2024-09-03 17:49   ` Lorenzo Stoakes
2024-09-03 18:20     ` Mark Brown
2024-09-03 19:24       ` Lorenzo Stoakes
2024-09-03 19:41   ` Liam R. Howlett
2024-09-03 19:57     ` Mark Brown
2024-09-04 19:07       ` Deepak Gupta
2024-09-04 18:51   ` Deepak Gupta [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=ZtisSerxbnDaWr5l@debug.ba.rivosinc.com \
    --to=debug@rivosinc$(echo .)com \
    --cc=James.Bottomley@hansenpartnership$(echo .)com \
    --cc=Liam.Howlett@oracle$(echo .)com \
    --cc=agordeev@linux$(echo .)ibm.com \
    --cc=akpm@linux-foundation$(echo .)org \
    --cc=andreas@gaisler$(echo .)com \
    --cc=borntraeger@linux$(echo .)ibm.com \
    --cc=bp@alien8$(echo .)de \
    --cc=broonie@kernel$(echo .)org \
    --cc=catalin.marinas@arm$(echo .)com \
    --cc=chenhuacai@kernel$(echo .)org \
    --cc=chris@zankel$(echo .)net \
    --cc=christophe.leroy@csgroup$(echo .)eu \
    --cc=dalias@libc$(echo .)org \
    --cc=dave.hansen@linux$(echo .)intel.com \
    --cc=davem@davemloft$(echo .)net \
    --cc=deller@gmx$(echo .)de \
    --cc=gerald.schaefer@linux$(echo .)ibm.com \
    --cc=glaubitz@physik$(echo .)fu-berlin.de \
    --cc=gor@linux$(echo .)ibm.com \
    --cc=guoren@kernel$(echo .)org \
    --cc=hca@linux$(echo .)ibm.com \
    --cc=hpa@zytor$(echo .)com \
    --cc=ink@jurassic$(echo .)park.msu.ru \
    --cc=jcmvbkbc@gmail$(echo .)com \
    --cc=kernel@xen0n$(echo .)name \
    --cc=linux-alpha@vger$(echo .)kernel.org \
    --cc=linux-arm-kernel@lists$(echo .)infradead.org \
    --cc=linux-csky@vger$(echo .)kernel.org \
    --cc=linux-kernel@vger$(echo .)kernel.org \
    --cc=linux-mm@kvack$(echo .)org \
    --cc=linux-parisc@vger$(echo .)kernel.org \
    --cc=linux-s390@vger$(echo .)kernel.org \
    --cc=linux-sh@vger$(echo .)kernel.org \
    --cc=linux-snps-arc@lists$(echo .)infradead.org \
    --cc=linux@armlinux$(echo .)org.uk \
    --cc=linuxppc-dev@lists$(echo .)ozlabs.org \
    --cc=loongarch@lists$(echo .)linux.dev \
    --cc=lorenzo.stoakes@oracle$(echo .)com \
    --cc=mattst88@gmail$(echo .)com \
    --cc=mingo@redhat$(echo .)com \
    --cc=mpe@ellerman$(echo .)id.au \
    --cc=naveen@kernel$(echo .)org \
    --cc=npiggin@gmail$(echo .)com \
    --cc=richard.henderson@linaro$(echo .)org \
    --cc=rick.p.edgecombe@intel$(echo .)com \
    --cc=sparclinux@vger$(echo .)kernel.org \
    --cc=svens@linux$(echo .)ibm.com \
    --cc=tglx@linutronix$(echo .)de \
    --cc=vbabka@suse$(echo .)cz \
    --cc=vgupta@kernel$(echo .)org \
    --cc=will@kernel$(echo .)org \
    --cc=x86@kernel$(echo .)org \
    --cc=ysato@users$(echo .)sourceforge.jp \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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