From af2f22807f975293bb55511b4e9ba416866fbb7a Mon Sep 17 00:00:00 2001 From: Bruce Evans Date: Thu, 20 Nov 1997 18:09:36 +0000 Subject: [PATCH] Fixed write enabling of the kernel text section. The overlap checking was mostly wrong at the boundaries. For the lower limit, VM_MIN_KERNEL_ADDRESS was used instead of btext and there was an off-by-(`size' - 1) error. For the upper limit, &etext was used instead of etext and there was an off-by-1 error. The bugs were harmless because `size' is not too large and some memory is mapped just beyond the ends. We still depend on the former to avoid having to handle the case where the memory range covers the whole text section, and on the latter to prevent problems when we map just beyond an end to allow writing an address range that overlaps the end. Fixed placement of a nearby comment. --- sys/amd64/amd64/db_interface.c | 12 +++++------- sys/i386/i386/db_interface.c | 12 +++++------- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/sys/amd64/amd64/db_interface.c b/sys/amd64/amd64/db_interface.c index b05285ad6c0..513c97edcd0 100644 --- a/sys/amd64/amd64/db_interface.c +++ b/sys/amd64/amd64/db_interface.c @@ -23,7 +23,7 @@ * any improvements or extensions that they make and grant Carnegie the * rights to redistribute these changes. * - * $Id: db_interface.c,v 1.36 1997/08/07 05:15:46 dyson Exp $ + * $Id: db_interface.c,v 1.37 1997/10/27 17:23:12 bde Exp $ */ /* @@ -41,7 +41,6 @@ #endif #include -#include #include #include @@ -247,17 +246,16 @@ db_write_bytes(addr, size, data) db_nofault = &db_jmpbuf; - if (addr >= VM_MIN_KERNEL_ADDRESS && - addr <= round_page((vm_offset_t)&etext)) { + if (addr > trunc_page((vm_offset_t)btext) - size && + addr < round_page((vm_offset_t)etext)) { ptep0 = pmap_pte(kernel_pmap, addr); oldmap0 = *ptep0; *ptep0 |= PG_RW; + + /* Map another page if the data crosses a page boundary. */ if ((*ptep0 & PG_PS) == 0) { - addr1 = trunc_page(addr + size - 1); - - /* Map another page if the data crosses a page boundary. */ if (trunc_page(addr) != addr1) { ptep1 = pmap_pte(kernel_pmap, addr1); oldmap1 = *ptep1; diff --git a/sys/i386/i386/db_interface.c b/sys/i386/i386/db_interface.c index b05285ad6c0..513c97edcd0 100644 --- a/sys/i386/i386/db_interface.c +++ b/sys/i386/i386/db_interface.c @@ -23,7 +23,7 @@ * any improvements or extensions that they make and grant Carnegie the * rights to redistribute these changes. * - * $Id: db_interface.c,v 1.36 1997/08/07 05:15:46 dyson Exp $ + * $Id: db_interface.c,v 1.37 1997/10/27 17:23:12 bde Exp $ */ /* @@ -41,7 +41,6 @@ #endif #include -#include #include #include @@ -247,17 +246,16 @@ db_write_bytes(addr, size, data) db_nofault = &db_jmpbuf; - if (addr >= VM_MIN_KERNEL_ADDRESS && - addr <= round_page((vm_offset_t)&etext)) { + if (addr > trunc_page((vm_offset_t)btext) - size && + addr < round_page((vm_offset_t)etext)) { ptep0 = pmap_pte(kernel_pmap, addr); oldmap0 = *ptep0; *ptep0 |= PG_RW; + + /* Map another page if the data crosses a page boundary. */ if ((*ptep0 & PG_PS) == 0) { - addr1 = trunc_page(addr + size - 1); - - /* Map another page if the data crosses a page boundary. */ if (trunc_page(addr) != addr1) { ptep1 = pmap_pte(kernel_pmap, addr1); oldmap1 = *ptep1;