Return-Path: Received: from mail-co1nam03on0121.outbound.protection.outlook.com ([104.47.40.121]:17856 "EHLO NAM03-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1032183AbeCAP3l (ORCPT ); Thu, 1 Mar 2018 10:29:41 -0500 From: Sasha Levin To: "stable@vger.kernel.org" , "stable-commits@vger.kernel.org" CC: Pete Zaitcev , Greg Kroah-Hartman , Sasha Levin Subject: [added to the 4.1 stable tree] USB: fix usbmon BUG trigger Date: Thu, 1 Mar 2018 15:24:09 +0000 Message-ID: <20180301152116.1486-163-alexander.levin@microsoft.com> References: <20180301152116.1486-1-alexander.levin@microsoft.com> In-Reply-To: <20180301152116.1486-1-alexander.levin@microsoft.com> Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org List-ID: From: Pete Zaitcev This patch has been added to the 4.1 stable tree. If you have any objections, please let us know. =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D [ Upstream commit 46eb14a6e1585d99c1b9f58d0e7389082a5f466b ] 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: Signed-off-by: Pete Zaitcev Cc: stable Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/usb/mon/mon_bin.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/usb/mon/mon_bin.c b/drivers/usb/mon/mon_bin.c index 9a62e89d6dc0..bbec84dd34fb 100644 --- a/drivers/usb/mon/mon_bin.c +++ b/drivers/usb/mon/mon_bin.c @@ -1000,7 +1000,9 @@ static long mon_bin_ioctl(struct file *file, unsigned= int cmd, unsigned long arg break; =20 case MON_IOCQ_RING_SIZE: + mutex_lock(&rp->fetch_lock); ret =3D rp->b_size; + mutex_unlock(&rp->fetch_lock); break; =20 case MON_IOCT_RING_SIZE: @@ -1227,12 +1229,16 @@ static int mon_bin_vma_fault(struct vm_area_struct = *vma, struct vm_fault *vmf) unsigned long offset, chunk_idx; struct page *pageptr; =20 + mutex_lock(&rp->fetch_lock); offset =3D vmf->pgoff << PAGE_SHIFT; - if (offset >=3D rp->b_size) + if (offset >=3D rp->b_size) { + mutex_unlock(&rp->fetch_lock); return VM_FAULT_SIGBUS; + } chunk_idx =3D offset / CHUNK_SIZE; pageptr =3D rp->b_vec[chunk_idx].pg; get_page(pageptr); + mutex_unlock(&rp->fetch_lock); vmf->page =3D pageptr; return 0; } --=20 2.14.1