All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alan Stern <stern@rowland.harvard.edu>
To: Tejun Heo <tj@kernel.org>, Greg KH <gregkh@linuxfoundation.org>
Cc: Kernel development list <linux-kernel@vger.kernel.org>
Subject: Bug in sysfs_break_active_protection()
Date: Mon, 4 Mar 2024 14:17:27 -0500	[thread overview]
Message-ID: <9c2484f4-df62-4d23-97a2-55a160eba55f@rowland.harvard.edu> (raw)
In-Reply-To: <416a8311-c725-419a-8b22-74c80207347f@rowland.harvard.edu>

Tejun:

It looks like there's a memory leak in sysfs_break_active_protection().  
It and its companion routine do this:

struct kernfs_node *sysfs_break_active_protection(struct kobject *kobj,
						  const struct attribute *attr)
{
	struct kernfs_node *kn;

	kobject_get(kobj);
	kn = kernfs_find_and_get(kobj->sd, attr->name);
	if (kn)
		kernfs_break_active_protection(kn);
	return kn;
}

void sysfs_unbreak_active_protection(struct kernfs_node *kn)
{
	struct kobject *kobj = kn->parent->priv;

	kernfs_unbreak_active_protection(kn);
	kernfs_put(kn);
	kobject_put(kobj);
}

If kn is NULL then the kobject_get(kobj) reference is never dropped.  
It looks like this could happen if two processes want to unregister the 
same kobject at the same time.

Shouldn't sysfs_break_active_protection() do this?

	kobject_get(kobj);
	kn = kernfs_find_and_get(kobj->sd, attr->name);
	if (kn)
		kernfs_break_active_protection(kn);
+	else
+		kobject_put(kobj);
	return kn;

Alan Stern

  reply	other threads:[~2024-03-04 19:17 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-04 12:10 [Bug] INFO: task hung in hub_activate Sam Sun
2024-03-04 13:37 ` Hillf Danton
2024-03-04 14:59 ` Alan Stern
2024-03-04 16:15 ` Alan Stern
2024-03-04 16:36   ` Greg KH
2024-03-04 18:30     ` Alan Stern
2024-03-04 19:17       ` Alan Stern [this message]
2024-03-13 20:21         ` Bug in sysfs_break_active_protection() Tejun Heo
2024-03-13 21:43           ` [PATCH] fs: sysfs: Fix reference leak " Alan Stern
2024-03-13 21:44             ` Tejun Heo
2024-03-13 22:10             ` Bart Van Assche
2024-03-05 12:03       ` [Bug] INFO: task hung in hub_activate Greg KH
2024-03-07 20:35 ` Alan Stern
2024-03-08  2:48   ` Sam Sun

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9c2484f4-df62-4d23-97a2-55a160eba55f@rowland.harvard.edu \
    --to=stern@rowland.harvard.edu \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tj@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.