Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp2905929ybk; Mon, 18 May 2020 10:47:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxL2om0793iC3BfGyl4/XgBuMdpDolUoR1PasQQ3xny17BQT9XYnDLaT/2dgqIKfoYz8OsK X-Received: by 2002:a50:cccc:: with SMTP id b12mr14180939edj.68.1589824065882; Mon, 18 May 2020 10:47:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589824065; cv=none; d=google.com; s=arc-20160816; b=P680elZinvklSTF24rwtmvuHY3zEbIvulpTS3nfbq0NRNZnE4A1Hd2PXIDXsBwrNer 7uS3cmQIYus14zH6Iq8E4xy/E6/0HEJFZN7HIYsUOiGoiDPvy1GftVITYOgR5QNZ/n31 97nChZQPIh3iiDQY9aopaW38F88X1VN63PC+j2UKMOwkgl+QjUnAHSXuzqi9VTwnutSO ODFh7zJoQV9sFUDPfD9SymcJTAV1/avXlEONkKfoC3Ox7HtOTSa2rX6EBLJCQr8Gyy/O VzPQjStu2lHTsKCNRD1JAqEgnscfL01fzodlcttwNi8BEFzF/VCisLZjt78DiYy/44H9 4ooA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=C55sZ4x+I+Yaxbh588jIkDmCHy1sQz4fB4HBO/QXiAM=; b=f4wun3qQZvfuc+7m+G+uh71Q3LefPvyOzGIGe/ZOyjRS3IY/kGoLwiBTjJ71K/cghs xj0f22SReD/sh25XvGaZDqC98HUM1JZC2pU3g32QXm8UnDnvWxbWmuELi8i2AWs93cjU ttbv+8SqkqGm/sHYjirSjmbqI/rT2Yphn3hR0JQ26rjTc6Nh/6Oaf4ro6DSXeWYa0WEp 05KBrcJ5Ad82r14+KTy2p8F3dNPjHuuWgMuF+v4mze7XDBXKD1qMbEU6V5BerHB/Iu7U b9B2y7jDz0ZpG+lZJy5QR7DqypajCcfMjulEAUA+FMumecTNyg3wvaDQyHLL7AFsIEIA H2ag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=r11vAlcp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k4si5650874edi.24.2020.05.18.10.47.23; Mon, 18 May 2020 10:47:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=r11vAlcp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729832AbgERRo7 (ORCPT + 99 others); Mon, 18 May 2020 13:44:59 -0400 Received: from mail.kernel.org ([198.145.29.99]:43316 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729803AbgERRot (ORCPT ); Mon, 18 May 2020 13:44:49 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id BEA842083E; Mon, 18 May 2020 17:44:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1589823888; bh=urpJaHN2EIxnumCX9RaMskzOc4V4jk6eMrt58IG4yMo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=r11vAlcpxpDYlORQrGasE5xY0aPvPMvQY4rNh3P7FUMuTl7PsUiLMgdQ1/m2VbJI6 5O0DVcoxNp1gYWygb5zYKH+qlepG3XV69cctWU+9Ifa2zGhEVNQurWQzOra1iO6PWm H3imyApIYPvWWBg4ncrlfVyNi3cS156tQ1l72EwA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kyungtae Kim , Felipe Balbi Subject: [PATCH 4.9 77/90] USB: gadget: fix illegal array access in binding with UDC Date: Mon, 18 May 2020 19:36:55 +0200 Message-Id: <20200518173506.941393298@linuxfoundation.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200518173450.930655662@linuxfoundation.org> References: <20200518173450.930655662@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Kyungtae Kim commit 15753588bcd4bbffae1cca33c8ced5722477fe1f upstream. FuzzUSB (a variant of syzkaller) found an illegal array access using an incorrect index while binding a gadget with UDC. Reference: https://www.spinics.net/lists/linux-usb/msg194331.html This bug occurs when a size variable used for a buffer is misused to access its strcpy-ed buffer. Given a buffer along with its size variable (taken from user input), from which, a new buffer is created using kstrdup(). Due to the original buffer containing 0 value in the middle, the size of the kstrdup-ed buffer becomes smaller than that of the original. So accessing the kstrdup-ed buffer with the same size variable triggers memory access violation. The fix makes sure no zero value in the buffer, by comparing the strlen() of the orignal buffer with the size variable, so that the access to the kstrdup-ed buffer is safe. BUG: KASAN: slab-out-of-bounds in gadget_dev_desc_UDC_store+0x1ba/0x200 drivers/usb/gadget/configfs.c:266 Read of size 1 at addr ffff88806a55dd7e by task syz-executor.0/17208 CPU: 2 PID: 17208 Comm: syz-executor.0 Not tainted 5.6.8 #1 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS Bochs 01/01/2011 Call Trace: __dump_stack lib/dump_stack.c:77 [inline] dump_stack+0xce/0x128 lib/dump_stack.c:118 print_address_description.constprop.4+0x21/0x3c0 mm/kasan/report.c:374 __kasan_report+0x131/0x1b0 mm/kasan/report.c:506 kasan_report+0x12/0x20 mm/kasan/common.c:641 __asan_report_load1_noabort+0x14/0x20 mm/kasan/generic_report.c:132 gadget_dev_desc_UDC_store+0x1ba/0x200 drivers/usb/gadget/configfs.c:266 flush_write_buffer fs/configfs/file.c:251 [inline] configfs_write_file+0x2f1/0x4c0 fs/configfs/file.c:283 __vfs_write+0x85/0x110 fs/read_write.c:494 vfs_write+0x1cd/0x510 fs/read_write.c:558 ksys_write+0x18a/0x220 fs/read_write.c:611 __do_sys_write fs/read_write.c:623 [inline] __se_sys_write fs/read_write.c:620 [inline] __x64_sys_write+0x73/0xb0 fs/read_write.c:620 do_syscall_64+0x9e/0x510 arch/x86/entry/common.c:294 entry_SYSCALL_64_after_hwframe+0x49/0xbe Signed-off-by: Kyungtae Kim Reported-and-tested-by: Kyungtae Kim Cc: Felipe Balbi Cc: stable Link: https://lore.kernel.org/r/20200510054326.GA19198@pizza01 Signed-off-by: Greg Kroah-Hartman --- drivers/usb/gadget/configfs.c | 3 +++ 1 file changed, 3 insertions(+) --- a/drivers/usb/gadget/configfs.c +++ b/drivers/usb/gadget/configfs.c @@ -259,6 +259,9 @@ static ssize_t gadget_dev_desc_UDC_store char *name; int ret; + if (strlen(page) < len) + return -EOVERFLOW; + name = kstrdup(page, GFP_KERNEL); if (!name) return -ENOMEM;