fix major validation
fileread/filewrite should validate major to avoid buffer overflows or bogus function pointers.
This commit is contained in:
parent
37df68e5de
commit
9ead904afe
|
@ -114,6 +114,8 @@ fileread(struct file *f, uint64 addr, int n)
|
||||||
if(f->type == FD_PIPE){
|
if(f->type == FD_PIPE){
|
||||||
r = piperead(f->pipe, addr, n);
|
r = piperead(f->pipe, addr, n);
|
||||||
} else if(f->type == FD_DEVICE){
|
} else if(f->type == FD_DEVICE){
|
||||||
|
if(f->major < 0 || f->major >= NDEV || !devsw[f->major].read)
|
||||||
|
return -1;
|
||||||
r = devsw[f->major].read(1, addr, n);
|
r = devsw[f->major].read(1, addr, n);
|
||||||
} else if(f->type == FD_INODE){
|
} else if(f->type == FD_INODE){
|
||||||
ilock(f->ip);
|
ilock(f->ip);
|
||||||
|
@ -140,6 +142,8 @@ filewrite(struct file *f, uint64 addr, int n)
|
||||||
if(f->type == FD_PIPE){
|
if(f->type == FD_PIPE){
|
||||||
ret = pipewrite(f->pipe, addr, n);
|
ret = pipewrite(f->pipe, addr, n);
|
||||||
} else if(f->type == FD_DEVICE){
|
} else if(f->type == FD_DEVICE){
|
||||||
|
if(f->major < 0 || f->major >= NDEV || !devsw[f->major].write)
|
||||||
|
return -1;
|
||||||
ret = devsw[f->major].write(1, addr, n);
|
ret = devsw[f->major].write(1, addr, n);
|
||||||
} else if(f->type == FD_INODE){
|
} else if(f->type == FD_INODE){
|
||||||
// write a few blocks at a time to avoid exceeding
|
// write a few blocks at a time to avoid exceeding
|
||||||
|
|
Loading…
Reference in a new issue