]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
btrfs: btrfs_permission's RO check shouldn't apply to device nodes
authorJeff Mahoney <jeffm@suse.de>
Mon, 15 Aug 2011 17:27:21 +0000 (17:27 +0000)
committerChris Mason <chris.mason@oracle.com>
Wed, 16 Nov 2011 00:56:33 +0000 (19:56 -0500)
This patch tightens the read-only access checks in btrfs_permission to
 match the constraints in inode_permission. Currently, even though the
 device node itself will be unmodified, read-write access to device nodes
 is denied to when the device node resides on a read-only subvolume or a
 is a file that has been marked read-only by the btrfs conversion utility.

 With this patch applied, the check only affects regular files,
 directories, and symlinks. It also restructures the code a bit so that
 we don't duplicate the MAY_WRITE check for both tests.

Signed-off-by: Jeff Mahoney <jeffm@suse.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
(cherry picked from commit cb6db4e57632ba8589cc2f9fe1d0aa9116b87ab8 with conflicts)

fs/btrfs/inode.c

index b3c39365f039fbd5229aecb1b15eb0010ce84a0b..36cbdaecaffdfe324c5ca22cf220a77ea14f82bf 100644 (file)
@@ -7321,11 +7321,15 @@ static int btrfs_set_page_dirty(struct page *page)
 static int btrfs_permission(struct inode *inode, int mask, unsigned int flags)
 {
        struct btrfs_root *root = BTRFS_I(inode)->root;
+       umode_t mode = inode->i_mode;
 
-       if (btrfs_root_readonly(root) && (mask & MAY_WRITE))
-               return -EROFS;
-       if ((BTRFS_I(inode)->flags & BTRFS_INODE_READONLY) && (mask & MAY_WRITE))
-               return -EACCES;
+       if (mask & MAY_WRITE &&
+           (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode))) {
+               if (btrfs_root_readonly(root))
+                       return -EROFS;
+               if (BTRFS_I(inode)->flags & BTRFS_INODE_READONLY)
+                       return -EACCES;
+       }
        return generic_permission(inode, mask, flags, btrfs_check_acl);
 }