map entire buffer to read procfs
Reading data from procfs file more than 4096 byte caused a buffer overrun in McKernel because the buffer was always mapped in McKernel 4096 byte regardless of actual buffer size.
This commit is contained in:
@ -252,6 +252,7 @@ void process_procfs_request(unsigned long rarg)
|
|||||||
unsigned long irqstate;
|
unsigned long irqstate;
|
||||||
unsigned long offset;
|
unsigned long offset;
|
||||||
int count;
|
int count;
|
||||||
|
int npages;
|
||||||
|
|
||||||
dprintf("process_procfs_request: invoked.\n");
|
dprintf("process_procfs_request: invoked.\n");
|
||||||
|
|
||||||
@ -271,7 +272,9 @@ void process_procfs_request(unsigned long rarg)
|
|||||||
dprintf("remote pbuf: %x\n", r->pbuf);
|
dprintf("remote pbuf: %x\n", r->pbuf);
|
||||||
pbuf = ihk_mc_map_memory(NULL, r->pbuf, r->count);
|
pbuf = ihk_mc_map_memory(NULL, r->pbuf, r->count);
|
||||||
dprintf("pbuf: %x\n", pbuf);
|
dprintf("pbuf: %x\n", pbuf);
|
||||||
buf = ihk_mc_map_virtual(pbuf, 1, PTATTR_WRITABLE | PTATTR_ACTIVE);
|
count = r->count + ((uintptr_t)pbuf & (PAGE_SIZE - 1));
|
||||||
|
npages = (count + (PAGE_SIZE - 1)) / PAGE_SIZE;
|
||||||
|
buf = ihk_mc_map_virtual(pbuf, npages, PTATTR_WRITABLE | PTATTR_ACTIVE);
|
||||||
dprintf("buf: %p\n", buf);
|
dprintf("buf: %p\n", buf);
|
||||||
if (buf == NULL) {
|
if (buf == NULL) {
|
||||||
kprintf("ERROR: process_procfs_request: got a null buffer.\n");
|
kprintf("ERROR: process_procfs_request: got a null buffer.\n");
|
||||||
@ -630,7 +633,7 @@ void process_procfs_request(unsigned long rarg)
|
|||||||
*/
|
*/
|
||||||
dprintf("could not find a matching entry for %s.\n", p);
|
dprintf("could not find a matching entry for %s.\n", p);
|
||||||
end:
|
end:
|
||||||
ihk_mc_unmap_virtual(buf, 1, 0);
|
ihk_mc_unmap_virtual(buf, npages, 0);
|
||||||
dprintf("ret: %d, eof: %d\n", ans, eof);
|
dprintf("ret: %d, eof: %d\n", ans, eof);
|
||||||
r->ret = ans;
|
r->ret = ans;
|
||||||
r->eof = eof;
|
r->eof = eof;
|
||||||
|
|||||||
Reference in New Issue
Block a user