Clearing registers on process startup

Kurt Garloff (K.Garloff@ping.de)
Wed, 30 Dec 1998 12:16:42 +0100


Hi Linus,

is there any reason why this patch (from John Reiser) didn't make it into
your tree?

diff -u linux-2.1.126/include/asm-i386/elf.h linux/include/asm-i386/elf.h
--- linux-2.1.126/include/asm-i386/elf.h Wed Jun 24 14:30:11 1998
+++ linux/include/asm-i386/elf.h Sat Oct 31 05:52:59 1998
@@ -33,7 +33,10 @@
shared libraries that have been loaded before the code runs.

A value of 0 tells we have no such handler. */
-#define ELF_PLAT_INIT(_r) _r->edx = 0
+#define ELF_PLAT_INIT(_r) _r->edi = _r->esi = _r->ebp = _r->ebx = _r->edx = _r->ecx = _r->eax = 0
+/* Clear all registers except %esp, to improve repeatability, debugability,
+ make life easier for conservative garbage collectors, and reduce
+ covert channels from one process to another. */

#define USE_ELF_CORE_DUMP
#define ELF_EXEC_PAGESIZE 4096

ELF_PLAT_INIT is used in fs/binfmt_elf.c

I think it's a good idea to have a defined state on process startup, if you
want to debug things by comparing two runs of a program.
It might also prevent information leak between programs.

This might not be the most important issue, but on the other hand, we can
spend this 3 CPU cycles (on modern CPUs) to clear 6 more registers ...

-- 
Kurt Garloff <kurt@garloff.de>                           [Dortmund, FRG]  
Plasma physics, high perf. computing              [Linux-ix86,-axp, DUX]
PGP key on http://www.garloff.de/kurt/        [Linux SCSI driver: DC390]

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