Skip to contentSkip to conversation

ubifs: implement POSIX Access Control Lists (ACLs)

PATCH In review Pascal Eberhard 4 participants 9 messages Oct 9, 2016 – Oct 20, 2016

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ubifs: implement POSIX Access Control Lists (ACLs)

This patch implements POSIX Access Control Lists (ACLs) in UBIFS. It uses posix_acl_(access|default)_xattr_handler ACL generic handlers as xattr handlers are now used in UBIFS.

---
 fs/ubifs/Kconfig  |  13 +++++
 fs/ubifs/Makefile |   1 +
 fs/ubifs/acl.c    | 143 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 fs/ubifs/dir.c    |  22 +++++++++
 fs/ubifs/file.c   |   9 ++++
 fs/ubifs/super.c  |  15 ++++++
 fs/ubifs/ubifs.h  |  18 +++++++
 fs/ubifs/xattr.c  |  11 +++--
 8 files changed, 229 insertions(+), 3 deletions(-)
 create mode 100644 fs/ubifs/acl.c
fs/ubifs/Kconfig +13 -0
index 7ff7712..39119e5 100644
@@ -50,3 +50,16 @@ config UBIFS_ATIME_SUPPORT
 	  strictatime is the "heavy", relatime is "lighter", etc.
 
 	  If unsure, say 'N'
+
+config UBIFS_FS_POSIX_ACL
+	bool "UBIFS POSIX Access Control Lists"
+	depends on UBIFS_FS
+	select FS_POSIX_ACL
+	help
+	  POSIX Access Control Lists (ACLs) support permissions for users and
+	  groups beyond the owner/group/world scheme.
+
+	  To learn more about Access Control Lists, visit the POSIX ACLs for
+	  Linux website <http://acl.bestbits.at/>.
+
+	  If you don't know what Access Control Lists are, say N
fs/ubifs/Makefile +1 -0
index c54a243..af7a83f 100644
@@ -5,3 +5,4 @@ ubifs-y += tnc.o master.o scan.o replay.o log.o commit.o gc.o orphan.o
 ubifs-y += budget.o find.o tnc_commit.o compress.o lpt.o lprops.o
 ubifs-y += recovery.o ioctl.o lpt_commit.o tnc_misc.o xattr.o debug.o
 ubifs-y += misc.o
+ubifs-$(CONFIG_UBIFS_FS_POSIX_ACL) += acl.o
\ No newline at end of file
fs/ubifs/acl.c new file +143 -0

143 lines not on this page · raw message

fs/ubifs/dir.c +22 -0
index ccd9128..a2e5609 100644
@@ -270,6 +270,10 @@ static int ubifs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
 		goto out_budg;
 	}
 
+	err = ubifs_init_acl(dir, inode);
+	if (err)
+		goto out_inode;
+
 	err = ubifs_init_security(dir, inode, &dentry->d_name);
 	if (err)
 		goto out_inode;
@@ -341,6 +345,10 @@ static int do_tmpfile(struct inode *dir, struct dentry *dentry,
 		ubifs_assert(inode->i_op == &ubifs_file_inode_operations);
 	}
 
+	err = ubifs_init_acl(dir, inode);
+	if (err)
+		goto out_inode;
+
 	err = ubifs_init_security(dir, inode, &dentry->d_name);
 	if (err)
 		goto out_inode;
@@ -821,6 +829,10 @@ static int ubifs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
 		goto out_budg;
 	}
 
+	err = ubifs_init_acl(dir, inode);
+	if (err)
+		goto out_inode;
+
 	err = ubifs_init_security(dir, inode, &dentry->d_name);
 	if (err)
 		goto out_inode;
@@ -903,6 +915,10 @@ static int ubifs_mknod(struct inode *dir, struct dentry *dentry,
 	ui->data = dev;
 	ui->data_len = devlen;
 
+	err = ubifs_init_acl(dir, inode);
+	if (err)
+		goto out_inode;
+
 	err = ubifs_init_security(dir, inode, &dentry->d_name);
 	if (err)
 		goto out_inode;
@@ -985,6 +1001,10 @@ static int ubifs_symlink(struct inode *dir, struct dentry *dentry,
 	ui->data_len = len;
 	inode->i_size = ubifs_inode(inode)->ui_size = len;
 
+	err = ubifs_init_acl(dir, inode);
+	if (err)
+		goto out_inode;
+
 	err = ubifs_init_security(dir, inode, &dentry->d_name);
 	if (err)
 		goto out_inode;
@@ -1395,6 +1415,8 @@ const struct inode_operations ubifs_dir_inode_operations = {
 	.update_time = ubifs_update_time,
 #endif
 	.tmpfile     = ubifs_tmpfile,
+	.get_acl     = ubifs_get_acl,
+	.set_acl     = ubifs_set_acl,
 };
 
 const struct file_operations ubifs_dir_operations = {
fs/ubifs/file.c +9 -0
index 4ed270b..17f6098 100644
@@ -53,6 +53,7 @@
 #include <linux/mount.h>
 #include <linux/slab.h>
 #include <linux/migrate.h>
+#include <linux/posix_acl.h>
 
 static int read_block(struct inode *inode, void *addr, unsigned int block,
 		      struct ubifs_data_node *dn)
@@ -1251,6 +1252,10 @@ static int do_setattr(struct ubifs_info *c, struct inode *inode,
 		ubifs_release_budget(c, &req);
 	if (IS_SYNC(inode))
 		err = inode->i_sb->s_op->write_inode(inode, NULL);
+
+	if (!err && (attr->ia_valid & ATTR_MODE))
+		err = posix_acl_chmod(inode, inode->i_mode);
+
 	return err;
 }
 
@@ -1628,6 +1633,8 @@ const struct inode_operations ubifs_file_inode_operations = {
 #ifdef CONFIG_UBIFS_ATIME_SUPPORT
 	.update_time = ubifs_update_time,
 #endif
+	.get_acl     = ubifs_get_acl,
+	.set_acl     = ubifs_set_acl,
 };
 
 const struct inode_operations ubifs_symlink_inode_operations = {
@@ -1642,6 +1649,8 @@ const struct inode_operations ubifs_symlink_inode_operations = {
 #ifdef CONFIG_UBIFS_ATIME_SUPPORT
 	.update_time = ubifs_update_time,
 #endif
+	.get_acl     = ubifs_get_acl,
+	.set_acl     = ubifs_set_acl,
 };
 
 const struct file_operations ubifs_file_operations = {
fs/ubifs/super.c +15 -0
index 4ec0510..8239dfd 100644
@@ -444,6 +444,9 @@ static int ubifs_show_options(struct seq_file *s, struct dentry *root)
 			   ubifs_compr_name(c->mount_opts.compr_type));
 	}
 
+	if (c->vfs_sb->s_flags & MS_POSIXACL)
+		seq_puts(s, ",acl");
+
 	return 0;
 }
 
@@ -929,6 +932,8 @@ enum {
 	Opt_chk_data_crc,
 	Opt_no_chk_data_crc,
 	Opt_override_compr,
+	Opt_acl,
+	Opt_noacl,
 	Opt_err,
 };
 
@@ -940,6 +945,8 @@ static const match_table_t tokens = {
 	{Opt_chk_data_crc, "chk_data_crc"},
 	{Opt_no_chk_data_crc, "no_chk_data_crc"},
 	{Opt_override_compr, "compr=%s"},
+	{Opt_acl, "acl"},
+	{Opt_noacl, "noacl"},
 	{Opt_err, NULL},
 };
 
@@ -1040,6 +1047,14 @@ static int ubifs_parse_options(struct ubifs_info *c, char *options,
 			c->default_compr = c->mount_opts.compr_type;
 			break;
 		}
+#ifdef CONFIG_UBIFS_FS_POSIX_ACL
+		case Opt_acl:
+			c->vfs_sb->s_flags |= MS_POSIXACL;
+			break;
+		case Opt_noacl:
+			c->vfs_sb->s_flags &= ~MS_POSIXACL;
+			break;
+#endif
 		default:
 		{
 			unsigned long flag;
fs/ubifs/ubifs.h +18 -0
index 096035e..7935449 100644
@@ -1743,6 +1743,24 @@ extern const struct xattr_handler *ubifs_xattr_handlers[];
 ssize_t ubifs_listxattr(struct dentry *dentry, char *buffer, size_t size);
 int ubifs_init_security(struct inode *dentry, struct inode *inode,
 			const struct qstr *qstr);
+ssize_t __ubifs_getxattr(struct inode *host, const char *name,
+				void *buf, size_t size);
+int __ubifs_setxattr(struct inode *host, const char *name,
+			    const void *value, size_t size, int flags);
+
+/* acl.c */
+#ifdef CONFIG_UBIFS_FS_POSIX_ACL
+int ubifs_init_acl(struct inode *dir, struct inode *inode);
+int ubifs_set_acl(struct inode *inode, struct posix_acl *acl, int type);
+struct posix_acl *ubifs_get_acl(struct inode *inode, int type);
+#else
+static inline int ubifs_init_acl(struct inode *inode, struct inode *dir)
+{
+	return 0;
+}
+#define ubifs_get_acl NULL
+#define ubifs_set_acl NULL
+#endif
 
 /* super.c */
 struct inode *ubifs_iget(struct super_block *sb, unsigned long inum);
fs/ubifs/xattr.c +8 -3
index 6c2f4d4..0a596a1 100644
@@ -52,13 +52,14 @@
  * in the VFS inode cache. The xentries are cached in the LNC cache (see
  * tnc.c).
  *
- * ACL support is not implemented.
+ * ACL support is now implemented.
  */
 
 #include "ubifs.h"
 #include <linux/fs.h>
 #include <linux/slab.h>
 #include <linux/xattr.h>
+#include <linux/posix_acl_xattr.h>
 
 /*
  * Limit the number of extended attributes per inode so that the total size
@@ -268,7 +269,7 @@ static struct inode *iget_xattr(struct ubifs_info *c, ino_t inum)
 	return ERR_PTR(-EINVAL);
 }
 
-static int __ubifs_setxattr(struct inode *host, const char *name,
+int __ubifs_setxattr(struct inode *host, const char *name,
 			    const void *value, size_t size, int flags)
 {
 	struct inode *inode;
@@ -328,7 +329,7 @@ out_free:
 	return err;
 }
 
-static ssize_t __ubifs_getxattr(struct inode *host, const char *name,
+ssize_t __ubifs_getxattr(struct inode *host, const char *name,
 				void *buf, size_t size)
 {
 	struct inode *inode;
@@ -619,5 +620,9 @@ const struct xattr_handler *ubifs_xattr_handlers[] = {
 	&ubifs_user_xattr_handler,
 	&ubifs_trusted_xattr_handler,
 	&ubifs_security_xattr_handler,
+#ifdef CONFIG_UBIFS_FS_POSIX_ACL
+	&posix_acl_access_xattr_handler,
+	&posix_acl_default_xattr_handler,
+#endif
 	NULL
 };
Signature · 1 line
2.7.4
#1 lore raw

Hi,

Quoted 1 line · Pascal Eberhard

This patch implements POSIX Access Control Lists (ACLs) in UBIFS.

The history of this patch might be of interest:
- I am running UBIFS with ACL for 2 years with kernel 3.2. The goal now is to -finally- get in sync with mainline.
APIs evolved a lot since 3.2, so porting this initial code to mainline did not really make sense as 80% of the code is now implemented in a generic manner.
- As well, I was pleased to see Sheng Yong patch proposal in 2015 in ML archives, but it seems it has not been finalized.

So this work is based on actual btrfs implementation and 'inspired' from Sheng Yong proposal, related discussions, as well as my 3.2 initial code.

This patch has been tested with:
- LTP fs/acl/tacl_xattr.sh (modified version),
- LTP fs/acls/acl_test01 (modified version),
- an ACL test suite made during initial 3.2 development.

Best regards,

Pascal

#2 lore raw
In reply to Pascal Eberhard

Pascal,

Quoted 3 lines · Pascal Eberhard

This patch implements POSIX Access Control Lists (ACLs) in UBIFS. It uses posix_acl_(access|default)_xattr_handler ACL generic handlers as xattr handlers are now used in UBIFS.

Cool! :)
CC'ing Andreas, maybe he also has comments.

Quoted 55 lines
---
 fs/ubifs/Kconfig  |  13 +++++
 fs/ubifs/Makefile |   1 +
 fs/ubifs/acl.c    | 143 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 fs/ubifs/dir.c    |  22 +++++++++
 fs/ubifs/file.c   |   9 ++++
 fs/ubifs/super.c  |  15 ++++++
 fs/ubifs/ubifs.h  |  18 +++++++
 fs/ubifs/xattr.c  |  11 +++--
 8 files changed, 229 insertions(+), 3 deletions(-)
 create mode 100644 fs/ubifs/acl.c
fs/ubifs/Kconfig +13 -0
index 7ff7712..39119e5 100644
@@ -50,3 +50,16 @@ config UBIFS_ATIME_SUPPORT
 	  strictatime is the "heavy", relatime is "lighter", etc.
 
 	  If unsure, say 'N'
+
+config UBIFS_FS_POSIX_ACL
+	bool "UBIFS POSIX Access Control Lists"
+	depends on UBIFS_FS
+	select FS_POSIX_ACL
+	help
+	  POSIX Access Control Lists (ACLs) support permissions for users and
+	  groups beyond the owner/group/world scheme.
+
+	  To learn more about Access Control Lists, visit the POSIX ACLs for
+	  Linux website <http://acl.bestbits.at/>.
+
+	  If you don't know what Access Control Lists are, say N
fs/ubifs/Makefile +1 -0
index c54a243..af7a83f 100644
@@ -5,3 +5,4 @@ ubifs-y += tnc.o master.o scan.o replay.o log.o commit.o gc.o orphan.o
 ubifs-y += budget.o find.o tnc_commit.o compress.o lpt.o lprops.o
 ubifs-y += recovery.o ioctl.o lpt_commit.o tnc_misc.o xattr.o debug.o
 ubifs-y += misc.o
+ubifs-$(CONFIG_UBIFS_FS_POSIX_ACL) += acl.o
\ No newline at end of file
fs/ubifs/acl.c new file +5 -0
new file mode 100644
index 0000000..a4d4734
@@ -0,0 +1,143 @@
+/*
+ * This file is part of UBIFS.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published by

fs/ubifs/acl.c line 15

Quoted 10 lines
fs/ubifs/acl.c new file +10 -0
+ * the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ */
+
+#include <linux/fs.h>

ubifs.h includes this already.

fs/ubifs/acl.c line 16

Quoted 1 line
fs/ubifs/acl.c new file +1 -0
+#include <linux/xattr.h>

Ditto.

Quoted 87 lines
fs/ubifs/acl.c new file +87 -0
+#include <linux/posix_acl_xattr.h>
+
+#include "ubifs.h"
+
+struct posix_acl *ubifs_get_acl(struct inode *inode, int type)
+{
+	int size;
+	const char *name;
+	char *value = NULL;
+	struct posix_acl *acl;
+
+	switch (type) {
+	case ACL_TYPE_ACCESS:
+		name = XATTR_NAME_POSIX_ACL_ACCESS;
+		break;
+	case ACL_TYPE_DEFAULT:
+		name = XATTR_NAME_POSIX_ACL_DEFAULT;
+		break;
+	default:
+		return ERR_PTR(-EINVAL);
+	}
+
+	size = __ubifs_getxattr(inode, name, NULL, 0);
+	if (size > 0) {
+		value = kzalloc(size, GFP_KERNEL);
+		if (!value)
+			return ERR_PTR(-ENOMEM);
+		size = __ubifs_getxattr(inode, name, value, size);
+	}
+	if (size > 0)
+		acl = posix_acl_from_xattr(&init_user_ns, value, size);
+	else if (size == -ERANGE || size == -ENODATA || size == 0)
+		acl = NULL;
+	else
+		acl = ERR_PTR(size);
+
+	kfree(value);
+	if (!IS_ERR(acl))
+		set_cached_acl(inode, type, acl);
+
+	return acl;
+}
+
+int ubifs_set_acl(struct inode *inode, struct posix_acl *acl, int type)
+{
+	int ret;
+	int size = 0;
+	const char *name;
+	char *value = NULL;
+	int flags = 0;
+
+	switch (type) {
+	case ACL_TYPE_ACCESS:
+		name = XATTR_NAME_POSIX_ACL_ACCESS;
+		if (acl) {
+			ret = posix_acl_equiv_mode(acl, &inode->i_mode);
+			if (ret < 0)
+				return ret;
+			if (ret == 0)
+				acl = NULL;
+		}
+		ret = 0;
+		break;
+	case ACL_TYPE_DEFAULT:
+		if (!S_ISDIR(inode->i_mode))
+			return acl ? -EINVAL : 0;
+		name = XATTR_NAME_POSIX_ACL_DEFAULT;
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	if (acl) {
+		size = posix_acl_xattr_size(acl->a_count);
+		value = kmalloc(size, GFP_KERNEL);
+		if (!value)
+			return -ENOMEM;
+
+		ret = posix_acl_to_xattr(&init_user_ns, acl, value, size);
+		if (ret < 0)
+			goto out;
+	}
+
+	if (size == 0)
+		flags = XATTR_REPLACE;
+	ret = __ubifs_setxattr(inode, name, value, size, flags);
+

fs/ubifs/acl.c line 113

Quoted 10 lines
fs/ubifs/acl.c new file +10 -0
+out:
+	kfree(value);
+	if (!ret)
+		set_cached_acl(inode, type, acl);
+
+	return ret;
+}
+
+/*
+ * Initialize the ACLs of a new inode.

Please use the Javadoc style we use for all UBIFS functions. (applies to other functions too in this patch)-

Quoted 46 lines
fs/ubifs/acl.c new file +30 -0
+ */
+int ubifs_init_acl(struct inode *dir, struct inode *inode)
+{
+	struct posix_acl *default_acl, *acl;
+	int ret = 0;
+
+	ret = posix_acl_create(dir, &inode->i_mode, &default_acl, &acl);
+	if (ret)
+		return ret;
+
+	if (default_acl) {
+		inode_lock(inode);
+		ret = ubifs_set_acl(inode, default_acl, ACL_TYPE_DEFAULT);
+		inode_unlock(inode);
+		posix_acl_release(default_acl);
+	}
+
+	if (acl) {
+		if (!ret) {
+			inode_lock(inode);
+			ret = ubifs_set_acl(inode, acl, ACL_TYPE_ACCESS);
+			inode_unlock(inode);
+		}
+		posix_acl_release(acl);
+	}
+
+	if (!default_acl && !acl)
+		cache_no_acl(inode);
+	return ret;
+}
fs/ubifs/dir.c +4 -0
index ccd9128..a2e5609 100644
@@ -270,6 +270,10 @@ static int ubifs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
 		goto out_budg;
 	}
 
+	err = ubifs_init_acl(dir, inode);
+	if (err)
+		goto out_inode;
+
 	err = ubifs_init_security(dir, inode, &dentry->d_name);
 	if (err)
 		goto out_inode;

fs/ubifs/dir.c static int do_tmpfile(struct inode *dir, struct dentry *dentry, · line 350

Quoted 6 lines
fs/ubifs/dir.c +3 -0
@@ -341,6 +345,10 @@ static int do_tmpfile(struct inode *dir, struct dentry *dentry,
 		ubifs_assert(inode->i_op == &ubifs_file_inode_operations);
 	}
 
+	err = ubifs_init_acl(dir, inode);
+	if (err)
+		goto out_inode;

Why do we need ACLs for O_TMPFILE?

Quoted 27 lines
fs/ubifs/dir.c +9 -0
+
 	err = ubifs_init_security(dir, inode, &dentry->d_name);
 	if (err)
 		goto out_inode;
@@ -821,6 +829,10 @@ static int ubifs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
 		goto out_budg;
 	}
 
+	err = ubifs_init_acl(dir, inode);
+	if (err)
+		goto out_inode;
+
 	err = ubifs_init_security(dir, inode, &dentry->d_name);
 	if (err)
 		goto out_inode;
@@ -903,6 +915,10 @@ static int ubifs_mknod(struct inode *dir, struct dentry *dentry,
 	ui->data = dev;
 	ui->data_len = devlen;
 
+	err = ubifs_init_acl(dir, inode);
+	if (err)
+		goto out_inode;
+
 	err = ubifs_init_security(dir, inode, &dentry->d_name);
 	if (err)
 		goto out_inode;

fs/ubifs/dir.c static int ubifs_symlink(struct inode *dir, struct dentry *dentry, · line 1006

Quoted 6 lines
fs/ubifs/dir.c +3 -0
@@ -985,6 +1001,10 @@ static int ubifs_symlink(struct inode *dir, struct dentry *dentry,
 	ui->data_len = len;
 	inode->i_size = ubifs_inode(inode)->ui_size = len;
 
+	err = ubifs_init_acl(dir, inode);
+	if (err)
+		goto out_inode;

Do we really need ACLs for symlinks too? I thought permissions for symlinks are irrelevant.

Quoted 134 lines
fs/ubifs/dir.c +2 -0
 	err = ubifs_init_security(dir, inode, &dentry->d_name);
 	if (err)
 		goto out_inode;
@@ -1395,6 +1415,8 @@ const struct inode_operations ubifs_dir_inode_operations = {
 	.update_time = ubifs_update_time,
 #endif
 	.tmpfile     = ubifs_tmpfile,
+	.get_acl     = ubifs_get_acl,
+	.set_acl     = ubifs_set_acl,
 };
 
 const struct file_operations ubifs_dir_operations = {
fs/ubifs/file.c +9 -0
index 4ed270b..17f6098 100644
@@ -53,6 +53,7 @@
 #include <linux/mount.h>
 #include <linux/slab.h>
 #include <linux/migrate.h>
+#include <linux/posix_acl.h>
 
 static int read_block(struct inode *inode, void *addr, unsigned int block,
 		      struct ubifs_data_node *dn)
@@ -1251,6 +1252,10 @@ static int do_setattr(struct ubifs_info *c, struct inode *inode,
 		ubifs_release_budget(c, &req);
 	if (IS_SYNC(inode))
 		err = inode->i_sb->s_op->write_inode(inode, NULL);
+
+	if (!err && (attr->ia_valid & ATTR_MODE))
+		err = posix_acl_chmod(inode, inode->i_mode);
+
 	return err;
 }
 
@@ -1628,6 +1633,8 @@ const struct inode_operations ubifs_file_inode_operations = {
 #ifdef CONFIG_UBIFS_ATIME_SUPPORT
 	.update_time = ubifs_update_time,
 #endif
+	.get_acl     = ubifs_get_acl,
+	.set_acl     = ubifs_set_acl,
 };
 
 const struct inode_operations ubifs_symlink_inode_operations = {
@@ -1642,6 +1649,8 @@ const struct inode_operations ubifs_symlink_inode_operations = {
 #ifdef CONFIG_UBIFS_ATIME_SUPPORT
 	.update_time = ubifs_update_time,
 #endif
+	.get_acl     = ubifs_get_acl,
+	.set_acl     = ubifs_set_acl,
 };
 
 const struct file_operations ubifs_file_operations = {
fs/ubifs/super.c +15 -0
index 4ec0510..8239dfd 100644
@@ -444,6 +444,9 @@ static int ubifs_show_options(struct seq_file *s, struct dentry *root)
 			   ubifs_compr_name(c->mount_opts.compr_type));
 	}
 
+	if (c->vfs_sb->s_flags & MS_POSIXACL)
+		seq_puts(s, ",acl");
+
 	return 0;
 }
 
@@ -929,6 +932,8 @@ enum {
 	Opt_chk_data_crc,
 	Opt_no_chk_data_crc,
 	Opt_override_compr,
+	Opt_acl,
+	Opt_noacl,
 	Opt_err,
 };
 
@@ -940,6 +945,8 @@ static const match_table_t tokens = {
 	{Opt_chk_data_crc, "chk_data_crc"},
 	{Opt_no_chk_data_crc, "no_chk_data_crc"},
 	{Opt_override_compr, "compr=%s"},
+	{Opt_acl, "acl"},
+	{Opt_noacl, "noacl"},
 	{Opt_err, NULL},
 };
 
@@ -1040,6 +1047,14 @@ static int ubifs_parse_options(struct ubifs_info *c, char *options,
 			c->default_compr = c->mount_opts.compr_type;
 			break;
 		}
+#ifdef CONFIG_UBIFS_FS_POSIX_ACL
+		case Opt_acl:
+			c->vfs_sb->s_flags |= MS_POSIXACL;
+			break;
+		case Opt_noacl:
+			c->vfs_sb->s_flags &= ~MS_POSIXACL;
+			break;
+#endif
 		default:
 		{
 			unsigned long flag;
fs/ubifs/ubifs.h +18 -0
index 096035e..7935449 100644
@@ -1743,6 +1743,24 @@ extern const struct xattr_handler *ubifs_xattr_handlers[];
 ssize_t ubifs_listxattr(struct dentry *dentry, char *buffer, size_t size);
 int ubifs_init_security(struct inode *dentry, struct inode *inode,
 			const struct qstr *qstr);
+ssize_t __ubifs_getxattr(struct inode *host, const char *name,
+				void *buf, size_t size);
+int __ubifs_setxattr(struct inode *host, const char *name,
+			    const void *value, size_t size, int flags);
+
+/* acl.c */
+#ifdef CONFIG_UBIFS_FS_POSIX_ACL
+int ubifs_init_acl(struct inode *dir, struct inode *inode);
+int ubifs_set_acl(struct inode *inode, struct posix_acl *acl, int type);
+struct posix_acl *ubifs_get_acl(struct inode *inode, int type);
+#else
+static inline int ubifs_init_acl(struct inode *inode, struct inode *dir)
+{
+	return 0;
+}
+#define ubifs_get_acl NULL
+#define ubifs_set_acl NULL
+#endif
 
 /* super.c */
 struct inode *ubifs_iget(struct super_block *sb, unsigned long inum);
fs/ubifs/xattr.c +0 -0
index 6c2f4d4..0a596a1 100644

fs/ubifs/xattr.c line 55

Quoted 5 lines
fs/ubifs/xattr.c +1 -1
@@ -52,13 +52,14 @@
  * in the VFS inode cache. The xentries are cached in the LNC cache (see
  * tnc.c).
  *
- * ACL support is not implemented.
+ * ACL support is now implemented.

I think we can just drop that line now. :-)

fs/ubifs/xattr.c line 62

Quoted 7 lines
fs/ubifs/xattr.c +1 -0
  */
 
 #include "ubifs.h"
 #include <linux/fs.h>
 #include <linux/slab.h>
 #include <linux/xattr.h>
+#include <linux/posix_acl_xattr.h>

While we are here, these includes should also be cleaned up.

Quoted 22 lines
fs/ubifs/xattr.c +2 -2
 /*
  * Limit the number of extended attributes per inode so that the total size
@@ -268,7 +269,7 @@ static struct inode *iget_xattr(struct ubifs_info *c, ino_t inum)
 	return ERR_PTR(-EINVAL);
 }
 
-static int __ubifs_setxattr(struct inode *host, const char *name,
+int __ubifs_setxattr(struct inode *host, const char *name,
 			    const void *value, size_t size, int flags)
 {
 	struct inode *inode;
@@ -328,7 +329,7 @@ out_free:
 	return err;
 }
 
-static ssize_t __ubifs_getxattr(struct inode *host, const char *name,
+ssize_t __ubifs_getxattr(struct inode *host, const char *name,
 				void *buf, size_t size)
 {
 	struct inode *inode;

fs/ubifs/xattr.c const struct xattr_handler *ubifs_xattr_handlers[] = { · line 628

Quoted 9 lines
fs/ubifs/xattr.c +4 -0
@@ -619,5 +620,9 @@ const struct xattr_handler *ubifs_xattr_handlers[] = {
 	&ubifs_user_xattr_handler,
 	&ubifs_trusted_xattr_handler,
 	&ubifs_security_xattr_handler,
+#ifdef CONFIG_UBIFS_FS_POSIX_ACL
+	&posix_acl_access_xattr_handler,
+	&posix_acl_default_xattr_handler,
+#endif
 	NULL
 };

Overall the patch does not look bad and I'm sure we can add it for v4.10 soon. I'm a bit confused since most stuff is not really UBIFS specific.
Andreas, is just "normal" for ACL support? I thought most code is generic and already in VFS.

Thanks,
//richard

#3 lore raw

Richard,

Thanks for your review.

Quoted 24 lines · Richard Weinberger

Pascal,

Quoted 3 lines · Pascal Eberhard

This patch implements POSIX Access Control Lists (ACLs) in UBIFS. It uses posix_acl_(access|default)_xattr_handler ACL generic handlers as xattr handlers are now used in UBIFS.

Cool! :)
CC'ing Andreas, maybe he also has comments.

Quoted 14 lines
---
 fs/ubifs/Kconfig  |  13 +++++
 fs/ubifs/Makefile |   1 +
 fs/ubifs/acl.c    | 143 
++++++++++++++++++++++++++++++++++++++++++++++++++++++
 fs/ubifs/dir.c    |  22 +++++++++
 fs/ubifs/file.c   |   9 ++++
 fs/ubifs/super.c  |  15 ++++++
 fs/ubifs/ubifs.h  |  18 +++++++
 fs/ubifs/xattr.c  |  11 +++--
 8 files changed, 229 insertions(+), 3 deletions(-)
 create mode 100644 fs/ubifs/acl.c

[...]

Quoted 4 lines
Quoted 1 line

+#include <linux/fs.h>

ubifs.h includes this already.

ok

Quoted 4 lines
Quoted 1 line

+#include <linux/xattr.h>

Ditto.

ok

[...]

Quoted 5 lines
Quoted 2 lines

+/*
+ * Initialize the ACLs of a new inode.

Please use the Javadoc style we use for all UBIFS functions. (applies to other functions too in this patch)-

ok

[...]

Quoted 21 lines
Quoted 21 lines
fs/ubifs/dir.c +4 -0
index ccd9128..a2e5609 100644
@@ -270,6 +270,10 @@ static int ubifs_create(struct inode *dir, struct 
 dentry *dentry, umode_t mode,
 		goto out_budg;
 	}
 
+	err = ubifs_init_acl(dir, inode);
+	if (err)
+		goto out_inode;
+
 	err = ubifs_init_security(dir, inode, &dentry->d_name);
 	if (err)
fs/ubifs/dir.c +0 -0
 		goto out_inode;
@@ -341,6 +345,10 @@ static int do_tmpfile(struct inode *dir, struct 
 dentry *dentry,
 		ubifs_assert(inode->i_op == &ubifs_file_inode_operations);
 	}
 
Quoted 5 lines

fs/ubifs/dir.c static int ubifs_create(struct inode *dir, struct dentry *dentry, umode_t mode, · line 275

Quoted 3 lines
fs/ubifs/dir.c +3 -0
+	err = ubifs_init_acl(dir, inode);
+	if (err)
+		goto out_inode;

Why do we need ACLs for O_TMPFILE?

O_TMPFILE files are unnamed... until linkat() is called.
open manpage says that when linkat() is called to a O_TMPFILE file:
"In this case, the open() mode argument determines the file permission mode, as with O_CREAT." And mode with O_CREAT is applied with respect of the default ACLs:
"in the absence of a default ACL, the mode of the created file is (mode & ~umask)"

So my interpretation is that default ACLs shall be propagated to O_TMPFILE at creation.

O_TMPFILE implementation for btrfs and xfs apply default ACLs as well.

[...]

Quoted 11 lines

fs/ubifs/dir.c static int ubifs_symlink(struct inode *dir, · line 1007

Quoted 8 lines
fs/ubifs/dir.c +3 -0
@@ -985,6 +1001,10 @@ static int ubifs_symlink(struct inode *dir, 
 struct dentry *dentry,
 	ui->data_len = len;
 	inode->i_size = ubifs_inode(inode)->ui_size = len;
 
+	err = ubifs_init_acl(dir, inode);
+	if (err)
+		goto out_inode;

Do we really need ACLs for symlinks too? I thought permissions for symlinks are irrelevant.

Indeed, they are irrelevant. It will be removed.

Quoted 5 lines
Quoted 5 lines
fs/ubifs/xattr.c +0 -0
index 6c2f4d4..0a596a1 100644
@@ -52,13 +52,14 @@
Quoted 8 lines
Quoted 6 lines
fs/ubifs/xattr.c +0 -0
  * in the VFS inode cache. The xentries are cached in the LNC cache 

(see
* tnc.c).
*
- * ACL support is not implemented.
+ * ACL support is now implemented.

I think we can just drop that line now. :-)

:-)

Quoted 11 lines
Quoted 8 lines

*/

#include "ubifs.h"
#include <linux/fs.h>
#include <linux/slab.h>
#include <linux/xattr.h>
+#include <linux/posix_acl_xattr.h>

While we are here, these includes should also be cleaned up.

Ok, and I'll remove the now obsolete enum just below too then:

/*
* Extended attribute type constants.
*
* USER_XATTR: user extended attribute ("user.*")
* TRUSTED_XATTR: trusted extended attribute ("trusted.*)
* SECURITY_XATTR: security extended attribute ("security.*") */

enum {
USER_XATTR,
TRUSTED_XATTR,
SECURITY_XATTR,
};

Quoted 2 lines

Overall the patch does not look bad and I'm sure we can add it for v4.10 soon.

ok, great!

Quoted 10 lines

I'm a bit confused since most stuff is not really UBIFS specific. Andreas, is just "normal" for ACL support? I thought most code is generic and already in VFS.

Thanks,
//richard

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

#4 lore raw
In reply to Richard Weinberger

Pascal,

Quoted 9 lines · Richard Weinberger

Pascal,

Quoted 3 lines · Pascal Eberhard

This patch implements POSIX Access Control Lists (ACLs) in UBIFS. It uses posix_acl_(access|default)_xattr_handler ACL generic handlers as xattr handlers are now used in UBIFS.

Cool! :)
CC'ing Andreas, maybe he also has comments.

please run this through xfstests as well. Note the following fixes / improvements I've made in the course of reviewing this; they've obviously not been merged, yet:

https://github.com/andreas-gruenbacher/xfsprogs-dev/commits/io
https://github.com/andreas-gruenbacher/xfstests/commits/tmpfile

Quoted 103 lines
Quoted 55 lines
---
 fs/ubifs/Kconfig  |  13 +++++
 fs/ubifs/Makefile |   1 +
 fs/ubifs/acl.c    | 143 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 fs/ubifs/dir.c    |  22 +++++++++
 fs/ubifs/file.c   |   9 ++++
 fs/ubifs/super.c  |  15 ++++++
 fs/ubifs/ubifs.h  |  18 +++++++
 fs/ubifs/xattr.c  |  11 +++--
 8 files changed, 229 insertions(+), 3 deletions(-)
 create mode 100644 fs/ubifs/acl.c
fs/ubifs/Kconfig +13 -0
index 7ff7712..39119e5 100644
@@ -50,3 +50,16 @@ config UBIFS_ATIME_SUPPORT
        strictatime is the "heavy", relatime is "lighter", etc.
 
        If unsure, say 'N'
+
+config UBIFS_FS_POSIX_ACL
+     bool "UBIFS POSIX Access Control Lists"
+     depends on UBIFS_FS
+     select FS_POSIX_ACL
+     help
+       POSIX Access Control Lists (ACLs) support permissions for users and
+       groups beyond the owner/group/world scheme.
+
+       To learn more about Access Control Lists, visit the POSIX ACLs for
+       Linux website <http://acl.bestbits.at/>.
+
+       If you don't know what Access Control Lists are, say N
fs/ubifs/Makefile +1 -0
index c54a243..af7a83f 100644
@@ -5,3 +5,4 @@ ubifs-y += tnc.o master.o scan.o replay.o log.o commit.o gc.o orphan.o
 ubifs-y += budget.o find.o tnc_commit.o compress.o lpt.o lprops.o
 ubifs-y += recovery.o ioctl.o lpt_commit.o tnc_misc.o xattr.o debug.o
 ubifs-y += misc.o
+ubifs-$(CONFIG_UBIFS_FS_POSIX_ACL) += acl.o
\ No newline at end of file
fs/ubifs/acl.c new file +5 -0
new file mode 100644
index 0000000..a4d4734
@@ -0,0 +1,143 @@
+/*
+ * This file is part of UBIFS.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published by

fs/ubifs/acl.c line 15

Quoted 10 lines
fs/ubifs/acl.c new file +10 -0
+ * the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ */
+
+#include <linux/fs.h>

ubifs.h includes this already.

fs/ubifs/acl.c line 16

Quoted 1 line
fs/ubifs/acl.c new file +1 -0
+#include <linux/xattr.h>

Ditto.

Quoted 31 lines
fs/ubifs/acl.c new file +31 -0
+#include <linux/posix_acl_xattr.h>
+
+#include "ubifs.h"
+
+struct posix_acl *ubifs_get_acl(struct inode *inode, int type)
+{
+     int size;
+     const char *name;
+     char *value = NULL;
+     struct posix_acl *acl;
+
+     switch (type) {
+     case ACL_TYPE_ACCESS:
+             name = XATTR_NAME_POSIX_ACL_ACCESS;
+             break;
+     case ACL_TYPE_DEFAULT:
+             name = XATTR_NAME_POSIX_ACL_DEFAULT;
+             break;
+     default:
+             return ERR_PTR(-EINVAL);
+     }
+
+     size = __ubifs_getxattr(inode, name, NULL, 0);
+     if (size > 0) {
+             value = kzalloc(size, GFP_KERNEL);
+             if (!value)
+                     return ERR_PTR(-ENOMEM);
+             size = __ubifs_getxattr(inode, name, value, size);
+     }
+     if (size > 0)
+             acl = posix_acl_from_xattr(&init_user_ns, value, size);
Quoted 8 lines

fs/ubifs/acl.c line 55

Quoted 8 lines
fs/ubifs/acl.c new file +8 -0
+     else if (size == -ERANGE || size == -ENODATA || size == 0)
+             acl = NULL;
+     else
+             acl = ERR_PTR(size);
+
+     kfree(value);
+     if (!IS_ERR(acl))
+             set_cached_acl(inode, type, acl);

The get_acl inode operation should no longer call set_cached_acl; the cached ACL is updated automatically. (It's correct to use set_cached_acl in the set_acl inode operation though.)

Quoted 62 lines
Quoted 48 lines
fs/ubifs/acl.c new file +48 -0
+
+     return acl;
+}
+
+int ubifs_set_acl(struct inode *inode, struct posix_acl *acl, int type)
+{
+     int ret;
+     int size = 0;
+     const char *name;
+     char *value = NULL;
+     int flags = 0;
+
+     switch (type) {
+     case ACL_TYPE_ACCESS:
+             name = XATTR_NAME_POSIX_ACL_ACCESS;
+             if (acl) {
+                     ret = posix_acl_equiv_mode(acl, &inode->i_mode);
+                     if (ret < 0)
+                             return ret;
+                     if (ret == 0)
+                             acl = NULL;
+             }
+             ret = 0;
+             break;
+     case ACL_TYPE_DEFAULT:
+             if (!S_ISDIR(inode->i_mode))
+                     return acl ? -EINVAL : 0;
+             name = XATTR_NAME_POSIX_ACL_DEFAULT;
+             break;
+     default:
+             return -EINVAL;
+     }
+
+     if (acl) {
+             size = posix_acl_xattr_size(acl->a_count);
+             value = kmalloc(size, GFP_KERNEL);
+             if (!value)
+                     return -ENOMEM;
+
+             ret = posix_acl_to_xattr(&init_user_ns, acl, value, size);
+             if (ret < 0)
+                     goto out;
+     }
+
+     if (size == 0)
+             flags = XATTR_REPLACE;
+     ret = __ubifs_setxattr(inode, name, value, size, flags);
+

fs/ubifs/acl.c line 113

Quoted 10 lines
fs/ubifs/acl.c new file +10 -0
+out:
+     kfree(value);
+     if (!ret)
+             set_cached_acl(inode, type, acl);
+
+     return ret;
+}
+
+/*
+ * Initialize the ACLs of a new inode.

Please use the Javadoc style we use for all UBIFS functions. (applies to other functions too in this patch)-

Quoted 12 lines

fs/ubifs/acl.c line 125

Quoted 12 lines
fs/ubifs/acl.c new file +12 -0
+ */
+int ubifs_init_acl(struct inode *dir, struct inode *inode)
+{
+     struct posix_acl *default_acl, *acl;
+     int ret = 0;
+
+     ret = posix_acl_create(dir, &inode->i_mode, &default_acl, &acl);
+     if (ret)
+             return ret;
+
+     if (default_acl) {
+             inode_lock(inode);

Why the inode locking here?

Quoted 8 lines

fs/ubifs/acl.c line 133

Quoted 8 lines
fs/ubifs/acl.c new file +8 -0
+             ret = ubifs_set_acl(inode, default_acl, ACL_TYPE_DEFAULT);
+             inode_unlock(inode);
+             posix_acl_release(default_acl);
+     }
+
+     if (acl) {
+             if (!ret) {
+                     inode_lock(inode);

Same here.

Quoted 8 lines

fs/ubifs/acl.c line 141

Quoted 8 lines
fs/ubifs/acl.c new file +8 -0
+                     ret = ubifs_set_acl(inode, acl, ACL_TYPE_ACCESS);
+                     inode_unlock(inode);
+             }
+             posix_acl_release(acl);
+     }
+
+     if (!default_acl && !acl)
+             cache_no_acl(inode);

This call to cache_no_acl doesn't make sense; please check. It may be wrong in btrfs as well; copying Josef for that.

Quoted 10 lines
Quoted 10 lines
fs/ubifs/acl.c new file +2 -0
+     return ret;
+}
fs/ubifs/dir.c +0 -0
index ccd9128..a2e5609 100644
@@ -270,6 +270,10 @@ static int ubifs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
              goto out_budg;
      }
 
Quoted 4 lines

fs/ubifs/dir.c static int ubifs_create(struct inode *dir, struct dentry *dentry, umode_t mode, · line 276

Quoted 4 lines
fs/ubifs/dir.c +4 -0
+     err = ubifs_init_acl(dir, inode);
+     if (err)
+             goto out_inode;
+

The pattern ubifs_budget_space / ubifs_new_inode / ubifs_init_acl / ubifs_init_security repeats a number of times in the code, so it should probably be put in a function.

Quoted 228 lines

fs/ubifs/dir.c static int do_tmpfile(struct inode *dir, struct dentry *dentry, · line 350

Quoted 10 lines
fs/ubifs/dir.c +3 -0
      err = ubifs_init_security(dir, inode, &dentry->d_name);
      if (err)
              goto out_inode;
@@ -341,6 +345,10 @@ static int do_tmpfile(struct inode *dir, struct dentry *dentry,
              ubifs_assert(inode->i_op == &ubifs_file_inode_operations);
      }
 
+     err = ubifs_init_acl(dir, inode);
+     if (err)
+             goto out_inode;

Why do we need ACLs for O_TMPFILE?

Quoted 27 lines
fs/ubifs/dir.c +9 -0
+
      err = ubifs_init_security(dir, inode, &dentry->d_name);
      if (err)
              goto out_inode;
@@ -821,6 +829,10 @@ static int ubifs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
              goto out_budg;
      }
 
+     err = ubifs_init_acl(dir, inode);
+     if (err)
+             goto out_inode;
+
      err = ubifs_init_security(dir, inode, &dentry->d_name);
      if (err)
              goto out_inode;
@@ -903,6 +915,10 @@ static int ubifs_mknod(struct inode *dir, struct dentry *dentry,
      ui->data = dev;
      ui->data_len = devlen;
 
+     err = ubifs_init_acl(dir, inode);
+     if (err)
+             goto out_inode;
+
      err = ubifs_init_security(dir, inode, &dentry->d_name);
      if (err)
              goto out_inode;

fs/ubifs/dir.c static int ubifs_symlink(struct inode *dir, struct dentry *dentry, · line 1006

Quoted 6 lines
fs/ubifs/dir.c +3 -0
@@ -985,6 +1001,10 @@ static int ubifs_symlink(struct inode *dir, struct dentry *dentry,
      ui->data_len = len;
      inode->i_size = ubifs_inode(inode)->ui_size = len;
 
+     err = ubifs_init_acl(dir, inode);
+     if (err)
+             goto out_inode;

Do we really need ACLs for symlinks too? I thought permissions for symlinks are irrelevant.

Quoted 134 lines
fs/ubifs/dir.c +2 -0
      err = ubifs_init_security(dir, inode, &dentry->d_name);
      if (err)
              goto out_inode;
@@ -1395,6 +1415,8 @@ const struct inode_operations ubifs_dir_inode_operations = {
      .update_time = ubifs_update_time,
 #endif
      .tmpfile     = ubifs_tmpfile,
+     .get_acl     = ubifs_get_acl,
+     .set_acl     = ubifs_set_acl,
 };
 
 const struct file_operations ubifs_dir_operations = {
fs/ubifs/file.c +9 -0
index 4ed270b..17f6098 100644
@@ -53,6 +53,7 @@
 #include <linux/mount.h>
 #include <linux/slab.h>
 #include <linux/migrate.h>
+#include <linux/posix_acl.h>
 
 static int read_block(struct inode *inode, void *addr, unsigned int block,
                    struct ubifs_data_node *dn)
@@ -1251,6 +1252,10 @@ static int do_setattr(struct ubifs_info *c, struct inode *inode,
              ubifs_release_budget(c, &req);
      if (IS_SYNC(inode))
              err = inode->i_sb->s_op->write_inode(inode, NULL);
+
+     if (!err && (attr->ia_valid & ATTR_MODE))
+             err = posix_acl_chmod(inode, inode->i_mode);
+
      return err;
 }
 
@@ -1628,6 +1633,8 @@ const struct inode_operations ubifs_file_inode_operations = {
 #ifdef CONFIG_UBIFS_ATIME_SUPPORT
      .update_time = ubifs_update_time,
 #endif
+     .get_acl     = ubifs_get_acl,
+     .set_acl     = ubifs_set_acl,
 };
 
 const struct inode_operations ubifs_symlink_inode_operations = {
@@ -1642,6 +1649,8 @@ const struct inode_operations ubifs_symlink_inode_operations = {
 #ifdef CONFIG_UBIFS_ATIME_SUPPORT
      .update_time = ubifs_update_time,
 #endif
+     .get_acl     = ubifs_get_acl,
+     .set_acl     = ubifs_set_acl,
 };
 
 const struct file_operations ubifs_file_operations = {
fs/ubifs/super.c +15 -0
index 4ec0510..8239dfd 100644
@@ -444,6 +444,9 @@ static int ubifs_show_options(struct seq_file *s, struct dentry *root)
                         ubifs_compr_name(c->mount_opts.compr_type));
      }
 
+     if (c->vfs_sb->s_flags & MS_POSIXACL)
+             seq_puts(s, ",acl");
+
      return 0;
 }
 
@@ -929,6 +932,8 @@ enum {
      Opt_chk_data_crc,
      Opt_no_chk_data_crc,
      Opt_override_compr,
+     Opt_acl,
+     Opt_noacl,
      Opt_err,
 };
 
@@ -940,6 +945,8 @@ static const match_table_t tokens = {
      {Opt_chk_data_crc, "chk_data_crc"},
      {Opt_no_chk_data_crc, "no_chk_data_crc"},
      {Opt_override_compr, "compr=%s"},
+     {Opt_acl, "acl"},
+     {Opt_noacl, "noacl"},
      {Opt_err, NULL},
 };
 
@@ -1040,6 +1047,14 @@ static int ubifs_parse_options(struct ubifs_info *c, char *options,
                      c->default_compr = c->mount_opts.compr_type;
                      break;
              }
+#ifdef CONFIG_UBIFS_FS_POSIX_ACL
+             case Opt_acl:
+                     c->vfs_sb->s_flags |= MS_POSIXACL;
+                     break;
+             case Opt_noacl:
+                     c->vfs_sb->s_flags &= ~MS_POSIXACL;
+                     break;
+#endif
              default:
              {
                      unsigned long flag;
fs/ubifs/ubifs.h +18 -0
index 096035e..7935449 100644
@@ -1743,6 +1743,24 @@ extern const struct xattr_handler *ubifs_xattr_handlers[];
 ssize_t ubifs_listxattr(struct dentry *dentry, char *buffer, size_t size);
 int ubifs_init_security(struct inode *dentry, struct inode *inode,
                      const struct qstr *qstr);
+ssize_t __ubifs_getxattr(struct inode *host, const char *name,
+                             void *buf, size_t size);
+int __ubifs_setxattr(struct inode *host, const char *name,
+                         const void *value, size_t size, int flags);
+
+/* acl.c */
+#ifdef CONFIG_UBIFS_FS_POSIX_ACL
+int ubifs_init_acl(struct inode *dir, struct inode *inode);
+int ubifs_set_acl(struct inode *inode, struct posix_acl *acl, int type);
+struct posix_acl *ubifs_get_acl(struct inode *inode, int type);
+#else
+static inline int ubifs_init_acl(struct inode *inode, struct inode *dir)
+{
+     return 0;
+}
+#define ubifs_get_acl NULL
+#define ubifs_set_acl NULL
+#endif
 
 /* super.c */
 struct inode *ubifs_iget(struct super_block *sb, unsigned long inum);
fs/ubifs/xattr.c +0 -0
index 6c2f4d4..0a596a1 100644

fs/ubifs/xattr.c line 55

Quoted 5 lines
fs/ubifs/xattr.c +1 -1
@@ -52,13 +52,14 @@
  * in the VFS inode cache. The xentries are cached in the LNC cache (see
  * tnc.c).
  *
- * ACL support is not implemented.
+ * ACL support is now implemented.

I think we can just drop that line now. :-)

fs/ubifs/xattr.c line 62

Quoted 7 lines
fs/ubifs/xattr.c +1 -0
  */
 
 #include "ubifs.h"
 #include <linux/fs.h>
 #include <linux/slab.h>
 #include <linux/xattr.h>
+#include <linux/posix_acl_xattr.h>

While we are here, these includes should also be cleaned up.

Quoted 27 lines
fs/ubifs/xattr.c +5 -2
 /*
  * Limit the number of extended attributes per inode so that the total size
@@ -268,7 +269,7 @@ static struct inode *iget_xattr(struct ubifs_info *c, ino_t inum)
      return ERR_PTR(-EINVAL);
 }
 
-static int __ubifs_setxattr(struct inode *host, const char *name,
+int __ubifs_setxattr(struct inode *host, const char *name,
                          const void *value, size_t size, int flags)
 {
      struct inode *inode;
@@ -328,7 +329,7 @@ out_free:
      return err;
 }
 
-static ssize_t __ubifs_getxattr(struct inode *host, const char *name,
+ssize_t __ubifs_getxattr(struct inode *host, const char *name,
                              void *buf, size_t size)
 {
      struct inode *inode;
@@ -619,5 +620,9 @@ const struct xattr_handler *ubifs_xattr_handlers[] = {
      &ubifs_user_xattr_handler,
      &ubifs_trusted_xattr_handler,
      &ubifs_security_xattr_handler,
+#ifdef CONFIG_UBIFS_FS_POSIX_ACL
+     &posix_acl_access_xattr_handler,
+     &posix_acl_default_xattr_handler,
Quoted 8 lines

fs/ubifs/xattr.c const struct xattr_handler *ubifs_xattr_handlers[] = { · line 628

Quoted 4 lines
fs/ubifs/xattr.c +1 -0
+#endif
      NULL
 };

Overall the patch does not look bad and I'm sure we can add it for v4.10 soon. I'm a bit confused since most stuff is not really UBIFS specific.
Andreas, is just "normal" for ACL support? I thought most code is generic and already in VFS.

There are several filesystems like ubifs that use the xattr representation as the on-disk format, so ubifs_get_acl and ubifs_set_acl could be abstracted and shared across those filesystems. The rest looks good.

Thanks,
Andreas

#5 lore raw
Quoted 233 lines · Andreas Gruenbacher

Pascal,

Quoted 9 lines · Richard Weinberger

Pascal,

Quoted 3 lines · Pascal Eberhard

This patch implements POSIX Access Control Lists (ACLs) in UBIFS. It uses posix_acl_(access|default)_xattr_handler ACL generic handlers as xattr handlers are now used in UBIFS.

Cool! :)
CC'ing Andreas, maybe he also has comments.

please run this through xfstests as well. Note the following fixes / improvements I've made in the course of reviewing this; they've obviously not been merged, yet:

https://github.com/andreas-gruenbacher/xfsprogs-dev/commits/io
https://github.com/andreas-gruenbacher/xfstests/commits/tmpfile

Quoted 103 lines
Quoted 55 lines
---
 fs/ubifs/Kconfig  |  13 +++++
 fs/ubifs/Makefile |   1 +
 fs/ubifs/acl.c    | 143 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 fs/ubifs/dir.c    |  22 +++++++++
 fs/ubifs/file.c   |   9 ++++
 fs/ubifs/super.c  |  15 ++++++
 fs/ubifs/ubifs.h  |  18 +++++++
 fs/ubifs/xattr.c  |  11 +++--
 8 files changed, 229 insertions(+), 3 deletions(-)
 create mode 100644 fs/ubifs/acl.c
fs/ubifs/Kconfig +13 -0
index 7ff7712..39119e5 100644
@@ -50,3 +50,16 @@ config UBIFS_ATIME_SUPPORT
        strictatime is the "heavy", relatime is "lighter", etc.
 
        If unsure, say 'N'
+
+config UBIFS_FS_POSIX_ACL
+     bool "UBIFS POSIX Access Control Lists"
+     depends on UBIFS_FS
+     select FS_POSIX_ACL
+     help
+       POSIX Access Control Lists (ACLs) support permissions for users and
+       groups beyond the owner/group/world scheme.
+
+       To learn more about Access Control Lists, visit the POSIX ACLs for
+       Linux website <http://acl.bestbits.at/>.
+
+       If you don't know what Access Control Lists are, say N
fs/ubifs/Makefile +1 -0
index c54a243..af7a83f 100644
@@ -5,3 +5,4 @@ ubifs-y += tnc.o master.o scan.o replay.o log.o commit.o gc.o orphan.o
 ubifs-y += budget.o find.o tnc_commit.o compress.o lpt.o lprops.o
 ubifs-y += recovery.o ioctl.o lpt_commit.o tnc_misc.o xattr.o debug.o
 ubifs-y += misc.o
+ubifs-$(CONFIG_UBIFS_FS_POSIX_ACL) += acl.o
\ No newline at end of file
fs/ubifs/acl.c new file +5 -0
new file mode 100644
index 0000000..a4d4734
@@ -0,0 +1,143 @@
+/*
+ * This file is part of UBIFS.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published by

fs/ubifs/acl.c line 15

Quoted 10 lines
fs/ubifs/acl.c new file +10 -0
+ * the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ */
+
+#include <linux/fs.h>

ubifs.h includes this already.

fs/ubifs/acl.c line 16

Quoted 1 line
fs/ubifs/acl.c new file +1 -0
+#include <linux/xattr.h>

Ditto.

Quoted 31 lines
fs/ubifs/acl.c new file +31 -0
+#include <linux/posix_acl_xattr.h>
+
+#include "ubifs.h"
+
+struct posix_acl *ubifs_get_acl(struct inode *inode, int type)
+{
+     int size;
+     const char *name;
+     char *value = NULL;
+     struct posix_acl *acl;
+
+     switch (type) {
+     case ACL_TYPE_ACCESS:
+             name = XATTR_NAME_POSIX_ACL_ACCESS;
+             break;
+     case ACL_TYPE_DEFAULT:
+             name = XATTR_NAME_POSIX_ACL_DEFAULT;
+             break;
+     default:
+             return ERR_PTR(-EINVAL);
+     }
+
+     size = __ubifs_getxattr(inode, name, NULL, 0);
+     if (size > 0) {
+             value = kzalloc(size, GFP_KERNEL);
+             if (!value)
+                     return ERR_PTR(-ENOMEM);
+             size = __ubifs_getxattr(inode, name, value, size);
+     }
+     if (size > 0)
+             acl = posix_acl_from_xattr(&init_user_ns, value, size);
Quoted 8 lines

fs/ubifs/acl.c line 55

Quoted 8 lines
fs/ubifs/acl.c new file +8 -0
+     else if (size == -ERANGE || size == -ENODATA || size == 0)
+             acl = NULL;
+     else
+             acl = ERR_PTR(size);
+
+     kfree(value);
+     if (!IS_ERR(acl))
+             set_cached_acl(inode, type, acl);

The get_acl inode operation should no longer call set_cached_acl; the cached ACL is updated automatically. (It's correct to use set_cached_acl in the set_acl inode operation though.)

Quoted 62 lines
Quoted 48 lines
fs/ubifs/acl.c new file +48 -0
+
+     return acl;
+}
+
+int ubifs_set_acl(struct inode *inode, struct posix_acl *acl, int type)
+{
+     int ret;
+     int size = 0;
+     const char *name;
+     char *value = NULL;
+     int flags = 0;
+
+     switch (type) {
+     case ACL_TYPE_ACCESS:
+             name = XATTR_NAME_POSIX_ACL_ACCESS;
+             if (acl) {
+                     ret = posix_acl_equiv_mode(acl, &inode->i_mode);
+                     if (ret < 0)
+                             return ret;
+                     if (ret == 0)
+                             acl = NULL;
+             }
+             ret = 0;
+             break;
+     case ACL_TYPE_DEFAULT:
+             if (!S_ISDIR(inode->i_mode))
+                     return acl ? -EINVAL : 0;
+             name = XATTR_NAME_POSIX_ACL_DEFAULT;
+             break;
+     default:
+             return -EINVAL;
+     }
+
+     if (acl) {
+             size = posix_acl_xattr_size(acl->a_count);
+             value = kmalloc(size, GFP_KERNEL);
+             if (!value)
+                     return -ENOMEM;
+
+             ret = posix_acl_to_xattr(&init_user_ns, acl, value, size);
+             if (ret < 0)
+                     goto out;
+     }
+
+     if (size == 0)
+             flags = XATTR_REPLACE;
+     ret = __ubifs_setxattr(inode, name, value, size, flags);
+

fs/ubifs/acl.c line 113

Quoted 10 lines
fs/ubifs/acl.c new file +10 -0
+out:
+     kfree(value);
+     if (!ret)
+             set_cached_acl(inode, type, acl);
+
+     return ret;
+}
+
+/*
+ * Initialize the ACLs of a new inode.

Please use the Javadoc style we use for all UBIFS functions. (applies to other functions too in this patch)-

Quoted 12 lines

fs/ubifs/acl.c line 125

Quoted 12 lines
fs/ubifs/acl.c new file +12 -0
+ */
+int ubifs_init_acl(struct inode *dir, struct inode *inode)
+{
+     struct posix_acl *default_acl, *acl;
+     int ret = 0;
+
+     ret = posix_acl_create(dir, &inode->i_mode, &default_acl, &acl);
+     if (ret)
+             return ret;
+
+     if (default_acl) {
+             inode_lock(inode);

Why the inode locking here?

Quoted 8 lines

fs/ubifs/acl.c line 133

Quoted 8 lines
fs/ubifs/acl.c new file +8 -0
+             ret = ubifs_set_acl(inode, default_acl, ACL_TYPE_DEFAULT);
+             inode_unlock(inode);
+             posix_acl_release(default_acl);
+     }
+
+     if (acl) {
+             if (!ret) {
+                     inode_lock(inode);

Same here.

Quoted 8 lines

fs/ubifs/acl.c line 141

Quoted 8 lines
fs/ubifs/acl.c new file +8 -0
+                     ret = ubifs_set_acl(inode, acl, ACL_TYPE_ACCESS);
+                     inode_unlock(inode);
+             }
+             posix_acl_release(acl);
+     }
+
+     if (!default_acl && !acl)
+             cache_no_acl(inode);
Quoted 2 lines

This call to cache_no_acl doesn't make sense; please check. It may be wrong in btrfs as well; copying Josef for that.

Now with Josef's current email address, hopefully.

Quoted 263 lines
Quoted 10 lines
Quoted 10 lines
fs/ubifs/acl.c new file +2 -0
+     return ret;
+}
fs/ubifs/dir.c +0 -0
index ccd9128..a2e5609 100644
@@ -270,6 +270,10 @@ static int ubifs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
              goto out_budg;
      }
 
Quoted 4 lines

fs/ubifs/dir.c static int ubifs_create(struct inode *dir, struct dentry *dentry, umode_t mode, · line 276

Quoted 4 lines
fs/ubifs/dir.c +4 -0
+     err = ubifs_init_acl(dir, inode);
+     if (err)
+             goto out_inode;
+

The pattern ubifs_budget_space / ubifs_new_inode / ubifs_init_acl / ubifs_init_security repeats a number of times in the code, so it should probably be put in a function.

Quoted 228 lines

fs/ubifs/dir.c static int do_tmpfile(struct inode *dir, struct dentry *dentry, · line 350

Quoted 10 lines
fs/ubifs/dir.c +3 -0
      err = ubifs_init_security(dir, inode, &dentry->d_name);
      if (err)
              goto out_inode;
@@ -341,6 +345,10 @@ static int do_tmpfile(struct inode *dir, struct dentry *dentry,
              ubifs_assert(inode->i_op == &ubifs_file_inode_operations);
      }
 
+     err = ubifs_init_acl(dir, inode);
+     if (err)
+             goto out_inode;

Why do we need ACLs for O_TMPFILE?

Quoted 27 lines
fs/ubifs/dir.c +9 -0
+
      err = ubifs_init_security(dir, inode, &dentry->d_name);
      if (err)
              goto out_inode;
@@ -821,6 +829,10 @@ static int ubifs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
              goto out_budg;
      }
 
+     err = ubifs_init_acl(dir, inode);
+     if (err)
+             goto out_inode;
+
      err = ubifs_init_security(dir, inode, &dentry->d_name);
      if (err)
              goto out_inode;
@@ -903,6 +915,10 @@ static int ubifs_mknod(struct inode *dir, struct dentry *dentry,
      ui->data = dev;
      ui->data_len = devlen;
 
+     err = ubifs_init_acl(dir, inode);
+     if (err)
+             goto out_inode;
+
      err = ubifs_init_security(dir, inode, &dentry->d_name);
      if (err)
              goto out_inode;

fs/ubifs/dir.c static int ubifs_symlink(struct inode *dir, struct dentry *dentry, · line 1006

Quoted 6 lines
fs/ubifs/dir.c +3 -0
@@ -985,6 +1001,10 @@ static int ubifs_symlink(struct inode *dir, struct dentry *dentry,
      ui->data_len = len;
      inode->i_size = ubifs_inode(inode)->ui_size = len;
 
+     err = ubifs_init_acl(dir, inode);
+     if (err)
+             goto out_inode;

Do we really need ACLs for symlinks too? I thought permissions for symlinks are irrelevant.

Quoted 134 lines
fs/ubifs/dir.c +2 -0
      err = ubifs_init_security(dir, inode, &dentry->d_name);
      if (err)
              goto out_inode;
@@ -1395,6 +1415,8 @@ const struct inode_operations ubifs_dir_inode_operations = {
      .update_time = ubifs_update_time,
 #endif
      .tmpfile     = ubifs_tmpfile,
+     .get_acl     = ubifs_get_acl,
+     .set_acl     = ubifs_set_acl,
 };
 
 const struct file_operations ubifs_dir_operations = {
fs/ubifs/file.c +9 -0
index 4ed270b..17f6098 100644
@@ -53,6 +53,7 @@
 #include <linux/mount.h>
 #include <linux/slab.h>
 #include <linux/migrate.h>
+#include <linux/posix_acl.h>
 
 static int read_block(struct inode *inode, void *addr, unsigned int block,
                    struct ubifs_data_node *dn)
@@ -1251,6 +1252,10 @@ static int do_setattr(struct ubifs_info *c, struct inode *inode,
              ubifs_release_budget(c, &req);
      if (IS_SYNC(inode))
              err = inode->i_sb->s_op->write_inode(inode, NULL);
+
+     if (!err && (attr->ia_valid & ATTR_MODE))
+             err = posix_acl_chmod(inode, inode->i_mode);
+
      return err;
 }
 
@@ -1628,6 +1633,8 @@ const struct inode_operations ubifs_file_inode_operations = {
 #ifdef CONFIG_UBIFS_ATIME_SUPPORT
      .update_time = ubifs_update_time,
 #endif
+     .get_acl     = ubifs_get_acl,
+     .set_acl     = ubifs_set_acl,
 };
 
 const struct inode_operations ubifs_symlink_inode_operations = {
@@ -1642,6 +1649,8 @@ const struct inode_operations ubifs_symlink_inode_operations = {
 #ifdef CONFIG_UBIFS_ATIME_SUPPORT
      .update_time = ubifs_update_time,
 #endif
+     .get_acl     = ubifs_get_acl,
+     .set_acl     = ubifs_set_acl,
 };
 
 const struct file_operations ubifs_file_operations = {
fs/ubifs/super.c +15 -0
index 4ec0510..8239dfd 100644
@@ -444,6 +444,9 @@ static int ubifs_show_options(struct seq_file *s, struct dentry *root)
                         ubifs_compr_name(c->mount_opts.compr_type));
      }
 
+     if (c->vfs_sb->s_flags & MS_POSIXACL)
+             seq_puts(s, ",acl");
+
      return 0;
 }
 
@@ -929,6 +932,8 @@ enum {
      Opt_chk_data_crc,
      Opt_no_chk_data_crc,
      Opt_override_compr,
+     Opt_acl,
+     Opt_noacl,
      Opt_err,
 };
 
@@ -940,6 +945,8 @@ static const match_table_t tokens = {
      {Opt_chk_data_crc, "chk_data_crc"},
      {Opt_no_chk_data_crc, "no_chk_data_crc"},
      {Opt_override_compr, "compr=%s"},
+     {Opt_acl, "acl"},
+     {Opt_noacl, "noacl"},
      {Opt_err, NULL},
 };
 
@@ -1040,6 +1047,14 @@ static int ubifs_parse_options(struct ubifs_info *c, char *options,
                      c->default_compr = c->mount_opts.compr_type;
                      break;
              }
+#ifdef CONFIG_UBIFS_FS_POSIX_ACL
+             case Opt_acl:
+                     c->vfs_sb->s_flags |= MS_POSIXACL;
+                     break;
+             case Opt_noacl:
+                     c->vfs_sb->s_flags &= ~MS_POSIXACL;
+                     break;
+#endif
              default:
              {
                      unsigned long flag;
fs/ubifs/ubifs.h +18 -0
index 096035e..7935449 100644
@@ -1743,6 +1743,24 @@ extern const struct xattr_handler *ubifs_xattr_handlers[];
 ssize_t ubifs_listxattr(struct dentry *dentry, char *buffer, size_t size);
 int ubifs_init_security(struct inode *dentry, struct inode *inode,
                      const struct qstr *qstr);
+ssize_t __ubifs_getxattr(struct inode *host, const char *name,
+                             void *buf, size_t size);
+int __ubifs_setxattr(struct inode *host, const char *name,
+                         const void *value, size_t size, int flags);
+
+/* acl.c */
+#ifdef CONFIG_UBIFS_FS_POSIX_ACL
+int ubifs_init_acl(struct inode *dir, struct inode *inode);
+int ubifs_set_acl(struct inode *inode, struct posix_acl *acl, int type);
+struct posix_acl *ubifs_get_acl(struct inode *inode, int type);
+#else
+static inline int ubifs_init_acl(struct inode *inode, struct inode *dir)
+{
+     return 0;
+}
+#define ubifs_get_acl NULL
+#define ubifs_set_acl NULL
+#endif
 
 /* super.c */
 struct inode *ubifs_iget(struct super_block *sb, unsigned long inum);
fs/ubifs/xattr.c +0 -0
index 6c2f4d4..0a596a1 100644

fs/ubifs/xattr.c line 55

Quoted 5 lines
fs/ubifs/xattr.c +1 -1
@@ -52,13 +52,14 @@
  * in the VFS inode cache. The xentries are cached in the LNC cache (see
  * tnc.c).
  *
- * ACL support is not implemented.
+ * ACL support is now implemented.

I think we can just drop that line now. :-)

fs/ubifs/xattr.c line 62

Quoted 7 lines
fs/ubifs/xattr.c +1 -0
  */
 
 #include "ubifs.h"
 #include <linux/fs.h>
 #include <linux/slab.h>
 #include <linux/xattr.h>
+#include <linux/posix_acl_xattr.h>

While we are here, these includes should also be cleaned up.

Quoted 27 lines
fs/ubifs/xattr.c +5 -2
 /*
  * Limit the number of extended attributes per inode so that the total size
@@ -268,7 +269,7 @@ static struct inode *iget_xattr(struct ubifs_info *c, ino_t inum)
      return ERR_PTR(-EINVAL);
 }
 
-static int __ubifs_setxattr(struct inode *host, const char *name,
+int __ubifs_setxattr(struct inode *host, const char *name,
                          const void *value, size_t size, int flags)
 {
      struct inode *inode;
@@ -328,7 +329,7 @@ out_free:
      return err;
 }
 
-static ssize_t __ubifs_getxattr(struct inode *host, const char *name,
+ssize_t __ubifs_getxattr(struct inode *host, const char *name,
                              void *buf, size_t size)
 {
      struct inode *inode;
@@ -619,5 +620,9 @@ const struct xattr_handler *ubifs_xattr_handlers[] = {
      &ubifs_user_xattr_handler,
      &ubifs_trusted_xattr_handler,
      &ubifs_security_xattr_handler,
+#ifdef CONFIG_UBIFS_FS_POSIX_ACL
+     &posix_acl_access_xattr_handler,
+     &posix_acl_default_xattr_handler,
Quoted 8 lines

fs/ubifs/xattr.c const struct xattr_handler *ubifs_xattr_handlers[] = { · line 628

Quoted 4 lines
fs/ubifs/xattr.c +1 -0
+#endif
      NULL
 };

Overall the patch does not look bad and I'm sure we can add it for v4.10 soon. I'm a bit confused since most stuff is not really UBIFS specific.
Andreas, is just "normal" for ACL support? I thought most code is generic and already in VFS.

There are several filesystems like ubifs that use the xattr representation as the on-disk format, so ubifs_get_acl and ubifs_set_acl could be abstracted and shared across those filesystems. The rest looks good.

Thanks,
Andreas

#6 lore raw
Quoted 235 lines · Andreas Gruenbacher
Quoted 233 lines · Andreas Gruenbacher

Pascal,

Quoted 9 lines · Richard Weinberger

Pascal,

Quoted 3 lines · Pascal Eberhard

This patch implements POSIX Access Control Lists (ACLs) in UBIFS. It uses posix_acl_(access|default)_xattr_handler ACL generic handlers as xattr handlers are now used in UBIFS.

Cool! :)
CC'ing Andreas, maybe he also has comments.

please run this through xfstests as well. Note the following fixes / improvements I've made in the course of reviewing this; they've obviously not been merged, yet:

https://github.com/andreas-gruenbacher/xfsprogs-dev/commits/io
https://github.com/andreas-gruenbacher/xfstests/commits/tmpfile

Quoted 103 lines
Quoted 55 lines
---
 fs/ubifs/Kconfig  |  13 +++++
 fs/ubifs/Makefile |   1 +
 fs/ubifs/acl.c    | 143 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 fs/ubifs/dir.c    |  22 +++++++++
 fs/ubifs/file.c   |   9 ++++
 fs/ubifs/super.c  |  15 ++++++
 fs/ubifs/ubifs.h  |  18 +++++++
 fs/ubifs/xattr.c  |  11 +++--
 8 files changed, 229 insertions(+), 3 deletions(-)
 create mode 100644 fs/ubifs/acl.c
fs/ubifs/Kconfig +13 -0
index 7ff7712..39119e5 100644
@@ -50,3 +50,16 @@ config UBIFS_ATIME_SUPPORT
        strictatime is the "heavy", relatime is "lighter", etc.
 
        If unsure, say 'N'
+
+config UBIFS_FS_POSIX_ACL
+     bool "UBIFS POSIX Access Control Lists"
+     depends on UBIFS_FS
+     select FS_POSIX_ACL
+     help
+       POSIX Access Control Lists (ACLs) support permissions for users and
+       groups beyond the owner/group/world scheme.
+
+       To learn more about Access Control Lists, visit the POSIX ACLs for
+       Linux website <https://urldefense.proofpoint.com/v2/url?u=http-3A__acl.bestbits.at_&d=DQIBaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=sDzg6MvHymKOUgI8SFIm4Q&m=kMcqxODxmAbECYcLW6bRou3Q-jJYfAL4HPw5ErTumUU&s=De0Qb4gRiGITbgivfS5NKW92fL7-HKCGNvCnAMU6CwM&e= >.
+
+       If you don't know what Access Control Lists are, say N
fs/ubifs/Makefile +1 -0
index c54a243..af7a83f 100644
@@ -5,3 +5,4 @@ ubifs-y += tnc.o master.o scan.o replay.o log.o commit.o gc.o orphan.o
 ubifs-y += budget.o find.o tnc_commit.o compress.o lpt.o lprops.o
 ubifs-y += recovery.o ioctl.o lpt_commit.o tnc_misc.o xattr.o debug.o
 ubifs-y += misc.o
+ubifs-$(CONFIG_UBIFS_FS_POSIX_ACL) += acl.o
\ No newline at end of file
fs/ubifs/acl.c new file +5 -0
new file mode 100644
index 0000000..a4d4734
@@ -0,0 +1,143 @@
+/*
+ * This file is part of UBIFS.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published by

fs/ubifs/acl.c line 15

Quoted 10 lines
fs/ubifs/acl.c new file +10 -0
+ * the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ */
+
+#include <linux/fs.h>

ubifs.h includes this already.

fs/ubifs/acl.c line 16

Quoted 1 line
fs/ubifs/acl.c new file +1 -0
+#include <linux/xattr.h>

Ditto.

Quoted 31 lines
fs/ubifs/acl.c new file +31 -0
+#include <linux/posix_acl_xattr.h>
+
+#include "ubifs.h"
+
+struct posix_acl *ubifs_get_acl(struct inode *inode, int type)
+{
+     int size;
+     const char *name;
+     char *value = NULL;
+     struct posix_acl *acl;
+
+     switch (type) {
+     case ACL_TYPE_ACCESS:
+             name = XATTR_NAME_POSIX_ACL_ACCESS;
+             break;
+     case ACL_TYPE_DEFAULT:
+             name = XATTR_NAME_POSIX_ACL_DEFAULT;
+             break;
+     default:
+             return ERR_PTR(-EINVAL);
+     }
+
+     size = __ubifs_getxattr(inode, name, NULL, 0);
+     if (size > 0) {
+             value = kzalloc(size, GFP_KERNEL);
+             if (!value)
+                     return ERR_PTR(-ENOMEM);
+             size = __ubifs_getxattr(inode, name, value, size);
+     }
+     if (size > 0)
+             acl = posix_acl_from_xattr(&init_user_ns, value, size);
Quoted 8 lines

fs/ubifs/acl.c line 55

Quoted 8 lines
fs/ubifs/acl.c new file +8 -0
+     else if (size == -ERANGE || size == -ENODATA || size == 0)
+             acl = NULL;
+     else
+             acl = ERR_PTR(size);
+
+     kfree(value);
+     if (!IS_ERR(acl))
+             set_cached_acl(inode, type, acl);

The get_acl inode operation should no longer call set_cached_acl; the cached ACL is updated automatically. (It's correct to use set_cached_acl in the set_acl inode operation though.)

Quoted 62 lines
Quoted 48 lines
fs/ubifs/acl.c new file +48 -0
+
+     return acl;
+}
+
+int ubifs_set_acl(struct inode *inode, struct posix_acl *acl, int type)
+{
+     int ret;
+     int size = 0;
+     const char *name;
+     char *value = NULL;
+     int flags = 0;
+
+     switch (type) {
+     case ACL_TYPE_ACCESS:
+             name = XATTR_NAME_POSIX_ACL_ACCESS;
+             if (acl) {
+                     ret = posix_acl_equiv_mode(acl, &inode->i_mode);
+                     if (ret < 0)
+                             return ret;
+                     if (ret == 0)
+                             acl = NULL;
+             }
+             ret = 0;
+             break;
+     case ACL_TYPE_DEFAULT:
+             if (!S_ISDIR(inode->i_mode))
+                     return acl ? -EINVAL : 0;
+             name = XATTR_NAME_POSIX_ACL_DEFAULT;
+             break;
+     default:
+             return -EINVAL;
+     }
+
+     if (acl) {
+             size = posix_acl_xattr_size(acl->a_count);
+             value = kmalloc(size, GFP_KERNEL);
+             if (!value)
+                     return -ENOMEM;
+
+             ret = posix_acl_to_xattr(&init_user_ns, acl, value, size);
+             if (ret < 0)
+                     goto out;
+     }
+
+     if (size == 0)
+             flags = XATTR_REPLACE;
+     ret = __ubifs_setxattr(inode, name, value, size, flags);
+

fs/ubifs/acl.c line 113

Quoted 10 lines
fs/ubifs/acl.c new file +10 -0
+out:
+     kfree(value);
+     if (!ret)
+             set_cached_acl(inode, type, acl);
+
+     return ret;
+}
+
+/*
+ * Initialize the ACLs of a new inode.

Please use the Javadoc style we use for all UBIFS functions. (applies to other functions too in this patch)-

Quoted 12 lines

fs/ubifs/acl.c line 125

Quoted 12 lines
fs/ubifs/acl.c new file +12 -0
+ */
+int ubifs_init_acl(struct inode *dir, struct inode *inode)
+{
+     struct posix_acl *default_acl, *acl;
+     int ret = 0;
+
+     ret = posix_acl_create(dir, &inode->i_mode, &default_acl, &acl);
+     if (ret)
+             return ret;
+
+     if (default_acl) {
+             inode_lock(inode);

Why the inode locking here?

Quoted 8 lines

fs/ubifs/acl.c line 133

Quoted 8 lines
fs/ubifs/acl.c new file +8 -0
+             ret = ubifs_set_acl(inode, default_acl, ACL_TYPE_DEFAULT);
+             inode_unlock(inode);
+             posix_acl_release(default_acl);
+     }
+
+     if (acl) {
+             if (!ret) {
+                     inode_lock(inode);

Same here.

Quoted 8 lines
Quoted 8 lines
fs/ubifs/acl.c new file +8 -0
+                     ret = ubifs_set_acl(inode, acl, ACL_TYPE_ACCESS);
+                     inode_unlock(inode);
+             }
+             posix_acl_release(acl);
+     }
+
+     if (!default_acl && !acl)
+             cache_no_acl(inode);
Quoted 5 lines
Quoted 2 lines

This call to cache_no_acl doesn't make sense; please check. It may be wrong in btrfs as well; copying Josef for that.

Now with Josef's current email address, hopefully.

Looks right to me, we call this during inode creation, so if there is no ACL to set then we cache no acl so we don't waste the lookup later. Thanks,

Josef

#7 lore raw
Quoted 2 lines · Josef Bacik

Looks right to me, we call this during inode creation, so if there is no ACL to set then we cache no acl so we don't waste the lookup later.

This is when we create an new inode, so neither i_acl nor i_default_acl should be ACL_NOT_CACHED when this function succeeds. So either we should make sure that i_acl and i_default_acl are already not set to ACL_NOT_CACHED anymore when entering this function, or cache_no_acl should be called unconditionally before setting the actual ACLs.

Thanks,
Andreas

#8 lore raw
In reply to Andreas Gruenbacher

Hi Andreas,

Thanks for your comments.

Quoted 13 lines · Andreas Gruenbacher

Pascal,

Quoted 9 lines · Richard Weinberger

Pascal,

Quoted 3 lines · Pascal Eberhard

This patch implements POSIX Access Control Lists (ACLs) in UBIFS. It uses posix_acl_(access|default)_xattr_handler ACL generic handlers as xattr handlers are now used in UBIFS.

Cool! :)
CC'ing Andreas, maybe he also has comments.

Quoted 6 lines

please run this through xfstests as well. Note the following fixes / improvements I've made in the course of reviewing this; they've obviously not been merged, yet:

https://github.com/andreas-gruenbacher/xfsprogs-dev/commits/io
https://github.com/andreas-gruenbacher/xfstests/commits/tmpfile

Ok, nice :), I will run them.

Quoted 117 lines
Quoted 117 lines
Quoted 73 lines
---
 fs/ubifs/Kconfig  |  13 +++++
 fs/ubifs/Makefile |   1 +
 fs/ubifs/acl.c    | 143 
++++++++++++++++++++++++++++++++++++++++++++++++++++++
 fs/ubifs/dir.c    |  22 +++++++++
 fs/ubifs/file.c   |   9 ++++
 fs/ubifs/super.c  |  15 ++++++
 fs/ubifs/ubifs.h  |  18 +++++++
 fs/ubifs/xattr.c  |  11 +++--
 8 files changed, 229 insertions(+), 3 deletions(-)
 create mode 100644 fs/ubifs/acl.c
fs/ubifs/Kconfig +7 -0
index 7ff7712..39119e5 100644
@@ -50,3 +50,16 @@ config UBIFS_ATIME_SUPPORT
        strictatime is the "heavy", relatime is "lighter", etc.
 
        If unsure, say 'N'
+
+config UBIFS_FS_POSIX_ACL
+     bool "UBIFS POSIX Access Control Lists"
+     depends on UBIFS_FS
+     select FS_POSIX_ACL
+     help
+       POSIX Access Control Lists (ACLs) support permissions for 

users and

fs/ubifs/Kconfig +3 -0
+       groups beyond the owner/group/world scheme.
+
+       To learn more about Access Control Lists, visit the POSIX 

ACLs for

fs/ubifs/Kconfig +3 -0
+       Linux website <http://acl.bestbits.at/>.
+
+       If you don't know what Access Control Lists are, say N
fs/ubifs/Makefile +0 -0
index c54a243..af7a83f 100644
@@ -5,3 +5,4 @@ ubifs-y += tnc.o master.o scan.o replay.o log.o 

commit.o gc.o orphan.o
ubifs-y += budget.o find.o tnc_commit.o compress.o lpt.o lprops.o ubifs-y += recovery.o ioctl.o lpt_commit.o tnc_misc.o xattr.o
debug.o
ubifs-y += misc.o

fs/ubifs/Makefile +1 -0
+ubifs-$(CONFIG_UBIFS_FS_POSIX_ACL) += acl.o
\ No newline at end of file
fs/ubifs/acl.c new file +4 -0
new file mode 100644
index 0000000..a4d4734
@@ -0,0 +1,143 @@
+/*
+ * This file is part of UBIFS.
+ *
+ * This program is free software; you can redistribute it and/or 

modify it
+ * under the terms of the GNU General Public License version 2 as published by
+ * the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ */

fs/ubifs/acl.c line 15

Quoted 2 lines
fs/ubifs/acl.c new file +2 -0
+
+#include <linux/fs.h>

ubifs.h includes this already.

Quoted 1 line

+#include <linux/xattr.h>

Ditto.

Quoted 35 lines
fs/ubifs/acl.c new file +35 -0
+#include <linux/posix_acl_xattr.h>
+
+#include "ubifs.h"
+
+struct posix_acl *ubifs_get_acl(struct inode *inode, int type)
+{
+     int size;
+     const char *name;
+     char *value = NULL;
+     struct posix_acl *acl;
+
+     switch (type) {
+     case ACL_TYPE_ACCESS:
+             name = XATTR_NAME_POSIX_ACL_ACCESS;
+             break;
+     case ACL_TYPE_DEFAULT:
+             name = XATTR_NAME_POSIX_ACL_DEFAULT;
+             break;
+     default:
+             return ERR_PTR(-EINVAL);
+     }
+
+     size = __ubifs_getxattr(inode, name, NULL, 0);
+     if (size > 0) {
+             value = kzalloc(size, GFP_KERNEL);
+             if (!value)
+                     return ERR_PTR(-ENOMEM);
+             size = __ubifs_getxattr(inode, name, value, size);
+     }
+     if (size > 0)
+             acl = posix_acl_from_xattr(&init_user_ns, value, size);
+     else if (size == -ERANGE || size == -ENODATA || size == 0)
+             acl = NULL;
+     else
+             acl = ERR_PTR(size);
Quoted 8 lines
Quoted 4 lines

fs/ubifs/acl.c line 55

Quoted 4 lines
fs/ubifs/acl.c new file +4 -0
+
+     kfree(value);
+     if (!IS_ERR(acl))
+             set_cached_acl(inode, type, acl);

The get_acl inode operation should no longer call set_cached_acl; the cached ACL is updated automatically. (It's correct to use set_cached_acl in the set_acl inode operation though.)

ok

Quoted 65 lines
Quoted 65 lines
Quoted 51 lines
fs/ubifs/acl.c new file +5 -0
+
+     return acl;
+}
+
+int ubifs_set_acl(struct inode *inode, struct posix_acl *acl, int 

type)

fs/ubifs/acl.c new file +12 -0
+{
+     int ret;
+     int size = 0;
+     const char *name;
+     char *value = NULL;
+     int flags = 0;
+
+     switch (type) {
+     case ACL_TYPE_ACCESS:
+             name = XATTR_NAME_POSIX_ACL_ACCESS;
+             if (acl) {
+                     ret = posix_acl_equiv_mode(acl, 

&inode->i_mode);

fs/ubifs/acl.c new file +23 -0
+                     if (ret < 0)
+                             return ret;
+                     if (ret == 0)
+                             acl = NULL;
+             }
+             ret = 0;
+             break;
+     case ACL_TYPE_DEFAULT:
+             if (!S_ISDIR(inode->i_mode))
+                     return acl ? -EINVAL : 0;
+             name = XATTR_NAME_POSIX_ACL_DEFAULT;
+             break;
+     default:
+             return -EINVAL;
+     }
+
+     if (acl) {
+             size = posix_acl_xattr_size(acl->a_count);
+             value = kmalloc(size, GFP_KERNEL);
+             if (!value)
+                     return -ENOMEM;
+
+             ret = posix_acl_to_xattr(&init_user_ns, acl, value, 

size);

fs/ubifs/acl.c new file +8 -0
+             if (ret < 0)
+                     goto out;
+     }
+
+     if (size == 0)
+             flags = XATTR_REPLACE;
+     ret = __ubifs_setxattr(inode, name, value, size, flags);
+

fs/ubifs/acl.c line 113

Quoted 10 lines
fs/ubifs/acl.c new file +10 -0
+out:
+     kfree(value);
+     if (!ret)
+             set_cached_acl(inode, type, acl);
+
+     return ret;
+}
+
+/*
+ * Initialize the ACLs of a new inode.

Please use the Javadoc style we use for all UBIFS functions. (applies to other functions too in this patch)-

Quoted 15 lines
Quoted 5 lines
Quoted 5 lines

+ */

fs/ubifs/acl.c new file +4 -0
+int ubifs_init_acl(struct inode *dir, struct inode *inode)
+{
+     struct posix_acl *default_acl, *acl;
+     int ret = 0;
Quoted 8 lines

fs/ubifs/acl.c line 125

Quoted 8 lines
fs/ubifs/acl.c new file +2 -0
+
+     ret = posix_acl_create(dir, &inode->i_mode, &default_acl, 

&acl);

fs/ubifs/acl.c new file +5 -0
+     if (ret)
+             return ret;
+
+     if (default_acl) {
+             inode_lock(inode);

Why the inode locking here?

I see no reason why we should keep it but I will double check.

Quoted 11 lines
Quoted 9 lines

fs/ubifs/acl.c line 133

Quoted 9 lines

+ ret = ubifs_set_acl(inode, default_acl,
ACL_TYPE_DEFAULT);

fs/ubifs/acl.c new file +7 -0
+             inode_unlock(inode);
+             posix_acl_release(default_acl);
+     }
+
+     if (acl) {
+             if (!ret) {
+                     inode_lock(inode);

Same here.

Same here :)

Quoted 10 lines
Quoted 9 lines

fs/ubifs/acl.c line 141

Quoted 9 lines

+ ret = ubifs_set_acl(inode, acl,
ACL_TYPE_ACCESS);

fs/ubifs/acl.c new file +7 -0
+                     inode_unlock(inode);
+             }
+             posix_acl_release(acl);
+     }
+
+     if (!default_acl && !acl)
+             cache_no_acl(inode);
Quoted 2 lines

This call to cache_no_acl doesn't make sense; please check. It may be wrong in btrfs as well; copying Josef for that.

Both i_acl and i_default_acl are set to ACL_NOT_CACHED when entering ubifs_init_acl().
As proposed, the function will be updated so cache_no_acl() will be called unconditionally before setting the actual ACLs (if any).

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
fs/ubifs/acl.c new file +2 -0
+     return ret;
+}
fs/ubifs/dir.c +0 -0
index ccd9128..a2e5609 100644
@@ -270,6 +270,10 @@ static int ubifs_create(struct inode *dir, 
 struct dentry *dentry, umode_t mode,
              goto out_budg;
      }
 
Quoted 8 lines
Quoted 4 lines

fs/ubifs/dir.c static int ubifs_create(struct inode *dir, struct dentry *dentry, umode_t mode, · line 276

Quoted 4 lines
fs/ubifs/dir.c +4 -0
+     err = ubifs_init_acl(dir, inode);
+     if (err)
+             goto out_inode;
+

The pattern ubifs_budget_space / ubifs_new_inode / ubifs_init_acl / ubifs_init_security repeats a number of times in the code, so it should probably be put in a function.

I will look into it.

Quoted 259 lines
Quoted 250 lines

fs/ubifs/dir.c static int do_tmpfile(struct inode *dir, struct · line 352

Quoted 12 lines
fs/ubifs/dir.c +0 -0
      err = ubifs_init_security(dir, inode, &dentry->d_name);
      if (err)
              goto out_inode;
fs/ubifs/dir.c +3 -0
@@ -341,6 +345,10 @@ static int do_tmpfile(struct inode *dir, struct 
 dentry *dentry,
              ubifs_assert(inode->i_op == 
 &ubifs_file_inode_operations);
      }
 
+     err = ubifs_init_acl(dir, inode);
+     if (err)
+             goto out_inode;

Why do we need ACLs for O_TMPFILE?

Quoted 29 lines
fs/ubifs/dir.c +1 -0
+
      err = ubifs_init_security(dir, inode, &dentry->d_name);
      if (err)
              goto out_inode;
fs/ubifs/dir.c +4 -0
@@ -821,6 +829,10 @@ static int ubifs_mkdir(struct inode *dir, struct 
 dentry *dentry, umode_t mode)
              goto out_budg;
      }
 
+     err = ubifs_init_acl(dir, inode);
+     if (err)
+             goto out_inode;
+
      err = ubifs_init_security(dir, inode, &dentry->d_name);
      if (err)
              goto out_inode;
fs/ubifs/dir.c +4 -0
@@ -903,6 +915,10 @@ static int ubifs_mknod(struct inode *dir, struct 
 dentry *dentry,
      ui->data = dev;
      ui->data_len = devlen;
 
+     err = ubifs_init_acl(dir, inode);
+     if (err)
+             goto out_inode;
+
      err = ubifs_init_security(dir, inode, &dentry->d_name);
      if (err)
              goto out_inode;

fs/ubifs/dir.c static int ubifs_symlink(struct inode *dir, · line 1007

Quoted 7 lines
fs/ubifs/dir.c +3 -0
@@ -985,6 +1001,10 @@ static int ubifs_symlink(struct inode *dir, 
 struct dentry *dentry,
      ui->data_len = len;
      inode->i_size = ubifs_inode(inode)->ui_size = len;
 
+     err = ubifs_init_acl(dir, inode);
+     if (err)
+             goto out_inode;

Do we really need ACLs for symlinks too? I thought permissions for symlinks are irrelevant.

Quoted 147 lines
fs/ubifs/dir.c +2 -0
      err = ubifs_init_security(dir, inode, &dentry->d_name);
      if (err)
              goto out_inode;
@@ -1395,6 +1415,8 @@ const struct inode_operations 
 ubifs_dir_inode_operations = {
      .update_time = ubifs_update_time,
 #endif
      .tmpfile     = ubifs_tmpfile,
+     .get_acl     = ubifs_get_acl,
+     .set_acl     = ubifs_set_acl,
 };
 

const struct file_operations ubifs_dir_operations = {

fs/ubifs/file.c +1 -0
index 4ed270b..17f6098 100644
@@ -53,6 +53,7 @@
 #include <linux/mount.h>
 #include <linux/slab.h>
 #include <linux/migrate.h>
+#include <linux/posix_acl.h>
 
 static int read_block(struct inode *inode, void *addr, unsigned int 
 block,

struct ubifs_data_node *dn)

fs/ubifs/file.c +6 -0
@@ -1251,6 +1252,10 @@ static int do_setattr(struct ubifs_info *c, 
 struct inode *inode,
              ubifs_release_budget(c, &req);
      if (IS_SYNC(inode))
              err = inode->i_sb->s_op->write_inode(inode, NULL);
+
+     if (!err && (attr->ia_valid & ATTR_MODE))
+             err = posix_acl_chmod(inode, inode->i_mode);
+
      return err;
 }
@@ -1628,6 +1633,8 @@ const struct inode_operations 
 ubifs_file_inode_operations = {
 #ifdef CONFIG_UBIFS_ATIME_SUPPORT
      .update_time = ubifs_update_time,
 #endif
+     .get_acl     = ubifs_get_acl,
+     .set_acl     = ubifs_set_acl,
 };
 

const struct inode_operations ubifs_symlink_inode_operations = {

fs/ubifs/file.c +2 -0
@@ -1642,6 +1649,8 @@ const struct inode_operations 
 ubifs_symlink_inode_operations = {
 #ifdef CONFIG_UBIFS_ATIME_SUPPORT
      .update_time = ubifs_update_time,
 #endif
+     .get_acl     = ubifs_get_acl,
+     .set_acl     = ubifs_set_acl,
 };
 

const struct file_operations ubifs_file_operations = {

fs/ubifs/super.c +15 -0
index 4ec0510..8239dfd 100644
@@ -444,6 +444,9 @@ static int ubifs_show_options(struct seq_file *s, 
 struct dentry *root)
                         ubifs_compr_name(c->mount_opts.compr_type));
      }
 
+     if (c->vfs_sb->s_flags & MS_POSIXACL)
+             seq_puts(s, ",acl");
+
      return 0;
 }
@@ -929,6 +932,8 @@ enum {
      Opt_chk_data_crc,
      Opt_no_chk_data_crc,
      Opt_override_compr,
+     Opt_acl,
+     Opt_noacl,
      Opt_err,
 };
 
@@ -940,6 +945,8 @@ static const match_table_t tokens = {
      {Opt_chk_data_crc, "chk_data_crc"},
      {Opt_no_chk_data_crc, "no_chk_data_crc"},
      {Opt_override_compr, "compr=%s"},
+     {Opt_acl, "acl"},
+     {Opt_noacl, "noacl"},
      {Opt_err, NULL},
 };
 
@@ -1040,6 +1047,14 @@ static int ubifs_parse_options(struct 
 ubifs_info *c, char *options,
                      c->default_compr = c->mount_opts.compr_type;
                      break;
              }
+#ifdef CONFIG_UBIFS_FS_POSIX_ACL
+             case Opt_acl:
+                     c->vfs_sb->s_flags |= MS_POSIXACL;
+                     break;
+             case Opt_noacl:
+                     c->vfs_sb->s_flags &= ~MS_POSIXACL;
+                     break;
+#endif
              default:
              {
                      unsigned long flag;
fs/ubifs/ubifs.h +12 -0
index 096035e..7935449 100644
@@ -1743,6 +1743,24 @@ extern const struct xattr_handler 
 *ubifs_xattr_handlers[];
 ssize_t ubifs_listxattr(struct dentry *dentry, char *buffer, size_t 
 size);
 int ubifs_init_security(struct inode *dentry, struct inode *inode,
                      const struct qstr *qstr);
+ssize_t __ubifs_getxattr(struct inode *host, const char *name,
+                             void *buf, size_t size);
+int __ubifs_setxattr(struct inode *host, const char *name,
+                         const void *value, size_t size, int flags);
+
+/* acl.c */
+#ifdef CONFIG_UBIFS_FS_POSIX_ACL
+int ubifs_init_acl(struct inode *dir, struct inode *inode);
+int ubifs_set_acl(struct inode *inode, struct posix_acl *acl, int 
 type);
+struct posix_acl *ubifs_get_acl(struct inode *inode, int type);
+#else
+static inline int ubifs_init_acl(struct inode *inode, struct inode 

*dir)

fs/ubifs/ubifs.h +6 -0
+{
+     return 0;
+}
+#define ubifs_get_acl NULL
+#define ubifs_set_acl NULL
+#endif
 
 /* super.c */
 struct inode *ubifs_iget(struct super_block *sb, unsigned long 

inum);

fs/ubifs/xattr.c +0 -0
index 6c2f4d4..0a596a1 100644
@@ -52,13 +52,14 @@
  * in the VFS inode cache. The xentries are cached in the LNC cache 
Quoted 5 lines

(see
* tnc.c).
*
- * ACL support is not implemented.
+ * ACL support is now implemented.

I think we can just drop that line now. :-)

Quoted 7 lines

*/

#include "ubifs.h"
#include <linux/fs.h>
#include <linux/slab.h>
#include <linux/xattr.h>
+#include <linux/posix_acl_xattr.h>

While we are here, these includes should also be cleaned up.

Quoted 31 lines

/*
* Limit the number of extended attributes per inode so that the
total size

fs/ubifs/xattr.c +1 -1
@@ -268,7 +269,7 @@ static struct inode *iget_xattr(struct ubifs_info 
 *c, ino_t inum)
      return ERR_PTR(-EINVAL);
 }
 
-static int __ubifs_setxattr(struct inode *host, const char *name,
+int __ubifs_setxattr(struct inode *host, const char *name,
                          const void *value, size_t size, int flags)
 {
      struct inode *inode;
fs/ubifs/xattr.c +1 -1
@@ -328,7 +329,7 @@ out_free:
      return err;
 }
 
-static ssize_t __ubifs_getxattr(struct inode *host, const char 
 *name,
+ssize_t __ubifs_getxattr(struct inode *host, const char *name,
                              void *buf, size_t size)
 {
      struct inode *inode;
fs/ubifs/xattr.c +3 -0
@@ -619,5 +620,9 @@ const struct xattr_handler 
 *ubifs_xattr_handlers[] = {
      &ubifs_user_xattr_handler,
      &ubifs_trusted_xattr_handler,
      &ubifs_security_xattr_handler,
+#ifdef CONFIG_UBIFS_FS_POSIX_ACL
+     &posix_acl_access_xattr_handler,
+     &posix_acl_default_xattr_handler,
Quoted 8 lines
Quoted 4 lines
fs/ubifs/xattr.c +1 -0
+#endif
      NULL

};

Overall the patch does not look bad and I'm sure we can add it for v4.10 soon. I'm a bit confused since most stuff is not really UBIFS specific.
Andreas, is just "normal" for ACL support? I thought most code is generic and already in VFS.

Quoted 3 lines

There are several filesystems like ubifs that use the xattr representation as the on-disk format, so ubifs_get_acl and ubifs_set_acl could be abstracted and shared across those filesystems.

I'd like that, unfortunately ubifs_[gs]et_acl() calls __ubifs_[gs]etxattr() which are internal ubifs functions. I am not sure yet how this could be abstracted. I will look into it too.

Quoted 4 lines

The rest looks good.

Thanks,
Andreas