Message ID | 20221122123523.3068034-3-john@metanate.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2178149wrr; Tue, 22 Nov 2022 04:46:08 -0800 (PST) X-Google-Smtp-Source: AA0mqf62vmIpQvUONr3Yon92GpRZ4aLImcbqm8dtAF276LI0Vz10546tFqSmEMurCRQ69QlV5bfS X-Received: by 2002:a17:902:c385:b0:186:944a:2560 with SMTP id g5-20020a170902c38500b00186944a2560mr4633425plg.84.1669121168461; Tue, 22 Nov 2022 04:46:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669121168; cv=none; d=google.com; s=arc-20160816; b=sH5Ie2u+dSe9fK4pPnbZ9e5p7ioJITDiONBnyG3dTSkHudpNEwQ2phNuajmyRrRYCp /SEQBLtYP/9kaH5aY3WnZ61CtRTVghfx+22BJ49XdXcw0FjRP6Hb6b9+Ln+65pq9v7vr EvO0DX4bxyb0tlj14wtQizpk8TGv+fqE7K6rMDAmiD7LS3Q9zr6ICzdoz8xxNa5mIH/L WAspCKmIYUvZ5ZKesxTQwDI8bDqMSQsonx8uecO4+prAPr1+X1JbC8SpRlPESd3ACmEf P7akdbVakaMNM3Pd+I9/bdpoBwnqRxDjODHjejlZNC3AVmHojrhOTOLK+YYLqf2jlzG7 H0TQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=3XtypsQCZfitCCQMZ1INOCA+bpbOa3aJWCZ30RBSfxk=; b=M78INDlIKLJNkbi98pcgFpwkIH8N8Pg32BG48LiGTdj4N2oj3SZxcNGKUMDUZeJ09a XLsRQoXxTOJxjZlvKwB/7QSMiDlcnKTEJT1LaeXC0PGrFPxP6whz5BN6DGAj+BpwvkLY wZHdBsU9cXMtdIWrfgHlwl4B8loLsmEa0WOcKMFwyvMsAbhOk6EZgqOfsI+15yKHKZAI Dp5hRvgwwA1s7iUei/12cBrxwy0DKyCJP5j1hrszZKm7CUKhxHX7V0+TCpMss99cmX4u PpePv6Ad0mXuKeLhnm9bw8kDs45IUGl/5c9PmeZMO/JqbnKqAAW14lfsVg87Rm0lTzIw bJFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass (test mode) header.i=@metanate.com header.s=stronger header.b=2rn+vgcs; 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=metanate.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t2-20020a170902b20200b001786b70f913si12708184plr.164.2022.11.22.04.45.53; Tue, 22 Nov 2022 04:46:08 -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 (test mode) header.i=@metanate.com header.s=stronger header.b=2rn+vgcs; 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=metanate.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233286AbiKVMft (ORCPT <rfc822;cjcooper78@gmail.com> + 99 others); Tue, 22 Nov 2022 07:35:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43940 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233565AbiKVMff (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 22 Nov 2022 07:35:35 -0500 Received: from metanate.com (unknown [IPv6:2001:8b0:1628:5005::111]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1814D5B852; Tue, 22 Nov 2022 04:35:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=metanate.com; s=stronger; h=Content-Transfer-Encoding:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Content-Type:Reply-To: Content-ID:Content-Description; bh=3XtypsQCZfitCCQMZ1INOCA+bpbOa3aJWCZ30RBSfxk=; b=2rn+vgcsNJmicNvWa5wF/GIy4x UxlKu5IshzDEjq5aSmeYRYuEs7FD750VvMNtMSQTvXT2rJhUQC17zuVlSHAr02mHxmY+9QfveG2O3 t9qBgfNgAIL6OIdR/9MiCe1HHzWDD2iej2/9sHiRmx5NVTFzBIAR3A3Ig75Sx+So037RT9yJ5z6Gg AOXVnmI0+st2vmoTplh36lbyHddmVEWV1rviobn5ORveSLp79psMWQ2yyAJg9NAd6pfeO+mViB4FT gUYGKdb2efe2Qseg1MnAJMSCKxA4/Hvp3CzfSIRDMJ4xpRwnSRGKQ2eg5afAagbDSyi8pmWK0O9Nq z2leee9A==; Received: from [81.174.171.191] (helo=donbot.metanate.com) by email.metanate.com with esmtpsa (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from <john@metanate.com>) id 1oxSUt-0003da-Gn; Tue, 22 Nov 2022 12:35:32 +0000 From: John Keeping <john@metanate.com> To: linux-usb@vger.kernel.org Cc: Fabien Chouteau <fabien.chouteau@barco.com>, Peter Korsgaard <peter.korsgaard@barco.com>, Felipe Balbi <balbi@ti.com>, Andrzej Pietrasiewicz <andrzej.p@samsung.com>, linux-kernel@vger.kernel.org, Greg Kroah-Hartman <gregkh@linuxfoundation.org>, John Keeping <john@metanate.com>, Lee Jones <lee@kernel.org>, Alan Stern <stern@rowland.harvard.edu> Subject: [PATCH 2/3] usb: gadget: f_hid: fix refcount leak on error path Date: Tue, 22 Nov 2022 12:35:22 +0000 Message-Id: <20221122123523.3068034-3-john@metanate.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221122123523.3068034-1-john@metanate.com> References: <20221122123523.3068034-1-john@metanate.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Authenticated: YES X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RDNS_NONE,SPF_HELO_PASS, SPF_PASS autolearn=no 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750200398521605534?= X-GMAIL-MSGID: =?utf-8?q?1750200398521605534?= |
Series |
usb: gadget: f_hid: fix f_hidg lifetime vs cdev
|
|
Commit Message
John Keeping
Nov. 22, 2022, 12:35 p.m. UTC
When failing to allocate report_desc, opts->refcnt has already been
incremented so it needs to be decremented to avoid leaving the options
structure permanently locked.
Fixes: 21a9476a7ba8 ("usb: gadget: hid: add configfs support")
Signed-off-by: John Keeping <john@metanate.com>
---
drivers/usb/gadget/function/f_hid.c | 1 +
1 file changed, 1 insertion(+)
Comments
W dniu 22.11.2022 o 13:35, John Keeping pisze: > When failing to allocate report_desc, opts->refcnt has already been > incremented so it needs to be decremented to avoid leaving the options > structure permanently locked. > > Fixes: 21a9476a7ba8 ("usb: gadget: hid: add configfs support") > Signed-off-by: John Keeping <john@metanate.com> I'd personally place the bugfix before patches 1 and 3, but anyway Reviewed-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com> > --- > drivers/usb/gadget/function/f_hid.c | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/drivers/usb/gadget/function/f_hid.c b/drivers/usb/gadget/function/f_hid.c > index 8b8bbeaa27cb..6be6009f911e 100644 > --- a/drivers/usb/gadget/function/f_hid.c > +++ b/drivers/usb/gadget/function/f_hid.c > @@ -1292,6 +1292,7 @@ static struct usb_function *hidg_alloc(struct usb_function_instance *fi) > GFP_KERNEL); > if (!hidg->report_desc) { > put_device(&hidg->dev); > + --opts->refcnt; > mutex_unlock(&opts->lock); > return ERR_PTR(-ENOMEM); > }
On Wed, Nov 23, 2022 at 12:55:14PM +0100, Andrzej Pietrasiewicz wrote: > W dniu 22.11.2022 o 13:35, John Keeping pisze: > > When failing to allocate report_desc, opts->refcnt has already been > > incremented so it needs to be decremented to avoid leaving the options > > structure permanently locked. > > > > Fixes: 21a9476a7ba8 ("usb: gadget: hid: add configfs support") > > Signed-off-by: John Keeping <john@metanate.com> > > I'd personally place the bugfix before patches 1 and 3, but anyway Patch 1 is also a bugfix, I ordered 1 & 2 based on the order of the commits in the Fixes: tags. > Reviewed-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com> > > > --- > > drivers/usb/gadget/function/f_hid.c | 1 + > > 1 file changed, 1 insertion(+) > > > > diff --git a/drivers/usb/gadget/function/f_hid.c b/drivers/usb/gadget/function/f_hid.c > > index 8b8bbeaa27cb..6be6009f911e 100644 > > --- a/drivers/usb/gadget/function/f_hid.c > > +++ b/drivers/usb/gadget/function/f_hid.c > > @@ -1292,6 +1292,7 @@ static struct usb_function *hidg_alloc(struct usb_function_instance *fi) > > GFP_KERNEL); > > if (!hidg->report_desc) { > > put_device(&hidg->dev); > > + --opts->refcnt; > > mutex_unlock(&opts->lock); > > return ERR_PTR(-ENOMEM); > > } >
diff --git a/drivers/usb/gadget/function/f_hid.c b/drivers/usb/gadget/function/f_hid.c index 8b8bbeaa27cb..6be6009f911e 100644 --- a/drivers/usb/gadget/function/f_hid.c +++ b/drivers/usb/gadget/function/f_hid.c @@ -1292,6 +1292,7 @@ static struct usb_function *hidg_alloc(struct usb_function_instance *fi) GFP_KERNEL); if (!hidg->report_desc) { put_device(&hidg->dev); + --opts->refcnt; mutex_unlock(&opts->lock); return ERR_PTR(-ENOMEM); }