Message ID | 2ddd10ec9e009bbb85518355f1e09e1ecd349925.1685340968.git.christophe.jaillet@wanadoo.fr (mailing list archive) |
---|---|
State | Changes Requested |
Delegated to: | Sakari Ailus |
Headers |
Received: from vger.kernel.org ([23.128.96.18]) by www.linuxtv.org with esmtp (Exim 4.92) (envelope-from <linux-media-owner@vger.kernel.org>) id 1q3WCz-00BQfe-8u; Mon, 29 May 2023 06:18:21 +0000 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231488AbjE2GSS (ORCPT <rfc822;mkrufky@linuxtv.org> + 1 other); Mon, 29 May 2023 02:18:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46492 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230042AbjE2GSO (ORCPT <rfc822;linux-media@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 B4FB2100 for <linux-media@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=unavailable 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-media.vger.kernel.org> X-Mailing-List: linux-media@vger.kernel.org X-LSpam-Score: -4.8 (----) X-LSpam-Report: No, score=-4.8 required=5.0 tests=BAYES_00=-1.9,DKIM_SIGNED=0.1,DKIM_VALID=-0.1,DKIM_VALID_AU=-0.1,FREEMAIL_FORGED_FROMDOMAIN=0.001,FREEMAIL_FROM=0.001,HEADER_FROM_DIFFERENT_DOMAINS=0.5,MAILING_LIST_MULTI=-1,RCVD_IN_DNSWL_MED=-2.3 autolearn=ham autolearn_force=no |
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; }