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] [day] [month] [year] [list]
Message-ID: <20210401212753.GB31698@redsun51.ssa.fujisawa.hgst.com>
Date:   Fri, 2 Apr 2021 06:27:53 +0900
From:   Keith Busch <kbusch@...nel.org>
To:     Dan Carpenter <dan.carpenter@...cle.com>
Cc:     linux-kernel@...r.kernel.org, kernel-janitors@...r.kernel.org,
        Jason Gunthorpe <jgg@...dia.com>
Subject: Re: [bug report] node: Add memory-side caching attributes

On Thu, Apr 01, 2021 at 12:00:39PM +0300, Dan Carpenter wrote:
> Hi Keith,
> 
> I've been trying to figure out ways Smatch can check for device managed
> resources.  Like adding rules that if we call dev_set_name(&foo->bar)
> then it's device managaged and if there is a kfree(foo) without calling
> device_put(&foo->bar) then that's a resource leak.
> 
> Of course one of the rules is that if you call device_register(dev) then
> you can't kfree(dev), it has to released with device_put(dev) and that's
> true even if the register fails.  But this code here feels very
> intentional so maybe there is an exception to the rule?

Thanks for the notice. There was no intentional use of this, so I
think it was a mistake. The proposal in the follow on replies looks much
better.
 
> The patch acc02a109b04: "node: Add memory-side caching attributes"
> from Mar 11, 2019, leads to the following static checker warning:
> 
> 	drivers/base/node.c:285 node_init_cache_dev()
> 	error: kfree after device_register(): 'dev'
> 
> drivers/base/node.c
>    263  static void node_init_cache_dev(struct node *node)
>    264  {
>    265          struct device *dev;
>    266  
>    267          dev = kzalloc(sizeof(*dev), GFP_KERNEL);
>    268          if (!dev)
>    269                  return;
>    270  
>    271          dev->parent = &node->dev;
>    272          dev->release = node_cache_release;
>    273          if (dev_set_name(dev, "memory_side_cache"))
>    274                  goto free_dev;
>    275  
>    276          if (device_register(dev))
>                     ^^^^^^^^^^^^^^^^^^^
>    277                  goto free_name;
>    278  
>    279          pm_runtime_no_callbacks(dev);
>    280          node->cache_dev = dev;
>    281          return;
>    282  free_name:
>    283          kfree_const(dev->kobj.name);
>    284  free_dev:
>    285          kfree(dev);
>                 ^^^^^^^^^^
>    286  }
> 
> regards,
> dan carpenter

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ