ref: 245d28ffe3e5d784b241b1f61adc9ab2f05cdf66
parent: e647914fba834ffb990607e7b232c240cba1399d
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Fri Feb 7 22:50:41 EST 2014
pc64: handle negative file offsets when accessing kernel memory with devproc file offset is 64 bit signed integer, negative offsets are invalid and rejected by the kernel. to still access kernel memory on amd64, we unconditionally clear the sign bit of the 64 bit offset in libmach and devproc sign extends the offset back to a 64 bit address.
--- a/sys/src/9/port/devproc.c
+++ b/sys/src/9/port/devproc.c
@@ -708,6 +708,10 @@
Waitq *wq;
a = va;
+
+ /* sign extend 63 bit to 64 bit */
+ off <<= 1;
+ off >>= 1;
offset = off;
if(c->qid.type & QTDIR)
--- a/sys/src/libmach/access.c
+++ b/sys/src/libmach/access.c
@@ -263,7 +263,17 @@
for (i = 0; i < map->nsegs; i++) {if (map->seg[i].inuse)
if (map->seg[i].b <= addr && addr < map->seg[i].e) {- *offp = addr + map->seg[i].f - map->seg[i].b;
+ addr += map->seg[i].f - map->seg[i].b;
+
+ /*
+ * avoid negative file offsets for kernel
+ * addresses by clearing the sign bit.
+ * devproc sign extends back to 64 bit.
+ */
+ addr <<= 1;
+ addr >>= 1;
+
+ *offp = addr;
return &map->seg[i];
}
}
--
⑨