From: "J. Bruce Fields" <bfields@fieldses.org>
To: linux-fsdevel <linux-fsdevel@vger.kernel.org>
Cc: "David M. Richter" <richterd@citi.umich.edu>
Subject: [PATCH] VFS: fix a race in lease-breaking during truncate
Date: Fri, 6 Jul 2007 15:54:13 -0400 [thread overview]
Message-ID: <20070706195413.GC28887@fieldses.org> (raw)
From: David M. Richter <richterd@citi.umich.edu>
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 <richterd@citi.umich.edu>
Signed-off-by: "J. Bruce Fields" <bfields@citi.umich.edu>
---
fs/open.c | 16 +++++++++-------
1 files changed, 9 insertions(+), 7 deletions(-)
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.2.rc3
next reply other threads:[~2007-07-06 19:54 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-07-06 19:54 J. Bruce Fields [this message]
-- strict thread matches above, loose matches on Subject: below --
2007-07-14 11:03 [PATCH] VFS: fix a race in lease-breaking during truncate J. 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=20070706195413.GC28887@fieldses.org \
--to=bfields@fieldses.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=richterd@citi.umich.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.