[module] check vmf->pgoff before using it

As reported by @Crispy-fried-chicken in issue  there is a potential
XXE vulnerability here. This fixes this problem by verifying the value
of `vmf->pgff` does not exceed the bounds of the memory mapping.

Fixes: 
This commit is contained in:
Geoffrey McRae 2024-08-26 14:37:21 +10:00
parent d060e375ea
commit 3ea37b86e3
2 changed files with 6 additions and 2 deletions

@ -1,5 +1,5 @@
PACKAGE_NAME="kvmfr"
PACKAGE_VERSION="0.0.10"
PACKAGE_VERSION="0.0.11"
BUILT_MODULE_NAME[0]="${PACKAGE_NAME}"
MAKE[0]="make KDIR=${kernel_source_dir}"
CLEAN="make KDIR=${kernel_source_dir} clean"

@ -88,8 +88,12 @@ static vm_fault_t kvmfr_vm_fault(struct vm_fault *vmf)
{
struct vm_area_struct *vma = vmf->vma;
struct kvmfrbuf *kbuf = (struct kvmfrbuf *)vma->vm_private_data;
pgoff_t pgoff = vmf->pgoff;
vmf->page = kbuf->pages[vmf->pgoff];
if (pgoff >= kbuf->pagecount)
return VM_FAULT_SIGBUS;
vmf->page = kbuf->pages[pgoff];
get_page(vmf->page);
return 0;
}