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 for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Fri, 18 Jun 2021 11:59:59 -0300
From:   Jason Gunthorpe <jgg@...dia.com>
To:     "Jason J. Herne" <jjherne@...ux.ibm.com>
Cc:     linux-s390@...r.kernel.org, linux-kernel@...r.kernel.org,
        pasic@...ux.ibm.com, akrowiak@...ux.ibm.com
Subject: Re: [PATCH] s390/vfio-ap: Fix module unload memory leak of matrix_dev

On Fri, Jun 18, 2021 at 10:35:21AM -0400, Jason J. Herne wrote:
> On 6/18/21 10:10 AM, Jason Gunthorpe wrote:
> > On Fri, Jun 18, 2021 at 09:35:24AM -0400, Jason J. Herne wrote:
> > > vfio_ap_matrix_dev_release is shadowing the global matrix_dev with driver
> > > data that never gets set. So when release is called we end up not freeing
> > > matrix_dev. The fix is to remove the shadow variable and just free the
> > > global.
> > 
> > I would clarify this commit message to say that the drv_data of the
> > matrix_dev is never set and so dev_get_drvdata() always returns NULL
> > 
> > And I would suggest to use
> > 
> >    container_of(dev, struct ap_matrix_dev, dev)
> > 
> > instead of the global variable, and probably NULL the global
> > too..
> > 
> 
> The use of driver_data seems to have been completely erroneous here. In this
> case the global matrix_dev is the top level struct. It is not contained in
> anything. matrix_dev is created upon module load, and it is freed when the
> module exits.
> 
> So I don't think using container_of makes sense. Unless I've
> misunderstood your suggestion?

	matrix_dev = kzalloc(sizeof(*matrix_dev), GFP_KERNEL);
	matrix_dev->device.release = vfio_ap_matrix_dev_release;
	ret = device_register(&matrix_dev->device);

"dev" is contained inside matrix_dev which is why we should use
container of to go from a struct device pointer back to the containing
matrix_dev pointer

Jason

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ