Skip to contentSkip to conversation

Tmpfs acls

PATCH In review Andreas Gruenbacher 5 participants 13 messages Sep 1, 2006 – Sep 6, 2006

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

cover Tmpfs acls

This is a refresh of the patches we have to support POSIX ACLs on tmpfs, with the request for inclusion.

The patches solve the following problem: We want to grant access to devices based on who is logged in from where, etc. This includes switching back and forth between multiple user sessions, etc.

Using ACLs to define device access for logged-in users gives us all the flexibility we need in order to fully solve the problem.

Device special files nowadays usually live on tmpfs, hence tmpfs ACLs.

Different distros have come up with solutions that solve the problem to different degrees: SUSE uses a resource manager which tracks login sessions and sets ACLs on device inodes as appropriate. RedHat uses pam_console, which changes the primary file ownership to the logged-in user. Others use a set of groups that users must be in in order to be granted the appropriate accesses.

The freedesktop.org project plans to implement a combination of a console-tracker and a HAL-device-list based solution to grant access to devices to users, and more distros will likely follow this approach.

-

These patches have first been posted here on 2 February 2005, and again on 8 January 2006. We have been shipping them in SLES9 and SLES10 with no problems reported. The previous submission is archived here:

http://lkml.org/lkml/2006/1/8/229
http://lkml.org/lkml/2006/1/8/230
http://lkml.org/lkml/2006/1/8/231

Could the patches please get included this time?

Andrew, is putting them in -mm for a while fine with you?

Thanks,
Andreas

--
Andreas Gruenbacher <[email protected]>
Novell / SUSE Labs

Signature · 1 line
VGER BF report: U 0.5
#1 lore raw

Generic infrastructure for acls

Add some infrastructure for access control lists on in-memory filesystems such as tmpfs.

---
 fs/Kconfig                  |    4 +
 fs/Makefile                 |    1 
 fs/generic_acl.c            |  172 ++++++++++++++++++++++++++++++++++++++++++++
 include/linux/generic_acl.h |   30 +++++++
 4 files changed, 207 insertions(+)
fs/Kconfig +4 -0
Index: linux-2.6.18-rc5/fs/Kconfig
===================================================================
@@ -1921,6 +1921,10 @@ config 9P_FS
 
 	  If unsure, say N.
 
+config GENERIC_ACL
+	bool
+	select FS_POSIX_ACL
+
 endmenu
 
 menu "Partition Types"
fs/Makefile +1 -0
Index: linux-2.6.18-rc5/fs/Makefile
===================================================================
@@ -35,6 +35,7 @@ obj-$(CONFIG_BINFMT_FLAT)	+= binfmt_flat
 obj-$(CONFIG_FS_MBCACHE)	+= mbcache.o
 obj-$(CONFIG_FS_POSIX_ACL)	+= posix_acl.o xattr_acl.o
 obj-$(CONFIG_NFS_COMMON)	+= nfs_common/
+obj-$(CONFIG_GENERIC_ACL)	+= generic_acl.o
 
 obj-$(CONFIG_QUOTA)		+= dquot.o
 obj-$(CONFIG_QFMT_V1)		+= quota_v1.o
include/linux/generic_acl.h new file +30 -0
Index: linux-2.6.18-rc5/include/linux/generic_acl.h
===================================================================
@@ -0,0 +1,30 @@
+/*
+ * fs/generic_acl.c
+ *
+ * (C) 2005 Andreas Gruenbacher <[email protected]>
+ *
+ * This file is released under the GPL.
+ */
+
+#ifndef GENERIC_ACL_H
+#define GENERIC_ACL_H
+
+#include <linux/posix_acl.h>
+#include <linux/posix_acl_xattr.h>
+
+struct generic_acl_operations {
+	struct posix_acl *(*getacl)(struct inode *, int);
+	void (*setacl)(struct inode *, int, struct posix_acl *);
+};
+
+size_t generic_acl_list(struct inode *, struct generic_acl_operations *, int,
+			char *, size_t);
+int generic_acl_get(struct inode *, struct generic_acl_operations *, int,
+		    void *, size_t);
+int generic_acl_set(struct inode *, struct generic_acl_operations *, int,
+		    const void *, size_t);
+int generic_acl_init(struct inode *, struct inode *,
+		     struct generic_acl_operations *);
+int generic_acl_chmod(struct inode *, struct generic_acl_operations *);
+
+#endif
fs/generic_acl.c new file +172 -0

172 lines not on this page · raw message

--
Andreas Gruenbacher <[email protected]>
SUSE Labs, SUSE LINUX Products GmbH / Novell Inc.

Signature · 1 line
VGER BF report: H 0
#2 lore raw

Re: Generic infrastructure for acls

Quoted 19 lines · On Sat, 02 Sep 2006 00:14:22 +0200 Andreas Gruenbacher <[email protected]> wrote:
fs/generic_acl.c new file +19 -0
+generic_acl_list(struct inode *inode, struct generic_acl_operations *ops,
+		 int type, char *list, size_t list_size)
+{
+	struct posix_acl *acl;
+	const char *name;
+	size_t size;
+
+	acl = ops->getacl(inode, type);
+	if (!acl)
+		return 0;
+	posix_acl_release(acl);
+
+	switch(type) {
+		case ACL_TYPE_ACCESS:
+			name = POSIX_ACL_XATTR_ACCESS;
+			break;
+
+		case ACL_TYPE_DEFAULT:
+			name = POSIX_ACL_XATTR_DEFAULT;

fs/generic_acl.c line 42

Quoted 10 lines
fs/generic_acl.c new file +10 -0
+			break;
+
+		default:
+			return 0;
+	}
+	size = strlen(name) + 1;
+	if (list && size <= list_size)
+		memcpy(list, name, size);
+	return size;
+}

That's a clumsy-looking interface. How is the caller to know that *list got filled in? By checking the generic_acl_list() return value against `list_size'?

If so, shouldn't this be covered in the API description (when you write it ;))?

Or should it be returning some error code in this case?

Or should we just strdup() the thing?

Or return `name' and let the caller worry about it?

Signature · 1 line
VGER BF report: H 1.83187e-15
#3 lore raw

Re: Generic infrastructure for acls

Quoted 26 lines · Andrew Morton

On Sat, 02 Sep 2006 00:14:22 +0200

Quoted 23 lines · Andreas Gruenbacher

+generic_acl_list(struct inode *inode, struct generic_acl_operations
*ops, + int type, char *list, size_t list_size)

fs/generic_acl.c new file +21 -0
+{
+	struct posix_acl *acl;
+	const char *name;
+	size_t size;
+
+	acl = ops->getacl(inode, type);
+	if (!acl)
+		return 0;
+	posix_acl_release(acl);
+
+	switch(type) {
+		case ACL_TYPE_ACCESS:
+			name = POSIX_ACL_XATTR_ACCESS;
+			break;
+
+		case ACL_TYPE_DEFAULT:
+			name = POSIX_ACL_XATTR_DEFAULT;
+			break;
+
+		default:
+			return 0;
Quoted 8 lines

fs/generic_acl.c line 42

Quoted 6 lines
fs/generic_acl.c new file +6 -0
+	}
+	size = strlen(name) + 1;
+	if (list && size <= list_size)
+		memcpy(list, name, size);
+	return size;
+}

That's a clumsy-looking interface.

We could get rid of the switch by passing in the type and the name, but otherwise that's pretty exactly what's needed, no matter if done in a fs-dependent or independent way.

Quoted 1 line

How is the caller to know that *list got filled in? By checking the

generic_acl_list() return value against `list_size'?

The return value determines how many bytes have been used or would be needed in the buffer -- generic_listxattr() in fs/xattr.c has this code:

Quoted 7 lines
for_each_xattr_handler(handlers, handler) {
    size = handler->list(inode, buf, buffer_size, NULL, 0);
    if (size > buffer_size) 
        return -ERANGE;
    buf += size;
    buffer_size -= size;
}

Andreas

Signature · 1 line
VGER BF report: H 0
#4 lore raw

Re: Generic infrastructure for acls

In reply to Andrew Morton
Quoted 1 line · Andrew Morton

That's a clumsy-looking interface.

I have added a little documentation now. This will hopefully suffice to clarify why the interface is as clumsy-looking as it is ;)

Thanks,
Andreas

From: Andreas Gruenbacher <[email protected]>
Subject: Generic infrastructure for acls

Add some infrastructure for access control lists on in-memory filesystems such as tmpfs.

---
 fs/Kconfig                  |    4 +
 fs/Makefile                 |    1 
 fs/generic_acl.c            |  172 ++++++++++++++++++++++++++++++++++++++++++++
 include/linux/generic_acl.h |   30 +++++++
 4 files changed, 207 insertions(+)
fs/Kconfig +4 -0
Index: linux-2.6.18-rc6/fs/Kconfig
===================================================================
@@ -1921,6 +1921,10 @@ config 9P_FS
 
 	  If unsure, say N.
 
+config GENERIC_ACL
+	bool
+	select FS_POSIX_ACL
+
 endmenu
 
 menu "Partition Types"
fs/Makefile +1 -0
Index: linux-2.6.18-rc6/fs/Makefile
===================================================================
@@ -35,6 +35,7 @@ obj-$(CONFIG_BINFMT_FLAT)	+= binfmt_flat
 obj-$(CONFIG_FS_MBCACHE)	+= mbcache.o
 obj-$(CONFIG_FS_POSIX_ACL)	+= posix_acl.o xattr_acl.o
 obj-$(CONFIG_NFS_COMMON)	+= nfs_common/
+obj-$(CONFIG_GENERIC_ACL)	+= generic_acl.o
 
 obj-$(CONFIG_QUOTA)		+= dquot.o
 obj-$(CONFIG_QFMT_V1)		+= quota_v1.o
include/linux/generic_acl.h new file +36 -0
Index: linux-2.6.18-rc6/include/linux/generic_acl.h
===================================================================
@@ -0,0 +1,36 @@
+/*
+ * fs/generic_acl.c
+ *
+ * (C) 2005 Andreas Gruenbacher <[email protected]>
+ *
+ * This file is released under the GPL.
+ */
+
+#ifndef GENERIC_ACL_H
+#define GENERIC_ACL_H
+
+#include <linux/posix_acl.h>
+#include <linux/posix_acl_xattr.h>
+
+/**
+ * struct generic_acl_operations  -  filesystem operations
+ *
+ * Filesystems must make these operations available to the generic
+ * operations.
+ */
+struct generic_acl_operations {
+	struct posix_acl *(*getacl)(struct inode *, int);
+	void (*setacl)(struct inode *, int, struct posix_acl *);
+};
+
+size_t generic_acl_list(struct inode *, struct generic_acl_operations *, int,
+			char *, size_t);
+int generic_acl_get(struct inode *, struct generic_acl_operations *, int,
+		    void *, size_t);
+int generic_acl_set(struct inode *, struct generic_acl_operations *, int,
+		    const void *, size_t);
+int generic_acl_init(struct inode *, struct inode *,
+		     struct generic_acl_operations *);
+int generic_acl_chmod(struct inode *, struct generic_acl_operations *);
+
+#endif
fs/generic_acl.c new file +197 -0

197 lines not on this page · raw message

#5 lore raw

Re: Generic infrastructure for acls

Quoted 5 lines · On Wed, 6 Sep 2006 18:40:12 +0200 Andreas Gruenbacher wrote:
Quoted 1 line · Andrew Morton

That's a clumsy-looking interface.

I have added a little documentation now. This will hopefully suffice to clarify why the interface is as clumsy-looking as it is ;)

oops. A bit difficult to comment on the patch. Anyway, for the kernel-doc function headers (Thanks), all of the parameters need to be listed, not just the first one (@ops).

---
~Randy

#6 lore raw

Re: Generic infrastructure for acls

In reply to Andreas Gruenbacher
Quoted 5 lines
fs/generic_acl.c new file +3 -0
+generic_acl_set(struct inode *inode, struct generic_acl_operations *ops,
+		int type, const void *value, size_t size)
+{

fs/generic_acl.c line 75

Quoted 10 lines
fs/generic_acl.c new file +9 -0
+	struct posix_acl *acl = NULL;
+	int error;
+
+	if (S_ISLNK(inode->i_mode))
+		return -EOPNOTSUPP;
+	if ((current->fsuid != inode->i_uid) && !capable(CAP_FOWNER))
 
+			if (error > 0) {
+				ops->setacl(inode, ACL_TYPE_ACCESS, clone);
+			}

redundant () {}

Jan Engelhardt

#7 lore raw

Access Control Lists for tmpfs

In reply to Andreas Gruenbacher

Add access control lists for tmpfs.

---
 fs/Kconfig               |   13 +++
 include/linux/shmem_fs.h |   21 ++++++
 mm/Makefile              |    1 
 mm/shmem.c               |   94 ++++++++++++++++++++++++++-
 mm/shmem_acl.c           |  163 +++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 290 insertions(+), 2 deletions(-)
fs/Kconfig +13 -0
Index: linux-2.6.18-rc5/fs/Kconfig
===================================================================
@@ -862,6 +862,19 @@ config TMPFS
 
 	  See <file:Documentation/filesystems/tmpfs.txt> for details.
 
+config TMPFS_POSIX_ACL
+	bool "Tmpfs POSIX Access Control Lists"
+	depends on TMPFS
+	select GENERIC_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.
+
 config HUGETLBFS
 	bool "HugeTLB file system support"
 	depends X86 || IA64 || PPC64 || SPARC64 || SUPERH || BROKEN
include/linux/shmem_fs.h +21 -0
Index: linux-2.6.18-rc5/include/linux/shmem_fs.h
===================================================================
@@ -19,6 +19,10 @@ struct shmem_inode_info {
 	swp_entry_t		i_direct[SHMEM_NR_DIRECT]; /* first blocks */
 	struct list_head	swaplist;	/* chain of maybes on swap */
 	struct inode		vfs_inode;
+#ifdef CONFIG_TMPFS_POSIX_ACL
+	struct posix_acl	*i_acl;
+	struct posix_acl	*i_default_acl;
+#endif
 };
 
 struct shmem_sb_info {
@@ -36,4 +40,21 @@ static inline struct shmem_inode_info *S
 	return container_of(inode, struct shmem_inode_info, vfs_inode);
 }
 
+#ifdef CONFIG_TMPFS_POSIX_ACL
+int shmem_permission(struct inode *, int, struct nameidata *);
+int shmem_acl_init(struct inode *, struct inode *);
+void shmem_acl_destroy_inode(struct inode *);
+
+extern struct xattr_handler shmem_xattr_acl_access_handler;
+extern struct xattr_handler shmem_xattr_acl_default_handler;
+#else
+static inline int shmem_acl_init(struct inode *inode, struct inode *dir)
+{
+	return 0;
+}
+static inline void shmem_acl_destroy_inode(struct inode *inode)
+{
+}
+#endif  /* CONFIG_TMPFS_POSIX_ACL */
+
 #endif
mm/Makefile +1 -0
Index: linux-2.6.18-rc5/mm/Makefile
===================================================================
@@ -17,6 +17,7 @@ obj-$(CONFIG_HUGETLBFS)	+= hugetlb.o
 obj-$(CONFIG_NUMA) 	+= mempolicy.o
 obj-$(CONFIG_SPARSEMEM)	+= sparse.o
 obj-$(CONFIG_SHMEM) += shmem.o
+obj-$(CONFIG_TMPFS_POSIX_ACL) += shmem_acl.o
 obj-$(CONFIG_TINY_SHMEM) += tiny-shmem.o
 obj-$(CONFIG_SLOB) += slob.o
 obj-$(CONFIG_SLAB) += slab.o
mm/shmem.c +92 -2

172 lines not on this page · raw message

mm/shmem_acl.c new file +163 -0

163 lines not on this page · raw message

--
Andreas Gruenbacher <[email protected]>
SUSE Labs, SUSE LINUX Products GmbH / Novell Inc.

Signature · 1 line
VGER BF report: H 0.0585043
#8 lore raw

Re: Access Control Lists for tmpfs

mm/shmem_acl.c line 43

Quoted 10 lines · On Sat, 02 Sep 2006 00:14:23 +0200 Andreas Gruenbacher <[email protected]> wrote:
mm/shmem_acl.c new file +10 -0
+static void
+shmem_set_acl(struct inode *inode, int type, struct posix_acl *acl)
+{
+	spin_lock(&inode->i_lock);
+	switch(type) {
+		case ACL_TYPE_ACCESS:
+			if (SHMEM_I(inode)->i_acl)
+				posix_acl_release(SHMEM_I(inode)->i_acl);
+			SHMEM_I(inode)->i_acl = posix_acl_dup(acl);
+			break;

i_lock is "general-purpose, innermost per-inode lock". Calling kfree() under it makes it no longer "innermost". But kfree() is surely atomic wrt everything which filesystems and the VFS will want to do, so that's OK.

However it does point at an inefficiency. There's no need at all to be holding onto that lock while running kfree().

Signature · 1 line
VGER BF report: H 0
#9 lore raw

Re: Access Control Lists for tmpfs

Quoted 17 lines · Andrew Morton

mm/shmem_acl.c line 43

Quoted 10 lines · On Sat, 02 Sep 2006 00:14:23 +0200 Andreas Gruenbacher <[email protected]> wrote:
mm/shmem_acl.c new file +10 -0
+static void
+shmem_set_acl(struct inode *inode, int type, struct posix_acl *acl)
+{
+	spin_lock(&inode->i_lock);
+	switch(type) {
+		case ACL_TYPE_ACCESS:
+			if (SHMEM_I(inode)->i_acl)
+				posix_acl_release(SHMEM_I(inode)->i_acl);
+			SHMEM_I(inode)->i_acl = posix_acl_dup(acl);
+			break;

i_lock is "general-purpose, innermost per-inode lock". Calling kfree() under it makes it no longer "innermost". But kfree() is surely atomic wrt everything which filesystems and the VFS will want to do, so that's OK.

and lockdep probably will yell loudly if there's a problem.

Signature · 1 line
VGER BF report: H 0
#10 lore raw

Re: Access Control Lists for tmpfs

In reply to Andreas Gruenbacher
Quoted 20 lines · On Sat, 02 Sep 2006 00:14:23 +0200 Andreas Gruenbacher <[email protected]> wrote:
mm/shmem.c +3 -0
@@ -26,6 +26,8 @@
 #include <linux/module.h>
 #include <linux/init.h>
 #include <linux/fs.h>
+#include <linux/xattr.h>
+#include <linux/generic_acl.h>
 #include <linux/mm.h>
 #include <linux/mman.h>
 #include <linux/file.h>
@@ -176,6 +178,7 @@ static const struct address_space_operat
 static struct file_operations shmem_file_operations;
 static struct inode_operations shmem_inode_operations;
 static struct inode_operations shmem_dir_inode_operations;
+static struct inode_operations shmem_special_inode_operations;
 static struct vm_operations_struct shmem_vm_ops;
 
 static struct backing_dev_info shmem_backing_dev_info  __read_mostly = {

mm/shmem.c static void shmem_truncate(struct inode · line 636

Quoted 4 lines
mm/shmem.c +1 -0
@@ -630,13 +633,15 @@ static void shmem_truncate(struct inode 
 	shmem_truncate_range(inode, inode->i_size, (loff_t)-1);
 }
 
+extern struct generic_acl_operations shmem_acl_ops;

Can we move this declaration into a header file please?

#11 lore raw

Re: Access Control Lists for tmpfs

Quoted 1 line · Andrew Morton

Can we move this declaration into a header file please?

That's better, yes. Attached is a version that incorporates the feedback so far.

Thanks,
Andreas

From: Andreas Gruenbacher <[email protected]>
Subject: Access Control Lists for tmpfs
References: 118299

Add access control lists for tmpfs.

---
 fs/Kconfig               |   13 +++
 include/linux/shmem_fs.h |   21 ++++++
 mm/Makefile              |    1 
 mm/shmem.c               |   94 ++++++++++++++++++++++++++-
 mm/shmem_acl.c           |  163 +++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 290 insertions(+), 2 deletions(-)
fs/Kconfig +13 -0
Index: linux-2.6.18-rc6/fs/Kconfig
===================================================================
@@ -862,6 +862,19 @@ config TMPFS
 
 	  See <file:Documentation/filesystems/tmpfs.txt> for details.
 
+config TMPFS_POSIX_ACL
+	bool "Tmpfs POSIX Access Control Lists"
+	depends on TMPFS
+	select GENERIC_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.
+
 config HUGETLBFS
 	bool "HugeTLB file system support"
 	depends X86 || IA64 || PPC64 || SPARC64 || SUPERH || BROKEN
include/linux/shmem_fs.h +24 -0
Index: linux-2.6.18-rc6/include/linux/shmem_fs.h
===================================================================
@@ -19,6 +19,10 @@ struct shmem_inode_info {
 	swp_entry_t		i_direct[SHMEM_NR_DIRECT]; /* first blocks */
 	struct list_head	swaplist;	/* chain of maybes on swap */
 	struct inode		vfs_inode;
+#ifdef CONFIG_TMPFS_POSIX_ACL
+	struct posix_acl	*i_acl;
+	struct posix_acl	*i_default_acl;
+#endif
 };
 
 struct shmem_sb_info {
@@ -36,4 +40,24 @@ static inline struct shmem_inode_info *S
 	return container_of(inode, struct shmem_inode_info, vfs_inode);
 }
 
+#ifdef CONFIG_TMPFS_POSIX_ACL
+int shmem_permission(struct inode *, int, struct nameidata *);
+int shmem_acl_init(struct inode *, struct inode *);
+void shmem_acl_destroy_inode(struct inode *);
+
+extern struct xattr_handler shmem_xattr_acl_access_handler;
+extern struct xattr_handler shmem_xattr_acl_default_handler;
+
+extern struct generic_acl_operations shmem_acl_ops;
+
+#else
+static inline int shmem_acl_init(struct inode *inode, struct inode *dir)
+{
+	return 0;
+}
+static inline void shmem_acl_destroy_inode(struct inode *inode)
+{
+}
+#endif  /* CONFIG_TMPFS_POSIX_ACL */
+
 #endif
mm/Makefile +1 -0
Index: linux-2.6.18-rc6/mm/Makefile
===================================================================
@@ -17,6 +17,7 @@ obj-$(CONFIG_HUGETLBFS)	+= hugetlb.o
 obj-$(CONFIG_NUMA) 	+= mempolicy.o
 obj-$(CONFIG_SPARSEMEM)	+= sparse.o
 obj-$(CONFIG_SHMEM) += shmem.o
+obj-$(CONFIG_TMPFS_POSIX_ACL) += shmem_acl.o
 obj-$(CONFIG_TINY_SHMEM) += tiny-shmem.o
 obj-$(CONFIG_SLOB) += slob.o
 obj-$(CONFIG_SLAB) += slab.o
mm/shmem.c +97 -2

171 lines not on this page · raw message

mm/shmem_acl.c new file +197 -0

197 lines not on this page · raw message

#12 lore raw

Re: Access Control Lists for tmpfs

In reply to Andreas Gruenbacher

mm/shmem_acl.c line 80

Quoted 7 lines
mm/shmem_acl.c new file +6 -0
+static int
+shmem_get_acl_access(struct inode *inode, const char *name, void *buffer,
+		     size_t size)
+{
+	if (strcmp(name, "") != 0)
+		return -EINVAL;

An interesting thing (tested in userspace):

strcmp(somestring, "")

will only evaluate to *sometring=='\0' if I add -static to CFLAGS.

Jan Engelhardt