Skip to content

Commit b09e0fa

Browse files
eparistorvalds
authored andcommitted
tmpfs: implement generic xattr support
Implement generic xattrs for tmpfs filesystems. The Feodra project, while trying to replace suid apps with file capabilities, realized that tmpfs, which is used on the build systems, does not support file capabilities and thus cannot be used to build packages which use file capabilities. Xattrs are also needed for overlayfs. The xattr interface is a bit odd. If a filesystem does not implement any {get,set,list}xattr functions the VFS will call into some random LSM hooks and the running LSM can then implement some method for handling xattrs. SELinux for example provides a method to support security.selinux but no other security.* xattrs. As it stands today when one enables CONFIG_TMPFS_POSIX_ACL tmpfs will have xattr handler routines specifically to handle acls. Because of this tmpfs would loose the VFS/LSM helpers to support the running LSM. To make up for that tmpfs had stub functions that did nothing but call into the LSM hooks which implement the helpers. This new patch does not use the LSM fallback functions and instead just implements a native get/set/list xattr feature for the full security.* and trusted.* namespace like a normal filesystem. This means that tmpfs can now support both security.selinux and security.capability, which was not previously possible. The basic implementation is that I attach a: struct shmem_xattr { struct list_head list; /* anchored by shmem_inode_info->xattr_list */ char *name; size_t size; char value[0]; }; Into the struct shmem_inode_info for each xattr that is set. This implementation could easily support the user.* namespace as well, except some care needs to be taken to prevent large amounts of unswappable memory being allocated for unprivileged users. [mszeredi@suse.cz: new config option, suport trusted.*, support symlinks] Signed-off-by: Eric Paris <eparis@redhat.com> Signed-off-by: Miklos Szeredi <mszeredi@suse.cz> Acked-by: Serge Hallyn <serge.hallyn@ubuntu.com> Tested-by: Serge Hallyn <serge.hallyn@ubuntu.com> Cc: Kyle McMartin <kyle@mcmartin.ca> Acked-by: Hugh Dickins <hughd@google.com> Tested-by: Jordi Pujol <jordipujolp@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 4eb3170 commit b09e0fa

File tree

3 files changed

+290
-56
lines changed

3 files changed

+290
-56
lines changed

fs/Kconfig

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,25 @@ config TMPFS
121121

122122
See <file:Documentation/filesystems/tmpfs.txt> for details.
123123

124+
config TMPFS_XATTR
125+
bool "Tmpfs extended attributes"
126+
depends on TMPFS
127+
default n
128+
help
129+
Extended attributes are name:value pairs associated with inodes by
130+
the kernel or by users (see the attr(5) manual page, or visit
131+
<http://acl.bestbits.at/> for details).
132+
133+
Currently this enables support for the trusted.* and
134+
security.* namespaces.
135+
136+
If unsure, say N.
137+
138+
You need this for POSIX ACL support on tmpfs.
139+
124140
config TMPFS_POSIX_ACL
125141
bool "Tmpfs POSIX Access Control Lists"
126-
depends on TMPFS
142+
depends on TMPFS_XATTR
127143
select GENERIC_ACL
128144
help
129145
POSIX Access Control Lists (ACLs) support permissions for users and

include/linux/shmem_fs.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
#define SHMEM_NR_DIRECT 16
1111

12+
#define SHMEM_SYMLINK_INLINE_LEN (SHMEM_NR_DIRECT * sizeof(swp_entry_t))
13+
1214
struct shmem_inode_info {
1315
spinlock_t lock;
1416
unsigned long flags;
@@ -17,8 +19,12 @@ struct shmem_inode_info {
1719
unsigned long next_index; /* highest alloced index + 1 */
1820
struct shared_policy policy; /* NUMA memory alloc policy */
1921
struct page *i_indirect; /* top indirect blocks page */
20-
swp_entry_t i_direct[SHMEM_NR_DIRECT]; /* first blocks */
22+
union {
23+
swp_entry_t i_direct[SHMEM_NR_DIRECT]; /* first blocks */
24+
char inline_symlink[SHMEM_SYMLINK_INLINE_LEN];
25+
};
2126
struct list_head swaplist; /* chain of maybes on swap */
27+
struct list_head xattr_list; /* list of shmem_xattr */
2228
struct inode vfs_inode;
2329
};
2430

0 commit comments

Comments
 (0)