All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tejun Heo <tj@kernel.org>
To: Alan Stern <stern@rowland.harvard.edu>
Cc: Greg KH <gregkh@linuxfoundation.org>,
	Kernel development list <linux-kernel@vger.kernel.org>
Subject: Re: Bug in sysfs_break_active_protection()
Date: Wed, 13 Mar 2024 10:21:20 -1000	[thread overview]
Message-ID: <ZfIKwFSmw-ACj_jO@slm.duckdns.org> (raw)
In-Reply-To: <9c2484f4-df62-4d23-97a2-55a160eba55f@rowland.harvard.edu>

Sorry about late reply.

On Mon, Mar 04, 2024 at 02:17:27PM -0500, Alan Stern wrote:
...
> 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;
> }
...
> 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;

Yeah, I think you're right. It's an obvious ref leak. Would you mind writing
up a patch?

Thank you.

-- 
tejun

  reply	other threads:[~2024-03-13 20:21 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       ` Bug in sysfs_break_active_protection() Alan Stern
2024-03-13 20:21         ` Tejun Heo [this message]
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=ZfIKwFSmw-ACj_jO@slm.duckdns.org \
    --to=tj@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stern@rowland.harvard.edu \
    /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.