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] [thread-next>] [day] [month] [year] [list]
Date:	Thu, 24 Jan 2013 16:46:12 -0800
From:	Andrew Morton <akpm@...ux-foundation.org>
To:	Aristeu Rozanski <aris@...hat.com>
Cc:	linux-kernel@...r.kernel.org, "Serge E. Hallyn" <serge@...lyn.com>,
	"Eric W. Biederman" <ebiederm@...ssion.com>
Subject: Re: [PATCH v2] userns: improve uid/gid map collision detection

On Thu, 24 Jan 2013 10:28:59 -0500
Aristeu Rozanski <aris@...hat.com> wrote:

> userns: improve uid/gid map collision detection
> 
> Initial implementation of the uid/gid maps (/proc/<pid>/{u,g}id_map) will
> enforce that the UID and GID maps be written in strict order as a simple
> way to check for range collision:
> 	local id	mapped to	count/range
> 	0		1000		50
> 	(ids 0-50 get mapped to 1000-1050)
> 	100		2120		10
> 	500		5000		200
> so for each new entry, local id must be bigger than last local id (plus
> count) and the ids it maps to also needs to be bigger than the last
> entry (plus count).
> 
> This makes impossible to have a use case like this:
> 	local id	mapped to	count/range
> 	0		1000		1
> 	48		500		20
> 
> because while 48+20 > 0+1, 500+20 < 1000+1.
> 
> This patch implements a more elaborate collision detection allowing any
> order to be used.
> 
> v2: improved the patch description as requested by Andrew

Thanks.

> --- a/kernel/user_namespace.c
> +++ b/kernel/user_namespace.c
> @@ -521,6 +521,28 @@ struct seq_operations proc_projid_seq_operations = {
>  
>  static DEFINE_MUTEX(id_map_mutex);
>  
> +#define in_range(b,first,len) ((b)>=(first)&&(b)<(first)+(len))

eek, a macro!  Macros are always bad.

This one is bad because

a) it's a macro

b) it evaluates its args multiple times and hence will cause nasty
   bugs if called with expressions-with-side-effects.

c) it evaluates its args multiple times and if called with
   non-trivial expressions the compiler might not be able to CSE those
   expressions, leading to code bloat.

Add lo, this patch:

--- a/kernel/user_namespace.c~userns-improve-uid-gid-map-collision-detection-fix
+++ a/kernel/user_namespace.c
@@ -521,7 +521,11 @@ struct seq_operations proc_projid_seq_op
 
 static DEFINE_MUTEX(id_map_mutex);
 
-#define in_range(b,first,len) ((b)>=(first)&&(b)<(first)+(len))
+static bool in_range(u32 b, u32 first, u32 len)
+{
+	return b >= first && b < first + len;
+}
+
 static inline int extent_collision(struct uid_gid_map *new_map,
 				   struct uid_gid_extent *extent)
 {

reduces the user_namespace.o text from 4822 bytes to 4727 with
gcc-4.4.4.  This is a remarkably large difference.


btw, what the heck is up with CONFIG_UIDGID_CONVERTED?  That thing
prevents userns from being compiled in an allmodconfig build, which is
rather undesirable.  Isn't there a better, more user-friendly way of
doing this?

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ