Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/aarch64/aarch64 avoid integer overflow when calcula...



details:   https://anonhg.NetBSD.org/src/rev/73538e978bb3
branches:  trunk
changeset: 837943:73538e978bb3
user:      mrg <mrg%NetBSD.org@localhost>
date:      Thu Dec 27 21:29:41 2018 +0000

description:
avoid integer overflow when calculating the end address of a ram
block.  fixes a bug when a PhysMem range covers more than 4GB.

with this, my OD1K (8GB ram) is almost able to properly coredump.
savecore finds the core, but can't read it properly.

diffstat:

 sys/arch/aarch64/aarch64/aarch64_machdep.c |  20 ++++++++++----------
 1 files changed, 10 insertions(+), 10 deletions(-)

diffs (58 lines):

diff -r 4880eb5984fc -r 73538e978bb3 sys/arch/aarch64/aarch64/aarch64_machdep.c
--- a/sys/arch/aarch64/aarch64/aarch64_machdep.c        Thu Dec 27 21:25:46 2018 +0000
+++ b/sys/arch/aarch64/aarch64/aarch64_machdep.c        Thu Dec 27 21:29:41 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: aarch64_machdep.c,v 1.24 2018/12/27 09:55:27 mrg Exp $ */
+/* $NetBSD: aarch64_machdep.c,v 1.25 2018/12/27 21:29:41 mrg Exp $ */
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(1, "$NetBSD: aarch64_machdep.c,v 1.24 2018/12/27 09:55:27 mrg Exp $");
+__KERNEL_RCSID(1, "$NetBSD: aarch64_machdep.c,v 1.25 2018/12/27 21:29:41 mrg Exp $");
 
 #include "opt_arm_debug.h"
 #include "opt_ddb.h"
@@ -586,7 +586,7 @@
        daddr_t blkno;
        int psize;
        int error;
-       paddr_t addr = 0;
+       paddr_t addr = 0, end;
        int block;
        psize_t len;
        vaddr_t dumpspace;
@@ -624,15 +624,15 @@
 
        blkno = dumplo + cpu_dumpsize();
        error = 0;
-       len = 0;
+       len = dumpsize;
 
        for (block = 0; block < bootconfig.dramblocks && error == 0; ++block) {
                addr = bootconfig.dram[block].address;
-               for (; addr < (bootconfig.dram[block].address
-                              + (bootconfig.dram[block].pages * PAGE_SIZE));
-                    addr += PAGE_SIZE) {
-                       if ((len % (1024*1024)) == 0)
-                               printf("%lu ", len / (1024*1024));
+               end = bootconfig.dram[block].address +
+                     ((uint64_t)bootconfig.dram[block].pages * PAGE_SIZE);
+               for (; addr < end; addr += PAGE_SIZE) {
+                       if (((len * PAGE_SIZE) % (1024*1024)) == 0)
+                               printf("%lu ", (len * PAGE_SIZE) / (1024 * 1024));
 
                        if (!mm_md_direct_mapped_phys(addr, &dumpspace)) {
                                error = ENOMEM;
@@ -644,7 +644,7 @@
                        if (error)
                                goto err;
                        blkno += btodb(PAGE_SIZE);
-                       len += PAGE_SIZE;
+                       len--;
                }
        }
 err:



Home | Main Index | Thread Index | Old Index