Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Fri, 26 Apr 2019 15:02:43 +0000
From: Jason Gunthorpe <jgg@...lanox.com>
To: Ingo Molnar <mingo@...nel.org>
CC: Kees Cook <keescook@...omium.org>, Andrew Morton
	<akpm@...ux-foundation.org>, Hector Marco-Gisbert <hecmargi@....es>, Marc
 Gonzalez <marc.w.gonzalez@...e.fr>, Will Deacon <will.deacon@....com>, X86 ML
	<x86@...nel.org>, Thomas Gleixner <tglx@...utronix.de>, Andy Lutomirski
	<luto@...capital.net>, Stephen Rothwell <sfr@...b.auug.org.au>, Catalin
 Marinas <catalin.marinas@....com>, Mark Rutland <mark.rutland@....com>, Arnd
 Bergmann <arnd@...db.de>, Linux ARM <linux-arm-kernel@...ts.infradead.org>,
	Kernel Hardening <kernel-hardening@...ts.openwall.com>, LKML
	<linux-kernel@...r.kernel.org>, Linus Torvalds
	<torvalds@...ux-foundation.org>, Borislav Petkov <bp@...en8.de>, Peter
 Zijlstra <a.p.zijlstra@...llo.nl>
Subject: Re: [PATCH v2] binfmt_elf: Update READ_IMPLIES_EXEC logic for modern
 CPUs

On Thu, Apr 25, 2019 at 10:07:25PM +0200, Ingo Molnar wrote:

> > But yes, your above diff for "has NX" is roughly correct. I'll walk
> > through each piece I'm thinking about. Here is the current state:
> > 
> >                CPU: | lacks NX*  | has NX, ia32     | has NX, x86_64 |
> >   ELF:              |            |                  |                |
> >   missing GNU_STACK | exec-all   | exec-all         | exec-all       |
> >   GNU_STACK == RWX  | exec-all   | exec-all         | exec-all       |
> >   GNU_STACK == RW   | exec-none  | exec-none        | exec-none      |
> > 
> > *this column has no architecture effect: NX markings are ignored by
> > hardware, but may have behavioral effects when "wants X" collides with
> > "cannot be X" constraints in memory permission flags, as in [1].
> 
> So [1] appears to be device driver mapping a BAR that isn't intended to 
> be excutable:
> 
>    https://lore.kernel.org/netdev/20190418055759.GA3155@mellanox.com/
> 
> and the question is, do we reject this at the device driver mmap() level 
> already, right?

No, we wanted to reject it at the driver mmap() level, but if an
executable is marked with GNU_STACK=RWX then the core mm code always
calls the driver with VM_EXEC (even though the mmap isn't a stack) and
the driver becomes incompatible with userspace using GNU_STACK=RWX (ie
some Fortran programs, apparently)

> I suspect the best behavior is to reject as early as possible, so I agree 
> with your change here - even though !NX systems tend to become less and 
> less relevant these days.

I suggested the idea of adding a flag in either the struct file or the
file_operations flag that says mmap is never to be executable for this
file with the idea that most/all cdev users would set it.

Does that seem reasonable?

Jason

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.