Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/amd64/amd64 If the preloaded modules cannot be mapp...



details:   https://anonhg.NetBSD.org/src/rev/2494df9287d8
branches:  trunk
changeset: 351320:2494df9287d8
user:      maxv <maxv%NetBSD.org@localhost>
date:      Thu Feb 09 19:30:56 2017 +0000

description:
If the preloaded modules cannot be mapped with the initial amount of VA,
discard the associated bootinfo entry. Otherwise the machine faults and
reboots immediately.

I spotted this bug more than a year ago, but I recently saw that there is
already PR/42645 (7 years old), so just fix it. The size has been increased
in the meantime, so the limit is unlikely to be reached anyway.

diffstat:

 sys/arch/amd64/amd64/locore.S |  35 +++++++++++++++++++++++++----------
 1 files changed, 25 insertions(+), 10 deletions(-)

diffs (86 lines):

diff -r 6cb02afc11b7 -r 2494df9287d8 sys/arch/amd64/amd64/locore.S
--- a/sys/arch/amd64/amd64/locore.S     Thu Feb 09 18:15:07 2017 +0000
+++ b/sys/arch/amd64/amd64/locore.S     Thu Feb 09 19:30:56 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: locore.S,v 1.120 2017/02/09 08:23:46 maxv Exp $        */
+/*     $NetBSD: locore.S,v 1.121 2017/02/09 19:30:56 maxv Exp $        */
 
 /*
  * Copyright-o-rama!
@@ -211,6 +211,10 @@
   ((NKL4_KIMG_ENTRIES + TABLE_L3_ENTRIES + TABLE_L2_ENTRIES + 1 + UPAGES) \
     * PAGE_SIZE)
 
+/* Amount of VA used to map the kernel, the syms and the preloaded modules */
+#define BOOTMAP_VA_SIZE \
+       (NKL2_KIMG_ENTRIES * (1 << L2_SHIFT) - TABLESIZE - IOM_SIZE)
+
 /*
  * fillkpt - Fill in a kernel page table
  *     eax = pte (page frame | control | status)
@@ -443,7 +447,7 @@
        testl   %eax,%eax               /* bootinfo = NULL? */
        jz      bootinfo_finished
 
-       movl    (%eax),%ebx             /* number of entries */
+       movl    (%eax),%ebx             /* bootinfo::bi_nentries */
        movl    $RELOC(bootinfo),%ebp
        movl    %ebp,%edx
        addl    $BOOTINFO_MAXSIZE,%ebp
@@ -462,7 +466,7 @@
 
        movl    (%ecx),%eax             /* btinfo_common::len (size of entry) */
        movl    %edx,%edi
-       addl    (%ecx),%edx             /* update dest pointer */
+       addl    %eax,%edx               /* update dest pointer */
        cmpl    %ebp,%edx               /* beyond bootinfo+BOOTINFO_MAXSIZE? */
        jg      bootinfo_overflow
 
@@ -470,20 +474,31 @@
        movl    %eax,%ecx
 
        /*
-        * If any modules were loaded, record where they end.  We'll need to
-        * skip over them.
+        * If any modules were loaded, record where they end. 'eblob' is used
+        * later to compute the initial bootstrap tables.
         */
        cmpl    $BTINFO_MODULELIST,4(%esi) /* btinfo_common::type */
-       jne     0f
+       jne     bootinfo_copy
 
-       pushl   12(%esi)                /* btinfo_modulelist::endpa */
-       popl    RELOC(eblob)
+       /* Skip the modules if we won't have enough VA to map them */
+       movl    12(%esi),%eax           /* btinfo_modulelist::endpa */
+       addl    $PGOFSET,%eax           /* roundup to a page */
+       andl    $~PGOFSET,%eax
+       cmpl    $BOOTMAP_VA_SIZE,%eax
+       jg      bootinfo_skip
+       movl    %eax,RELOC(eblob)
        addl    $KERNBASE_LO,RELOC(eblob)
        adcl    $KERNBASE_HI,RELOC(eblob)+4
 
-0:
+bootinfo_copy:
        rep
        movsb                           /* copy esi -> edi */
+       jmp     bootinfo_next
+
+bootinfo_skip:
+       subl    %ecx,%edx               /* revert dest pointer */
+
+bootinfo_next:
        popl    %eax
        popl    %esi
        popl    %edi
@@ -501,8 +516,8 @@
        movl    $RELOC(bootinfo),%ebp
        movl    %ebp,%edx
        subl    %ebx,(%edx)             /* correct the number of entries */
+bootinfo_finished:
 
-bootinfo_finished:
        /* Load 'esym' */
        movl    16(%esp),%eax
        testl   %eax,%eax               /* esym = NULL? */



Home | Main Index | Thread Index | Old Index