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-next>] [day] [month] [year] [list]
Message-Id: <20200604193623.16946-1-jorhand@linux.microsoft.com>
Date:   Thu,  4 Jun 2020 12:36:23 -0700
From:   jorhand@...ux.microsoft.com
To:     Heikki Krogerus <heikki.krogerus@...ux.intel.com>,
        "Rafael J . Wysocki" <rafael@...nel.org>
Cc:     Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
        linux-kernel@...r.kernel.org, linux-next@...r.kernel.org,
        Jordan Hand <jorhand@...ux.microsoft.com>
Subject: [PATCH] software node: recursively unregister child swnodes

From: Jordan Hand <jorhand@...ux.microsoft.com>

If a child swnode is unregistered after it's parent, it can lead to
undefined behavior.

When a swnode is unregistered, recursively free it's children to avoid
this condition.

Signed-off-by: Jordan Hand <jorhand@...ux.microsoft.com>
---
 drivers/base/swnode.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/drivers/base/swnode.c b/drivers/base/swnode.c
index e5eb27375416..e63093b1542b 100644
--- a/drivers/base/swnode.c
+++ b/drivers/base/swnode.c
@@ -619,6 +619,8 @@ static void software_node_release(struct kobject *kobj)
 		property_entries_free(swnode->node->properties);
 		kfree(swnode->node);
 	}
+
+	list_del(&kobj->entry);
 	ida_destroy(&swnode->child_ids);
 	kfree(swnode);
 }
@@ -712,11 +714,6 @@ EXPORT_SYMBOL_GPL(software_node_register_nodes);
  * @nodes: Zero terminated array of software nodes to be unregistered
  *
  * Unregister multiple software nodes at once.
- *
- * NOTE: Be careful using this call if the nodes had parent pointers set up in
- * them before registering.  If so, it is wiser to remove the nodes
- * individually, in the correct order (child before parent) instead of relying
- * on the sequential order of the list of nodes in the array.
  */
 void software_node_unregister_nodes(const struct software_node *nodes)
 {
@@ -839,10 +836,16 @@ EXPORT_SYMBOL_GPL(fwnode_create_software_node);
 void fwnode_remove_software_node(struct fwnode_handle *fwnode)
 {
 	struct swnode *swnode = to_swnode(fwnode);
+	struct swnode *child = NULL;
 
 	if (!swnode)
 		return;
 
+	while (!list_empty(&swnode->children)) {
+		child = list_first_entry_or_null(&swnode->children, struct swnode, entry);
+		fwnode_remove_software_node(&child->fwnode);
+	}
+
 	kobject_put(&swnode->kobj);
 }
 EXPORT_SYMBOL_GPL(fwnode_remove_software_node);
-- 
2.17.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ