Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp1775769pxp; Mon, 7 Mar 2022 02:02:55 -0800 (PST) X-Google-Smtp-Source: ABdhPJx4wWqTDjzIEM1Ncba1ZNzEM8s1dlP0xiMYOOEafJiUKfSBhwIL6miUWgBGgtV1M/0TuYey X-Received: by 2002:a17:902:b185:b0:14f:2d94:184 with SMTP id s5-20020a170902b18500b0014f2d940184mr11177936plr.56.1646647375070; Mon, 07 Mar 2022 02:02:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646647375; cv=none; d=google.com; s=arc-20160816; b=M2bO9AWnYL3yPHii50/WUlqohyTJFFr72UbfcKeYZ3mL3oPIcxWqWAJuyoEpyarV+e uVrBZzItg/Uo77vVo9MKL9o9PUNAf5PV+VHbQ6Bin6aKkYuHCp7G7Rq2tI80D1fSxi5R Gf107dSO494X7KpT5z+7TwD2A7upIgNadcuFOerD26304NTPv94uo0Ilt+awqHmFdf4/ JXU/voLJDsrqEgB3D0KOlXHTSn9MvnLf4pTo3V6sOOCQLMcRj4QqFUHB+0skYrjxc2N7 hIU/D436AVO4tr8yYqcmNOfbnD17QUg22dThG3nMqjlYsIg3wt4HEPkBmcSiFP0de2Ex ckXg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=h0dzkUUlwXjjztueLcojLqgZsnmfSkYpnK/vPKvBYqc=; b=wqI5Dlcf9Yw02Zw5b1iBjr7NDLuKyzjyYBGdHFF4FKlmV+o/slYhfmb4pYqho9Agni dGiqRdH6KR/PZOQDu6x7CN0kL9cVLqUPCwRwCzByHMlA6nu0e1WaOk0xQKShhxSnha9j HaVIevA4jIbM0wwaAiJuh+fAEu8rVBY4OLfXBm7u7c7wtQDXPPmC2TEXxxUAqNzeWlZY pM0kN2d0d4vhmy3E+aA+OEbpJJknaaxn3f4JqLy3dZcx3POTALD21Q3AEhO2yzBzCJr9 AugWwZaXAJrhLZjawJK0VFfZwflcFTZyra+gwlULki/asoCOKkkD+MEAmhuCvsvhSL5N ANag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=oFlIO2VG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u21-20020a170902a61500b0014a421ec0cesi12668478plq.218.2022.03.07.02.02.40; Mon, 07 Mar 2022 02:02:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=oFlIO2VG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236902AbiCGJ0F (ORCPT + 99 others); Mon, 7 Mar 2022 04:26:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52656 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236950AbiCGJXP (ORCPT ); Mon, 7 Mar 2022 04:23:15 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8343865830; Mon, 7 Mar 2022 01:21:28 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 3D470B810BD; Mon, 7 Mar 2022 09:21:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6B826C340F5; Mon, 7 Mar 2022 09:21:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1646644885; bh=0Q2WVn2wAh2H+CtyxAHWdQFdZ4PNcyjRU4u5dhDfKhU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oFlIO2VGTvSeTK6qui5Ra5ww1tkxwwLO8pgmr7HnUxM4nwdZTadfT/YqOzUmgv/eI HYtwWpwz/OnMjOdlHCGh9fDy/u4ryRZXjdOJAgz2/6Q1iAK1UscS6ExarhQyR9LRop mO51fuXefVgwmLZkOs0+18OqIUIJXVgSmZm6fJk4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Alan Stern , Hangyu Hua Subject: [PATCH 4.14 11/42] usb: gadget: clear related members when goto fail Date: Mon, 7 Mar 2022 10:18:45 +0100 Message-Id: <20220307091636.478364799@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220307091636.146155347@linuxfoundation.org> References: <20220307091636.146155347@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Hangyu Hua commit 501e38a5531efbd77d5c73c0ba838a889bfc1d74 upstream. dev->config and dev->hs_config and dev->dev need to be cleaned if dev_config fails to avoid UAF. Acked-by: Alan Stern Signed-off-by: Hangyu Hua Link: https://lore.kernel.org/r/20211231172138.7993-3-hbh25y@gmail.com Signed-off-by: Greg Kroah-Hartman --- drivers/usb/gadget/legacy/inode.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) --- a/drivers/usb/gadget/legacy/inode.c +++ b/drivers/usb/gadget/legacy/inode.c @@ -1882,8 +1882,8 @@ dev_config (struct file *fd, const char value = usb_gadget_probe_driver(&gadgetfs_driver); if (value != 0) { - kfree (dev->buf); - dev->buf = NULL; + spin_lock_irq(&dev->lock); + goto fail; } else { /* at this point "good" hardware has for the first time * let the USB the host see us. alternatively, if users @@ -1900,6 +1900,9 @@ dev_config (struct file *fd, const char return value; fail: + dev->config = NULL; + dev->hs_config = NULL; + dev->dev = NULL; spin_unlock_irq (&dev->lock); pr_debug ("%s: %s fail %zd, %p\n", shortname, __func__, value, dev); kfree (dev->buf);