Re: kobject_init_and_add is easy to misuse

2020-06-03 Thread Jason Gunthorpe
On Wed, Jun 03, 2020 at 01:56:20PM -0700, James Bottomley wrote: > The store of state_in_sysfs is already done in kobject_add_internal(). > It's an existing flag people already use to tell if the kobject has > been exposed in sysfs. However, it's set after the sysfs directory > creation

Re: kobject_init_and_add is easy to misuse

2020-06-03 Thread James Bottomley
On Wed, 2020-06-03 at 16:30 -0300, Jason Gunthorpe wrote: > On Wed, Jun 03, 2020 at 12:02:08PM -0700, James Bottomley wrote: > > On Wed, 2020-06-03 at 15:36 -0300, Jason Gunthorpe wrote: > > > On Wed, Jun 03, 2020 at 11:04:35AM -0700, James Bottomley wrote: > > > > On Tue, 2020-06-02 at 21:22

Re: kobject_init_and_add is easy to misuse

2020-06-03 Thread Jason Gunthorpe
On Wed, Jun 03, 2020 at 12:02:08PM -0700, James Bottomley wrote: > On Wed, 2020-06-03 at 15:36 -0300, Jason Gunthorpe wrote: > > On Wed, Jun 03, 2020 at 11:04:35AM -0700, James Bottomley wrote: > > > On Tue, 2020-06-02 at 21:22 -0300, Jason Gunthorpe wrote: > > > > On Tue, Jun 02, 2020 at

Re: kobject_init_and_add is easy to misuse

2020-06-03 Thread James Bottomley
On Wed, 2020-06-03 at 15:36 -0300, Jason Gunthorpe wrote: > On Wed, Jun 03, 2020 at 11:04:35AM -0700, James Bottomley wrote: > > On Tue, 2020-06-02 at 21:22 -0300, Jason Gunthorpe wrote: > > > On Tue, Jun 02, 2020 at 02:51:10PM -0700, James Bottomley wrote: > > > > > > > My first thought was

Re: kobject_init_and_add is easy to misuse

2020-06-03 Thread Jason Gunthorpe
On Wed, Jun 03, 2020 at 11:04:35AM -0700, James Bottomley wrote: > On Tue, 2020-06-02 at 21:22 -0300, Jason Gunthorpe wrote: > > On Tue, Jun 02, 2020 at 02:51:10PM -0700, James Bottomley wrote: > > > > > My first thought was "what? I got suckered into creating a patch", > > > thanks ;-) But now

Re: kobject_init_and_add is easy to misuse

2020-06-03 Thread James Bottomley
On Tue, 2020-06-02 at 21:22 -0300, Jason Gunthorpe wrote: > On Tue, Jun 02, 2020 at 02:51:10PM -0700, James Bottomley wrote: > > > My first thought was "what? I got suckered into creating a patch", > > thanks ;-) But now I look, all the error paths do unwind back to > > the initial state, so

Re: kobject_init_and_add is easy to misuse

2020-06-02 Thread Jason Gunthorpe
On Tue, Jun 02, 2020 at 02:51:10PM -0700, James Bottomley wrote: > My first thought was "what? I got suckered into creating a patch", > thanks ;-) But now I look, all the error paths do unwind back to the > initial state, so kfree() on error looks to be completely correct. It doesn't fully

Re: kobject_init_and_add is easy to misuse

2020-06-02 Thread James Bottomley
On Tue, 2020-06-02 at 14:51 -0700, James Bottomley wrote: > On Tue, 2020-06-02 at 22:07 +0200, Greg Kroah-Hartman wrote: > > On Tue, Jun 02, 2020 at 12:54:16PM -0700, James Bottomley wrote: > > [...] > > > I think the only way we can make the failure semantics consistent > > > is to have the

Re: kobject_init_and_add is easy to misuse

2020-06-02 Thread James Bottomley
On Tue, 2020-06-02 at 22:07 +0200, Greg Kroah-Hartman wrote: > On Tue, Jun 02, 2020 at 12:54:16PM -0700, James Bottomley wrote: [...] > > I think the only way we can make the failure semantics consistent > > is to have the kobject_init() ones (so kfree on failure). That > > means for the add

Re: kobject_init_and_add is easy to misuse

2020-06-02 Thread Greg Kroah-Hartman
On Tue, Jun 02, 2020 at 12:54:16PM -0700, James Bottomley wrote: > On Tue, 2020-06-02 at 19:36 +0200, Greg Kroah-Hartman wrote: > > On Tue, Jun 02, 2020 at 08:25:14AM -0700, James Bottomley wrote: > > > On Tue, 2020-06-02 at 05:10 -0700, Matthew Wilcox wrote: > > > > On Tue, Jun 02, 2020 at

Re: kobject_init_and_add is easy to misuse

2020-06-02 Thread James Bottomley
On Tue, 2020-06-02 at 19:36 +0200, Greg Kroah-Hartman wrote: > On Tue, Jun 02, 2020 at 08:25:14AM -0700, James Bottomley wrote: > > On Tue, 2020-06-02 at 05:10 -0700, Matthew Wilcox wrote: > > > On Tue, Jun 02, 2020 at 07:50:33PM +0800, Wang Hai wrote: > > > > syzkaller reports for memory leak

Re: kobject_init_and_add is easy to misuse

2020-06-02 Thread Jason Gunthorpe
On Tue, Jun 02, 2020 at 05:10:35AM -0700, Matthew Wilcox wrote: > On Tue, Jun 02, 2020 at 07:50:33PM +0800, Wang Hai wrote: > > syzkaller reports for memory leak when kobject_init_and_add() > > returns an error in the function sysfs_slab_add() [1] > > > > When this happened, the function

Re: kobject_init_and_add is easy to misuse

2020-06-02 Thread Greg Kroah-Hartman
On Tue, Jun 02, 2020 at 08:25:14AM -0700, James Bottomley wrote: > On Tue, 2020-06-02 at 05:10 -0700, Matthew Wilcox wrote: > > On Tue, Jun 02, 2020 at 07:50:33PM +0800, Wang Hai wrote: > > > syzkaller reports for memory leak when kobject_init_and_add() > > > returns an error in the function

Re: kobject_init_and_add is easy to misuse

2020-06-02 Thread James Bottomley
On Tue, 2020-06-02 at 05:10 -0700, Matthew Wilcox wrote: > On Tue, Jun 02, 2020 at 07:50:33PM +0800, Wang Hai wrote: > > syzkaller reports for memory leak when kobject_init_and_add() > > returns an error in the function sysfs_slab_add() [1] > > > > When this happened, the function kobject_put()

Re: kobject_init_and_add is easy to misuse

2020-06-02 Thread Matthew Wilcox
On Tue, Jun 02, 2020 at 04:04:04PM +0200, Greg Kroah-Hartman wrote: > On Tue, Jun 02, 2020 at 05:10:35AM -0700, Matthew Wilcox wrote: > > On Tue, Jun 02, 2020 at 07:50:33PM +0800, Wang Hai wrote: > > > syzkaller reports for memory leak when kobject_init_and_add() > > > returns an error in the

Re: kobject_init_and_add is easy to misuse

2020-06-02 Thread Greg Kroah-Hartman
On Tue, Jun 02, 2020 at 05:10:35AM -0700, Matthew Wilcox wrote: > On Tue, Jun 02, 2020 at 07:50:33PM +0800, Wang Hai wrote: > > syzkaller reports for memory leak when kobject_init_and_add() > > returns an error in the function sysfs_slab_add() [1] > > > > When this happened, the function

Re: kobject_init_and_add is easy to misuse

2020-06-02 Thread Konstantin Khlebnikov
On 02/06/2020 15.10, Matthew Wilcox wrote: On Tue, Jun 02, 2020 at 07:50:33PM +0800, Wang Hai wrote: syzkaller reports for memory leak when kobject_init_and_add() returns an error in the function sysfs_slab_add() [1] When this happened, the function kobject_put() is not called for the

kobject_init_and_add is easy to misuse

2020-06-02 Thread Matthew Wilcox
On Tue, Jun 02, 2020 at 07:50:33PM +0800, Wang Hai wrote: > syzkaller reports for memory leak when kobject_init_and_add() > returns an error in the function sysfs_slab_add() [1] > > When this happened, the function kobject_put() is not called for the > corresponding kobject, which potentially