LWN.net Logo

Patch 3/6 per process flag

From:  Arjan van de Ven <arjan@infradead.org>
To:  linux-kernel@vger.kernel.org, akpm@osdl.org, torvalds@osdl.org
Subject:  Re: Patch 3/6 per process flag
Date:  Thu, 27 Jan 2005 10:12:54 +0000



Even thoguh there is a global flag to disable randomisation, it's useful to
have a per process flag too; the patch below introduces this per process
flag and automatically sets it for "new" binaries.

Eventually we will want to tie this to the legacy-va-space personality

Signed-off-by: Arjan van de Ven <arjan@infradead.org>

diff -purN linux-step-4a/fs/binfmt_elf.c linux-step-5/fs/binfmt_elf.c
--- linux-step-3/fs/binfmt_elf.c	2005-01-26 21:18:49.000000000 +0100
+++ linux-step-2/fs/binfmt_elf.c	2005-01-27 09:08:41.000000000 +0100
@@ -757,6 +759,9 @@ static int load_elf_binary(struct linux_
 	if (elf_read_implies_exec(loc->elf_ex, have_pt_gnu_stack))
 		current->personality |= READ_IMPLIES_EXEC;
 
+	if (executable_stack == EXSTACK_DISABLE_X && randomize_va_space) {
+		current->flags |= PF_RANDOMIZE;
+	}
 	arch_pick_mmap_layout(current->mm);
 
 	/* Do this so that we can load the interpreter, if need be.  We will
diff -purN linux-step-3/fs/exec.c linux-step-2/fs/exec.c
--- linux-step-3/fs/exec.c	2005-01-26 18:24:38.762322000 +0100
+++ linux-step-2/fs/exec.c	2005-01-26 21:15:33.860310848 +0100
@@ -877,6 +877,7 @@ int flush_old_exec(struct linux_binprm *
 	tcomm[i] = '\0';
 	set_task_comm(current, tcomm);
 
+	current->flags &= ~PF_RANDOMIZE;
 	flush_thread();
 
 	if (bprm->e_uid != current->euid || bprm->e_gid != current->egid || 
diff -purN linux-step-3/include/linux/sched.h
linux-step-2/include/linux/sched.h
--- linux-step-3/include/linux/sched.h	2005-01-26 18:24:39.606194000 +0100
+++ linux-step-2/include/linux/sched.h	2005-01-26 21:13:28.692339272 +0100
@@ -736,6 +736,7 @@ do { if (atomic_dec_and_test(&(tsk)->usa
 #define PF_LESS_THROTTLE 0x00100000	/* Throttle me less: I clean memory */
 #define PF_SYNCWRITE	0x00200000	/* I am doing a sync write */
 #define PF_BORROWED_MM	0x00400000	/* I am a kthread doing use_mm */
+#define PF_RANDOMIZE	0x00800000	/* randomize virtual address space */
 
 #ifdef CONFIG_SMP
 extern int set_cpus_allowed(task_t *p, cpumask_t new_mask);
-
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/

Copyright © 2005, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds