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: <20200417113956.GA3728594@kuha.fi.intel.com>
Date:   Fri, 17 Apr 2020 14:39:56 +0300
From:   Heikki Krogerus <heikki.krogerus@...ux.intel.com>
To:     Greg KH <gregkh@...uxfoundation.org>,
        "Rafael J. Wysocki" <rafael@...nel.org>,
        Brendan Higgins <brendanhiggins@...gle.com>,
        Randy Dunlap <rdunlap@...radead.org>
Cc:     Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
        Naresh Kamboju <naresh.kamboju@...aro.org>,
        Sakari Ailus <sakari.ailus@...ux.intel.com>,
        Andy Shevchenko <andy.shevchenko@...il.com>,
        Hans de Goede <hdegoede@...hat.com>,
        Rafael Wysocki <rafael.j.wysocki@...el.com>,
        linux-kselftest@...r.kernel.org,
        Steven Rostedt <rostedt@...dmis.org>,
        Sergey Senozhatsky <sergey.senozhatsky@...il.com>,
        Andy Shevchenko <andriy.shevchenko@...ux.intel.com>,
        Shuah Khan <shuah@...nel.org>, anders.roxell@...aro.org,
        lkft-triage@...ts.linaro.org,
        Rasmus Villemoes <linux@...musvillemoes.dk>
Subject: Re: [PATCH v1] kobject: make sure parent is not released before
 children

Hi,

> > > An alternative might be to define something like __kobject_del() doing
> > > everything that kobject_del() does *without* the
> > > kobject_put(kobj->parent).
> > > 
> > > Then, kobject_del() could be defined as something like (pseudocode):
> > > 
> > > kobject_del(kobj)
> > > {
> > >     kobject *perent = kobj->parent;
> > > 
> > >     __kobject_del(kobj);
> > >     kobject_put(parent);
> > > }
> > > 
> > > and kobject_cleanup() could call __kobject_del() instead of
> > > kobject_del() and then do the last kobject_put(parent) when it is done
> > > with the child.
> > > 
> > > Would that work?
> > 
> > I think so. Greg, what do you think?
> 
> Hm, maybe.  Can someone test it out with the reproducer?

Brendan, or Randy! Can you guys test Rafael's proposal? I think it
would look like this:

diff --git a/lib/kobject.c b/lib/kobject.c
index 83198cb37d8d..2bd631460e18 100644
--- a/lib/kobject.c
+++ b/lib/kobject.c
@@ -599,14 +599,7 @@ int kobject_move(struct kobject *kobj, struct kobject *new_parent)
 }
 EXPORT_SYMBOL_GPL(kobject_move);
 
-/**
- * kobject_del() - Unlink kobject from hierarchy.
- * @kobj: object.
- *
- * This is the function that should be called to delete an object
- * successfully added via kobject_add().
- */
-void kobject_del(struct kobject *kobj)
+static void __kobject_del(struct kobject *kobj)
 {
        struct kernfs_node *sd;
        const struct kobj_type *ktype;
@@ -625,9 +618,23 @@ void kobject_del(struct kobject *kobj)
 
        kobj->state_in_sysfs = 0;
        kobj_kset_leave(kobj);
-       kobject_put(kobj->parent);
        kobj->parent = NULL;
 }
+
+/**
+ * kobject_del() - Unlink kobject from hierarchy.
+ * @kobj: object.
+ *
+ * This is the function that should be called to delete an object
+ * successfully added via kobject_add().
+ */
+void kobject_del(struct kobject *kobj)
+{
+       struct kobject *parent = kobj->parent;
+
+       __kobject_del(kobj);
+       kobject_put(parent);
+}
 EXPORT_SYMBOL(kobject_del);
 
 /**
@@ -663,6 +670,7 @@ EXPORT_SYMBOL(kobject_get_unless_zero);
  */
 static void kobject_cleanup(struct kobject *kobj)
 {
+       struct kobject *parent = kobj->parent;
        struct kobj_type *t = get_ktype(kobj);
        const char *name = kobj->name;
 
@@ -684,7 +692,7 @@ static void kobject_cleanup(struct kobject *kobj)
        if (kobj->state_in_sysfs) {
                pr_debug("kobject: '%s' (%p): auto cleanup kobject_del\n",
                         kobject_name(kobj), kobj);
-               kobject_del(kobj);
+               __kobject_del(kobj);
        }
 
        if (t && t->release) {
@@ -698,6 +706,8 @@ static void kobject_cleanup(struct kobject *kobj)
                pr_debug("kobject: '%s': free name\n", name);
                kfree_const(name);
        }
+
+       kobject_put(parent);
 }

 #ifdef CONFIG_DEBUG_KOBJECT_RELEASE


thanks,

-- 
heikki

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ