Skip to contentSkip to conversation

btrfs: btrfs_permission's RO check shouldn't apply to device nodes

PATCH New Jeff Mahoney 1 participant 1 message Aug 15, 2011 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 btrfs: btrfs_permission's RO check shouldn't apply to device nodes

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.

---
 fs/btrfs/inode.c |   12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
fs/btrfs/inode.c +8 -4
@@ -7354,11 +7354,15 @@ static int btrfs_set_page_dirty(struct p
 static int btrfs_permission(struct inode *inode, int mask)
 {
 	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);
 }
 

Jeff Mahoney
SUSE Labs