From mboxrd@z Thu Jan 1 00:00:00 1970 From: "J. Bruce Fields" Subject: [PATCH] VFS: fix a race in lease-breaking during truncate Date: Sat, 14 Jul 2007 07:03:57 -0400 Message-ID: <20070714110357.GA11089@fieldses.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: linux-fsdevel@vger.kernel.org, richterd@citi.umich.edu To: Andrew Morton Return-path: Received: from mail.fieldses.org ([66.93.2.214]:35076 "EHLO fieldses.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756244AbXGNLD6 (ORCPT ); Sat, 14 Jul 2007 07:03:58 -0400 Content-Disposition: inline Sender: linux-fsdevel-owner@vger.kernel.org List-Id: linux-fsdevel.vger.kernel.org From: david m. richter It is possible that another process could acquire a new file lease right after break_lease() is called during a truncate, but before lease-granting is disabled by the subsequent get_write_access(). Merely switching the order of the break_lease() and get_write_access() calls prevents this race. Signed-off-by: David M. Richter Signed-off-by: "J. Bruce Fields" --- fs/open.c | 16 +++++++++------- 1 files changed, 9 insertions(+), 7 deletions(-) I posted this patch to linux-fsdevel last week and nobody said anything. Thus, it is perfect. --b. diff --git a/fs/open.c b/fs/open.c index 0d515d1..c32aba0 100644 --- a/fs/open.c +++ b/fs/open.c @@ -255,24 +255,26 @@ static long do_sys_truncate(const char __user * path, loff_t length) if (IS_IMMUTABLE(inode) || IS_APPEND(inode)) goto dput_and_out; - /* - * Make sure that there are no leases. - */ - error = break_lease(inode, FMODE_WRITE); + error = get_write_access(inode); if (error) goto dput_and_out; - error = get_write_access(inode); + /* + * Make sure that there are no leases. get_write_access() protects + * against the truncate racing with a lease-granting setlease(). + */ + error = break_lease(inode, FMODE_WRITE); if (error) - goto dput_and_out; + goto put_write_and_out; error = locks_verify_truncate(inode, NULL, length); if (!error) { DQUOT_INIT(inode); error = do_truncate(nd.dentry, length, 0, NULL); } - put_write_access(inode); +put_write_and_out: + put_write_access(inode); dput_and_out: path_release(&nd); out: -- 1.5.3.rc0.63.gc956