Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754233AbcL0LWu (ORCPT ); Tue, 27 Dec 2016 06:22:50 -0500 Received: from mga04.intel.com ([192.55.52.120]:60589 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753688AbcL0LWl (ORCPT ); Tue, 27 Dec 2016 06:22:41 -0500 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.33,416,1477983600"; d="asc'?scan'208";a="802640446" From: Felipe Balbi To: Alan Stern , Andrey Konovalov Cc: Greg Kroah-Hartman , Al Viro , Marek Szyprowski , David Sterba , Ryusuke Konishi , David Eccher , Bin Liu , Mathieu Laurendeau , Binyamin Sharet , "Kirill A. Shutemov" , linux-usb@vger.kernel.org, LKML , Dmitry Vyukov , Kostya Serebryany , syzkaller Subject: Re: net/gadget: slab-out-of-bounds write in dev_config In-Reply-To: References: Date: Tue, 27 Dec 2016 13:21:02 +0200 Message-ID: <87o9zx1uu9.fsf@linux.intel.com> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 4750 Lines: 113 --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable Hi, Alan Stern writes: > On Tue, 6 Dec 2016, Andrey Konovalov wrote: > >> Hi! >>=20 >> I've got the following error report while running the syzkaller fuzzer. >>=20 >> ep0_write() doesn't check the length, so a user can cause an >> out-of-bounds with both size and data controlled. >> There's a comment which says "IN DATA+STATUS caller makes len <=3D >> wLength". While I'm not exactly sure what that means, the length seems >> to be passed unmodified directly from dev_config(). > > You're right about the comment being misleading. It looks like=20 > somebody forgot to actually do the check. > >> This doesn't seem to be a critical security issue since gadgetfs can't >> be mounted from a user namespace. >>=20 >> On commit 3c49de52d5647cda8b42c4255cf8a29d1e22eff5 (Dec 2). >>=20 >> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D >> BUG: KASAN: slab-out-of-bounds in dev_config+0x86f/0x1190 at addr >> ffff88003c47e160 >> Write of size 65537 by task syz-executor0/6356 >> CPU: 3 PID: 6356 Comm: syz-executor0 Not tainted 4.9.0-rc7+ #19 >> Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS Bochs 01/01/= 2011 >> ffff88003c107ad8 ffffffff81f96aba ffffffff3dc11ef0 1ffff10007820eee >> ffffed0007820ee6 ffff88003dc11f00 0000000041b58ab3 ffffffff8598b4c8 >> ffffffff81f96828 ffffffff813fb4a0 ffff88003b6eadc0 ffff88003c107738 >> Call Trace: >> [< inline >] __dump_stack lib/dump_stack.c:15 >> [] dump_stack+0x292/0x398 lib/dump_stack.c:51 >> [] kasan_object_err+0x1c/0x70 mm/kasan/report.c:159 >> [< inline >] print_address_description mm/kasan/report.c:197 >> [] kasan_report_error+0x1f0/0x4e0 mm/kasan/report.c:2= 86 >> [] kasan_report+0x35/0x40 mm/kasan/report.c:306 >> [< inline >] check_memory_region_inline mm/kasan/kasan.c:308 >> [] check_memory_region+0x139/0x190 mm/kasan/kasan.c:3= 15 >> [] kasan_check_write+0x14/0x20 mm/kasan/kasan.c:326 >> [< inline >] copy_from_user arch/x86/include/asm/uaccess.h:689 >> [< inline >] ep0_write drivers/usb/gadget/legacy/inode.c:1135 >> [] dev_config+0x86f/0x1190 >> drivers/usb/gadget/legacy/inode.c:1759 >> [] __vfs_write+0x5d5/0x760 fs/read_write.c:510 >> [] vfs_write+0x170/0x4e0 fs/read_write.c:560 >> [< inline >] SYSC_write fs/read_write.c:607 >> [] SyS_write+0xfb/0x230 fs/read_write.c:599 >> [] entry_SYSCALL_64_fastpath+0x1f/0xc2 > > How does this patch work out? > > Alan Stern > > > > Index: usb-4.x/drivers/usb/gadget/legacy/inode.c > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > --- usb-4.x.orig/drivers/usb/gadget/legacy/inode.c > +++ usb-4.x/drivers/usb/gadget/legacy/inode.c > @@ -1126,7 +1126,7 @@ ep0_write (struct file *fd, const char _ > /* data and/or status stage for control request */ > } else if (dev->state =3D=3D STATE_DEV_SETUP) { >=20=20 > - /* IN DATA+STATUS caller makes len <=3D wLength */ > + len =3D min(len, (size_t) dev->setup_wLength); > if (dev->setup_in) { > retval =3D setup_req (dev->gadget->ep0, dev->req, len); > if (retval =3D=3D 0) { > I already have a patch from Greg for this. See [1] [1] https://git.kernel.org/cgit/linux/kernel/git/balbi/usb.git/commit/?id= =3D230bc0cb8ff222d9f0fbbd93a80393140b39481f =2D-=20 balbi --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEElLzh7wn96CXwjh2IzL64meEamQYFAlhiTp4ACgkQzL64meEa mQarQA/8Ck5vr08naCbUQYKwVa8ZBm7U0MwdTab89W+U0JJXJadj5n06SE8M0huy BarwDyjYCtvfXzx7krmpAUAZAdn9WqSp7tVTIJUYHJZYmEbj+P3nuAz+HXV7Qmlo IWAB1PQT9v7LxYsWNtUk3C/zr1pXFi6OTC9hfpJ5C6Rcq6Z1ymAKMX7JtuSyr6o2 DA/vbn0WRXySBSd2uAFYu+Vw9i5C45K9VIpQlgiOPECdDCbk7ZW9weKJHrRtT1NY 8QVoq0AoO0S5TT0pgY8bqiElg1/VfDyeG7tScHK410jZ+2IJDP0FqcKxup9MTkhA IEzzNDKH8yek8wZFLfGRRPqexhLb4vdFAe23AqwKUNshX17eFW2mN0veMRYzL+BK d/kymjLlC1bfTDAPVTxomLqSKWL3AgiPr0tbTpJ4zAkLfDtXViGEkFnUMDdn/gGZ Tcm5x04R5cjOWj/qn9e2kCZxnUgZl5R6el+3RXynUKOzcg0wwfzKx18REnq/i0ln 7ZGCHwl9EL7gFMllIYkwq2JIVzYYZH9QtDAfIGXgXb1cSe+/yZJO9+zLo15i53WF tl0wC2wWUQUlTTBuQZ21Fybc5q8Vrsdw2fBF3aME3fzOIxN+g/AzXk3C2BaD/AxD yQYQ60fDCdP7uQaSUuQHB+jP4/3a5Nf0RZj8EAhn+3q7w/y2xqQ= =E9X/ -----END PGP SIGNATURE----- --=-=-=--