Patchwork [1/1] personality handling: fix PER_CLEAR_ON_SETID for security reasons

login
register
mail settings
Submitter Julien Tinnes
Date June 26, 2009, 6:27 p.m.
Message ID <deb7a2310906261127v2fd1564elb823716ae03fc0d4@mail.gmail.com>
Download mbox | patch
Permalink /patch/32598/
State New, archived
Headers show

Comments

Julien Tinnes - June 26, 2009, 6:27 p.m.
Hello,

We have found that the current PER_CLEAR_ON_SETID mask on Linux
doesn't include neither ADDR_COMPAT_LAYOUT, nor MMAP_PAGE_ZERO.

The current mask is READ_IMPLIES_EXEC|ADDR_NO_RANDOMIZE.

We believe it is important to add MMAP_PAGE_ZERO, because by using
this personality it is possible to have the first page mapped inside a
process running as setuid root. This could be used in those scenarios:

- Exploiting a NULL pointer dereference issue in a setuid root binary
- Bypassing the mmap_min_addr restrictions of the Linux kernel: by
running a setuid binary that would drop privileges before giving us
control back (for instance by loading a user-supplied library), we
could get the first page mapped in a process we control. By further
using mremap and mprotect on this mapping, we can then completely
bypass the mmap_min_addr restrictions.

Less importantly, we believe ADDR_COMPAT_LAYOUT should also be added
since on x86 32bits it will in practice disable most of the address
space layout randomization (only the stack will remain randomized).

Signed-off-by: Julien Tinnes <jt@cr0.org> and Tavis Ormandy
<taviso@sdf.lonestar.org>

---


  * Personality types.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/
Christoph Hellwig - June 28, 2009, 8:40 p.m.
On Fri, Jun 26, 2009 at 08:27:40PM +0200, Julien Tinnes wrote:
> Hello,
> 
> We have found that the current PER_CLEAR_ON_SETID mask on Linux
> doesn't include neither ADDR_COMPAT_LAYOUT, nor MMAP_PAGE_ZERO.
> 
> The current mask is READ_IMPLIES_EXEC|ADDR_NO_RANDOMIZE.
> 
> We believe it is important to add MMAP_PAGE_ZERO, because by using
> this personality it is possible to have the first page mapped inside a
> process running as setuid root. This could be used in those scenarios:

I agree.

> Less importantly, we believe ADDR_COMPAT_LAYOUT should also be added
> since on x86 32bits it will in practice disable most of the address
> space layout randomization (only the stack will remain randomized).

Agree on this on, too.

> -#define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC|ADDR_NO_RANDOMIZE)
> +#define PER_CLEAR_ON_SETID
> (READ_IMPLIES_EXEC|ADDR_NO_RANDOMIZE|ADDR_COMPAT_LAYOUT|MMAP_PAGE_ZERO)

#define PER_CLEAR_ON_SETID \
	(READ_IMPLIES_EXEC | \
	 ADDR_NO_RANDOMIZE | \
	 ADDR_COMPAT_LAYOUT | \
	 MMAP_PAGE_ZERO)

to make it a little more readable (and work around your mailer
corrupting long lines :))
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Patch

diff -r f70f443c9ead include/linux/personality.h
--- a/include/linux/personality.h	Fri Jun 26 19:59:33 2009 +0200
+++ b/include/linux/personality.h	Fri Jun 26 20:00:40 2009 +0200
@@ -40,7 +40,7 @@  enum {
  * Security-relevant compatibility flags that must be
  * cleared upon setuid or setgid exec:
  */
-#define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC|ADDR_NO_RANDOMIZE)
+#define PER_CLEAR_ON_SETID
(READ_IMPLIES_EXEC|ADDR_NO_RANDOMIZE|ADDR_COMPAT_LAYOUT|MMAP_PAGE_ZERO)

 /*