Message ID | 2ddd10ec9e009bbb85518355f1e09e1ecd349925.1685340968.git.christophe.jaillet@wanadoo.fr |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1308442vqr; Sun, 28 May 2023 23:19:06 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5A1wz0pNxoMWdTFRoPz8LWy20i5szdVQ5ilr/VAbWCC+NUQH7VnA3Wgmouo5Sruia7mpV2 X-Received: by 2002:a05:6a20:4394:b0:10f:52e2:4a0a with SMTP id i20-20020a056a20439400b0010f52e24a0amr7173871pzl.18.1685341146371; Sun, 28 May 2023 23:19:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685341146; cv=none; d=google.com; s=arc-20160816; b=Er6bKDp4/r/Qmp58hxKC9MQxz5paSDiadFgNUezoZkrVpKSWtY971hkb4GJSNk2Ntu rn8/hd6s/wWIFk7Sc0/S81eK9c93LOSUDbzdQ0yXTFU8X5MTtkRMgUnWPVV/T8gKnRQ7 OVn4hc7lxnzhj6Ubudn3GuRtOou0eeJAn4ql9FIi2HnzNR7vIcJ58Xwd2rdFMDxQs2hQ NV6DK6r2fvD5C71dTIzDnH+/bdfnnaOaGth8wCrX4NPrKdoD6lgAwzml+a2Z0HEogyGi 8NRcdAUX3bZZhrH/gIhZlwdwnfTpKPrc+AIdWz8twkWjzl3gqwPTfXg9ZdnV1pHxv1bd 3kvw== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=LMsxEc3jzv9WRfxtgBWJr+2up3zRX/dSTarm2zC7inQ=; b=bGA2fJriBwCXREBF1px+gHsHlT8HbtZ+Zcx2nXJyqprIEMN2TRu6XbLcrbVVYfiUrH gfTGwP4bO7UApPYkHEHAosRcgCsOlYweKpg+a387j8xlkUvh/uP8/gS3RdqhLmsJLls+ US3KLfXZrN36CbetYOkZOPTVfRCHRHBF137LsCNXirvMEYaSBuW/X8ktGYnW1LfTSXyT q7pcOLOeeW8C3gtgRdZNiQZp9N/rzG6Ok/HjoWih1kN/fj57sYXDf/QpnoGL2GkKlKw4 ZiWEKvdhrBjs3hpZicb3txNqP4hMziM0WvTJZl2BS7fg84/M7qAe6s+Uat7FDPmTxhyx 4I0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b="gi6/9Y3B"; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v15-20020a63bf0f000000b0053eef60f942si8292451pgf.764.2023.05.28.23.18.54; Sun, 28 May 2023 23:19:06 -0700 (PDT) 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=@wanadoo.fr header.s=t20230301 header.b="gi6/9Y3B"; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230042AbjE2GSS (ORCPT <rfc822;callmefire3@gmail.com> + 99 others); Mon, 29 May 2023 02:18:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46552 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231516AbjE2GSO (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 29 May 2023 02:18:14 -0400 Received: from smtp.smtpout.orange.fr (smtp-22.smtpout.orange.fr [80.12.242.22]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 750FFF3 for <linux-kernel@vger.kernel.org>; Sun, 28 May 2023 23:17:48 -0700 (PDT) Received: from pop-os.home ([86.243.2.178]) by smtp.orange.fr with ESMTPA id 3WC0q1f0vZvWO3WC0qfklE; Mon, 29 May 2023 08:17:22 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wanadoo.fr; s=t20230301; t=1685341042; bh=LMsxEc3jzv9WRfxtgBWJr+2up3zRX/dSTarm2zC7inQ=; h=From:To:Cc:Subject:Date; b=gi6/9Y3BHoprXzB1QmpY0l7JSneYVDhaJtKS42KT08OOYih3CNQZe2o+xGWLGGQ2P IPizhyvuUSVqgUfgccbqmgypYzMDED6uDiO+Fjk4/bwv86QtekVzH62640Gzqf4Wjb sTqcTCXDneuOqmYJYJJy2hKGfV5w6Y+xHJBetUzkN4Jp0mVLH8HuQQvSioZdQ1X9hA k+cyRePBjlmwiobd5KDUWdqgdOGZ6ItqpNdoFvtEiRP+C8aOIdTek0LoL81tdjB/Dh ssOZLKRDkpfqIndPScmjh67ONpCxVdqNP1C0WwmXqq5X9DhRrGthC+eB+BbDuAWPYt n+04tTi8+jGsQ== X-ME-Helo: pop-os.home X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Mon, 29 May 2023 08:17:22 +0200 X-ME-IP: 86.243.2.178 From: Christophe JAILLET <christophe.jaillet@wanadoo.fr> To: Mauro Carvalho Chehab <mchehab@kernel.org>, Sakari Ailus <sakari.ailus@linux.intel.com> Cc: linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET <christophe.jaillet@wanadoo.fr>, linux-media@vger.kernel.org Subject: [PATCH] media: v4l2-core: Fix a potential resource leak in v4l2_fwnode_parse_link() Date: Mon, 29 May 2023 08:17:18 +0200 Message-Id: <2ddd10ec9e009bbb85518355f1e09e1ecd349925.1685340968.git.christophe.jaillet@wanadoo.fr> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_PASS,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: <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?1767208277655654676?= X-GMAIL-MSGID: =?utf-8?q?1767208277655654676?= |
Series |
media: v4l2-core: Fix a potential resource leak in v4l2_fwnode_parse_link()
|
|
Commit Message
Christophe JAILLET
May 29, 2023, 6:17 a.m. UTC
'fwnode is known to be NULL, at this point, so fwnode_handle_put() is a
no-op.
Release the reference taken from a previous fwnode_graph_get_port_parent()
call instead.
Fixes: ca50c197bd96 ("[media] v4l: fwnode: Support generic fwnode for parsing standardised properties")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
/!\ THIS PATCH IS SPECULATIVE /!\
review with care
---
drivers/media/v4l2-core/v4l2-fwnode.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
Comments
Hi Christophe, On Mon, May 29, 2023 at 08:17:18AM +0200, Christophe JAILLET wrote: > 'fwnode is known to be NULL, at this point, so fwnode_handle_put() is a > no-op. > > Release the reference taken from a previous fwnode_graph_get_port_parent() > call instead. > > Fixes: ca50c197bd96 ("[media] v4l: fwnode: Support generic fwnode for parsing standardised properties") > Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr> > --- > /!\ THIS PATCH IS SPECULATIVE /!\ > review with care > --- > drivers/media/v4l2-core/v4l2-fwnode.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/media/v4l2-core/v4l2-fwnode.c b/drivers/media/v4l2-core/v4l2-fwnode.c > index 049c2f2001ea..b7dd467c53fd 100644 > --- a/drivers/media/v4l2-core/v4l2-fwnode.c > +++ b/drivers/media/v4l2-core/v4l2-fwnode.c > @@ -571,7 +571,7 @@ int v4l2_fwnode_parse_link(struct fwnode_handle *fwnode, > > fwnode = fwnode_graph_get_remote_endpoint(fwnode); > if (!fwnode) { > - fwnode_handle_put(fwnode); > + fwnode_handle_put(link->local_node); link->local_node also needs to be non-NULL for the successful case. The condition should take that into account. Could you send v2 with that? > return -ENOLINK; > } >
Le 13/06/2023 à 12:55, Sakari Ailus a écrit : > Hi Christophe, > > On Mon, May 29, 2023 at 08:17:18AM +0200, Christophe JAILLET wrote: >> 'fwnode is known to be NULL, at this point, so fwnode_handle_put() is a >> no-op. >> >> Release the reference taken from a previous fwnode_graph_get_port_parent() >> call instead. >> >> Fixes: ca50c197bd96 ("[media] v4l: fwnode: Support generic fwnode for parsing standardised properties") >> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr> >> --- >> /!\ THIS PATCH IS SPECULATIVE /!\ >> review with care >> --- >> drivers/media/v4l2-core/v4l2-fwnode.c | 2 +- >> 1 file changed, 1 insertion(+), 1 deletion(-) >> >> diff --git a/drivers/media/v4l2-core/v4l2-fwnode.c b/drivers/media/v4l2-core/v4l2-fwnode.c >> index 049c2f2001ea..b7dd467c53fd 100644 >> --- a/drivers/media/v4l2-core/v4l2-fwnode.c >> +++ b/drivers/media/v4l2-core/v4l2-fwnode.c >> @@ -571,7 +571,7 @@ int v4l2_fwnode_parse_link(struct fwnode_handle *fwnode, >> >> fwnode = fwnode_graph_get_remote_endpoint(fwnode); >> if (!fwnode) { >> - fwnode_handle_put(fwnode); >> + fwnode_handle_put(link->local_node); > > link->local_node also needs to be non-NULL for the successful case. The > condition should take that into account. Could you send v2 with that? > >> return -ENOLINK; >> } >> > Hi, something like below? @@ -568,19 +568,25 @@ int v4l2_fwnode_parse_link(struct fwnode_handle *fwnode, link->local_id = fwep.id; link->local_port = fwep.port; link->local_node = fwnode_graph_get_port_parent(fwnode); + if (!link->local_node) + return -ENOLINK; fwnode = fwnode_graph_get_remote_endpoint(fwnode); - if (!fwnode) { - fwnode_handle_put(fwnode); - return -ENOLINK; - } + if (!fwnode) + goto err_put_local_node; fwnode_graph_parse_endpoint(fwnode, &fwep); link->remote_id = fwep.id; link->remote_port = fwep.port; link->remote_node = fwnode_graph_get_port_parent(fwnode); + if (!link->remote_node) + goto err_put_local_node; return 0; + +err_put_local_node: + fwnode_handle_put(link->local_node); + return -ENOLINK; } EXPORT_SYMBOL_GPL(v4l2_fwnode_parse_link); CJ
Hi Christophe, On Tue, Jun 13, 2023 at 07:15:40PM +0200, Christophe JAILLET wrote: > Le 13/06/2023 à 12:55, Sakari Ailus a écrit : > > Hi Christophe, > > > > On Mon, May 29, 2023 at 08:17:18AM +0200, Christophe JAILLET wrote: > > > 'fwnode is known to be NULL, at this point, so fwnode_handle_put() is a > > > no-op. > > > > > > Release the reference taken from a previous fwnode_graph_get_port_parent() > > > call instead. > > > > > > Fixes: ca50c197bd96 ("[media] v4l: fwnode: Support generic fwnode for parsing standardised properties") > > > Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr> > > > --- > > > /!\ THIS PATCH IS SPECULATIVE /!\ > > > review with care > > > --- > > > drivers/media/v4l2-core/v4l2-fwnode.c | 2 +- > > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > > > diff --git a/drivers/media/v4l2-core/v4l2-fwnode.c b/drivers/media/v4l2-core/v4l2-fwnode.c > > > index 049c2f2001ea..b7dd467c53fd 100644 > > > --- a/drivers/media/v4l2-core/v4l2-fwnode.c > > > +++ b/drivers/media/v4l2-core/v4l2-fwnode.c > > > @@ -571,7 +571,7 @@ int v4l2_fwnode_parse_link(struct fwnode_handle *fwnode, > > > fwnode = fwnode_graph_get_remote_endpoint(fwnode); > > > if (!fwnode) { > > > - fwnode_handle_put(fwnode); > > > + fwnode_handle_put(link->local_node); > > > > link->local_node also needs to be non-NULL for the successful case. The > > condition should take that into account. Could you send v2 with that? > > > > > return -ENOLINK; > > > } > > > > Hi, > something like below? Ah, remote_node must be non-NULL, too, indeed. It was surprisingly broken. > > @@ -568,19 +568,25 @@ int v4l2_fwnode_parse_link(struct fwnode_handle > *fwnode, > link->local_id = fwep.id; > link->local_port = fwep.port; > link->local_node = fwnode_graph_get_port_parent(fwnode); > + if (!link->local_node) > + return -ENOLINK; > > fwnode = fwnode_graph_get_remote_endpoint(fwnode); > - if (!fwnode) { > - fwnode_handle_put(fwnode); > - return -ENOLINK; > - } > + if (!fwnode) > + goto err_put_local_node; On error, fwnode needs to be put from this onwards, too. But you can use a single label: fwnode_handle_put() is NULL-safe. > > fwnode_graph_parse_endpoint(fwnode, &fwep); > link->remote_id = fwep.id; > link->remote_port = fwep.port; > link->remote_node = fwnode_graph_get_port_parent(fwnode); > + if (!link->remote_node) > + goto err_put_local_node; > > return 0; > + > +err_put_local_node: > + fwnode_handle_put(link->local_node); > + return -ENOLINK; > } > EXPORT_SYMBOL_GPL(v4l2_fwnode_parse_link);
diff --git a/drivers/media/v4l2-core/v4l2-fwnode.c b/drivers/media/v4l2-core/v4l2-fwnode.c index 049c2f2001ea..b7dd467c53fd 100644 --- a/drivers/media/v4l2-core/v4l2-fwnode.c +++ b/drivers/media/v4l2-core/v4l2-fwnode.c @@ -571,7 +571,7 @@ int v4l2_fwnode_parse_link(struct fwnode_handle *fwnode, fwnode = fwnode_graph_get_remote_endpoint(fwnode); if (!fwnode) { - fwnode_handle_put(fwnode); + fwnode_handle_put(link->local_node); return -ENOLINK; }