From patchwork Thu Mar 3 08:42:27 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marco Stornelli X-Patchwork-Id: 85246 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 50155B70B0 for ; Thu, 3 Mar 2011 19:47:59 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756485Ab1CCIrj (ORCPT ); Thu, 3 Mar 2011 03:47:39 -0500 Received: from mail-ww0-f44.google.com ([74.125.82.44]:45879 "EHLO mail-ww0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751133Ab1CCIri (ORCPT ); Thu, 3 Mar 2011 03:47:38 -0500 Received: by wwb22 with SMTP id 22so1076574wwb.1 for ; Thu, 03 Mar 2011 00:47:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:message-id:date:from:user-agent:mime-version:to :cc:subject:references:in-reply-to:content-type :content-transfer-encoding; bh=23Kfkt1+U4fNxc8kC7f/TUGxpbJ9PddNPv8HyKq4jnM=; b=Apg9JdER0PPw9P5DQA0dU6NZosddd8YcJ1uA78DhjhT/MpkKbiKwSRW1GX4XhCH/AH b2LWPz4cvUKKvcngRoOVC1dKPlrV7Pg9KBfJLiByICFaty/ETncidYENy9sISV83h3cz 48/FQHT3iLdhcixb2BWMrdjjJ/Vs+vpGk2HS8= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; b=Eco5Lpx+HMBTNCIWhf9yaEYPL69d+JW+PD7lQ1YhdclLzGEKQReSMcqvr2CcQtS7hN skXKSrbz99g0LoD5BjwA63X6asCjrtHz8lKs5vozTH6Gi3BI4+HY9njTkPhS1CnI2+t7 Y6s9hL6XL3M/DLwNEz2NaLHkuODXKH1ADRCPc= Received: by 10.216.13.194 with SMTP id b44mr593000web.68.1299142056461; Thu, 03 Mar 2011 00:47:36 -0800 (PST) Received: from [82.55.225.229] (host229-225-dynamic.55-82-r.retail.telecomitalia.it [82.55.225.229]) by mx.google.com with ESMTPS id t11sm448785wes.17.2011.03.03.00.47.33 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 03 Mar 2011 00:47:34 -0800 (PST) Message-ID: <4D6F5473.2070709@gmail.com> Date: Thu, 03 Mar 2011 09:42:27 +0100 From: Marco Stornelli User-Agent: Mozilla/5.0 (X11; U; Linux i686; it; rv:1.9.1.16) Gecko/20101125 SUSE/3.0.11 Thunderbird/3.0.11 MIME-Version: 1.0 To: Linux Kernel CC: linux-ext4@vger.kernel.org, linux-btrfs@vger.kernel.org, cluster-devel@redhat.com, xfs@oss.sgi.com, Linux FS Devel Subject: [PATCH v2] Check for immutable flag in fallocate path References: <4D6221B8.9040303@gmail.com> In-Reply-To: <4D6221B8.9040303@gmail.com> Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org From: Marco Stornelli 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. Signed-off-by: Marco Stornelli --- Patch is against 2.6.38-rc5 ChangeLog v2: Added the check for append-only file for XFS v1: First draft -- To unsubscribe from this list: send the line "unsubscribe linux-ext4" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html --- linux-2.6.38-rc5-orig/fs/ext4/extents.c 2011-02-16 04:23:45.000000000 +0100 +++ linux-2.6.38-rc5/fs/ext4/extents.c 2011-02-21 08:43:37.000000000 +0100 @@ -3670,6 +3670,12 @@ long ext4_fallocate(struct file *file, i */ credits = ext4_chunk_trans_blocks(inode, max_blocks); mutex_lock(&inode->i_mutex); + + if (IS_IMMUTABLE(inode)) { + mutex_unlock(&inode->i_mutex); + return -EPERM; + } + ret = inode_newsize_ok(inode, (len + offset)); if (ret) { mutex_unlock(&inode->i_mutex); --- linux-2.6.38-rc5-orig/fs/btrfs/file.c 2011-02-16 04:23:45.000000000 +0100 +++ linux-2.6.38-rc5/fs/btrfs/file.c 2011-02-21 08:55:58.000000000 +0100 @@ -1289,6 +1289,12 @@ static long btrfs_fallocate(struct file btrfs_wait_ordered_range(inode, alloc_start, alloc_end - alloc_start); mutex_lock(&inode->i_mutex); + + if (IS_IMMUTABLE(inode)) { + ret = -EPERM; + goto out; + } + ret = inode_newsize_ok(inode, alloc_end); if (ret) goto out; --- linux-2.6.38-rc5-orig/fs/gfs2/file.c 2011-02-16 04:23:45.000000000 +0100 +++ linux-2.6.38-rc5/fs/gfs2/file.c 2011-02-21 09:09:17.000000000 +0100 @@ -797,6 +797,11 @@ static long gfs2_fallocate(struct file * if (unlikely(error)) goto out_uninit; + if (IS_IMMUTABLE(inode)) { + error = -EPERM; + goto out_unlock; + } + if (!gfs2_write_alloc_required(ip, offset, len)) goto out_unlock; --- ./linux-2.6.38-rc5/fs/xfs/linux-2.6/xfs_file.c 2011-02-16 04:23:45.000000000 +0100 +++ ./linux-2.6.38-rc5/fs/xfs/linux-2.6/xfs_file.c 2011-03-03 09:25:32.000000000 +0100 @@ -906,8 +906,18 @@ xfs_file_fallocate( xfs_ilock(ip, XFS_IOLOCK_EXCL); - if (mode & FALLOC_FL_PUNCH_HOLE) + if (mode & FALLOC_FL_PUNCH_HOLE) { cmd = XFS_IOC_UNRESVSP; + if (IS_APPEND(inode)) { + error = -EPERM; + goto out_unlock; + } + } + + if (IS_IMMUTABLE(inode)) { + error = -EPERM; + goto out_unlock; + } /* check the new inode size is valid before allocating */ if (!(mode & FALLOC_FL_KEEP_SIZE) &&