Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/kern When choosing the start address of a dynamic (ie re...



details:   https://anonhg.NetBSD.org/src/rev/5ace5da74d1f
branches:  trunk
changeset: 753318:5ace5da74d1f
user:      drochner <drochner%NetBSD.org@localhost>
date:      Mon Mar 22 22:10:10 2010 +0000

description:
When choosing the start address of a dynamic (ie relocatable) executable,
respect the alignment in the ELF phdr.
Also, for correctness, use the maximum alignment of the PT_LOAD
sections rather than just the first one found.
Also, use more meaningful types.

diffstat:

 sys/kern/exec_elf.c |  26 ++++++++++----------------
 1 files changed, 10 insertions(+), 16 deletions(-)

diffs (64 lines):

diff -r cc041b82d8e7 -r 5ace5da74d1f sys/kern/exec_elf.c
--- a/sys/kern/exec_elf.c       Mon Mar 22 22:03:30 2010 +0000
+++ b/sys/kern/exec_elf.c       Mon Mar 22 22:10:10 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: exec_elf.c,v 1.18 2010/03/20 01:52:16 christos Exp $   */
+/*     $NetBSD: exec_elf.c,v 1.19 2010/03/22 22:10:10 drochner Exp $   */
 
 /*-
  * Copyright (c) 1994, 2000, 2005 The NetBSD Foundation, Inc.
@@ -57,7 +57,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(1, "$NetBSD: exec_elf.c,v 1.18 2010/03/20 01:52:16 christos Exp $");
+__KERNEL_RCSID(1, "$NetBSD: exec_elf.c,v 1.19 2010/03/22 22:10:10 drochner Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_pax.h"
@@ -116,29 +116,23 @@
 #define MAXSHNUM       32768
 #define MAXNOTESIZE    1024
 
-/*
- * We don't move this code in kern_pax.c because it is compiled twice.
- */
 static void
 elf_placedynexec(struct lwp *l, struct exec_package *epp, Elf_Ehdr *eh,
     Elf_Phdr *ph)
 {
-       size_t offset, i;
+       Elf_Addr align, offset;
+       int i;
+
+       for (align = i = 0; i < eh->e_phnum; i++)
+               if (ph[i].p_type == PT_LOAD && ph[i].p_align > align)
+                       align = ph[i].p_align;
 
 #ifdef PAX_ASLR
        if (pax_aslr_active(l)) {
                size_t pax_align, l2, delta;
                uint32_t r;
 
-               /*
-                * find align XXX: not all sections might have the same
-                * alignment
-                */
-               for (pax_align = i = 0; i < eh->e_phnum; i++)
-                       if (ph[i].p_type == PT_LOAD) {
-                               pax_align = ph[i].p_align;
-                               break;
-                       }
+               pax_align = align;
 
                r = arc4random();
 
@@ -155,7 +149,7 @@
 #endif /* PAX_ASLR_DEBUG */
        } else
 #endif /* PAX_ASLR */
-               offset = PAGE_SIZE;
+               offset = MAX(align, PAGE_SIZE);
 
        for (i = 0; i < eh->e_phnum; i++)
                ph[i].p_vaddr += offset;



Home | Main Index | Thread Index | Old Index