From: Jan Kara <jack@suse.cz>
To: Djalal Harouni <tixxdz@opendz.org>
Cc: Jan Kara <jack@suse.cz>,
Andrew Morton <akpm@linux-foundation.org>,
Andreas Dilger <adilger.kernel@dilger.ca>,
Theodore Ts'o <tytso@mit.edu>,
Yongqiang Yang <xiaoqiangnk@gmail.com>,
linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org,
Al Viro <viro@zeniv.linux.org.uk>
Subject: Re: [PATCH] fs/ext{3,4}: fix potential race when setversion ioctl updates inode
Date: Tue, 3 Jan 2012 13:46:24 +0100 [thread overview]
Message-ID: <20120103124624.GB31457@quack.suse.cz> (raw)
In-Reply-To: <20120103013152.GA26455@dztty>
Hello,
On Tue 03-01-12 02:31:52, Djalal Harouni wrote:
>
> The EXT{3,4}_IOC_SETVERSION ioctl() updates the inode without i_mutex,
> this can lead to a race with the other operations that update the same
> inode.
>
> Patch tested.
Thanks for the patch but I don't quite understand the problem.
i_generation is set when:
a) inode is loaded from disk
b) inode is allocated
c) in SETVERSION ioctl
The only thing that can race here seems to be c) against c) and that is
racy with i_mutex as well. So what problems do you exactly observe without
the patch?
Honza
> Signed-off-by: Djalal Harouni <tixxdz@opendz.org>
> ---
> fs/ext3/ioctl.c | 6 +++++-
> fs/ext4/ioctl.c | 6 +++++-
> 2 files changed, 10 insertions(+), 2 deletions(-)
>
> diff --git a/fs/ext3/ioctl.c b/fs/ext3/ioctl.c
> index ba1b54e..e7b2ed9 100644
> --- a/fs/ext3/ioctl.c
> +++ b/fs/ext3/ioctl.c
> @@ -134,10 +134,11 @@ flags_out:
> goto setversion_out;
> }
>
> + mutex_lock(&inode->i_mutex);
> handle = ext3_journal_start(inode, 1);
> if (IS_ERR(handle)) {
> err = PTR_ERR(handle);
> - goto setversion_out;
> + goto unlock_out;
> }
> err = ext3_reserve_inode_write(handle, inode, &iloc);
> if (err == 0) {
> @@ -146,6 +147,9 @@ flags_out:
> err = ext3_mark_iloc_dirty(handle, inode, &iloc);
> }
> ext3_journal_stop(handle);
> +
> +unlock_out:
> + mutex_unlock(&inode->i_mutex);
> setversion_out:
> mnt_drop_write(filp->f_path.mnt);
> return err;
> diff --git a/fs/ext4/ioctl.c b/fs/ext4/ioctl.c
> index a567968..46a8de6 100644
> --- a/fs/ext4/ioctl.c
> +++ b/fs/ext4/ioctl.c
> @@ -158,10 +158,11 @@ flags_out:
> goto setversion_out;
> }
>
> + mutex_lock(&inode->i_mutex);
> handle = ext4_journal_start(inode, 1);
> if (IS_ERR(handle)) {
> err = PTR_ERR(handle);
> - goto setversion_out;
> + goto unlock_out;
> }
> err = ext4_reserve_inode_write(handle, inode, &iloc);
> if (err == 0) {
> @@ -170,6 +171,9 @@ flags_out:
> err = ext4_mark_iloc_dirty(handle, inode, &iloc);
> }
> ext4_journal_stop(handle);
> +
> +unlock_out:
> + mutex_unlock(&inode->i_mutex);
> setversion_out:
> mnt_drop_write(filp->f_path.mnt);
> return err;
> --
> 1.7.1
--
Jan Kara <jack@suse.cz>
SUSE Labs, CR
next prev parent reply other threads:[~2012-01-03 12:46 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-01-03 1:31 [PATCH] fs/ext{3,4}: fix potential race when setversion ioctl updates inode Djalal Harouni
2012-01-03 12:46 ` Jan Kara [this message]
2012-01-03 23:14 ` Djalal Harouni
2012-01-04 17:34 ` Jan Kara
2012-01-04 17:46 ` Jan Kara
2012-01-04 23:15 ` Andreas Dilger
2012-01-04 23:32 ` Jan Kara
2012-01-04 23:56 ` Andreas Dilger
2012-01-05 0:40 ` Djalal Harouni
2012-01-05 11:42 ` Jan Kara
2012-01-06 1:00 ` Djalal Harouni
2012-01-09 15:03 ` Jan Kara
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=20120103124624.GB31457@quack.suse.cz \
--to=jack@suse.cz \
--cc=adilger.kernel@dilger.ca \
--cc=akpm@linux-foundation.org \
--cc=linux-ext4@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=tixxdz@opendz.org \
--cc=tytso@mit.edu \
--cc=viro@zeniv.linux.org.uk \
--cc=xiaoqiangnk@gmail.com \
/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).