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.front
parent
43212f6432
commit
6b146c70c2
|
@ -708,6 +708,10 @@ procread(Chan *c, void *va, long n, vlong off)
|
|||
Waitq *wq;
|
||||
|
||||
a = va;
|
||||
|
||||
/* sign extend 63 bit to 64 bit */
|
||||
off <<= 1;
|
||||
off >>= 1;
|
||||
offset = off;
|
||||
|
||||
if(c->qid.type & QTDIR)
|
||||
|
|
|
@ -263,7 +263,17 @@ reloc(Map *map, uvlong addr, vlong *offp)
|
|||
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];
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue