Skip to contentSkip to conversation

erofs: mark inodes without acls in erofs_read_inode()

PATCH Superseded Gao Xiang 2 participants 4 messages Jan 28 EROFS file system

lore
Share & tools
lore

Gao Xiang

author
#0 lore raw

PATCH 1/1 erofs: mark inodes without acls in erofs_read_inode()

Similar to commit 91ef18b567da ("ext4: mark inodes without acls in __ext4_iget()"), the ACL state won't be read when the file owner performs a lookup, and the RCU fast path for lookups won't work because the ACL state remains unknown.

If there are no extended attributes, or if the xattr filter indicates that no ACL xattr is present, call cache_no_acl() directly.

---
 fs/erofs/inode.c |  5 +++++
 fs/erofs/xattr.c | 20 ++++++++++++++++++++
 fs/erofs/xattr.h |  1 +
 3 files changed, 26 insertions(+)
fs/erofs/inode.c +5 -0
index bce98c845a18..2e02d4b466ce 100644
@@ -137,6 +137,11 @@ static int erofs_read_inode(struct inode *inode)
 		err = -EFSCORRUPTED;
 		goto err_out;
 	}
+
+	if (IS_ENABLED(CONFIG_EROFS_FS_POSIX_ACL) &&
+	    erofs_inode_has_noacl(inode, ptr, ofs))
+		cache_no_acl(inode);
+
 	switch (inode->i_mode & S_IFMT) {
 	case S_IFDIR:
 		vi->dot_omitted = (ifmt >> EROFS_I_DOT_OMITTED_BIT) & 1;
fs/erofs/xattr.c +20 -0
index 512b998bdfff..14d22adc1476 100644
@@ -574,4 +574,24 @@ struct posix_acl *erofs_get_acl(struct inode *inode, int type, bool rcu)
 	kfree(value);
 	return acl;
 }
+
+bool erofs_inode_has_noacl(struct inode *inode, void *kaddr, unsigned int ofs)
+{
+	static const unsigned int bitmask =
+		BIT(21) |	/* system.posix_acl_default */
+		BIT(30);	/* system.posix_acl_access */
+	struct erofs_sb_info *sbi = EROFS_I_SB(inode);
+	const struct erofs_xattr_ibody_header *ih = kaddr + ofs;
+
+	if (EROFS_I(inode)->xattr_isize < sizeof(*ih))
+		return true;
+
+	if (erofs_sb_has_xattr_filter(sbi) && !sbi->xattr_filter_reserved &&
+	    !check_add_overflow(ofs, sizeof(*ih), &ofs) &&
+	    ofs <= i_blocksize(inode)) {
+		if ((ih->h_name_filter & bitmask) == bitmask)
+			return true;
+	}
+	return false;
+}
 #endif
fs/erofs/xattr.h +1 -0
index 36f2667afc2d..a3ceefa1554d 100644
@@ -30,4 +30,5 @@ struct posix_acl *erofs_get_acl(struct inode *inode, int type, bool rcu);
 #define erofs_get_acl	(NULL)
 #endif
 
+bool erofs_inode_has_noacl(struct inode *inode, void *kaddr, unsigned int ofs);
 #endif
Signature · 1 line
2.43.5
Reviewed-by on v1 1/1
#1 lore raw

Hi, Xiang

Quoted 36 lines · Gao Xiang

Similar to commit 91ef18b567da ("ext4: mark inodes without acls in __ext4_iget()"), the ACL state won't be read when the file owner performs a lookup, and the RCU fast path for lookups won't work because the ACL state remains unknown.

If there are no extended attributes, or if the xattr filter indicates that no ACL xattr is present, call cache_no_acl() directly.

---
  fs/erofs/inode.c |  5 +++++
  fs/erofs/xattr.c | 20 ++++++++++++++++++++
  fs/erofs/xattr.h |  1 +
  3 files changed, 26 insertions(+)
fs/erofs/inode.c +5 -0
index bce98c845a18..2e02d4b466ce 100644
@@ -137,6 +137,11 @@ static int erofs_read_inode(struct inode *inode)
  		err = -EFSCORRUPTED;
  		goto err_out;
  	}
+
+	if (IS_ENABLED(CONFIG_EROFS_FS_POSIX_ACL) &&
+	    erofs_inode_has_noacl(inode, ptr, ofs))
+		cache_no_acl(inode);
+
  	switch (inode->i_mode & S_IFMT) {
  	case S_IFDIR:
  		vi->dot_omitted = (ifmt >> EROFS_I_DOT_OMITTED_BIT) & 1;
fs/erofs/xattr.c +0 -0
index 512b998bdfff..14d22adc1476 100644

fs/erofs/xattr.c struct posix_acl *erofs_get_acl(struct inode *inode, int type, bool rcu) · line 579

Quoted 6 lines
fs/erofs/xattr.c +3 -0
@@ -574,4 +574,24 @@ struct posix_acl *erofs_get_acl(struct inode *inode, int type, bool rcu)
  	kfree(value);
  	return acl;
  }
+
+bool erofs_inode_has_noacl(struct inode *inode, void *kaddr, unsigned int ofs)
+{

How about put the definition and declare of erofs_inode_has_noacl before the erofs_get_acl helper? Since it is no need to resolved the context conflicts for page sharing.

Otherwise it looks good to me:

Thanks,
Hongbo

Quoted 28 lines
fs/erofs/xattr.c +17 -0
+	static const unsigned int bitmask =
+		BIT(21) |	/* system.posix_acl_default */
+		BIT(30);	/* system.posix_acl_access */
+	struct erofs_sb_info *sbi = EROFS_I_SB(inode);
+	const struct erofs_xattr_ibody_header *ih = kaddr + ofs;
+
+	if (EROFS_I(inode)->xattr_isize < sizeof(*ih))
+		return true;
+
+	if (erofs_sb_has_xattr_filter(sbi) && !sbi->xattr_filter_reserved &&
+	    !check_add_overflow(ofs, sizeof(*ih), &ofs) &&
+	    ofs <= i_blocksize(inode)) {
+		if ((ih->h_name_filter & bitmask) == bitmask)
+			return true;
+	}
+	return false;
+}
  #endif
fs/erofs/xattr.h +1 -0
index 36f2667afc2d..a3ceefa1554d 100644
@@ -30,4 +30,5 @@ struct posix_acl *erofs_get_acl(struct inode *inode, int type, bool rcu);
  #define erofs_get_acl	(NULL)
  #endif
 
+bool erofs_inode_has_noacl(struct inode *inode, void *kaddr, unsigned int ofs);
  #endif
author
#2 lore raw
Quoted 39 lines · Hongbo Li

Hi, Xiang

Quoted 36 lines · Gao Xiang

Similar to commit 91ef18b567da ("ext4: mark inodes without acls in __ext4_iget()"), the ACL state won't be read when the file owner performs a lookup, and the RCU fast path for lookups won't work because the ACL state remains unknown.

If there are no extended attributes, or if the xattr filter indicates that no ACL xattr is present, call cache_no_acl() directly.

---

  fs/erofs/inode.c |  5 +++++
  fs/erofs/xattr.c | 20 ++++++++++++++++++++
  fs/erofs/xattr.h |  1 +
  3 files changed, 26 insertions(+)
fs/erofs/inode.c +5 -0
index bce98c845a18..2e02d4b466ce 100644
@@ -137,6 +137,11 @@ static int erofs_read_inode(struct inode *inode)
           err = -EFSCORRUPTED;
           goto err_out;
       }
+
+    if (IS_ENABLED(CONFIG_EROFS_FS_POSIX_ACL) &&
+        erofs_inode_has_noacl(inode, ptr, ofs))
+        cache_no_acl(inode);
+
       switch (inode->i_mode & S_IFMT) {

      case S_IFDIR:
          vi->dot_omitted = (ifmt >> EROFS_I_DOT_OMITTED_BIT) & 1;

fs/erofs/xattr.c +0 -0
index 512b998bdfff..14d22adc1476 100644
@@ -574,4 +574,24 @@ struct posix_acl *erofs_get_acl(struct inode *inode, int type, bool rcu)
Quoted 8 lines

fs/erofs/xattr.c struct posix_acl *erofs_get_acl(struct inode *inode, int type, bool rcu) · line 579

Quoted 6 lines
fs/erofs/xattr.c +3 -0
       kfree(value);
       return acl;
   }
+
+bool erofs_inode_has_noacl(struct inode *inode, void *kaddr, unsigned int ofs)
+{

How about put the definition and declare of erofs_inode_has_noacl before the erofs_get_acl helper? Since it is no need to resolved the context conflicts for page sharing.

I've resolved it manually.

Quoted 3 lines

Otherwise it looks good to me:

Thanks,
Gao Xiang

Quoted 3 lines

Thanks,
Hongbo

author
#3 lore raw

PATCH v2 1/1 erofs: mark inodes without acls in erofs_read_inode()

In reply to Gao Xiang

Similar to commit 91ef18b567da ("ext4: mark inodes without acls in __ext4_iget()"), the ACL state won't be read when the file owner performs a lookup, and the RCU fast path for lookups won't work because the ACL state remains unknown.

If there are no extended attributes, or if the xattr filter indicates that no ACL xattr is present, call cache_no_acl() directly.

---
v2:
- use le32_to_cpu for ih->h_name_filter.

 fs/erofs/inode.c |  5 +++++
 fs/erofs/xattr.c | 20 ++++++++++++++++++++
 fs/erofs/xattr.h |  1 +
 3 files changed, 26 insertions(+)
fs/erofs/inode.c +5 -0
index bce98c845a18..2e02d4b466ce 100644
@@ -137,6 +137,11 @@ static int erofs_read_inode(struct inode *inode)
 		err = -EFSCORRUPTED;
 		goto err_out;
 	}
+
+	if (IS_ENABLED(CONFIG_EROFS_FS_POSIX_ACL) &&
+	    erofs_inode_has_noacl(inode, ptr, ofs))
+		cache_no_acl(inode);
+
 	switch (inode->i_mode & S_IFMT) {
 	case S_IFDIR:
 		vi->dot_omitted = (ifmt >> EROFS_I_DOT_OMITTED_BIT) & 1;
fs/erofs/xattr.c +20 -0
index 512b998bdfff..14d22adc1476 100644
@@ -574,4 +574,24 @@ struct posix_acl *erofs_get_acl(struct inode *inode, int type, bool rcu)
 	kfree(value);
 	return acl;
 }
+
+bool erofs_inode_has_noacl(struct inode *inode, void *kaddr, unsigned int ofs)
+{
+	static const unsigned int bitmask =
+		BIT(21) |	/* system.posix_acl_default */
+		BIT(30);	/* system.posix_acl_access */
+	struct erofs_sb_info *sbi = EROFS_I_SB(inode);
+	const struct erofs_xattr_ibody_header *ih = kaddr + ofs;
+
+	if (EROFS_I(inode)->xattr_isize < sizeof(*ih))
+		return true;
+
+	if (erofs_sb_has_xattr_filter(sbi) && !sbi->xattr_filter_reserved &&
+	    !check_add_overflow(ofs, sizeof(*ih), &ofs) &&
+	    ofs <= i_blocksize(inode)) {
+		if ((le32_to_cpu(ih->h_name_filter) & bitmask) == bitmask)
+			return true;
+	}
+	return false;
+}
 #endif
fs/erofs/xattr.h +1 -0
index 36f2667afc2d..a3ceefa1554d 100644
@@ -30,4 +30,5 @@ struct posix_acl *erofs_get_acl(struct inode *inode, int type, bool rcu);
 #define erofs_get_acl	(NULL)
 #endif
 
+bool erofs_inode_has_noacl(struct inode *inode, void *kaddr, unsigned int ofs);
 #endif
Signature · 1 line
2.43.5