lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250414145932.GA1508032@horms.kernel.org>
Date: Mon, 14 Apr 2025 15:59:32 +0100
From: Simon Horman <horms@...nel.org>
To: Abdun Nihaal <abdun.nihaal@...il.com>
Cc: Markus Elfring <Markus.Elfring@....de>, netdev@...r.kernel.org,
	LKML <linux-kernel@...r.kernel.org>,
	Andrew Lunn <andrew+netdev@...n.ch>,
	"David S. Miller" <davem@...emloft.net>,
	Eric Dumazet <edumazet@...gle.com>,
	Jakub Kicinski <kuba@...nel.org>, Paolo Abeni <pabeni@...hat.com>,
	Potnuri Bharat Teja <bharat@...lsio.com>,
	Rahul Lakkireddy <rahul.lakkireddy@...lsio.com>,
	Vishal Kulkarni <vishal@...lsio.com>
Subject: Re: [PATCH net-next] cxgb4: fix memory leak in
 cxgb4_init_ethtool_filters() error path

On Mon, Apr 14, 2025 at 03:56:22PM +0100, Simon Horman wrote:
> On Fri, Apr 11, 2025 at 09:52:29PM +0530, Abdun Nihaal wrote:
> > On Fri, Apr 11, 2025 at 03:57:34PM +0100, Simon Horman wrote:
> > > On Wed, Apr 09, 2025 at 05:47:46PM +0200, Markus Elfring wrote:
> > > > …
> > > > > +++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_ethtool.c
> > > > > @@ -2270,6 +2270,7 @@ int cxgb4_init_ethtool_filters(struct adapter *adap)
> > > > >  		eth_filter->port[i].bmap = bitmap_zalloc(nentries, GFP_KERNEL);
> > > > >  		if (!eth_filter->port[i].bmap) {
> > > > >  			ret = -ENOMEM;
> > > > > +			kvfree(eth_filter->port[i].loc_array);
> > > > >  			goto free_eth_finfo;
> > > > >  		}
> > > > >  	}
> > > > 
> > > > How do you think about to move the shown error code assignment behind the mentioned label
> > > > (so that another bit of duplicate source code could be avoided)?
> > > 
> > > Hi Markus,
> > > 
> > > If you mean something like the following. Then I agree that it
> > > is both in keeping with the existing error handling in this function
> > > and addresses the problem at hand.
> > > 
> > > diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_ethtool.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_ethtool.c
> > > index 7f3f5afa864f..df26d3388c00 100644
> > > --- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_ethtool.c
> > > +++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_ethtool.c
> > > @@ -2270,13 +2270,15 @@ int cxgb4_init_ethtool_filters(struct adapter *adap)
> > >                 eth_filter->port[i].bmap = bitmap_zalloc(nentries, GFP_KERNEL);
> > >                 if (!eth_filter->port[i].bmap) {
> > >                         ret = -ENOMEM;
> > > -                       goto free_eth_finfo;
> > > +                       goto free_eth_finfo_loc_array;
> > >                 }
> > >         }
> > > 
> > >         adap->ethtool_filters = eth_filter;
> > >         return 0;
> > > 
> > > +free_eth_finfo_loc_array:
> > > +       kvfree(eth_filter->port[i].loc_array);
> > >  free_eth_finfo:
> > >         while (i-- > 0) {
> > >                 bitmap_free(eth_filter->port[i].bmap);
> > > 
> > 
> > I think what Markus meant, was to move the ret = -ENOMEM from both the
> > allocations in the loop, to after the free_eth_finfo label because it is
> > -ENOMEM on both goto jumps.
> > 
> > But personally I would prefer having the ret code right after the call 
> > that is failing. Also I would avoid creating new goto labels unless
> > necessary, because it is easier to see the kvfree in context inside the
> > loop, than to put it in a separate label.
> > 
> > I just tried to make the most minimal code change to fix the memory leak.
> 
> Thanks Nihaal,
> 
> I agree that your patch is fine as-is for the reasons you describe above.
> 
> Reviewed-by: Simon Horman <horms@...nel.org>

As the patch was marked as changes requested, presumably due to earlier
discussion in this thread, could you please post a v2. You can include my
tag above. And note under the scissors ("---") that adding the tag was the
only change between v1 and v2.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ