xfs
[Top] [All Lists]

Re: [PATCH] Check for immutable flag in fallocate path

To: "Ted Ts'o" <tytso@xxxxxxx>, Marco Stornelli <marco.stornelli@xxxxxxxxx>, Christoph Hellwig <hch@xxxxxxxxxxxxx>, Linux Kernel <linux-kernel@xxxxxxxxxxxxxxx>, cluster-devel@xxxxxxxxxx, Linux FS Devel <linux-fsdevel@xxxxxxxxxxxxxxx>, linux-ext4@xxxxxxxxxxxxxxx, linux-btrfs@xxxxxxxxxxxxxxx, xfs@xxxxxxxxxxx
Subject: Re: [PATCH] Check for immutable flag in fallocate path
From: Marco Stornelli <marco.stornelli@xxxxxxxxx>
Date: Mon, 28 Feb 2011 08:53:31 +0100
Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:date :message-id:subject:from:to:content-type:content-transfer-encoding; bh=BKsMiYBK83IrnJzBTpd7cXl0ptAgC21oNLDQxhMfhO8=; b=ubuUMjR1H3kizMJfoJ2Jvgom9WTaw/Nx1HgvU1YAFmFBvVOAkmctZwildxZltFSZs2 Nf3VC3qqhZQ8Jt/ewzUCoEOYbhdgCQdKkHwgM68vmQ5Bjnocb4RvKZNFbkpz9FJioaX4 6uUAEdoCs6I87RR+PjnMPMQ+SCzkoyrg1YjSg=
Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=jkUjjC73O4U3DTNNK0kTKbrNH4LvWdWj/BtwzbI+FqBWyT9Gn8goddPhtnuFaYBAun l+ZK78PkcE6RwaUYRqMOpznfw7tQvc2FIBFFHdCpaRTrQXCnKc2IrMMB0497IvO3lF1P +7ZIdu5woatQfUvDxQJTJeCM0IHo2ZdIz8rUU=
In-reply-to: <20110227224940.GL2924@xxxxxxxxx>
References: <4D6221B8.9040303@xxxxxxxxx> <20110221124635.GA5525@xxxxxxxxxxxxx> <AANLkTi=bJBeR0m3xuGX_9YZPqRFuMY=bKoxZEWJt37=M@xxxxxxxxxxxxxx> <20110227224940.GL2924@xxxxxxxxx>
2011/2/27 Ted Ts'o <tytso@xxxxxxx>:
> On Mon, Feb 21, 2011 at 05:50:21PM +0100, Marco Stornelli wrote:
>> 2011/2/21 Christoph Hellwig <hch@xxxxxxxxxxxxx>:
>> > On Mon, Feb 21, 2011 at 09:26:32AM +0100, Marco Stornelli wrote:
>> >> From: Marco Stornelli <marco.stornelli@xxxxxxxxx>
>> >>
>> >> All fs must check for the immutable flag in their fallocate callback.
>> >> It's possible to have a race condition in this scenario: an application
>> >> open a file in read/write and it does something, meanwhile root set the
>> >> immutable flag on the file, the application at that point can call
>> >> fallocate with success. Only Ocfs2 check for the immutable flag at the
>> >> moment.
>> >
>> > Please add the check in fs/open.c:do_fallocate() so that it covers all
>> > filesystems.
>> >
>> >
>>
>> The check should be done after the fs got the inode mutex lock.
>
> Why?  None of the other places which check the IMMUTABLE flag do so
> under the inode mutex lock.  Yes, it's true that we're not properly
> doing proper locking when updating i_flags from the ioctl (this is
> true for all file systems), but this has been true for quite some
> time, and using a mutex to protect bit set/clear/test operations would
> be like using a sledgehammer to kill a fly.
>
> A proper fix if we want to be completely correct about updates to
> i_flags would involve using test_bit, set_bit, and clear_bit, which is
> guaranteed to be atomic.  This is how we update the
> ext4_inode_info->i_flags (which is different from inode->i_flags) (see
> the definition and use of EXT4_INODE_BIT_FNS in fs/ext4/ext4.h).
>
> At some point, it would be good to fix how we set/get i_flags values,
> but that's independent of the change that's being discussed here.
>
>                                                  - Ted
>

I was thinking to the possible race with setattr callback.

Marco

<Prev in Thread] Current Thread [Next in Thread>