lkml.org 
[lkml]   [2020]   [Jun]   [3]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: kobject_init_and_add is easy to misuse
From
Date
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 kfree() on error looks to be completely
> > correct.
>
> It doesn't fully unwind if the kobject is put into a kset, then
> another thread can get the kref during kset_find_obj() and kfree()
> won't wait for the kref to go to 0. It must use put.

That does seem a bit contrived: the only failure kobject_add_internal()
can get after kobj_kset_join() is from directory creation. If
directory creation fails, no name appears in sysfs and no event for the
name is sent, how did another thread get the name to pass in to
kset_find_obj()?

James

\
 
 \ /
  Last update: 2020-06-03 20:05    [W:0.048 / U:1.388 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site