linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff Layton <jlayton@redhat.com>
To: Al Viro <viro@ZenIV.linux.org.uk>
Cc: linux-fsdevel@vger.kernel.org,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Bruce Fields <bfields@fieldses.org>
Subject: Re: [RFC] F_SETLEASE mess
Date: Fri, 05 Jul 2013 08:08:44 -0400	[thread overview]
Message-ID: <1373026124.4269.2.camel@tlielax.poochiereds.net> (raw)
In-Reply-To: <1373021495.2216.25.camel@tlielax.poochiereds.net>

On Fri, 2013-07-05 at 06:51 -0400, Jeff Layton wrote:
> On Fri, 2013-07-05 at 10:04 +0100, Al Viro wrote:
> > 	generic_add_lease() with F_WRLCK checks for other openers
> > in a very crude way - it wants no extra references to dentry (thus
> > excluding other struct file pointing to it) *and* no extra references
> > to in-core inode, excluding openers of other links.  It fails with
> > EAGAIN if those conditions are not met.
> > 
> > 	The way it deals with another open(2) racing with it (i.e.
> > managing to squeeze between the check and locks_insert_lock()) is
> > theoretically racy; do_dentry_open() would spin on ->i_lock, all
> > right, but... only if there already is something in inode->i_flock.
> > If this is the first lease/lock being set, break_lease() will do
> > nothing, rather than call __break_lease() and spin there.
> > 
> > 	It's _very_ hard to hit; we are holding ->i_lock and thus can't
> > be preempted, so open(2) would have to get *everything* (pathname
> > lookup, etc.) done in a very narrow window.  So I don't believe it's
> > exploitable, but it really smells bad.  The check is extremely crude
> > and if nothing else it's a DoS fodder - a luser that keeps hitting that
> > file with stat(2) can prevent F_SETLEASE from succeeding, even though
> > he wouldn't be able to open the damn thing at all...
> 
> (cc'ing Bruce since he's been poking around in this area recently and
> might have ideas...)
> 
> I see what you mean. I haven't looked closely at this yet, and I'm on
> holiday today, but I'll plan to give this more scrutiny when I get back
> next week. Giving it an initial look though...
> 
> We already hold an extra reference to the dentry via the path_get in
> do_dentry_open. So is this race possible if the two tasks are working on
> the same dentry? Or does it require a hardlinked inode?
> 
> If it's not possible to race on the same dentry, then one possible fix
> would be to go ahead and do an extra igrab(inode) in do_dentry_open
> before calling break_lease. I'm not particularly fond of that since it
> means taking the i_lock an extra time, but it looks like it would close
> the race.
> 


Hrm. I think we'd also need to couple that with an extra check for a
high refcount after doing locks_insert_lock in generic_add_lease, and
then call locks_delete_lock and return -EAGAIN if the counts have
changed.

-- 
Jeff Layton <jlayton@redhat.com>


  reply	other threads:[~2013-07-05 12:08 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-05  9:04 [RFC] F_SETLEASE mess Al Viro
2013-07-05 10:51 ` Jeff Layton
2013-07-05 12:08   ` Jeff Layton [this message]
2013-07-05 16:25     ` Bruce Fields
2013-07-05 21:46       ` Jeff Layton
2013-07-08 14:17         ` Bruce Fields
2013-07-08 14:33           ` Jeff Layton
2013-07-08 18:10           ` Myklebust, Trond
2013-07-08 18:53             ` Bruce Fields
2013-07-08 19:21               ` Myklebust, Trond
2013-07-08 19:34                 ` Bruce Fields
2013-07-08 20:14                   ` Myklebust, Trond
2013-07-08 21:17                     ` Bruce Fields
2013-07-08 22:25                       ` Myklebust, Trond
2013-07-08 23:19                         ` Bruce Fields

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=1373026124.4269.2.camel@tlielax.poochiereds.net \
    --to=jlayton@redhat.com \
    --cc=bfields@fieldses.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=torvalds@linux-foundation.org \
    --cc=viro@ZenIV.linux.org.uk \
    /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;
as well as URLs for NNTP newsgroup(s).