From: Tejun Heo <tj@kernel.org>
To: Greg KH <gregkh@linuxfoundation.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
ebiederm@xmission.com, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] sysfs: move assignment to be under lock in sysfs_remove_dir()
Date: Wed, 30 Oct 2013 09:14:29 -0400 [thread overview]
Message-ID: <20131030131429.GA27632@htj.dyndns.org> (raw)
In-Reply-To: <20131029220939.GA23060@kroah.com>
Hey, guys.
On Tue, Oct 29, 2013 at 03:09:39PM -0700, Greg KH wrote:
> From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
>
> Linus noticed that the assignment of sd isn't protected by the lock in
> sysfs_remove_dir(), so move the assignment of the variable under the
> lock to be safe.
>
> Reported-by: Linus Torvalds <torvalds@linux-foundation.org>
> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> ---
>
> Tejun, any objection to this patch? You consolidated the locks back in
> 2007 on this function, and nothing has changed there since then, so odds
> are it's not a problem, but nice to be safe, right?
IIRC, it was a lock added to specifically address race between kobject
removal and someone else symlinking to it. In all other cases, the
rule is that the kobject owner is responsible for ensuring that
removal doesn't race against other sysfs operations on the kobject.
However, someone else linking to it didn't have any way to ensure that
kobj->sd won't be removed underneath it - it holds the target kobject
but that doesn't do anything to prevent the target's owner from
disassociating the kobject from its sysfs_dirent.
So, sysfs_assoc_lock is protecting against that specific scenario - it
guarantees that either kobj->sd is disassociated and symlinking sees
that or symlinking grabs sysfs_dirent's reference before
disassociation happens. It addresses the one exception case of the
general "kobject owner handles exclusion among operations" rule.
Moving "sd = kobj->sd" inside the spinlock doesn't make any difference
but what we really need is a comment explaining what that odd piece of
locking is about.
Thanks.
--
tejun
next prev parent reply other threads:[~2013-10-30 13:14 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-10-29 22:09 Greg KH
2013-10-30 0:39 ` Eric W. Biederman
2013-10-30 1:25 ` Linus Torvalds
2013-10-30 5:29 ` Eric W. Biederman
2013-10-30 13:28 ` Tejun Heo
2013-10-30 14:28 ` [PATCH driver-core-next] sysfs: rename sysfs_assoc_lock and explain what it's about Tejun Heo
2013-10-30 22:29 ` Eric W. Biederman
2013-10-31 17:11 ` Tejun Heo
2013-10-30 21:41 ` [PATCH] sysfs: move assignment to be under lock in sysfs_remove_dir() Eric W. Biederman
2013-10-30 22:00 ` Tejun Heo
2013-10-30 22:38 ` Greg KH
2013-10-30 13:14 ` Tejun Heo [this message]
2013-10-30 21:42 ` Eric W. Biederman
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=20131030131429.GA27632@htj.dyndns.org \
--to=tj@kernel.org \
--cc=ebiederm@xmission.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=torvalds@linux-foundation.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome