security,anon_inodes,kvm: enable security support for anon inodes
Subsystems (4)
RFC PATCH 1/1 security,anon_inodes,kvm: enable security support for anon inodes
Add support for labeling and controlling access to files attached to anon inodes. Introduce extended interfaces for creating such files to permit passing a related file as an input to decide how to label the anon inode. Define a security hook for initializing the anon inode security attributes. Security attributes are either inherited from a related file or determined based on some combination of the creating task and policy (in the case of SELinux, using type_transition rules). As an example user of the inheritance support, convert kvm to use the new interface for passing the related file so that the anon inode can inherit the security attributes of /dev/kvm and provide consistent access control for subsequent ioctl operations. Other users of anon inodes, including userfaultfd, will default to the transition-based mechanism instead.
Compared to the series in
https://lore.kernel.org/selinux/[email protected]/,
this approach differs in that it does not require creation of a separate anonymous inode for each file (instead storing the per-instance security information in the file security blob), it applies labeling and control to all users of anonymous inodes rather than requiring opt-in via a new flag, it supports labeling based on a related inode if provided, it relies on type transitions to compute the label of the anon inode when there is no related inode, and it does not require introducing a new security class for each user of anonymous inodes.
On the other hand, the approach in this patch does expose the name passed by the creator of the anon inode to the policy (an indirect mapping could be provided within SELinux if these names aren't considered to be stable), requires the definition of type_transition rules to distinguish userfaultfd inodes from proc inodes based on type since they share the same class, doesn't support denying the creation of anonymous inodes (making the hook added by this patch return something other than void is problematic due to it being called after the file is already allocated and error handling in the callers can't presently account for this scenario and end up calling release methods multiple times), and may be more expensive (security_transition_sid overhead on each anon inode allocation).
We are primarily posting this RFC patch now so that the two different approaches can be concretely compared. We anticipate a hybrid of the two approaches being the likely outcome in the end. In particular if support for allocating a separate inode for each of these files is acceptable, then we would favor storing the security information in the inode security blob and using it instead of the file security blob.
This patch only converts kvm to use a related inode (/dev/kvm) for the creation of anon inodes as an example user. We would look to incrementally convert other subsystems where applicable. This could potentially cause policy breakage if policies are written for a subsystem using the type_transition rules and then the subsystem is later converted to use a related inode, so some means of compatible evolution would be required.
There are a number of file permission checks in SELinux that do not currently use the file_has_perm() helper and therefore do not pick up the logic for handling these anonymous inodes. These will need to be looked at further to see whether they are relevant to anonymous inodes and should be updated with the new logic.
Any hooks that are directly passed a dentry or inode and not a file will still skip permission checking by virtue of the S_ISPRIVATE() checks in security/security.c and in security/selinux/hooks.c. At some point they need to be audited to determine whether they are relevant to anonymous inodes.
This change may create compatibility issues since it unconditionally enables labeling and access control for all anonymous inodes; it is known to break two selinux-testsuite bpf tests without adjusting its policy. It will likely need to be wrapped by a SELinux policy capability before being merged to prevent breaking existing policies.
An example of a sample program and policy will follow in a follow-up to this patch to demonstrate the effect on userfaultfd and kvm.
--- fs/anon_inodes.c | 53 +++++++++++++++++------- include/linux/anon_inodes.h | 7 ++++ include/linux/lsm_hooks.h | 11 +++++ include/linux/security.h | 8 ++++ security/security.c | 7 ++++ security/selinux/hooks.c | 69 ++++++++++++++++++++++++++++--- security/selinux/include/objsec.h | 4 ++ virt/kvm/kvm_main.c | 27 +++++++----- 8 files changed, 155 insertions(+), 31 deletions(-)
fs/anon_inodes.c +39 -14
@@ -21,6 +21,7 @@#include <linux/magic.h> #include <linux/anon_inodes.h> #include <linux/pseudo_fs.h> +#include <linux/security.h> #include <linux/uaccess.h>
@@ -55,15 +56,25 @@ static struct file_system_type anon_inode_fs_type = { .kill_sb = kill_anon_super, }; +struct file *anon_inode_getfile (const char *name, +const struct file_operations *fops, +void *priv,int flags) +{ +return anon_inode_getfile_inherit (name, fops, priv, flags,NULL ); +} +EXPORT_SYMBOL_GPL (anon_inode_getfile); +/** -* anon_inode_getfile - creates a new file instance by hooking it up to an -* anonymous inode, and a dentry that describe the "class" -* of the file +* anon_inode_getfile_inherit - creates a new file instance by hooking it up to +* an anonymous inode, and a dentry that describe +* the "class" of the file * * @name: [in] name of the "class" of the new file * @fops: [in] file operations for the new file * @priv: [in] private data for the new file (will be file's private_data) * @flags: [in] flags +* @related: [in optional] a related file that security attributes will be +* inherited from. * * Creates a new file by hooking it on a single inode. This is useful for files * that do not need to have a full-fledged inode in order to operate correctly.
@@ -71,9 +82,10 @@ static struct file_system_type anon_inode_fs_type = {* hence saving memory and avoiding code duplication for the file/inode/dentry * setup. Returns the newly created file* or an error pointer. */ -struct file *anon_inode_getfile (const char *name, -const struct file_operations *fops, -void *priv,int flags) +struct file *anon_inode_getfile_inherit (const char *name, +const struct file_operations *fops, +void *priv,int flags, +const struct file *related) {struct file *file;
@@ -97,6 +109,8 @@ struct file *anon_inode_getfile(const char *name, file->private_data = priv; +security_anon_file_init (file, related, name); +return file; err:
@@ -104,17 +118,27 @@ struct file *anon_inode_getfile(const char *name,module_put (fops->owner);return file; } -EXPORT_SYMBOL_GPL (anon_inode_getfile); +EXPORT_SYMBOL_GPL (anon_inode_getfile_inherit); + +int anon_inode_getfd (const char *name, +const struct file_operations *fops,void *priv, +int flags) +{ +return anon_inode_getfd_inherit (name, fops, priv, flags,NULL ); +} +EXPORT_SYMBOL_GPL (anon_inode_getfd);/** -* anon_inode_getfd - creates a new file instance by hooking it up to an -* anonymous inode, and a dentry that describe the "class" -* of the file +* anon_inode_getfd_inherit - creates and installs a new file instance by +* hooking it up to an anonymous inode, and a dentry +* that describe the "class" of the file * * @name: [in] name of the "class" of the new file * @fops: [in] file operations for the new file * @priv: [in] private data for the new file (will be file's private_data) * @flags: [in] flags +* @related: [in optional] a related file that security attributes will be +* inherited from. * * Creates a new file by hooking it on a single inode. This is useful for files * that do not need to have a full-fledged inode in order to operate correctly.
@@ -122,8 +146,9 @@ EXPORT_SYMBOL_GPL(anon_inode_getfile);* hence saving memory and avoiding code duplication for the file/inode/dentry * setup. Returns new descriptor or an error code. */ -int anon_inode_getfd (const char *name,const struct file_operations *fops, -void *priv,int flags) +int anon_inode_getfd_inherit (const char *name, +const struct file_operations *fops,void *priv, +int flags,const struct file *related) {int error, fd;struct file *file;
@@ -133,7 +158,7 @@ int anon_inode_getfd(const char *name, const struct file_operations *fops,return error; fd = error; - file =anon_inode_getfile (name, fops, priv, flags); + file =anon_inode_getfile_inherit (name, fops, priv, flags, related);if (IS_ERR (file)) { error =PTR_ERR (file); goto err_put_unused_fd;
@@ -146,7 +171,7 @@ int anon_inode_getfd(const char *name, const struct file_operations *fops,put_unused_fd (fd);return error; } -EXPORT_SYMBOL_GPL (anon_inode_getfd); +EXPORT_SYMBOL_GPL (anon_inode_getfd_inherit);static int __init anon_inode_init (void ) {
include/linux/anon_inodes.h +7 -0
@@ -14,8 +14,15 @@ struct file_operations;struct file *anon_inode_getfile (const char *name,const struct file_operations *fops,void *priv,int flags); +struct file *anon_inode_getfile_inherit (const char *name, +const struct file_operations *fops, +void *priv,int flags, +const struct file *related);int anon_inode_getfd (const char *name,const struct file_operations *fops,void *priv,int flags); +int anon_inode_getfd_inherit (const char *name, +const struct file_operations *fops,void *priv, +int flags,const struct file *related);#endif /* _LINUX_ANON_INODES_H */
include/linux/lsm_hooks.h +11 -0
@@ -1454,6 +1454,14 @@* code execution in kernel space should be permitted. * * @what: kernel feature being accessed +* +* @anon_file_init: +* Initialize the security attributes of a file attached to an anonymous +* inode. +* @file contains the file to initialize +* @related contains a related file that security attributes will be +* inherited from. +* @name contains the name of the "class" of the file */ union security_list_options {int (*binder_set_context_mgr)(struct task_struct *mgr);
@@ -1818,6 +1826,8 @@ union security_list_options {void (*bpf_prog_free_security)(struct bpf_prog_aux *aux);#endif /* CONFIG_BPF_SYSCALL */ int (*locked_down)(enum lockdown_reason what); +void (*anon_file_init)(struct file *file,const struct file *related, +const char *name);#ifdef CONFIG_PERF_EVENTS int (*perf_event_open)(struct perf_event_attr *attr,int type);int (*perf_event_alloc)(struct perf_event *event);
@@ -2068,6 +2078,7 @@ struct security_hook_heads {struct hlist_head bpf_prog_free_security;#endif /* CONFIG_BPF_SYSCALL */ struct hlist_head locked_down; +struct hlist_head anon_file_init;#ifdef CONFIG_PERF_EVENTS struct hlist_head perf_event_open;struct hlist_head perf_event_alloc;
include/linux/security.h +8 -0
@@ -447,6 +447,8 @@ int security_inode_notifysecctx(struct inode *inode, void *ctx, u32 ctxlen);int security_inode_setsecctx (struct dentry *dentry,void *ctx,u32 ctxlen);int security_inode_getsecctx (struct inode *inode,void **ctx,u32 *ctxlen);int security_locked_down (enum lockdown_reason what); +void security_anon_file_init (struct file *file,const struct file *related, +const char *name);#else /* CONFIG_SECURITY */ static inline int call_blocking_lsm_notifier (enum lsm_event event,void *data)
@@ -1274,6 +1276,12 @@ static inline int security_locked_down(enum lockdown_reason what) {return 0 ; } +static inline void security_anon_file_init (struct file *file, +const struct file *related, +const char *name); +{ +return 0 ; +}#endif /* CONFIG_SECURITY */ #ifdef CONFIG_SECURITY_NETWORK
security/security.c +7 -0
@@ -2437,6 +2437,13 @@ int security_locked_down(enum lockdown_reason what) }EXPORT_SYMBOL (security_locked_down); +void security_anon_file_init (struct file *file,const struct file *related, +const char *name) +{ +call_void_hook (anon_file_init, file, related, name); +} +EXPORT_SYMBOL (security_anon_file_init); +#ifdef CONFIG_PERF_EVENTS int security_perf_event_open (struct perf_event_attr *attr,int type) {
security/selinux/hooks.c +63 -6
101 lines not on this page · raw message
security/selinux/include/objsec.h +4 -0
@@ -57,6 +57,10 @@ struct file_security_struct {u32 sid;/* SID of open file description */ u32 fown_sid;/* SID of file owner (for SIGIO) */ u32 isid;/* SID of inode at the time of file open */ +bool anon;/* Is file connected to an anonymous inode */ +u16 anon_sclass;/* inode security class if connected +* to an anonymous inode +*/ u32 pseqno;/* Policy seqno at the time of file open */ };
virt/kvm/kvm_main.c +16 -11
@@ -2756,12 +2756,13 @@ static struct file_operations kvm_vcpu_fops = {/* * Allocates an inode for the vcpu. */ -static int create_vcpu_fd (struct kvm_vcpu *vcpu) +static int create_vcpu_fd (struct kvm_vcpu *vcpu,const struct file *filp) {char name[8 +1 +ITOA_MAX_LEN +1 ];snprintf (name,sizeof (name),"kvm-vcpu:%d" , vcpu->vcpu_id); -return anon_inode_getfd (name, &kvm_vcpu_fops, vcpu,O_RDWR |O_CLOEXEC ); +return anon_inode_getfd_inherit (name, &kvm_vcpu_fops, vcpu, +O_RDWR |O_CLOEXEC , filp); }static void kvm_create_vcpu_debugfs (struct kvm_vcpu *vcpu)
@@ -2783,7 +2784,8 @@ static void kvm_create_vcpu_debugfs(struct kvm_vcpu *vcpu)/* * Creates some virtual cpus. Good luck creating more than one. */ -static int kvm_vm_ioctl_create_vcpu (struct kvm *kvm,u32 id) +static int kvm_vm_ioctl_create_vcpu (struct kvm *kvm,u32 id, +const struct file *filp) {int r;struct kvm_vcpu *vcpu;
@@ -2838,7 +2840,7 @@ static int kvm_vm_ioctl_create_vcpu(struct kvm *kvm, u32 id)/* Now it's all set up, let userspace reach it */ kvm_get_kvm (kvm); - r =create_vcpu_fd (vcpu); + r =create_vcpu_fd (vcpu, filp);if (r <0 ) {kvm_put_kvm_no_destroy (kvm); goto unlock_vcpu_destroy;
@@ -3239,7 +3241,8 @@ void kvm_unregister_device_ops(u32 type) }static int kvm_ioctl_create_device (struct kvm *kvm, -struct kvm_create_device *cd) +struct kvm_create_device *cd, +const struct file *filp) {const struct kvm_device_ops *ops =NULL ;struct kvm_device *dev;
@@ -3279,7 +3282,8 @@ static int kvm_ioctl_create_device(struct kvm *kvm, ops->init (dev);kvm_get_kvm (kvm); - ret =anon_inode_getfd (ops->name, &kvm_device_fops, dev,O_RDWR |O_CLOEXEC ); + ret =anon_inode_getfd_inherit (ops->name, &kvm_device_fops, dev, +O_RDWR |O_CLOEXEC , filp);if (ret <0 ) {kvm_put_kvm_no_destroy (kvm);mutex_lock (&kvm->lock);
@@ -3369,7 +3373,7 @@ static long kvm_vm_ioctl(struct file *filp,return -EIO ;switch (ioctl) {case KVM_CREATE_VCPU : - r =kvm_vm_ioctl_create_vcpu (kvm, arg); + r =kvm_vm_ioctl_create_vcpu (kvm, arg, filp);break ;case KVM_ENABLE_CAP : {struct kvm_enable_cap cap;
@@ -3526,7 +3530,7 @@ static long kvm_vm_ioctl(struct file *filp,if (copy_from_user (&cd, argp,sizeof (cd))) goto out; - r =kvm_ioctl_create_device (kvm, &cd); + r =kvm_ioctl_create_device (kvm, &cd, filp);if (r) goto out;
@@ -3595,7 +3599,7 @@ static struct file_operations kvm_vm_fops = { KVM_COMPAT(kvm_vm_compat_ioctl), }; -static int kvm_dev_ioctl_create_vm (unsigned long type) +static int kvm_dev_ioctl_create_vm (unsigned long type,const struct file *filp) {int r;struct kvm *kvm;
@@ -3613,7 +3617,8 @@ static int kvm_dev_ioctl_create_vm(unsigned long type)if (r <0 ) goto put_kvm; - file =anon_inode_getfile ("kvm-vm" , &kvm_vm_fops, kvm,O_RDWR ); + file =anon_inode_getfile_inherit ("kvm-vm" , &kvm_vm_fops, kvm,O_RDWR , + filp);if (IS_ERR (file)) {put_unused_fd (r); r =PTR_ERR (file);
@@ -3653,7 +3658,7 @@ static long kvm_dev_ioctl(struct file *filp, r =KVM_API_VERSION ;break ;case KVM_CREATE_VM : - r =kvm_dev_ioctl_create_vm (arg); + r =kvm_dev_ioctl_create_vm (arg, filp);break ;case KVM_CHECK_EXTENSION : r =kvm_vm_ioctl_check_extension_generic (NULL , arg);
Signature · 1 line
2.24.1
Quoted 2 lines · Stephen Smalley
An example of a sample program and policy will follow in a follow-up to this patch to demonstrate the effect on userfaultfd and kvm.
Attached are example test programs and policies to demonstrate the change in behavior before and after this RFC patch for userfaultfd and kvm. The test policies can be edited to selectively allow specific permissions for testing various scenarios, but with the defaults in them, one should see the following behavior:
sudo semodule -i kvm.cil userfaultfd.cil
make kvm userfaultfd
Before:
(no labeling/access control applied by SELinux to userfaultfd files or to anon inodes created by kvm)
$ ./userfaultfd api: 170 features: 510 ioctls: 9223372036854775811
read: Resource temporarily unavailable
$ ./kvm api version: 12
created vm
created vcpu
rax: 0
rbx: 0
rcx: 0
rdx: 1536
rdi: 0
rsi: 0
rsp: 0
rbp: 0
r8: 0
r9: 0
r10: 0
r11: 0
r12: 0
r13: 0
r14: 0
r15: 0
rip: 65520
rflags: 2
created device
checked device attr
After:
(SELinux ioctl whitelisting used to selectively deny access)
./userfaultfdUFFDIO_API: Permission denied
$ ./kvm api version: 12
created vm
created vcpu
KVM_GET_REGS: Permission denied
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/ioctl.h>
#include <linux/kvm.h>
void print_regs(const struct kvm_regs *regs)
{
printf("rax: %llu\n", regs->rax);
printf("rbx: %llu\n", regs->rbx);
printf("rcx: %llu\n", regs->rcx);
printf("rdx: %llu\n", regs->rdx);
printf("rdi: %llu\n", regs->rdi);
printf("rsi: %llu\n", regs->rsi);
printf("rsp: %llu\n", regs->rsp);
printf("rbp: %llu\n", regs->rbp);
printf("r8: %llu\n", regs->r8);
printf("r9: %llu\n", regs->r9);
printf("r10: %llu\n", regs->r10);
printf("r11: %llu\n", regs->r11);
printf("r12: %llu\n", regs->r12);
printf("r13: %llu\n", regs->r13);
printf("r14: %llu\n", regs->r14);
printf("r15: %llu\n", regs->r15);
printf("rip: %llu\n", regs->rip);
printf("rflags: %llu\n", regs->rflags);
printf("\n");
}void print_device_attr(const struct kvm_device_attr *dev_attr)
{
printf("flags: %u\n", dev_attr->flags);
printf("group: %u\n", dev_attr->group);
printf("attr: %llu\n", dev_attr->attr);
printf("addr: %llu\n", dev_attr->addr);
printf("\n");
}int main(void)
{
int fd = open("/dev/kvm", O_RDWR);
if (fd < 0) {
perror("/dev/kvm");
return -1;
}
int ret = ioctl(fd, KVM_GET_API_VERSION, 0);
if (ret < 0) {
perror("KVM_GET_API_VERSION");
return -1;
}
printf("api version: %d\n\n", ret);
int vmfd = ioctl(fd, KVM_CREATE_VM, 0);
if (vmfd < 0) {
perror("KVM_CREATE_VM");
return -1;
}
printf("created vm\n\n");
int vcpufd = ioctl(vmfd, KVM_CREATE_VCPU, 0);
if (vcpufd < 0) {
perror("KVM_CREATE_VCPU");
return -1;
}
printf("created vcpu\n\n");
struct kvm_regs regs;
if (ioctl(vcpufd, KVM_GET_REGS, ®s) < 0) {
perror("KVM_GET_REGS");
return -1;
}
print_regs(®s);
struct kvm_create_device dev = {0};
dev.type = KVM_DEV_TYPE_VFIO;
if (ioctl(vmfd, KVM_CREATE_DEVICE, &dev) < 0) {
perror("KVM_CREATE_DEVICE");
return -1;
}
printf("created device\n\n");
struct kvm_device_attr dev_attr = {0};
dev_attr.group = KVM_DEV_VFIO_GROUP;
dev_attr.attr = KVM_DEV_VFIO_GROUP_ADD;
if (ioctl(dev.fd, KVM_HAS_DEVICE_ATTR, &dev_attr) < 0) {
perror("KVM_HAS_DEVICE_ATTR");
return -1;
}
printf("checked device attr\n\n");
return 0;
}#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/syscall.h>
#include <linux/userfaultfd.h>
void print_api(const struct uffdio_api *api)
{
printf("api: %llu\n", api->api);
printf("features: %llu\n", api->features);
printf("ioctls: %llu\n", api->ioctls);
printf("\n");
}int main(void)
{
long uffd = syscall(__NR_userfaultfd, O_CLOEXEC | O_NONBLOCK);
if (uffd < 0) {
perror("syscall(userfaultfd)");
return -1;
}
struct uffdio_api api = {0};
api.api = UFFD_API;
if (ioctl(uffd, UFFDIO_API, &api) < 0) {
perror("UFFDIO_API");
return -1;
}
print_api(&api);
struct uffd_msg msg = {0};
ssize_t count = read(uffd, &msg, sizeof(msg));
if (count < 0) {
perror("read");
return -1;
} else if (count == 0) {
printf("read EOF\n\n");
}
printf("read uffd\n\n");
return 0;
}Paul Moore
maintainerQuoted 37 lines · Stephen Smalley
Add support for labeling and controlling access to files attached to anon inodes. Introduce extended interfaces for creating such files to permit passing a related file as an input to decide how to label the anon inode. Define a security hook for initializing the anon inode security attributes. Security attributes are either inherited from a related file or determined based on some combination of the creating task and policy (in the case of SELinux, using
type_transitionrules). As an example user of the inheritance support, convert kvm to use the new interface for passing the related file so that the anon inode can inherit the security attributes of/dev/kvmand provide consistent access control for subsequent ioctl operations. Other users of anon inodes, including userfaultfd, will default to the transition-based mechanism instead.Compared to the series in
https://lore.kernel.org/selinux/[email protected]/,
this approach differs in that it does not require creation of a separate anonymous inode for each file (instead storing the per-instance security information in the file security blob), it applies labeling and control to all users of anonymous inodes rather than requiring opt-in via a new flag, it supports labeling based on a related inode if provided, it relies on type transitions to compute the label of the anon inode when there is no related inode, and it does not require introducing a new security class for each user of anonymous inodes.On the other hand, the approach in this patch does expose the name passed by the creator of the anon inode to the policy (an indirect mapping could be provided within SELinux if these names aren't considered to be stable), requires the definition of
type_transitionrules to distinguish userfaultfd inodes from proc inodes based on type since they share the same class, doesn't support denying the creation of anonymous inodes (making the hook added by this patch return something other than void is problematic due to it being called after the file is already allocated and error handling in the callers can't presently account for this scenario and end up calling release methods multiple times), and may be more expensive (security_transition_sidoverhead on each anon inode allocation).
Quoted 7 lines
We are primarily posting this RFC patch now so that the two different approaches can be concretely compared. We anticipate a hybrid of the two approaches being the likely outcome in the end. In particular if support for allocating a separate inode for each of these files is acceptable, then we would favor storing the security information in the inode security blob and using it instead of the file security blob.
Bringing this back up in hopes of attracting some attention from the fs-devel crowd and Al. As Stephen already mentioned, from a SELinux perspective we would prefer to attach the security blob to the inode as opposed to the file struct; does anyone have any objections to that?
Signature · 2 lines
paul moore www.paul-moore.com
Quoted 44 lines · Paul Moore
Quoted 36 lines · Stephen Smalley
Add support for labeling and controlling access to files attached to anon inodes. Introduce extended interfaces for creating such files to permit passing a related file as an input to decide how to label the anon inode. Define a security hook for initializing the anon inode security attributes. Security attributes are either inherited from a related file or determined based on some combination of the creating task and policy (in the case of SELinux, using
type_transitionrules). As an example user of the inheritance support, convert kvm to use the new interface for passing the related file so that the anon inode can inherit the security attributes of/dev/kvmand provide consistent access control for subsequent ioctl operations. Other users of anon inodes, including userfaultfd, will default to the transition-based mechanism instead.Compared to the series in
https://lore.kernel.org/selinux/[email protected]/,
this approach differs in that it does not require creation of a separate anonymous inode for each file (instead storing the per-instance security information in the file security blob), it applies labeling and control to all users of anonymous inodes rather than requiring opt-in via a new flag, it supports labeling based on a related inode if provided, it relies on type transitions to compute the label of the anon inode when there is no related inode, and it does not require introducing a new security class for each user of anonymous inodes.On the other hand, the approach in this patch does expose the name passed by the creator of the anon inode to the policy (an indirect mapping could be provided within SELinux if these names aren't considered to be stable), requires the definition of
type_transitionrules to distinguish userfaultfd inodes from proc inodes based on type since they share the same class, doesn't support denying the creation of anonymous inodes (making the hook added by this patch return something other than void is problematic due to it being called after the file is already allocated and error handling in the callers can't presently account for this scenario and end up calling release methods multiple times), and may be more expensive (security_transition_sidoverhead on each anon inode allocation).Quoted 7 lines
We are primarily posting this RFC patch now so that the two different approaches can be concretely compared. We anticipate a hybrid of the two approaches being the likely outcome in the end. In particular if support for allocating a separate inode for each of these files is acceptable, then we would favor storing the security information in the inode security blob and using it instead of the file security blob.
Quoted 5 lines
Bringing this back up in hopes of attracting some attention from the fs-devel crowd and Al. As Stephen already mentioned, from a SELinux perspective we would prefer to attach the security blob to the inode as opposed to the file struct; does anyone have any objections to that?
Sorry for the delay - been sick the past few days.
I agree that the inode is a better place than the file for information about the inode. This is especially true for Smack, which uses multiple extended attributes in some cases. I don't believe that any except the access label will be relevant to anonymous inodes, but I can imagine security modules with policies that would.
I am always an advocate of full xattr support. It goes a long way in reducing the number and complexity of special case interfaces.
Quoted 54 lines · Casey Schaufler
Quoted 44 lines · Paul Moore
Quoted 36 lines · Stephen Smalley
Add support for labeling and controlling access to files attached to anon inodes. Introduce extended interfaces for creating such files to permit passing a related file as an input to decide how to label the anon inode. Define a security hook for initializing the anon inode security attributes. Security attributes are either inherited from a related file or determined based on some combination of the creating task and policy (in the case of SELinux, using
type_transitionrules). As an example user of the inheritance support, convert kvm to use the new interface for passing the related file so that the anon inode can inherit the security attributes of/dev/kvmand provide consistent access control for subsequent ioctl operations. Other users of anon inodes, including userfaultfd, will default to the transition-based mechanism instead.Compared to the series in
https://lore.kernel.org/selinux/[email protected]/,
this approach differs in that it does not require creation of a separate anonymous inode for each file (instead storing the per-instance security information in the file security blob), it applies labeling and control to all users of anonymous inodes rather than requiring opt-in via a new flag, it supports labeling based on a related inode if provided, it relies on type transitions to compute the label of the anon inode when there is no related inode, and it does not require introducing a new security class for each user of anonymous inodes.On the other hand, the approach in this patch does expose the name passed by the creator of the anon inode to the policy (an indirect mapping could be provided within SELinux if these names aren't considered to be stable), requires the definition of
type_transitionrules to distinguish userfaultfd inodes from proc inodes based on type since they share the same class, doesn't support denying the creation of anonymous inodes (making the hook added by this patch return something other than void is problematic due to it being called after the file is already allocated and error handling in the callers can't presently account for this scenario and end up calling release methods multiple times), and may be more expensive (security_transition_sidoverhead on each anon inode allocation).Quoted 7 lines
We are primarily posting this RFC patch now so that the two different approaches can be concretely compared. We anticipate a hybrid of the two approaches being the likely outcome in the end. In particular if support for allocating a separate inode for each of these files is acceptable, then we would favor storing the security information in the inode security blob and using it instead of the file security blob.
Quoted 5 lines
Bringing this back up in hopes of attracting some attention from the fs-devel crowd and Al. As Stephen already mentioned, from a SELinux perspective we would prefer to attach the security blob to the inode as opposed to the file struct; does anyone have any objections to that?
Sorry for the delay - been sick the past few days.
Quoted 8 lines
I agree that the inode is a better place than the file for information about the inode. This is especially true for Smack, which uses multiple extended attributes in some cases. I don't believe that any except the access label will be relevant to anonymous inodes, but I can imagine security modules with policies that would.
I am always an advocate of full xattr support. It goes a long way in reducing the number and complexity of special case interfaces.
It sounds like we have broad consensus on using the inode to hold security information, implying that anon_inodes should create new inodes. Do any of the VFS people want to object?
Quoted 62 lines · Daniel Colascione
Quoted 60 lines · Casey Schaufler
Quoted 44 lines · Paul Moore
Quoted 36 lines · Stephen Smalley
Add support for labeling and controlling access to files attached to anon inodes. Introduce extended interfaces for creating such files to permit passing a related file as an input to decide how to label the anon inode. Define a security hook for initializing the anon inode security attributes. Security attributes are either inherited from a related file or determined based on some combination of the creating task and policy (in the case of SELinux, using
type_transitionrules). As an example user of the inheritance support, convert kvm to use the new interface for passing the related file so that the anon inode can inherit the security attributes of/dev/kvmand provide consistent access control for subsequent ioctl operations. Other users of anon inodes, including userfaultfd, will default to the transition-based mechanism instead.Compared to the series in
https://lore.kernel.org/selinux/[email protected]/,
this approach differs in that it does not require creation of a separate anonymous inode for each file (instead storing the per-instance security information in the file security blob), it applies labeling and control to all users of anonymous inodes rather than requiring opt-in via a new flag, it supports labeling based on a related inode if provided, it relies on type transitions to compute the label of the anon inode when there is no related inode, and it does not require introducing a new security class for each user of anonymous inodes.On the other hand, the approach in this patch does expose the name passed by the creator of the anon inode to the policy (an indirect mapping could be provided within SELinux if these names aren't considered to be stable), requires the definition of
type_transitionrules to distinguish userfaultfd inodes from proc inodes based on type since they share the same class, doesn't support denying the creation of anonymous inodes (making the hook added by this patch return something other than void is problematic due to it being called after the file is already allocated and error handling in the callers can't presently account for this scenario and end up calling release methods multiple times), and may be more expensive (security_transition_sidoverhead on each anon inode allocation).Quoted 7 lines
We are primarily posting this RFC patch now so that the two different approaches can be concretely compared. We anticipate a hybrid of the two approaches being the likely outcome in the end. In particular if support for allocating a separate inode for each of these files is acceptable, then we would favor storing the security information in the inode security blob and using it instead of the file security blob.
Quoted 5 lines
Bringing this back up in hopes of attracting some attention from the fs-devel crowd and Al. As Stephen already mentioned, from a SELinux perspective we would prefer to attach the security blob to the inode as opposed to the file struct; does anyone have any objections to that?
Sorry for the delay - been sick the past few days.
I agree that the inode is a better place than the file for information about the inode. This is especially true for Smack, which uses multiple extended attributes in some cases. I don't believe that any except the access label will be relevant to anonymous inodes, but I can imagine security modules with policies that would.
Quoted 6 lines
Quoted 2 lines
I am always an advocate of full xattr support. It goes a long way in reducing the number and complexity of special case interfaces.
It sounds like we have broad consensus on using the inode to hold security information, implying that
anon_inodesshould create new inodes. Do any of the VFS people want to object?
Ping?
Stephen Smalley
maintainerQuoted 64 lines · Daniel Colascione
Quoted 62 lines · Daniel Colascione
Quoted 60 lines · Casey Schaufler
Quoted 44 lines · Paul Moore
Quoted 36 lines · Stephen Smalley
Add support for labeling and controlling access to files attached to anon inodes. Introduce extended interfaces for creating such files to permit passing a related file as an input to decide how to label the anon inode. Define a security hook for initializing the anon inode security attributes. Security attributes are either inherited from a related file or determined based on some combination of the creating task and policy (in the case of SELinux, using
type_transitionrules). As an example user of the inheritance support, convert kvm to use the new interface for passing the related file so that the anon inode can inherit the security attributes of/dev/kvmand provide consistent access control for subsequent ioctl operations. Other users of anon inodes, including userfaultfd, will default to the transition-based mechanism instead.Compared to the series in
https://lore.kernel.org/selinux/[email protected]/,
this approach differs in that it does not require creation of a separate anonymous inode for each file (instead storing the per-instance security information in the file security blob), it applies labeling and control to all users of anonymous inodes rather than requiring opt-in via a new flag, it supports labeling based on a related inode if provided, it relies on type transitions to compute the label of the anon inode when there is no related inode, and it does not require introducing a new security class for each user of anonymous inodes.On the other hand, the approach in this patch does expose the name passed by the creator of the anon inode to the policy (an indirect mapping could be provided within SELinux if these names aren't considered to be stable), requires the definition of
type_transitionrules to distinguish userfaultfd inodes from proc inodes based on type since they share the same class, doesn't support denying the creation of anonymous inodes (making the hook added by this patch return something other than void is problematic due to it being called after the file is already allocated and error handling in the callers can't presently account for this scenario and end up calling release methods multiple times), and may be more expensive (security_transition_sidoverhead on each anon inode allocation).Quoted 7 lines
We are primarily posting this RFC patch now so that the two different approaches can be concretely compared. We anticipate a hybrid of the two approaches being the likely outcome in the end. In particular if support for allocating a separate inode for each of these files is acceptable, then we would favor storing the security information in the inode security blob and using it instead of the file security blob.
Quoted 5 lines
Bringing this back up in hopes of attracting some attention from the fs-devel crowd and Al. As Stephen already mentioned, from a SELinux perspective we would prefer to attach the security blob to the inode as opposed to the file struct; does anyone have any objections to that?
Sorry for the delay - been sick the past few days.
I agree that the inode is a better place than the file for information about the inode. This is especially true for Smack, which uses multiple extended attributes in some cases. I don't believe that any except the access label will be relevant to anonymous inodes, but I can imagine security modules with policies that would.
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
I am always an advocate of full xattr support. It goes a long way in reducing the number and complexity of special case interfaces.
It sounds like we have broad consensus on using the inode to hold security information, implying that
anon_inodesshould create new inodes. Do any of the VFS people want to object?Ping?
I'd recommend refreshing your patch series to incorporate feedback on the previous version and re-post,
including viro and linux-fsdevel on the cc, and see if they have any comments on it.
Quoted 73 lines · Stephen Smalley
Quoted 71 lines · Daniel Colascione
Quoted 68 lines · Daniel Colascione
Quoted 54 lines · Casey Schaufler
Quoted 44 lines · Paul Moore
Quoted 36 lines · Stephen Smalley
Add support for labeling and controlling access to files attached to anon inodes. Introduce extended interfaces for creating such files to permit passing a related file as an input to decide how to label the anon inode. Define a security hook for initializing the anon inode security attributes. Security attributes are either inherited from a related file or determined based on some combination of the creating task and policy (in the case of SELinux, using
type_transitionrules). As an example user of the inheritance support, convert kvm to use the new interface for passing the related file so that the anon inode can inherit the security attributes of/dev/kvmand provide consistent access control for subsequent ioctl operations. Other users of anon inodes, including userfaultfd, will default to the transition-based mechanism instead.Compared to the series in
https://lore.kernel.org/selinux/[email protected]/,
this approach differs in that it does not require creation of a separate anonymous inode for each file (instead storing the per-instance security information in the file security blob), it applies labeling and control to all users of anonymous inodes rather than requiring opt-in via a new flag, it supports labeling based on a related inode if provided, it relies on type transitions to compute the label of the anon inode when there is no related inode, and it does not require introducing a new security class for each user of anonymous inodes.On the other hand, the approach in this patch does expose the name passed by the creator of the anon inode to the policy (an indirect mapping could be provided within SELinux if these names aren't considered to be stable), requires the definition of
type_transitionrules to distinguish userfaultfd inodes from proc inodes based on type since they share the same class, doesn't support denying the creation of anonymous inodes (making the hook added by this patch return something other than void is problematic due to it being called after the file is already allocated and error handling in the callers can't presently account for this scenario and end up calling release methods multiple times), and may be more expensive (security_transition_sidoverhead on each anon inode allocation).Quoted 7 lines
We are primarily posting this RFC patch now so that the two different approaches can be concretely compared. We anticipate a hybrid of the two approaches being the likely outcome in the end. In particular if support for allocating a separate inode for each of these files is acceptable, then we would favor storing the security information in the inode security blob and using it instead of the file security blob.
Quoted 5 lines
Bringing this back up in hopes of attracting some attention from the fs-devel crowd and Al. As Stephen already mentioned, from a SELinux perspective we would prefer to attach the security blob to the inode as opposed to the file struct; does anyone have any objections to that?
Sorry for the delay - been sick the past few days.
Quoted 8 lines
I agree that the inode is a better place than the file for information about the inode. This is especially true for Smack, which uses multiple extended attributes in some cases. I don't believe that any except the access label will be relevant to anonymous inodes, but I can imagine security modules with policies that would.
I am always an advocate of full xattr support. It goes a long way in reducing the number and complexity of special case interfaces.
It sounds like we have broad consensus on using the inode to hold security information, implying that
anon_inodesshould create new inodes. Do any of the VFS people want to object?
Quoted 6 lines
Quoted 1 line
Ping?
I'd recommend refreshing your patch series to incorporate feedback on the previous version and re-post,
including viro and linux-fsdevel on the cc, and see if they have any comments on it.
I don't think there's anything in the patch series that needs to change right now. AFAICT, we're still just waiting on comment from the VFS people, who should be on this thread. Did I miss something?
Stephen Smalley
maintainerQuoted 42 lines · Daniel Colascione
Quoted 39 lines · Stephen Smalley
Quoted 36 lines · Daniel Colascione
Quoted 26 lines · Daniel Colascione
Quoted 24 lines · Casey Schaufler
Quoted 8 lines · Paul Moore
Quoted 7 lines · Stephen Smalley
We are primarily posting this RFC patch now so that the two different approaches can be concretely compared. We anticipate a hybrid of the two approaches being the likely outcome in the end. In particular if support for allocating a separate inode for each of these files is acceptable, then we would favor storing the security information in the inode security blob and using it instead of the file security blob.
Quoted 5 lines
Bringing this back up in hopes of attracting some attention from the fs-devel crowd and Al. As Stephen already mentioned, from a SELinux perspective we would prefer to attach the security blob to the inode as opposed to the file struct; does anyone have any objections to that?
Sorry for the delay - been sick the past few days.
I agree that the inode is a better place than the file for information about the inode. This is especially true for Smack, which uses multiple extended attributes in some cases. I don't believe that any except the access label will be relevant to anonymous inodes, but I can imagine security modules with policies that would.
Quoted 6 lines
Quoted 2 lines
I am always an advocate of full xattr support. It goes a long way in reducing the number and complexity of special case interfaces.
It sounds like we have broad consensus on using the inode to hold security information, implying that
anon_inodesshould create new inodes. Do any of the VFS people want to object?Ping?
Quoted 8 lines
Quoted 4 lines
I'd recommend refreshing your patch series to incorporate feedback on the previous version and re-post,
including viro and linux-fsdevel on the cc, and see if they have any comments on it.I don't think there's anything in the patch series that needs to change right now. AFAICT, we're still just waiting on comment from the VFS people, who should be on this thread. Did I miss something?
There was some discussion on the SELinux bits in patch 2/3. I would take the silence on
the vfs bits as implicit acceptance until you hear otherwise and just submit a v2 that addresses
the SELinux bits.