fix major validation

fileread/filewrite should validate major to avoid buffer overflows
or bogus function pointers.
This commit is contained in:
Xi Wang 2019-09-19 10:31:04 -07:00 committed by Frans Kaashoek
parent 37df68e5de
commit 9ead904afe

View file

@ -114,6 +114,8 @@ fileread(struct file *f, uint64 addr, int n)
if(f->type == FD_PIPE){
r = piperead(f->pipe, addr, n);
} 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);
} else if(f->type == FD_INODE){
ilock(f->ip);
@ -140,6 +142,8 @@ filewrite(struct file *f, uint64 addr, int n)
if(f->type == FD_PIPE){
ret = pipewrite(f->pipe, addr, n);
} 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);
} else if(f->type == FD_INODE){
// write a few blocks at a time to avoid exceeding