Commit 677da9b2 authored by Pete Zaitcev's avatar Pete Zaitcev Committed by Kleber Sacilotto de Souza

USB: fix usbmon BUG trigger

BugLink: http://bugs.launchpad.net/bugs/1745266

commit 46eb14a6 upstream.

Automated tests triggered this by opening usbmon and accessing the
mmap while simultaneously resizing the buffers. This bug was with
us since 2006, because typically applications only size the buffers
once and thus avoid racing. Reported by Kirill A. Shutemov.

Reported-by: <syzbot+f9831b881b3e849829fc@syzkaller.appspotmail.com>
Signed-off-by: default avatarPete Zaitcev <zaitcev@redhat.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: default avatarKhalid Elmously <khalid.elmously@canonical.com>
Signed-off-by: default avatarStefan Bader <stefan.bader@canonical.com>
parent 761a088c
...@@ -1001,7 +1001,9 @@ static long mon_bin_ioctl(struct file *file, unsigned int cmd, unsigned long arg ...@@ -1001,7 +1001,9 @@ static long mon_bin_ioctl(struct file *file, unsigned int cmd, unsigned long arg
break; break;
case MON_IOCQ_RING_SIZE: case MON_IOCQ_RING_SIZE:
mutex_lock(&rp->fetch_lock);
ret = rp->b_size; ret = rp->b_size;
mutex_unlock(&rp->fetch_lock);
break; break;
case MON_IOCT_RING_SIZE: case MON_IOCT_RING_SIZE:
...@@ -1228,12 +1230,16 @@ static int mon_bin_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf) ...@@ -1228,12 +1230,16 @@ static int mon_bin_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
unsigned long offset, chunk_idx; unsigned long offset, chunk_idx;
struct page *pageptr; struct page *pageptr;
mutex_lock(&rp->fetch_lock);
offset = vmf->pgoff << PAGE_SHIFT; offset = vmf->pgoff << PAGE_SHIFT;
if (offset >= rp->b_size) if (offset >= rp->b_size) {
mutex_unlock(&rp->fetch_lock);
return VM_FAULT_SIGBUS; return VM_FAULT_SIGBUS;
}
chunk_idx = offset / CHUNK_SIZE; chunk_idx = offset / CHUNK_SIZE;
pageptr = rp->b_vec[chunk_idx].pg; pageptr = rp->b_vec[chunk_idx].pg;
get_page(pageptr); get_page(pageptr);
mutex_unlock(&rp->fetch_lock);
vmf->page = pageptr; vmf->page = pageptr;
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment