Source-Changes-HG archive

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

[src/trunk]: src/sys/compat Increase LINUX32_ELF_AUX_ENTRIES to avoid overrun...



details:   https://anonhg.NetBSD.org/src/rev/814f407ec302
branches:  trunk
changeset: 326879:814f407ec302
user:      maxv <maxv%NetBSD.org@localhost>
date:      Fri Feb 21 07:53:53 2014 +0000

description:
Increase LINUX32_ELF_AUX_ENTRIES to avoid overrun in linux32/. Also,
add comments and KASSERTs to make sure people don't forget to increase
XX_AUX_ENTRIES's when adding vectors.

Reported by martin@ (CV), with suggestions from chs@.

ok martin@ chs@

diffstat:

 sys/compat/linux/arch/amd64/linux_exec_machdep.c |  13 ++++---------
 sys/compat/linux/common/linux_exec.h             |   3 ++-
 sys/compat/linux/common/linux_exec_elf32.c       |   5 +++--
 sys/compat/linux32/arch/amd64/linux32_exec.h     |   5 +++--
 sys/compat/linux32/common/linux32_exec_elf32.c   |   7 +++++--
 5 files changed, 17 insertions(+), 16 deletions(-)

diffs (131 lines):

diff -r d8e75f488e1e -r 814f407ec302 sys/compat/linux/arch/amd64/linux_exec_machdep.c
--- a/sys/compat/linux/arch/amd64/linux_exec_machdep.c  Fri Feb 21 07:47:02 2014 +0000
+++ b/sys/compat/linux/arch/amd64/linux_exec_machdep.c  Fri Feb 21 07:53:53 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: linux_exec_machdep.c,v 1.20 2013/11/18 01:32:22 chs Exp $ */
+/*     $NetBSD: linux_exec_machdep.c,v 1.21 2014/02/21 07:53:53 maxv Exp $ */
 
 /*-
  * Copyright (c) 2005 Emmanuel Dreyfus, all rights reserved
@@ -32,7 +32,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: linux_exec_machdep.c,v 1.20 2013/11/18 01:32:22 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_exec_machdep.c,v 1.21 2014/02/21 07:53:53 maxv Exp $");
 
 #define ELFSIZE 64
 
@@ -233,13 +233,8 @@
        esd.ai[i].a_type = AT_NULL;
        esd.ai[i++].a_v = 0;
 
-#ifdef DEBUG_LINUX
-       if (i != LINUX_ELF_AUX_ENTRIES) {
-               printf("linux_elf64_copyargs: %d Aux entries\n", i);
-               return EINVAL;
-       }
-#endif
-               
+       KASSERT(i == LINUX_ELF_AUX_ENTRIES);
+
        strcpy(esd.hw_platform, LINUX_PLATFORM); 
 
        exec_free_emul_arg(pack);
diff -r d8e75f488e1e -r 814f407ec302 sys/compat/linux/common/linux_exec.h
--- a/sys/compat/linux/common/linux_exec.h      Fri Feb 21 07:47:02 2014 +0000
+++ b/sys/compat/linux/common/linux_exec.h      Fri Feb 21 07:53:53 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: linux_exec.h,v 1.50 2014/02/09 16:41:42 chs Exp $      */
+/*     $NetBSD: linux_exec.h,v 1.51 2014/02/21 07:53:53 maxv Exp $     */
 
 /*-
  * Copyright (c) 1995, 1998 The NetBSD Foundation, Inc.
@@ -82,6 +82,7 @@
 #define LINUX_N_BSSADDR(x,m) (LINUX_N_DATADDR(x,m) + (x).a_data)
 
 #ifndef LINUX_MACHDEP_ELF_COPYARGS
+/* Counted from linux_exec_elf32.c */
 #define LINUX_ELF_AUX_ENTRIES  14
 #endif
 
diff -r d8e75f488e1e -r 814f407ec302 sys/compat/linux/common/linux_exec_elf32.c
--- a/sys/compat/linux/common/linux_exec_elf32.c        Fri Feb 21 07:47:02 2014 +0000
+++ b/sys/compat/linux/common/linux_exec_elf32.c        Fri Feb 21 07:53:53 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: linux_exec_elf32.c,v 1.88 2014/02/09 16:41:42 chs Exp $        */
+/*     $NetBSD: linux_exec_elf32.c,v 1.89 2014/02/21 07:53:53 maxv Exp $       */
 
 /*-
  * Copyright (c) 1995, 1998, 2000, 2001 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: linux_exec_elf32.c,v 1.88 2014/02/09 16:41:42 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_exec_elf32.c,v 1.89 2014/02/21 07:53:53 maxv Exp $");
 
 #ifndef ELFSIZE
 /* XXX should die */
@@ -495,6 +495,7 @@
        *stackp += len;
 
        len = (a - ai) * sizeof(AuxInfo);
+       KASSERT(len <= LINUX_ELF_AUX_ENTRIES);
        if ((error = copyout(ai, *stackp, len)) != 0)
                return error;
        *stackp += len;
diff -r d8e75f488e1e -r 814f407ec302 sys/compat/linux32/arch/amd64/linux32_exec.h
--- a/sys/compat/linux32/arch/amd64/linux32_exec.h      Fri Feb 21 07:47:02 2014 +0000
+++ b/sys/compat/linux32/arch/amd64/linux32_exec.h      Fri Feb 21 07:53:53 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: linux32_exec.h,v 1.5 2014/02/09 16:41:42 chs Exp $ */
+/*     $NetBSD: linux32_exec.h,v 1.6 2014/02/21 07:53:53 maxv Exp $ */
 
 /*-
  * Copyright (c) 2006 Emmanuel Dreyfus, all rights reserved.
@@ -41,7 +41,8 @@
 
 #define LINUX32_DEBUGLINK_SIGNATURE    1
 
-#define LINUX32_ELF_AUX_ENTRIES 14
+/* Counted from common/linux32_exec_elf32.c */
+#define LINUX32_ELF_AUX_ENTRIES 15
 
 #define LINUX32_RANDOM_BYTES 16                /* 16 bytes for AT_RANDOM */
 
diff -r d8e75f488e1e -r 814f407ec302 sys/compat/linux32/common/linux32_exec_elf32.c
--- a/sys/compat/linux32/common/linux32_exec_elf32.c    Fri Feb 21 07:47:02 2014 +0000
+++ b/sys/compat/linux32/common/linux32_exec_elf32.c    Fri Feb 21 07:53:53 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: linux32_exec_elf32.c,v 1.14 2014/02/09 16:41:42 chs Exp $ */
+/*     $NetBSD: linux32_exec_elf32.c,v 1.15 2014/02/21 07:53:53 maxv Exp $ */
 
 /*-                     
  * Copyright (c) 1995, 1998, 2000, 2001,2006 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: linux32_exec_elf32.c,v 1.14 2014/02/09 16:41:42 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux32_exec_elf32.c,v 1.15 2014/02/21 07:53:53 maxv Exp $");
 
 #define        ELFSIZE         32
 
@@ -191,6 +191,8 @@
        a++;
 
 #if 0
+       /* XXX: increase LINUX32_ELF_AUX_ENTRIES if we enable those things */
+
        a->a_type = LINUX_AT_SYSINFO;
        a->a_v = NETBSD32PTR32I(&esdp->kernel_vsyscall[0]);
        a++;
@@ -239,6 +241,7 @@
 #endif
 
        len = (a - ai) * sizeof(AuxInfo);
+       KASSERT(len <= LINUX32_ELF_AUX_ENTRIES);
        if ((error = copyout(ai, *stackp, len)) != 0)
                return error;
        *stackp += len;



Home | Main Index | Thread Index | Old Index