From: Al Viro Subject: [RFC] F_SETLEASE mess Date: Fri, 5 Jul 2013 10:04:49 +0100 Message-ID: <20130705090449.GQ4165@ZenIV.linux.org.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: linux-fsdevel@vger.kernel.org, Linus Torvalds To: Jeff Layton Return-path: Received: from zeniv.linux.org.uk ([195.92.253.2]:49307 "EHLO ZenIV.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757219Ab3GEJEv (ORCPT ); Fri, 5 Jul 2013 05:04:51 -0400 Content-Disposition: inline Sender: linux-fsdevel-owner@vger.kernel.org List-ID: 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...