[PATCH 2/3] sys_personality: make sure (int)personality >= 0

From: Oleg Nesterov
Date: Thu May 27 2010 - 11:37:52 EST


Not sure about this patch. The kernel/libc part is correct, but
since user-space declares "int personality(unsigned long persona)"
the current behaviour can confuse the (poor written) applications
even on 64-bit machines.

Consider:

personality(0xffffffff - 1); // == (int)-2

...

int ret = personality(0); // returns the old personality
if (ret < 0)
oops_we_cant_set_PER_LINUX(errno);

And, since libc correctly detects the successful return from syscall,
errno is random.

Change sys_personality() to ensure personality can not look like a
negative int. This disallows the MSB, it is not used for PER_ flags.

Suggested-by: Wenming Zhang <wezhang@xxxxxxxxxx>
Signed-off-by: Oleg Nesterov <oleg@xxxxxxxxxx>
---

kernel/exec_domain.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

--- 34-rc1/kernel/exec_domain.c~2_MAKE_IT_POSITIVE 2010-05-27 15:15:12.000000000 +0200
+++ 34-rc1/kernel/exec_domain.c 2010-05-27 15:54:33.000000000 +0200
@@ -193,7 +193,8 @@ SYSCALL_DEFINE1(personality, u_long, per
u_long old = current->personality;

if (personality != 0xffffffff) {
- if ((unsigned int)personality != personality)
+ /* ensure it never looks like a negative int to user-space */
+ if (personality > 0x7fffffff)
return -EINVAL;
set_personality(personality);
}

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