LSM: Identify modules by more than name
Subsystems (34)
A message that is not in the archive (sent off-list or not yet received): [email protected]
Casey Schaufler
maintainerv15 cover LSM: Three basic syscalls
Add three system calls for the Linux Security Module ABI.
lsm_get_self_attr() provides the security module specific attributes that have previously been visible in the /proc/self/attr directory. For each security module that uses the specified attribute on the current process the system call will return an LSM identifier and the value of the attribute. The LSM and attribute identifier values are defined in include/uapi/linux/lsm.h
LSM identifiers are simple integers and reflect the order in which the LSM was added to the mainline kernel. This is a convention, not a promise of the API. LSM identifiers below the value of 100 are reserved for unspecified future uses. That could include information about the security infrastructure itself, or about how multiple LSMs might interact with each other.
A new LSM hook security_getselfattr() is introduced to get the required information from the security modules. This is similar to the existing security_getprocattr() hook, but specifies the format in which string data is returned and requires the module to put the information into a userspace destination.
lsm_set_self_attr() changes the specified LSM attribute. Only one attribute can be changed at a time, and then only if the specified security module allows the change.
A new LSM hook security_setselfattr() is introduced to set the required information in the security modules. This is similar to the existing security_setprocattr() hook, but specifies the format in which string data is presented and requires the module to get the information from a userspace destination.
lsm_list_modules() provides the LSM identifiers, in order, of the security modules that are active on the system. This has been available in the securityfs file /sys/kernel/security/lsm.
Patch 0001 changes the LSM registration from passing the name of the module to passing a lsm_id structure that contains the name of the module, an LSM identifier number and an attribute identifier.
Patch 0002 adds the registered lsm_ids to a table.
Patch 0003 changes security_[gs]etprocattr() to use LSM IDs instead of LSM names.
Patch 0004 implements lsm_get_self_attr() and lsm_set_self_attr(). New LSM hooks security_getselfattr() and security_setselfattr() are defined.
Patch 0005 implements lsm_list_modules().
Patch 0006 wires up the syscalls.
Patch 0007 implements helper functions to make it easier for security modules to use lsm_ctx structures.
Patch 0008 provides the Smack implementation for [gs]etselfattr(). Patch 0009 provides the AppArmor implementation for [gs]etselfattr(). Patch 0010 provides the SELinux implementation for [gs]etselfattr(). Patch 0011 implements selftests for the three new syscalls.
https://github.com/cschaufler/lsm-stacking.git#syscalls-6.5-rc7-v14
v15: Rebased on 6.6-rc1.
Adopt suggested improvements to security_getprocattr, making the code easier to read.
Squash a code fix from 0011 to 0004.
v14: Make the handling of LSM_FLAG_SINGLE easier to understand.
Tighten the comments and documentation.
Better use of const, static, and __ro_after_init. Add selftests for LSM_FLAG_SINGLE cases.
v13: Change the setselfattr code to do a single user copy.
Make the self tests more robust.
Improve use of const.
Change syscall numbers to reflect upstream additions.
v12: Repair a registration time overflow check.
v11: Remove redundent alignment code
Improve a few comments.
Use LSM_ATTR_UNDEF in place of 0 in a few places. Correct a return of -EINVAL to -E2BIG.
v10: Correct use of __user.
Improve a few comments.
Revert unnecessary changes in module initialization.
v9: Support a flag LSM_FLAG_SINGLE in lsm_get_self_attr() that
instructs the call to provide only the attribute for the LSM identified in the referenced lsm_ctx structure.
Fix a typing error.
Change some coding style.
v8: Allow an LSM to provide more than one instance of an attribute,
even though none of the existing modules do so.
Pad the data returned by lsm_get_self_attr() to the size of the struct lsm_ctx.
Change some displeasing varilable names.
v7: Pass the attribute desired to lsm_[gs]et_self_attr in its own
parameter rather than encoding it in the flags. Change the flags parameters to u32.
Don't shortcut out of calling LSM specific code in the infrastructure, let the LSM report that doesn't support an attribute instead. With that it is not necessary to maintain a set of supported attributes in the lsm_id structure. Fix a typing error.
v6: Switch from reusing security_[gs]procattr() to using new
security_[gs]selfattr() hooks. Use explicit sized data types in the lsm_ctx structure.
v5: Correct syscall parameter data types.
v4: Restore "reserved" LSM ID values. Add explaination.
Squash patches that introduce fields in lsm_id. Correct a wireup error.
v3: Add lsm_set_self_attr().
Rename lsm_self_attr() to lsm_get_self_attr(). Provide the values only for a specifed attribute in lsm_get_self_attr().
Add selftests for the three new syscalls. Correct some parameter checking.
v2: Use user-interface safe data types.
Remove "reserved" LSM ID values.
Improve kerneldoc comments
Include copyright dates
Use more descriptive name for LSM counter
Add documentation
Correct wireup errors
Casey Schaufler (11):
LSM: Identify modules by more than name
LSM: Maintain a table of LSM attribute data
proc: Use lsmids instead of lsm names for attrs
LSM: syscalls for current process attributes
LSM: Create lsm_list_modules system call
LSM: wireup Linux Security Module syscalls
LSM: Helpers for attribute names and filling lsm_ctx
Smack: implement setselfattr and getselfattr hooks
AppArmor: Add selfattr hooks
SELinux: Add selfattr hooks
LSM: selftests for Linux Security Module syscalls
Documentation/userspace-api/index.rst | 1 + Documentation/userspace-api/lsm.rst | 73 +++++ MAINTAINERS | 2 + arch/alpha/kernel/syscalls/syscall.tbl | 3 + arch/arm/tools/syscall.tbl | 3 + arch/arm64/include/asm/unistd.h | 2 +- arch/arm64/include/asm/unistd32.h | 6 + arch/ia64/kernel/syscalls/syscall.tbl | 3 + arch/m68k/kernel/syscalls/syscall.tbl | 3 + arch/microblaze/kernel/syscalls/syscall.tbl | 3 + arch/mips/kernel/syscalls/syscall_n32.tbl | 3 + arch/mips/kernel/syscalls/syscall_n64.tbl | 3 + arch/mips/kernel/syscalls/syscall_o32.tbl | 3 + arch/parisc/kernel/syscalls/syscall.tbl | 3 + arch/powerpc/kernel/syscalls/syscall.tbl | 3 + arch/s390/kernel/syscalls/syscall.tbl | 3 + arch/sh/kernel/syscalls/syscall.tbl | 3 + arch/sparc/kernel/syscalls/syscall.tbl | 3 + arch/x86/entry/syscalls/syscall_32.tbl | 3 + arch/x86/entry/syscalls/syscall_64.tbl | 3 + arch/xtensa/kernel/syscalls/syscall.tbl | 3 + fs/proc/base.c | 29 +- fs/proc/internal.h | 2 +- include/linux/lsm_hook_defs.h | 4 + include/linux/lsm_hooks.h | 17 +- include/linux/security.h | 46 ++- include/linux/syscalls.h | 6 + include/uapi/asm-generic/unistd.h | 9 +- include/uapi/linux/lsm.h | 90 ++++++ kernel/sys_ni.c | 3 + security/Makefile | 1 + security/apparmor/include/procattr.h | 2 +- security/apparmor/lsm.c | 99 ++++++- security/apparmor/procattr.c | 10 +- security/bpf/hooks.c | 9 +- security/commoncap.c | 8 +- security/landlock/cred.c | 2 +- security/landlock/fs.c | 2 +- security/landlock/ptrace.c | 2 +- security/landlock/setup.c | 6 + security/landlock/setup.h | 1 + security/loadpin/loadpin.c | 9 +- security/lockdown/lockdown.c | 8 +- security/lsm_syscalls.c | 120 ++++++++ security/safesetid/lsm.c | 9 +- security/security.c | 253 +++++++++++++++- security/selinux/hooks.c | 143 +++++++-- security/smack/smack_lsm.c | 103 ++++++- security/tomoyo/tomoyo.c | 9 +- security/yama/yama_lsm.c | 8 +- .../arch/mips/entry/syscalls/syscall_n64.tbl | 3 + .../arch/powerpc/entry/syscalls/syscall.tbl | 3 + .../perf/arch/s390/entry/syscalls/syscall.tbl | 3 + .../arch/x86/entry/syscalls/syscall_64.tbl | 3 + tools/testing/selftests/Makefile | 1 + tools/testing/selftests/lsm/.gitignore | 1 + tools/testing/selftests/lsm/Makefile | 17 ++ tools/testing/selftests/lsm/common.c | 89 ++++++ tools/testing/selftests/lsm/common.h | 33 +++ tools/testing/selftests/lsm/config | 3 + .../selftests/lsm/lsm_get_self_attr_test.c | 275 ++++++++++++++++++ .../selftests/lsm/lsm_list_modules_test.c | 140 +++++++++ .../selftests/lsm/lsm_set_self_attr_test.c | 74 +++++ 63 files changed, 1694 insertions(+), 93 deletions(-) create mode 100644 Documentation/userspace-api/lsm.rst create mode 100644 include/uapi/linux/lsm.h create mode 100644 security/lsm_syscalls.c create mode 100644 tools/testing/selftests/lsm/.gitignore create mode 100644 tools/testing/selftests/lsm/Makefile create mode 100644 tools/testing/selftests/lsm/common.c create mode 100644 tools/testing/selftests/lsm/common.h create mode 100644 tools/testing/selftests/lsm/config create mode 100644 tools/testing/selftests/lsm/lsm_get_self_attr_test.c create mode 100644 tools/testing/selftests/lsm/lsm_list_modules_test.c create mode 100644 tools/testing/selftests/lsm/lsm_set_self_attr_test.c
Signature · 1 line
2.41.0
Casey Schaufler
maintainerPATCH v15 1/11 LSM: Identify modules by more than name
Create a struct lsm_id to contain identifying information about Linux Security Modules (LSMs). At inception this contains the name of the module and an identifier associated with the security module. Change the security_add_hooks() interface to use this structure. Change the individual modules to maintain their own struct lsm_id and pass it to security_add_hooks().
The values are for LSM identifiers are defined in a new UAPI header file linux/lsm.h. Each existing LSM has been updated to include it's LSMID in the lsm_id.
The LSM ID values are sequential, with the oldest module LSM_ID_CAPABILITY being the lowest value and the existing modules numbered in the order they were included in the main line kernel. This is an arbitrary convention for assigning the values, but none better presents itself. The value 0 is defined as being invalid. The values 1-99 are reserved for any special case uses which may arise in the future. This may include attributes of the LSM infrastructure itself, possibly related to namespacing or network attribute management. A special range is identified for such attributes to help reduce confusion for developers unfamiliar with LSMs.
LSM attribute values are defined for the attributes presented by modules that are available today. As with the LSM IDs, The value 0 is defined as being invalid. The values 1-99 are reserved for any special case uses which may arise in the future.
--- Documentation/userspace-api/index.rst | 1 + MAINTAINERS | 1 + include/linux/lsm_hooks.h | 16 +++++++- include/uapi/linux/lsm.h | 54 +++++++++++++++++++++++++++ security/apparmor/lsm.c | 8 +++- security/bpf/hooks.c | 9 ++++- security/commoncap.c | 8 +++- security/landlock/cred.c | 2 +- security/landlock/fs.c | 2 +- security/landlock/ptrace.c | 2 +- security/landlock/setup.c | 6 +++ security/landlock/setup.h | 1 + security/loadpin/loadpin.c | 9 ++++- security/lockdown/lockdown.c | 8 +++- security/safesetid/lsm.c | 9 ++++- security/security.c | 12 +++--- security/selinux/hooks.c | 9 ++++- security/smack/smack_lsm.c | 8 +++- security/tomoyo/tomoyo.c | 9 ++++- security/yama/yama_lsm.c | 8 +++- 20 files changed, 161 insertions(+), 21 deletions(-) create mode 100644 include/uapi/linux/lsm.h
Documentation/userspace-api/index.rst +1 -0
@@ -32,6 +32,7 @@ place where this information is gathered. sysfs-platform_profile vduse futex2 + lsm .. only:: subproject and html
MAINTAINERS +1 -0
@@ -19307,6 +19307,7 @@ L: [email protected] (suggested Cc:) S: Supported W: http://kernsec.org/ T: git git://git.kernel.org/pub/scm/linux/kernel/git/pcmoore/lsm.git +F: include/uapi/linux/lsm.h F: security/ X: security/selinux/
include/linux/lsm_hooks.h +14 -2
@@ -42,6 +42,18 @@ struct security_hook_heads {#undef LSM_HOOK } __randomize_layout; +/** +* struct lsm_id - Identify a Linux Security Module. +* @lsm: name of the LSM, must be approved by the LSM maintainers +* @id: LSM ID number from uapi/linux/lsm.h +* +* Contains the information that identifies the LSM. +*/ +struct lsm_id { +const char *name; +u64 id; +}; +/* * Security module hook list structure. * For use with generic list macros for common operations.
@@ -50,7 +62,7 @@ struct security_hook_list {struct hlist_node list;struct hlist_head *head;union security_list_options hook; -const char *lsm; +const struct lsm_id *lsmid; } __randomize_layout;/*
@@ -104,7 +116,7 @@ extern struct security_hook_heads security_hook_heads;extern char *lsm_names;extern void security_add_hooks (struct security_hook_list *hooks,int count, -const char *lsm); +const struct lsm_id *lsmid);#define LSM_FLAG_LEGACY_MAJOR BIT(0)#define LSM_FLAG_EXCLUSIVE BIT(1)
include/uapi/linux/lsm.h new file +54 -0
54 lines not on this page · raw message
security/apparmor/lsm.c +7 -1
@@ -24,6 +24,7 @@#include <linux/zstd.h> #include <net/sock.h> #include <uapi/linux/mount.h> +#include <uapi/linux/lsm.h> #include "include/apparmor.h" #include "include/apparmorfs.h"
@@ -1215,6 +1216,11 @@ struct lsm_blob_sizes apparmor_blob_sizes __ro_after_init = { .lbs_task = sizeof(struct aa_task_ctx), }; +const struct lsm_id apparmor_lsmid = { + .name ="apparmor" , + .id =LSM_ID_APPARMOR , +}; +static struct security_hook_list apparmor_hooks[]__ro_after_init = {LSM_HOOK_INIT (ptrace_access_check, apparmor_ptrace_access_check),LSM_HOOK_INIT (ptrace_traceme, apparmor_ptrace_traceme),
@@ -1904,7 +1910,7 @@ static int __init apparmor_init(void) goto buffers_out; }security_add_hooks (apparmor_hooks,ARRAY_SIZE (apparmor_hooks), -"apparmor" ); + &apparmor_lsmid);/* Report that AppArmor successfully initialized */ apparmor_initialized =1 ;
security/bpf/hooks.c +8 -1
@@ -5,6 +5,7 @@*/ #include <linux/lsm_hooks.h> #include <linux/bpf_lsm.h> +#include <uapi/linux/lsm.h> static struct security_hook_list bpf_lsm_hooks[]__ro_after_init = { #define LSM_HOOK(RET, DEFAULT, NAME, ...) \
@@ -15,9 +16,15 @@ static struct security_hook_list bpf_lsm_hooks[] __ro_after_init = { LSM_HOOK_INIT(task_free, bpf_task_storage_free), }; +const struct lsm_id bpf_lsmid = { + .name ="bpf" , + .id =LSM_ID_BPF , +}; +static int __init bpf_lsm_init (void ) { -security_add_hooks (bpf_lsm_hooks,ARRAY_SIZE (bpf_lsm_hooks),"bpf" ); +security_add_hooks (bpf_lsm_hooks,ARRAY_SIZE (bpf_lsm_hooks), + &bpf_lsmid);pr_info ("LSM support for eBPF active\n" );return 0 ; }
security/commoncap.c +7 -1
@@ -25,6 +25,7 @@#include <linux/binfmts.h> #include <linux/personality.h> #include <linux/mnt_idmapping.h> +#include <uapi/linux/lsm.h> /* * If a non-root user executes a setuid-root binary in
@@ -1440,6 +1441,11 @@ int cap_mmap_file(struct file *file, unsigned long reqprot,#ifdef CONFIG_SECURITY +const struct lsm_id capability_lsmid = { + .name ="capability" , + .id =LSM_ID_CAPABILITY , +}; +static struct security_hook_list capability_hooks[]__ro_after_init = {LSM_HOOK_INIT (capable, cap_capable), LSM_HOOK_INIT(settime, cap_settime),
@@ -1464,7 +1470,7 @@ static struct security_hook_list capability_hooks[] __ro_after_init = {static int __init capability_init (void ) {security_add_hooks (capability_hooks,ARRAY_SIZE (capability_hooks), -"capability" ); + &capability_lsmid);return 0 ; }
security/landlock/cred.c +1 -1
@@ -42,5 +42,5 @@ static struct security_hook_list landlock_hooks[] __ro_after_init = {__init void landlock_add_cred_hooks (void ) {security_add_hooks (landlock_hooks,ARRAY_SIZE (landlock_hooks), -LANDLOCK_NAME ); + &landlock_lsmid); }
security/landlock/fs.c +1 -1
@@ -1307,5 +1307,5 @@ static struct security_hook_list landlock_hooks[] __ro_after_init = {__init void landlock_add_fs_hooks (void ) {security_add_hooks (landlock_hooks,ARRAY_SIZE (landlock_hooks), -LANDLOCK_NAME ); + &landlock_lsmid); }
security/landlock/ptrace.c +1 -1
@@ -116,5 +116,5 @@ static struct security_hook_list landlock_hooks[] __ro_after_init = {__init void landlock_add_ptrace_hooks (void ) {security_add_hooks (landlock_hooks,ARRAY_SIZE (landlock_hooks), -LANDLOCK_NAME ); + &landlock_lsmid); }
security/landlock/setup.c +6 -0
@@ -8,6 +8,7 @@#include <linux/init.h> #include <linux/lsm_hooks.h> +#include <uapi/linux/lsm.h> #include "common.h" #include "cred.h"
@@ -24,6 +25,11 @@ struct lsm_blob_sizes landlock_blob_sizes __ro_after_init = { .lbs_superblock = sizeof(struct landlock_superblock_security), }; +const struct lsm_id landlock_lsmid = { + .name =LANDLOCK_NAME , + .id =LSM_ID_LANDLOCK , +}; +static int __init landlock_init (void ) {landlock_add_cred_hooks ();
security/landlock/setup.h +1 -0
@@ -14,5 +14,6 @@extern bool landlock_initialized;extern struct lsm_blob_sizes landlock_blob_sizes; +extern const struct lsm_id landlock_lsmid;#endif /* _SECURITY_LANDLOCK_SETUP_H */
security/loadpin/loadpin.c +8 -1
@@ -20,6 +20,7 @@#include <linux/string_helpers.h> #include <linux/dm-verity-loadpin.h> #include <uapi/linux/loadpin.h> +#include <uapi/linux/lsm.h> #define VERITY_DIGEST_FILE_HEADER "# LOADPIN_TRUSTED_VERITY_ROOT_DIGESTS"
@@ -208,6 +209,11 @@ static int loadpin_load_data(enum kernel_load_data_id id, bool contents)return loadpin_check (NULL , (enum kernel_read_file_id ) id); } +const struct lsm_id loadpin_lsmid = { + .name ="loadpin" , + .id =LSM_ID_LOADPIN , +}; +static struct security_hook_list loadpin_hooks[]__ro_after_init = {LSM_HOOK_INIT (sb_free_security, loadpin_sb_free_security),LSM_HOOK_INIT (kernel_read_file, loadpin_read_file),
@@ -259,7 +265,8 @@ static int __init loadpin_init(void)if (!register_sysctl ("kernel/loadpin" , loadpin_sysctl_table))pr_notice ("sysctl registration failed!\n" );#endif -security_add_hooks (loadpin_hooks,ARRAY_SIZE (loadpin_hooks),"loadpin" ); +security_add_hooks (loadpin_hooks,ARRAY_SIZE (loadpin_hooks), + &loadpin_lsmid);return 0 ; }
security/lockdown/lockdown.c +7 -1
@@ -13,6 +13,7 @@#include <linux/security.h> #include <linux/export.h> #include <linux/lsm_hooks.h> +#include <uapi/linux/lsm.h> static enum lockdown_reason kernel_locked_down;
@@ -75,6 +76,11 @@ static struct security_hook_list lockdown_hooks[] __ro_after_init = { LSM_HOOK_INIT(locked_down, lockdown_is_locked_down), }; +const struct lsm_id lockdown_lsmid = { + .name ="lockdown" , + .id =LSM_ID_LOCKDOWN , +}; +static int __init lockdown_lsm_init (void ) {#if defined(CONFIG_LOCK_DOWN_KERNEL_FORCE_INTEGRITY )
@@ -83,7 +89,7 @@ static int __init lockdown_lsm_init(void)lock_kernel_down ("Kernel configuration" ,LOCKDOWN_CONFIDENTIALITY_MAX );#endif security_add_hooks (lockdown_hooks,ARRAY_SIZE (lockdown_hooks), -"lockdown" ); + &lockdown_lsmid);return 0 ; }
security/safesetid/lsm.c +8 -1
@@ -19,6 +19,7 @@#include <linux/ptrace.h> #include <linux/sched/task_stack.h> #include <linux/security.h> +#include <uapi/linux/lsm.h> #include "lsm.h" /* Flag indicating whether initialization completed */
@@ -261,6 +262,11 @@ static int safesetid_task_fix_setgroups(struct cred *new, const struct cred *oldreturn 0 ; } +const struct lsm_id safesetid_lsmid = { + .name ="safesetid" , + .id =LSM_ID_SAFESETID , +}; +static struct security_hook_list safesetid_security_hooks[] = {LSM_HOOK_INIT (task_fix_setuid, safesetid_task_fix_setuid),LSM_HOOK_INIT (task_fix_setgid, safesetid_task_fix_setgid),
@@ -271,7 +277,8 @@ static struct security_hook_list safesetid_security_hooks[] = {static int __init safesetid_security_init (void ) {security_add_hooks (safesetid_security_hooks, -ARRAY_SIZE (safesetid_security_hooks),"safesetid" ); +ARRAY_SIZE (safesetid_security_hooks), + &safesetid_lsmid);/* Report that SafeSetID successfully initialized */ safesetid_initialized =1 ;
security/security.c +6 -6
@@ -513,17 +513,17 @@ static int lsm_append(const char *new, char **result)* security_add_hooks - Add a modules hooks to the hook lists. * @hooks: the hooks to add * @count: the number of hooks to add -* @lsm: the name of the security module +* @lsmid: the identification information for the security module * * Each LSM has to register its hooks with the infrastructure. */ void __init security_add_hooks (struct security_hook_list *hooks,int count, -const char *lsm) +const struct lsm_id *lsmid) {int i;for (i =0 ; i < count; i++) { - hooks[i].lsm = lsm; + hooks[i].lsmid = lsmid;hlist_add_tail_rcu (&hooks[i].list, hooks[i].head); }
@@ -532,7 +532,7 @@ void __init security_add_hooks(struct security_hook_list *hooks, int count,* and fix this up afterwards. */ if (slab_is_available ()) { -if (lsm_append (lsm, &lsm_names) <0 ) +if (lsm_append (lsmid->name, &lsm_names) <0 )panic ("%s - Cannot get early memory.\n" , __func__); } }
@@ -3817,7 +3817,7 @@ int security_getprocattr(struct task_struct *p, const char *lsm,struct security_hook_list *hp;hlist_for_each_entry (hp, &security_hook_heads.getprocattr, list) { -if (lsm !=NULL &&strcmp (lsm, hp->lsm)) +if (lsm !=NULL &&strcmp (lsm, hp->lsmid->name))continue ;return hp->hook.getprocattr (p, name, value); }
@@ -3842,7 +3842,7 @@ int security_setprocattr(const char *lsm, const char *name, void *value,struct security_hook_list *hp;hlist_for_each_entry (hp, &security_hook_heads.setprocattr, list) { -if (lsm !=NULL &&strcmp (lsm, hp->lsm)) +if (lsm !=NULL &&strcmp (lsm, hp->lsmid->name))continue ;return hp->hook.setprocattr (name, value, size); }
security/selinux/hooks.c +8 -1
@@ -92,6 +92,7 @@#include <linux/fsnotify.h> #include <linux/fanotify.h> #include <linux/io_uring.h> +#include <uapi/linux/lsm.h> #include "avc.h" #include "objsec.h"
@@ -6944,6 +6945,11 @@ static int selinux_uring_cmd(struct io_uring_cmd *ioucmd) }#endif /* CONFIG_IO_URING */ +const struct lsm_id selinux_lsmid = { + .name ="selinux" , + .id =LSM_ID_SELINUX , +}; +/* * IMPORTANT NOTE: When adding new hooks, please be careful to keep this order: * 1. any hooks that don't belong to (2.) or (3.) below,
@@ -7264,7 +7270,8 @@ static __init int selinux_init(void)hashtab_cache_init (); -security_add_hooks (selinux_hooks,ARRAY_SIZE (selinux_hooks),"selinux" ); +security_add_hooks (selinux_hooks,ARRAY_SIZE (selinux_hooks), + &selinux_lsmid);if (avc_add_callback (selinux_netcache_avc_callback,AVC_CALLBACK_RESET ))panic ("SELinux: Unable to register AVC netcache callback\n" );
security/smack/smack_lsm.c +7 -1
@@ -43,6 +43,7 @@#include <linux/fs_parser.h> #include <linux/watch_queue.h> #include <linux/io_uring.h> +#include <uapi/linux/lsm.h> #include "smack.h" #define TRANS_TRUE "TRUE"
@@ -4933,6 +4934,11 @@ struct lsm_blob_sizes smack_blob_sizes __ro_after_init = { .lbs_xattr_count = SMACK_INODE_INIT_XATTRS, }; +const struct lsm_id smack_lsmid = { + .name ="smack" , + .id =LSM_ID_SMACK , +}; +static struct security_hook_list smack_hooks[]__ro_after_init = {LSM_HOOK_INIT (ptrace_access_check, smack_ptrace_access_check),LSM_HOOK_INIT (ptrace_traceme, smack_ptrace_traceme),
@@ -5140,7 +5146,7 @@ static __init int smack_init(void)/* * Register with LSM */ -security_add_hooks (smack_hooks,ARRAY_SIZE (smack_hooks),"smack" ); +security_add_hooks (smack_hooks,ARRAY_SIZE (smack_hooks), &smack_lsmid); smack_enabled =1 ;pr_info ("Smack: Initializing.\n" );
security/tomoyo/tomoyo.c +8 -1
@@ -6,6 +6,7 @@*/ #include <linux/lsm_hooks.h> +#include <uapi/linux/lsm.h> #include "common.h" /**
@@ -542,6 +543,11 @@ static void tomoyo_task_free(struct task_struct *task) } } +const struct lsm_id tomoyo_lsmid = { + .name ="tomoyo" , + .id =LSM_ID_TOMOYO , +}; +/* * tomoyo_security_ops is a "struct security_operations" which is used for * registering TOMOYO.
@@ -595,7 +601,8 @@ static int __init tomoyo_init(void)struct tomoyo_task *s =tomoyo_task (current);/* register ourselves with the security framework */ -security_add_hooks (tomoyo_hooks,ARRAY_SIZE (tomoyo_hooks),"tomoyo" ); +security_add_hooks (tomoyo_hooks,ARRAY_SIZE (tomoyo_hooks), + &tomoyo_lsmid);pr_info ("TOMOYO Linux initialized\n" ); s->domain_info = &tomoyo_kernel_domain;atomic_inc (&tomoyo_kernel_domain.users);
security/yama/yama_lsm.c +7 -1
@@ -18,6 +18,7 @@#include <linux/task_work.h> #include <linux/sched.h> #include <linux/spinlock.h> +#include <uapi/linux/lsm.h> #define YAMA_SCOPE_DISABLED 0#define YAMA_SCOPE_RELATIONAL 1
@@ -421,6 +422,11 @@ static int yama_ptrace_traceme(struct task_struct *parent)return rc; } +const struct lsm_id yama_lsmid = { + .name ="yama" , + .id =LSM_ID_YAMA , +}; +static struct security_hook_list yama_hooks[]__ro_after_init = {LSM_HOOK_INIT (ptrace_access_check, yama_ptrace_access_check),LSM_HOOK_INIT (ptrace_traceme, yama_ptrace_traceme),
@@ -471,7 +477,7 @@ static inline void yama_init_sysctl(void) { }static int __init yama_init (void ) {pr_info ("Yama: becoming mindful.\n" ); -security_add_hooks (yama_hooks,ARRAY_SIZE (yama_hooks),"yama" ); +security_add_hooks (yama_hooks,ARRAY_SIZE (yama_hooks), &yama_lsmid);yama_init_sysctl ();return 0 ; }
Signature · 1 line
2.41.0
Quoted 27 lines · Casey Schaufler
Create a struct
lsm_idto contain identifying information about Linux Security Modules (LSMs). At inception this contains the name of the module and an identifier associated with the security module. Change thesecurity_add_hooks()interface to use this structure. Change the individual modules to maintain their own structlsm_idand pass it tosecurity_add_hooks().The values are for LSM identifiers are defined in a new UAPI header file
linux/lsm.h. Each existing LSM has been updated to include it's LSMID in thelsm_id.The LSM ID values are sequential, with the oldest module
LSM_ID_CAPABILITYbeing the lowest value and the existing modules numbered in the order they were included in the main line kernel. This is an arbitrary convention for assigning the values, but none better presents itself. The value 0 is defined as being invalid. The values 1-99 are reserved for any special case uses which may arise in the future. This may include attributes of the LSM infrastructure itself, possibly related to namespacing or network attribute management. A special range is identified for such attributes to help reduce confusion for developers unfamiliar with LSMs.LSM attribute values are defined for the attributes presented by modules that are available today. As with the LSM IDs, The value 0 is defined as being invalid. The values 1-99 are reserved for any special case uses which may arise in the future.
Quoted 6 lines
Signed-off-by Casey Schaufler <[email protected]>Cc linux-security-module <[email protected]>Reviewed-by Kees Cook <[email protected]>Reviewed-by Serge Hallyn <[email protected]>Reviewed-by Mickael Salaun <[email protected]>Reviewed-by John Johansen <[email protected]>
Casey Schaufler
maintainerQuoted 28 lines · Tetsuo Handa
Quoted 27 lines · Casey Schaufler
Create a struct
lsm_idto contain identifying information about Linux Security Modules (LSMs). At inception this contains the name of the module and an identifier associated with the security module. Change thesecurity_add_hooks()interface to use this structure. Change the individual modules to maintain their own structlsm_idand pass it tosecurity_add_hooks().The values are for LSM identifiers are defined in a new UAPI header file
linux/lsm.h. Each existing LSM has been updated to include it's LSMID in thelsm_id.The LSM ID values are sequential, with the oldest module
LSM_ID_CAPABILITYbeing the lowest value and the existing modules numbered in the order they were included in the main line kernel. This is an arbitrary convention for assigning the values, but none better presents itself. The value 0 is defined as being invalid. The values 1-99 are reserved for any special case uses which may arise in the future. This may include attributes of the LSM infrastructure itself, possibly related to namespacing or network attribute management. A special range is identified for such attributes to help reduce confusion for developers unfamiliar with LSMs.LSM attribute values are defined for the attributes presented by modules that are available today. As with the LSM IDs, The value 0 is defined as being invalid. The values 1-99 are reserved for any special case uses which may arise in the future.
Quoted 7 lines
Quoted 6 lines
Signed-off-by Casey Schaufler <[email protected]>Cc linux-security-module <[email protected]>Reviewed-by Kees Cook <[email protected]>Reviewed-by Serge Hallyn <[email protected]>Reviewed-by Mickael Salaun <[email protected]>Reviewed-by John Johansen <[email protected]>Nacked-by Tetsuo Handa <[email protected]>
I *could* respond with:
-#define LSM_ID_TOMOYO 103
but I won't. I won't make a difference because TOMOYO doesn't present any attributes. I understand your objections, but don't believe that they can't be worked around. The argument that a LSM ID will prevent new LSM development is rebuffed by the exact same situation with system calls, PRCTL and IOCTL values. The argument that it somehow prevents out-of-tree modules falls on deaf ears. The argument that it prevents dynamic security modules is subsumed by the other issues surrounding dynamic security modules, and does nothing to decrease the likelihood of that facility going upstream. Especially since, to the best of my knowledge, no one is working on it.
Quoted 2 lines
Tetsuo Handa
maintainerQuoted 4 lines · Casey Schaufler
I *could* respond with:
-#define
LSM_ID_TOMOYO103
Quoted 10 lines
but I won't. I won't make a difference because TOMOYO doesn't present any attributes. I understand your objections, but don't believe that they can't be worked around. The argument that a LSM ID will prevent new LSM development is rebuffed by the exact same situation with system calls, PRCTL and IOCTL values. The argument that it somehow prevents out-of-tree modules falls on deaf ears. The argument that it prevents dynamic security modules is subsumed by the other issues surrounding dynamic security modules, and does nothing to decrease the likelihood of that facility going upstream. Especially since, to the best of my knowledge, no one is working on it.
+/**
+ * struct lsm_id - Identify a Linux Security Module.
+ * @lsm: name of the LSM, must be approved by the LSM maintainers
Why can't you understand that "approved by the LSM maintainers" is a horrible requirement for LSM modules which cannot become one of in-tree LSMs?
One of reasons for not every proposed LSM module can become in-tree is out of the LSM community's resources for reviewing/maintaining (or failure to acquire attention from the LSM community enough to get reviewed).
+ * @id: LSM ID number from uapi/linux/lsm.h
Since the LSM community cannot accept all of proposed LSMs due to limited resources, the LSM community is responsible for allowing whatever proposed LSMs (effectively any publicly available LSMs) to live as out-of-tree LSMs, by approving the LSM name and assigning a permanent LSM ID number.
The only exception the LSM community can refuse to approve/assign would be that the name is not appropriate (e.g. a LSM module named "FuckYou") or the name is misleading (e.g. "selinux+", "smock", "tomato", "apparmour"). Otherwise, no matter how many times you repeat "we don't care out-of-tree LSMs" or "I do not intentionally plan to make life difficult for the out-of-tree LSMs", this patch is intended to lock out out-of-tree LSMs.
+ *
+ * Contains the information that identifies the LSM.
+ */
+struct lsm_id {
+ const char *name;
+ u64 id;
+};
Therefore, unless you change the policy for assigning LSM ID, I keep NACK on this change.
Casey Schaufler
maintainerQuoted 33 lines · Tetsuo Handa
Quoted 4 lines · Casey Schaufler
I *could* respond with:
-#define
LSM_ID_TOMOYO103Quoted 10 lines
but I won't. I won't make a difference because TOMOYO doesn't present any attributes. I understand your objections, but don't believe that they can't be worked around. The argument that a LSM ID will prevent new LSM development is rebuffed by the exact same situation with system calls, PRCTL and IOCTL values. The argument that it somehow prevents out-of-tree modules falls on deaf ears. The argument that it prevents dynamic security modules is subsumed by the other issues surrounding dynamic security modules, and does nothing to decrease the likelihood of that facility going upstream. Especially since, to the best of my knowledge, no one is working on it.
+/**
+ * structlsm_id- Identify a Linux Security Module.
+ * @lsm: name of the LSM, must be approved by the LSM maintainersWhy can't you understand that "approved by the LSM maintainers" is a horrible requirement for LSM modules which cannot become one of in-tree LSMs?
One of reasons for not every proposed LSM module can become in-tree is out of the LSM community's resources for reviewing/maintaining (or failure to acquire attention from the LSM community enough to get reviewed).
+ * @id: LSM ID number from
uapi/linux/lsm.hSince the LSM community cannot accept all of proposed LSMs due to limited resources, the LSM community is responsible for allowing whatever proposed LSMs (effectively any publicly available LSMs) to live as out-of-tree LSMs, by approving the LSM name and assigning a permanent LSM ID number.
Quoted 5 lines
The only exception the LSM community can refuse to approve/assign would be that the name is not appropriate (e.g. a LSM module named "FuckYou") or the name is misleading (e.g. "selinux+", "smock", "tomato", "apparmour"). Otherwise, no matter how many times you repeat "we don't care out-of-tree LSMs" or "I do not intentionally plan to make life difficult for the out-of-tree LSMs", this patch is intended to lock out out-of-tree LSMs.
That is a false statement. There is a huge difference between apathy and malice.
Quoted 11 lines
+ *
+ * Contains the information that identifies the LSM.
+ */include/linux/lsm_hooks.h +4
-0+struct lsm_id { +const char *name; +u64 id; +};Therefore, unless you change the policy for assigning LSM ID, I keep NACK on this change.
Tetsuo Handa
maintainerQuoted 19 lines · Casey Schaufler
Quoted 18 lines · Tetsuo Handa
+/**
+ * structlsm_id- Identify a Linux Security Module.
+ * @lsm: name of the LSM, must be approved by the LSM maintainersWhy can't you understand that "approved by the LSM maintainers" is a horrible requirement for LSM modules which cannot become one of in-tree LSMs?
One of reasons for not every proposed LSM module can become in-tree is out of the LSM community's resources for reviewing/maintaining (or failure to acquire attention from the LSM community enough to get reviewed).
+ * @id: LSM ID number from
uapi/linux/lsm.hSince the LSM community cannot accept all of proposed LSMs due to limited resources, the LSM community is responsible for allowing whatever proposed LSMs (effectively any publicly available LSMs) to live as out-of-tree LSMs, by approving the LSM name and assigning a permanent LSM ID number.
Quoted 7 lines
Quoted 5 lines
The only exception the LSM community can refuse to approve/assign would be that the name is not appropriate (e.g. a LSM module named "FuckYou") or the name is misleading (e.g. "selinux+", "smock", "tomato", "apparmour"). Otherwise, no matter how many times you repeat "we don't care out-of-tree LSMs" or "I do not intentionally plan to make life difficult for the out-of-tree LSMs", this patch is intended to lock out out-of-tree LSMs.
That is a false statement. There is a huge difference between apathy and malice.
Dave Chinner wrote at https://lkml.kernel.org/r/[email protected]
as a response to "We don't care about out of tree filesystems.":
In this case, we most certainly do care. Downstream distros support all sorts of out of tree filesystems loaded via kernel modules, so a syscall that is used to uniquely identify a filesystem type to userspace *must* have a mechanism for the filesystem to provide that unique identifier to userspace.
Fundamentally, the kernel does not and should not dictate what filesystem types it supports; the user decides what filesystem they need to use, and it is the kernel's job to provide infrastructure that works with that user's choice.
Can you see? What you are trying to is NACKed by simple s/filesystem/LSM/g .
The kernel is ultimately there for users. The kernel is never there for doing patent acquisition competition. If the LSM community accepts only LSMs which won the patent acquisition competition as in-tree (as described in "ANN: new LSM guidelines"), the LSM community is responsible for allowing any publicly available LSMs to live as out of tree modules.
Unless the policy is updated to approve any publicly available LSMs and assign a unique identifier (which can be passed to the syscalls introduced by this series) to each publicly available LSM, this series is a regression.
The "[PATCH v15 01/11] LSM: Identify modules by more than name" is exactly doing "LSM: allow only in-tree LSM modules, lock out out-of-tree LSM modules". Nack, Nack, Nack, Nack, Nack!!!!!
Quoted 12 lines
Quoted 12 lines
+ *
+ * Contains the information that identifies the LSM.
+ */include/linux/lsm_hooks.h +4
-0+struct lsm_id { +const char *name; +u64 id; +};Therefore, unless you change the policy for assigning LSM ID, I keep NACK on this change.
Quoted 50 lines · Tetsuo Handa
Quoted 19 lines · Casey Schaufler
Quoted 18 lines · Tetsuo Handa
+/**
+ * structlsm_id- Identify a Linux Security Module.
+ * @lsm: name of the LSM, must be approved by the LSM maintainersWhy can't you understand that "approved by the LSM maintainers" is a horrible requirement for LSM modules which cannot become one of in-tree LSMs?
One of reasons for not every proposed LSM module can become in-tree is out of the LSM community's resources for reviewing/maintaining (or failure to acquire attention from the LSM community enough to get reviewed).
+ * @id: LSM ID number from
uapi/linux/lsm.hSince the LSM community cannot accept all of proposed LSMs due to limited resources, the LSM community is responsible for allowing whatever proposed LSMs (effectively any publicly available LSMs) to live as out-of-tree LSMs, by approving the LSM name and assigning a permanent LSM ID number.
Quoted 7 lines
Quoted 5 lines
The only exception the LSM community can refuse to approve/assign would be that the name is not appropriate (e.g. a LSM module named "FuckYou") or the name is misleading (e.g. "selinux+", "smock", "tomato", "apparmour"). Otherwise, no matter how many times you repeat "we don't care out-of-tree LSMs" or "I do not intentionally plan to make life difficult for the out-of-tree LSMs", this patch is intended to lock out out-of-tree LSMs.
That is a false statement. There is a huge difference between apathy and malice.
Dave Chinner wrote at https://lkml.kernel.org/r/[email protected]
as a response to "We don't care about out of tree filesystems.":In this case, we most certainly do care. Downstream distros support all sorts of out of tree filesystems loaded via kernel modules, so a syscall that is used to uniquely identify a filesystem type to userspace *must* have a mechanism for the filesystem to provide that unique identifier to userspace.
Fundamentally, the kernel does not and should not dictate what filesystem types it supports; the user decides what filesystem they need to use, and it is the kernel's job to provide infrastructure that works with that user's choice.
Can you see? What you are trying to is NACKed by simple s/filesystem/LSM/g .
The kernel is ultimately there for users. The kernel is never there for doing patent acquisition competition. If the LSM community accepts only LSMs which won the patent acquisition competition as in-tree (as described in "ANN: new LSM guidelines"), the LSM community is responsible for allowing any publicly available LSMs to live as out of tree modules.
Quoted 7 lines
Unless the policy is updated to approve any publicly available LSMs and assign a unique identifier (which can be passed to the syscalls introduced by this series) to each publicly available LSM, this series is a regression.
The "[PATCH v15 01/11] LSM: Identify modules by more than name" is exactly doing "LSM: allow only in-tree LSM modules, lock out out-of-tree LSM modules". Nack, Nack, Nack, Nack, Nack!!!!!
I feel like you are willfully not listening to us when we say that this doesn't block out of tree LSMs. Again, there is nothing here that stops it. To prove this point, here is an out of tree LSM that works with this series. So let's move from theoretical to practical: given this example, why do you think out of tree LSMs are blocked?
From a6f50cb719aac2452506babda07657f9f6961a95 Mon Sep 17 00:00:00 2001
From: Kees Cook <[email protected]>
Date: Wed, 20 Sep 2023 08:00:31 -0700
Subject: [PATCH] security: Add GOAT LSM
This will never go upstream, but it still works with the new LSM syscalls.
--- include/uapi/linux/lsm.h | 2 ++ security/Kconfig | 1 + security/Makefile | 1 + security/goat/Kconfig | 9 +++++++ security/goat/Makefile | 2 ++ security/goat/goat.c | 51 ++++++++++++++++++++++++++++++++++++++++ 6 files changed, 66 insertions(+) create mode 100644 security/goat/Kconfig create mode 100644 security/goat/Makefile create mode 100644 security/goat/goat.c
include/uapi/linux/lsm.h +2 -0
@@ -63,6 +63,8 @@ struct lsm_ctx {#define LSM_ID_BPF 110#define LSM_ID_LANDLOCK 111 +#define LSM_ID_GOAT 1138 +/* * LSM_ATTR_XXX definitions identify different LSM attributes * which are used in the kernel's LSM userspace API. Support
security/Kconfig +1 -0
@@ -194,6 +194,7 @@ source "security/yama/Kconfig" source "security/safesetid/Kconfig" source "security/lockdown/Kconfig" source "security/landlock/Kconfig" +source "security/goat/Kconfig" source "security/integrity/Kconfig"
security/Makefile +1 -0
@@ -25,6 +25,7 @@ obj-$(CONFIG_SECURITY_LOCKDOWN_LSM) += lockdown/ obj-$(CONFIG_CGROUPS) += device_cgroup.o obj-$(CONFIG_BPF_LSM) += bpf/ obj-$(CONFIG_SECURITY_LANDLOCK) += landlock/ +obj-$(CONFIG_SECURITY_GOAT) += goat/ # Object integrity file lists obj-$(CONFIG_INTEGRITY) += integrity/
security/goat/Kconfig new file +9 -0
@@ -0,0 +1,9 @@ +# SPDX-License-Identifier: GPL-2.0-only +config SECURITY_GOAT + bool "Greatest Of All Time security features" + depends on SECURITY + help + This LSM provides the greatest security features of all + time. + + If in doubt, choose "Heck yeah".
security/goat/Makefile new file +2 -0
@@ -0,0 +1,2 @@ +# SPDX-License-Identifier: GPL-2.0-only +obj-$(CONFIG_SECURITY_GOAT) += goat.o
security/goat/goat.c new file +49 -0
49 lines not on this page · raw message
Signature · 5 lines
2.34.1 -- Kees Cook
Tetsuo Handa
maintainerQuoted 5 lines · Kees Cook
I feel like you are willfully not listening to us when we say that this doesn't block out of tree LSMs. Again, there is nothing here that stops it. To prove this point, here is an out of tree LSM that works with this series. So let's move from theoretical to practical: given this example, why do you think out of tree LSMs are blocked?
Because an LSM ID value
include/uapi/linux/lsm.h struct lsm_ctx { · line 70
Quoted 13 lines
include/uapi/linux/lsm.h +2
-0@@ -63,6 +63,8 @@ struct lsm_ctx {#define LSM_ID_BPF 110#define LSM_ID_LANDLOCK 111 +#define LSM_ID_GOAT 1138 +/* * LSM_ATTR_XXX definitions identify different LSM attributes * which are used in the kernel's LSM userspace API. Support
is assigned to LSM only when that LSM became no longer out of tree.
I'm against the policy that only LSM modules that succeeded to become in-tree are assigned LSM ID. That's not a good usage of identifier.
Quoting from https://lkml.kernel.org/r/[email protected] :
The sane and the better usage of LSM ID is to register any publicly available LSMs. If LSM ID serves as an index for what LSMs are available in the world, by maintaining "the LSM module name, the LSM ID value, short description about that LSM module, the public git repository or web site for more information about that LSM module" pairs, people can easily find what LSMs could be used for their purpose, and developers can avoid re-inventing similar LSM modules which are already available somewhere in the world (and optionally helps avoiding module name collisions with any publicly available LSMs).
You must not say "We don't care about out of tree LSMs." when talking about this patch.
Quoted 8 lines · Tetsuo Handa
Quoted 5 lines · Kees Cook
I feel like you are willfully not listening to us when we say that this doesn't block out of tree LSMs. Again, there is nothing here that stops it. To prove this point, here is an out of tree LSM that works with this series. So let's move from theoretical to practical: given this example, why do you think out of tree LSMs are blocked?
Because an LSM ID value
But my example includes one.
Quoted 8 lines
Quoted 8 lines
include/uapi/linux/lsm.h +0
-0@@ -63,6 +63,8 @@ struct lsm_ctx {#define LSM_ID_BPF 110#define LSM_ID_LANDLOCK 111
Quoted 7 lines
include/uapi/linux/lsm.h struct lsm_ctx { · line 70
Quoted 5 lines
include/uapi/linux/lsm.h +2
-0+#define LSM_ID_GOAT 1138 +/* * LSM_ATTR_XXX definitions identify different LSM attributes * which are used in the kernel's LSM userspace API. Support is assigned to LSM only when that LSM became no longer out of tree.
Why? My example code will work just fine. The only possible reason it could be awkward would be if an out of tree LSM became so useful that the author decided to upstream it, and risked colliding with an existing LSM id. But lsm_id::id is a u64 (not an enum!), so there is a HUGE space available. If out of tree LSMs used the epoch time they were first authored as their id, the chances of a collision would be approaching zero. There isn't an out of tree LSM written every second, but if there were, it would take 584 billion years to run out of LSM ids.
And, as mentioned several times before, this is _not a new problem_, and exists for out of tree syscalls, out of tree prctls, etc. I even DID this for the Yama LSM when it looked like it wasn't going to get upstream in the early days. Its prctl number _is not sequential_:
include/uapi/linux/prctl.h:#define PR_SET_PTRACER 0x59616d61
(And you'll see 0x59616d61 in ASCII is "Yama"; my effort to avoid collision.)
So, there is both ability (u64) and precedent (Yama) for this. Having an LSM id is _not_ a blocker for out of tree LSMs, and I've given the proof.
-Kees
Signature · 1 line
Kees Cook
Tetsuo Handa
maintainerPatch description says
The LSM ID values are sequential, with the oldest module LSM_ID_CAPABILITY being the lowest value and the existing modules numbered in the order they were included in the main line kernel. This is an arbitrary convention for assigning the values, but none better presents itself. The value 0 is defined as being invalid.
and your non-sequential assignment
Quoted 1 line
But
lsm_id::idis a u64 (not an enum!), so there is a HUGE space available.
violated it. include/uapi/linux/lsm.h is a userspace API file, where we can't change this value after once defined.
You withdraw your "Reviewed-by" response unless "The LSM ID values are sequential" and "must be approved by the LSM maintainers" are removed and "the LSM maintainers/community shall never complain about what names and/or values are assigned" is added, don't you?
Quoting from https://lkml.kernel.org/r/[email protected] :
You are intentionally making life difficult for the out-of-tree LSMs, by requiring an LSM ID (and facilitating LSM ID collisions). No matter how priority of out-of-tree LSMs is low for you, what you are about to merge goes against the "developers try to avoid identifier collisions" effort.
Introducing a numeric identifier is a good opportunity for permanently eliminating possibility of identifier collisions. But current usage of this numeric identifier is designed for facilitating possibility of identifier collisions.
Keeping how the HUGE space is used under control of the LSM community will be better for both in-tree and out-of-tree LSM modules. I really can't understand why you don't want to utilize this opportunity.
Kees Cook
maintainerQuoted 7 lines · Tetsuo Handa
Patch description says
The LSM ID values are sequential, with the oldest module
LSM_ID_CAPABILITYbeing the lowest value and the existing modules numbered in the order they were included in the main line kernel. This is an arbitrary convention for assigning the values, but none better presents itself. The value 0 is defined as being invalid.
"in the order they were included in the main line kernel" Out of trees aren't in main line.
And "This is an arbitrary convention" specifically says it's arbitrary.
There is literally nothing here stopping out of tree modules. I have proven this, and so have you with these quotes. What is left to object to?
Quoted 3 lines
You withdraw your "Reviewed-by" response unless "The LSM ID values are sequential" and "must be approved by the LSM maintainers" are removed and "the LSM maintainers/community shall never complain about what names and/or values are assigned" is added, don't you?
*For main line kernels*
Please, understand both the *intent* and *reality*: this does not block out of tree LSMs, full stop.
Quoted 3 lines
Keeping how the HUGE space is used under control of the LSM community will be better for both in-tree and out-of-tree LSM modules. I really can't understand why you don't want to utilize this opportunity.
I cannot understand what else you need to hear.
-Kees
Signature · 1 line
Kees Cook
Tetsuo Handa
maintainerQuoted 6 lines · Casey Schaufler
Create a struct
lsm_idto contain identifying information about Linux Security Modules (LSMs). At inception this contains the name of the module and an identifier associated with the security module. Change thesecurity_add_hooks()interface to use this structure. Change the individual modules to maintain their own structlsm_idand pass it tosecurity_add_hooks().
I came to worry about what purpose does the LSM ID value (or more precisely, "struct lsm_id") is used for. If the LSM ID value is used for only switch {reading,writing} /proc/self/attr/ of specific LSM module's information, only LSM modules that use /proc/self/attr/ will need the LSM ID value.
But this series uses "struct lsm_id" as one of arguments for security_add_hooks(), and might be reused for different purposes.
Then, BPF-based LSMs (which are not considered as in-tree LSM modules, for only BPF hook is considered as in-tree LSM module) might receive unfavorable treatment than non BPF-based LSMs?
[PATCH v15 05/11] says
Create a system call to report the list of Linux Security Modules that are active on the system. The list is provided as an array of LSM ID numbers.
The calling application can use this list determine what LSM specific actions it might take. That might include choosing an output format, determining required privilege or bypassing security module specific behavior.
but, at least, name of BPF-based LSMs won't be shown up in lsm_list_modules() compared to non BPF-based LSMs? Then, the calling application can't use this list determine what BPF-based LSM specific actions it might take?
Casey Schaufler
maintainerQuoted 25 lines · Tetsuo Handa
Quoted 6 lines · Casey Schaufler
Create a struct
lsm_idto contain identifying information about Linux Security Modules (LSMs). At inception this contains the name of the module and an identifier associated with the security module. Change thesecurity_add_hooks()interface to use this structure. Change the individual modules to maintain their own structlsm_idand pass it tosecurity_add_hooks().I came to worry about what purpose does the LSM ID value (or more precisely, "struct
lsm_id") is used for. If the LSM ID value is used for only switch {reading,writing}/proc/self/attr/of specific LSM module's information, only LSM modules that use/proc/self/attr/will need the LSM ID value.But this series uses "struct
lsm_id" as one of arguments forsecurity_add_hooks(), and might be reused for different purposes.Then, BPF-based LSMs (which are not considered as in-tree LSM modules, for only BPF hook is considered as in-tree LSM module) might receive unfavorable treatment than non BPF-based LSMs?
[PATCH v15 05/11] says
Create a system call to report the list of Linux Security Modules that are active on the system. The list is provided as an array of LSM ID numbers.
Quoted 8 lines
The calling application can use this list determine what LSM specific actions it might take. That might include choosing an output format, determining required privilege or bypassing security module specific behavior.
but, at least, name of BPF-based LSMs won't be shown up in
lsm_list_modules()compared to non BPF-based LSMs? Then, the calling application can't use this list determine what BPF-based LSM specific actions it might take?
That is correct. Just as knowing that your system is using SELinux won't tell you whether a specific action might be permitted because that's driven by the loaded policy, so too knowing that your system is using BPF won't tell you whether a specific action might be permitted because that's driven by the eBPF programs in place.
I wish we could stop people from saying "BPF-based LSM". BPF is the LSM. The eBPF programs that implement a "policy" are NOT a LSM. There needs to be a name for that, but LSM is not it.
Tetsuo Handa
maintainerQuoted 35 lines · Casey Schaufler
Quoted 25 lines · Tetsuo Handa
Quoted 6 lines · Casey Schaufler
Create a struct
lsm_idto contain identifying information about Linux Security Modules (LSMs). At inception this contains the name of the module and an identifier associated with the security module. Change thesecurity_add_hooks()interface to use this structure. Change the individual modules to maintain their own structlsm_idand pass it tosecurity_add_hooks().I came to worry about what purpose does the LSM ID value (or more precisely, "struct
lsm_id") is used for. If the LSM ID value is used for only switch {reading,writing}/proc/self/attr/of specific LSM module's information, only LSM modules that use/proc/self/attr/will need the LSM ID value.But this series uses "struct
lsm_id" as one of arguments forsecurity_add_hooks(), and might be reused for different purposes.Then, BPF-based LSMs (which are not considered as in-tree LSM modules, for only BPF hook is considered as in-tree LSM module) might receive unfavorable treatment than non BPF-based LSMs?
[PATCH v15 05/11] says
Create a system call to report the list of Linux Security Modules that are active on the system. The list is provided as an array of LSM ID numbers.
Quoted 8 lines
The calling application can use this list determine what LSM specific actions it might take. That might include choosing an output format, determining required privilege or bypassing security module specific behavior.
but, at least, name of BPF-based LSMs won't be shown up in
lsm_list_modules()compared to non BPF-based LSMs? Then, the calling application can't use this list determine what BPF-based LSM specific actions it might take?
Quoted 5 lines
That is correct. Just as knowing that your system is using SELinux won't tell you whether a specific action might be permitted because that's driven by the loaded policy, so too knowing that your system is using BPF won't tell you whether a specific action might be permitted because that's driven by the eBPF programs in place.
If the system call returning LSM ID value for SELinux but does not tell the caller of that system call whether a specific action might be permitted, what information does LSM ID value tell?
The patch description lacks relationship between LSM ID value and data. In other words, why LSM ID values are needed (and are useful for doing what). If the only information the caller can know from the LSM ID value were what LSMs are enabled (i.e. the content of /sys/kernel/security/lsm ), why bother to use LSM ID values? (Yes, integer comparison is faster than string comparison. But that is not enough justification for not allowing out-of-tree LSMs and eBPF-based access control mechanisms to have stable LSM ID values.)
What does "choosing an output format", "determining required privilege", "bypassing security module specific behavior" mean? How can they choose meaningful output format, determine appropriate privilege, bypass security module specific behavior (if the only information the caller can know from the LSM ID value were what LSMs are enabled) ?
Quoted 3 lines
I wish we could stop people from saying "BPF-based LSM". BPF is the LSM. The eBPF programs that implement a "policy" are NOT a LSM. There needs to be a name for that, but LSM is not it.
My understanding is that "BPF is not an LSM module but infrastructure for using LSM hooks".
Say, an access control implementation consists of two parts; "code" and "data". The "code" is written by developers and is determined at compile time and is interpreted by CPU, and the "data" is written by administrators and is interpreted by "code". The "data" part can be either built-in (determined at compile time) or loadable (configurable at run-time).
eBPF-based access control implementations (which can be loaded via bpf() system call after boot) consists of "code" and "data". BPF will remain no-op unless eBPF-based access control implementations are loaded via bpf() system call. Thus, I believe that an eBPF-based access control implementation should be considered as an LSM module (like SELinux etc.)
Casey Schaufler
maintainerQuoted 35 lines · Tetsuo Handa
Quoted 34 lines · Casey Schaufler
Quoted 33 lines · Tetsuo Handa
Quoted 6 lines · Casey Schaufler
Create a struct
lsm_idto contain identifying information about Linux Security Modules (LSMs). At inception this contains the name of the module and an identifier associated with the security module. Change thesecurity_add_hooks()interface to use this structure. Change the individual modules to maintain their own structlsm_idand pass it tosecurity_add_hooks().I came to worry about what purpose does the LSM ID value (or more precisely, "struct
lsm_id") is used for. If the LSM ID value is used for only switch {reading,writing}/proc/self/attr/of specific LSM module's information, only LSM modules that use/proc/self/attr/will need the LSM ID value.But this series uses "struct
lsm_id" as one of arguments forsecurity_add_hooks(), and might be reused for different purposes.Then, BPF-based LSMs (which are not considered as in-tree LSM modules, for only BPF hook is considered as in-tree LSM module) might receive unfavorable treatment than non BPF-based LSMs?
[PATCH v15 05/11] says
Create a system call to report the list of Linux Security Modules that are active on the system. The list is provided as an array of LSM ID numbers.
The calling application can use this list determine what LSM specific actions it might take. That might include choosing an output format, determining required privilege or bypassing security module specific behavior.
but, at least, name of BPF-based LSMs won't be shown up in
lsm_list_modules()compared to non BPF-based LSMs? Then, the calling application can't use this list determine what BPF-based LSM specific actions it might take?
Quoted 8 lines
Quoted 5 lines
That is correct. Just as knowing that your system is using SELinux won't tell you whether a specific action might be permitted because that's driven by the loaded policy, so too knowing that your system is using BPF won't tell you whether a specific action might be permitted because that's driven by the eBPF programs in place.
If the system call returning LSM ID value for SELinux but does not tell the caller of that system call whether a specific action might be permitted, what information does LSM ID value tell?
It tells the caller that the LSM is active on the system. That's it. Just like reading /sys/kernel/security/lsm.
Quoted 9 lines
The patch description lacks relationship between LSM ID value and data. In other words, why LSM ID values are needed (and are useful for doing what). If the only information the caller can know from the LSM ID value were what LSMs are enabled (i.e. the content of
/sys/kernel/security/lsm), why bother to use LSM ID values? (Yes, integer comparison is faster than string comparison. But that is not enough justification for not allowing out-of-tree LSMs and eBPF-based access control mechanisms to have stable LSM ID values.)
Quoted 5 lines
What does "choosing an output format", "determining required privilege", "bypassing security module specific behavior" mean? How can they choose meaningful output format, determine appropriate privilege, bypass security module specific behavior (if the only information the caller can know from the LSM ID value were what LSMs are enabled) ?
If Smack and SELinux not enabled on the system there is no point in setting up a netlabel configuration, for example.
Quoted 5 lines
Quoted 3 lines
I wish we could stop people from saying "BPF-based LSM". BPF is the LSM. The eBPF programs that implement a "policy" are NOT a LSM. There needs to be a name for that, but LSM is not it.
My understanding is that "BPF is not an LSM module but infrastructure for using LSM hooks".
As BPF is implemented as a LSM I suggest your statement is incorrect.
Quoted 11 lines
Say, an access control implementation consists of two parts; "code" and "data". The "code" is written by developers and is determined at compile time and is interpreted by CPU, and the "data" is written by administrators and is interpreted by "code". The "data" part can be either built-in (determined at compile time) or loadable (configurable at run-time).
eBPF-based access control implementations (which can be loaded via
bpf()system call after boot) consists of "code" and "data". BPF will remain no-op unless eBPF-based access control implementations are loaded viabpf()system call. Thus, I believe that an eBPF-based access control implementation should be considered as an LSM module (like SELinux etc.)
And I say you're wrong. Your arguments are gibberish.
Tetsuo Handa
maintainerQuoted 6 lines · Casey Schaufler
Quoted 3 lines
If the system call returning LSM ID value for SELinux but does not tell the caller of that system call whether a specific action might be permitted, what information does LSM ID value tell?
It tells the caller that the LSM is active on the system. That's it. Just like reading
/sys/kernel/security/lsm.
Then, the
The calling application can use this list determine what LSM specific actions it might take. That might include choosing an output format, determining required privilege or bypassing security module specific behavior.
part should be removed from the description. Instead, the description should emphasis that the numeric LSM ID values are there in order to allow identifying what LSM modules are active without interpreting string LSM names in /sys/kernel/security/lsm .
Quoted 8 lines
Quoted 5 lines
What does "choosing an output format", "determining required privilege", "bypassing security module specific behavior" mean? How can they choose meaningful output format, determine appropriate privilege, bypass security module specific behavior (if the only information the caller can know from the LSM ID value were what LSMs are enabled) ?
If Smack and SELinux not enabled on the system there is no point in setting up a netlabel configuration, for example.
I know nothing about netlabel. But can userspace make such assumption from this granularity? For example, if TOMOYO and AppArmor start supporting netlabel configuration, your assumption
If Smack and SELinux not enabled on the system there is no point in setting up a netlabel configuration
becomes no longer true. It is also possible that a new LSM implementation obtains an LSM ID for that LSM, and starts supporting netlabel configuration some timer later. I don't know if we come to the point where we can enable SELinux and Smack at the same time. But when it becomes possible to enable SELinux and Smack at the same time, the userspace might have already written code based on current situation that netlabel configuration are exclusive. Then, someday starting to return both LSM ID for SELinux and LSM ID for Smack might confuse userspace.
Thus, it might be safe to determine what LSMs are active from the LSM ID values returned from the system call. But it is not safe to assume what functionality is active (e.g. netlabel configuration is interpreted) from the LSM ID values returned from the system call.
If you want to allow userspace to make such assumption using the system call, the granularity the system call returns needs to be what access control mechanism (not only LSM modules but also eBPF-based access control mechanisms) hooks which LSM hooks. More information than interpreting string LSM names in /sys/kernel/security/lsm will be needed.
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
I wish we could stop people from saying "BPF-based LSM". BPF is the LSM. The eBPF programs that implement a "policy" are NOT a LSM. There needs to be a name for that, but LSM is not it.
My understanding is that "BPF is not an LSM module but infrastructure for using LSM hooks".
As BPF is implemented as a LSM I suggest your statement is incorrect.
Enumerating only LSM modules are not useful. "ID for access control mechanisms that can be controlled via LSM hooks" will be needed.
Quoted 10 lines
Quoted 10 lines
The patch description lacks relationship between LSM ID value and data. In other words, why LSM ID values are needed (and are useful for doing what). If the only information the caller can know from the LSM ID value were what LSMs are enabled (i.e. the content of
/sys/kernel/security/lsm), why bother to use LSM ID values? (Yes, integer comparison is faster than string comparison. But that is not enough justification for not allowing out-of-tree LSMs and eBPF-based access control mechanisms to have stable LSM ID values.)
I conclude that LSM ID values are pointless and are NOT needed.
Casey Schaufler
maintainerQuoted 13 lines · Tetsuo Handa
Quoted 5 lines · Casey Schaufler
Quoted 3 lines
If the system call returning LSM ID value for SELinux but does not tell the caller of that system call whether a specific action might be permitted, what information does LSM ID value tell?
It tells the caller that the LSM is active on the system. That's it. Just like reading
/sys/kernel/security/lsm.Then, the
The calling application can use this list determine what LSM specific actions it might take. That might include choosing an output format, determining required privilege or bypassing security module specific behavior.
Quoted 4 lines
part should be removed from the description. Instead, the description should emphasis that the numeric LSM ID values are there in order to allow identifying what LSM modules are active without interpreting string LSM names in
/sys/kernel/security/lsm.
No, I stand by the description as written.
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines
What does "choosing an output format", "determining required privilege", "bypassing security module specific behavior" mean? How can they choose meaningful output format, determine appropriate privilege, bypass security module specific behavior (if the only information the caller can know from the LSM ID value were what LSMs are enabled) ?
If Smack and SELinux not enabled on the system there is no point in setting up a netlabel configuration, for example.
Quoted 8 lines
I know nothing about netlabel. But can userspace make such assumption from this granularity? For example, if TOMOYO and AppArmor start supporting netlabel configuration, your assumption
If Smack and SELinux not enabled on the system there is no point in setting up a netlabel configuration
becomes no longer true.
You are correct. If I thought there was the remotest possibility of that, I wouldn't have used it as an example.
If Smack isn't enabled there's no point in running the Smack testsuite. If SELinux isn't enabled there's no point in running the SELinux testsuite. If SELinux isn't enabled there's no reason to invoke SELinux userspace features.
Quoted 8 lines
It is also possible that a new LSM implementation
obtains an LSM ID for that LSM, and starts supporting netlabel configuration some timer later. I don't know if we come to the point where we can enable SELinux and Smack at the same time. But when it becomes possible to enable SELinux and Smack at the same time, the userspace might have already written code based on current situation that netlabel configuration are exclusive. Then, someday starting to return both LSM ID for SELinux and LSM ID for Smack might confuse userspace.
Believe me, that's way down on the list of userspace issues with using Smack and SELinux together in a meaningful way.
Quoted 5 lines
Thus, it might be safe to determine what LSMs are active from the LSM ID values returned from the system call. But it is not safe to assume what functionality is active (e.g. netlabel configuration is interpreted) from the LSM ID values returned from the system call.
That is correct.
Quoted 5 lines
If you want to allow userspace to make such assumption using the system call, the granularity the system call returns needs to be what access control mechanism (not only LSM modules but also eBPF-based access control mechanisms) hooks which LSM hooks. More information than interpreting string LSM names in
/sys/kernel/security/lsmwill be needed.
That's already true. You have to understand all sorts of factors, like SELinux policy, Smack rule sets and AppArmor policy definitions. Then there's netfilter configuration.
Quoted 8 lines
Quoted 6 lines
Quoted 5 lines
Quoted 3 lines
I wish we could stop people from saying "BPF-based LSM". BPF is the LSM. The eBPF programs that implement a "policy" are NOT a LSM. There needs to be a name for that, but LSM is not it.
My understanding is that "BPF is not an LSM module but infrastructure for using LSM hooks".
As BPF is implemented as a LSM I suggest your statement is incorrect.
Enumerating only LSM modules are not useful. "ID for access control mechanisms that can be controlled via LSM hooks" will be needed.
The BPF program set is no different from the SELinux policy in this regard. It's completely user defined, and out of the kernel's control. I seriously doubt that you want an ID for "SELinux reference policy 4.3.2 with Infiniband"
Quoted 9 lines
Quoted 8 lines
Quoted 8 lines
The patch description lacks relationship between LSM ID value and data. In other words, why LSM ID values are needed (and are useful for doing what). If the only information the caller can know from the LSM ID value were what LSMs are enabled (i.e. the content of
/sys/kernel/security/lsm), why bother to use LSM ID values? (Yes, integer comparison is faster than string comparison. But that is not enough justification for not allowing out-of-tree LSMs and eBPF-based access control mechanisms to have stable LSM ID values.)I conclude that LSM ID values are pointless and are NOT needed.
OK.
Casey Schaufler
maintainerPATCH v15 2/11 LSM: Maintain a table of LSM attribute data
In reply to Casey SchauflerAs LSMs are registered add their lsm_id pointers to a table. This will be used later for attribute reporting.
Determine the number of possible security modules based on their respective CONFIG options. This allows the number to be known at build time. This allows data structures and tables to use the constant.
--- include/linux/security.h | 2 ++ security/security.c | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+)
include/linux/security.h +2 -0
@@ -138,6 +138,8 @@ enum lockdown_reason { };extern const char *const lockdown_reasons[LOCKDOWN_CONFIDENTIALITY_MAX +1 ]; +extern u32 lsm_active_cnt; +extern const struct lsm_id *lsm_idlist[];/* These functions are in security/commoncap.c */ extern int cap_capable(const struct cred *cred, struct user_namespace *ns,
security/security.c +37 -0
@@ -34,6 +34,25 @@/* How many LSMs were built into the kernel? */ #define LSM_COUNT (__end_lsm_info - __start_lsm_info) +/* +* How many LSMs are built into the kernel as determined at +* build time. Used to determine fixed array sizes. +* The capability module is accounted for by CONFIG_SECURITY +*/ +#define LSM_CONFIG_COUNT ( \ + (IS_ENABLED(CONFIG_SECURITY) ? 1 : 0) + \ + (IS_ENABLED(CONFIG_SECURITY_SELINUX) ? 1 : 0) + \ + (IS_ENABLED(CONFIG_SECURITY_SMACK) ? 1 : 0) + \ + (IS_ENABLED(CONFIG_SECURITY_TOMOYO) ? 1 : 0) + \ + (IS_ENABLED(CONFIG_IMA) ? 1 : 0) + \ + (IS_ENABLED(CONFIG_SECURITY_APPARMOR) ? 1 : 0) + \ + (IS_ENABLED(CONFIG_SECURITY_YAMA) ? 1 : 0) + \ + (IS_ENABLED(CONFIG_SECURITY_LOADPIN) ? 1 : 0) + \ + (IS_ENABLED(CONFIG_SECURITY_SAFESETID) ? 1 : 0) + \ + (IS_ENABLED(CONFIG_SECURITY_LOCKDOWN_LSM) ? 1 : 0) + \ + (IS_ENABLED(CONFIG_BPF_LSM) ? 1 : 0) + \ + (IS_ENABLED(CONFIG_SECURITY_LANDLOCK) ? 1 : 0)) +/* * These are descriptions of the reasons that can be passed to the * security_locked_down() LSM hook. Placing this array here allows
@@ -245,6 +264,12 @@ static void __init initialize_lsm(struct lsm_info *lsm) } } +/* +* Current index to use while initializing the lsm id list. +*/ +u32 lsm_active_cnt__ro_after_init ; +const struct lsm_id *lsm_idlist[LSM_CONFIG_COUNT ]; +/* Populate ordered LSMs list from comma-separated LSM name list. */ static void __init ordered_lsm_parse (const char *order,const char *origin) {
@@ -522,6 +547,18 @@ void __init security_add_hooks(struct security_hook_list *hooks, int count, {int i; +/* +* A security module may call security_add_hooks() more +* than once during initialization, and LSM initialization +* is serialized. Landlock is one such case. +* Look at the previous entry, if there is one, for duplication. +*/ +if (lsm_active_cnt ==0 || lsm_idlist[lsm_active_cnt -1 ] != lsmid) { +if (lsm_active_cnt >=LSM_CONFIG_COUNT ) +panic ("%s Too many LSMs registered.\n" , __func__); + lsm_idlist[lsm_active_cnt++] = lsmid; + } +for (i =0 ; i < count; i++) { hooks[i].lsmid = lsmid;hlist_add_tail_rcu (&hooks[i].list, hooks[i].head);
Signature · 1 line
2.41.0
Casey Schaufler
maintainerPATCH v15 3/11 proc: Use lsmids instead of lsm names for attrs
In reply to Casey SchauflerUse the LSM ID number instead of the LSM name to identify which security module's attibute data should be shown in /proc/self/attr. The security_[gs]etprocattr() functions have been changed to expect the LSM ID. The change from a string comparison to an integer comparison in these functions will provide a minor performance improvement.
--- fs/proc/base.c | 29 +++++++++++++++-------------- fs/proc/internal.h | 2 +- include/linux/security.h | 11 +++++------ security/security.c | 15 +++++++-------- 4 files changed, 28 insertions(+), 29 deletions(-)
fs/proc/base.c +15 -14
@@ -97,6 +97,7 @@#include <linux/resctrl.h> #include <linux/cn_proc.h> #include <linux/ksm.h> +#include <uapi/linux/lsm.h> #include <trace/events/oom.h> #include "internal.h" #include "fd.h"
@@ -146,10 +147,10 @@ struct pid_entry {NOD (NAME , (S_IFREG |(MODE )), \NULL , &proc_single_file_operations, \ { .proc_show = show } ) -#define ATTR (LSM ,NAME ,MODE ) \ +#define ATTR (LSMID ,NAME ,MODE ) \ NOD(NAME, (S_IFREG|(MODE)), \ NULL, &proc_pid_attr_operations, \ - { .lsm = LSM }) + { .lsmid = LSMID })/* * Count the number of hardlinks for the pid_entry table, excluding the .
@@ -2730,7 +2731,7 @@ static ssize_t proc_pid_attr_read(struct file * file, char __user * buf,if (!task)return -ESRCH ; - length =security_getprocattr (task,PROC_I (inode)->op.lsm, + length =security_getprocattr (task,PROC_I (inode)->op.lsmid, file->f_path.dentry->d_name.name, &p);put_task_struct (task);
@@ -2788,7 +2789,7 @@ static ssize_t proc_pid_attr_write(struct file * file, const char __user * buf,if (rv <0 ) goto out_free; - rv =security_setprocattr (PROC_I (inode)->op.lsm, + rv =security_setprocattr (PROC_I (inode)->op.lsmid, file->f_path.dentry->d_name.name, page, count);mutex_unlock (¤t->signal->cred_guard_mutex);
@@ -2837,27 +2838,27 @@ static const struct inode_operations proc_##LSM##_attr_dir_inode_ops = { \#ifdef CONFIG_SECURITY_SMACK static const struct pid_entry smack_attr_dir_stuff[] = { -ATTR ("smack" ,"current" ,0666 ), +ATTR (LSM_ID_SMACK ,"current" ,0666 ), };LSM_DIR_OPS (smack);#endif #ifdef CONFIG_SECURITY_APPARMOR static const struct pid_entry apparmor_attr_dir_stuff[] = { -ATTR ("apparmor" ,"current" ,0666 ), -ATTR ("apparmor" ,"prev" ,0444 ), -ATTR ("apparmor" ,"exec" ,0666 ), +ATTR (LSM_ID_APPARMOR ,"current" ,0666 ), +ATTR (LSM_ID_APPARMOR ,"prev" ,0444 ), +ATTR (LSM_ID_APPARMOR ,"exec" ,0666 ), };LSM_DIR_OPS (apparmor);#endif static const struct pid_entry attr_dir_stuff[] = { -ATTR (NULL ,"current" ,0666 ), -ATTR (NULL ,"prev" ,0444 ), -ATTR (NULL ,"exec" ,0666 ), -ATTR (NULL ,"fscreate" ,0666 ), -ATTR (NULL ,"keycreate" ,0666 ), -ATTR (NULL ,"sockcreate" ,0666 ), +ATTR (LSM_ID_UNDEF ,"current" ,0666 ), +ATTR (LSM_ID_UNDEF ,"prev" ,0444 ), +ATTR (LSM_ID_UNDEF ,"exec" ,0666 ), +ATTR (LSM_ID_UNDEF ,"fscreate" ,0666 ), +ATTR (LSM_ID_UNDEF ,"keycreate" ,0666 ), +ATTR (LSM_ID_UNDEF ,"sockcreate" ,0666 ), #ifdef CONFIG_SECURITY_SMACKDIR ("smack" ,0555 , proc_smack_attr_dir_inode_ops, proc_smack_attr_dir_ops),
fs/proc/internal.h +1 -1
@@ -92,7 +92,7 @@ union proc_op {int (*proc_show)(struct seq_file *m,struct pid_namespace *ns,struct pid *pid,struct task_struct *task); -const char *lsm; +int lsmid; };struct proc_inode {
include/linux/security.h +5 -6
@@ -472,10 +472,9 @@ int security_sem_semctl(struct kern_ipc_perm *sma, int cmd);int security_sem_semop (struct kern_ipc_perm *sma,struct sembuf *sops,unsigned nsops,int alter);void security_d_instantiate (struct dentry *dentry,struct inode *inode); -int security_getprocattr (struct task_struct *p,const char *lsm,const char *name, +int security_getprocattr (struct task_struct *p,int lsmid,const char *name,char **value); -int security_setprocattr (const char *lsm,const char *name,void *value, -size_t size); +int security_setprocattr (int lsmid,const char *name,void *value,size_t size);int security_netlink_send (struct sock *sk,struct sk_buff *skb);int security_ismaclabel (const char *name);int security_secid_to_secctx (u32 secid,char **secdata,u32 *seclen);
@@ -1339,14 +1338,14 @@ static inline void security_d_instantiate(struct dentry *dentry, struct inode *inode) { } -static inline int security_getprocattr (struct task_struct *p,const char *lsm, +static inline int security_getprocattr (struct task_struct *p,int lsmid,const char *name,char **value) {return -EINVAL ; } -static inline int security_setprocattr (const char *lsm,char *name, -void *value,size_t size) +static inline int security_setprocattr (int lsmid,char *name,void *value, +size_t size) {return -EINVAL ; }
security/security.c +7 -8
@@ -3840,7 +3840,7 @@ EXPORT_SYMBOL(security_d_instantiate);/** * security_getprocattr() - Read an attribute for a task * @p: the task -* @lsm: LSM name +* @lsmid: LSM identification * @name: attribute name * @value: attribute value *
@@ -3848,13 +3848,13 @@ EXPORT_SYMBOL(security_d_instantiate);* * Return: Returns the length of @value on success, a negative value otherwise. */ -int security_getprocattr (struct task_struct *p,const char *lsm, -const char *name,char **value) +int security_getprocattr (struct task_struct *p,int lsmid,const char *name, +char **value) {struct security_hook_list *hp;hlist_for_each_entry (hp, &security_hook_heads.getprocattr, list) { -if (lsm !=NULL &&strcmp (lsm, hp->lsmid->name)) +if (lsmid !=0 && lsmid != hp->lsmid->id)continue ;return hp->hook.getprocattr (p, name, value); }
@@ -3863,7 +3863,7 @@ int security_getprocattr(struct task_struct *p, const char *lsm,/** * security_setprocattr() - Set an attribute for a task -* @lsm: LSM name +* @lsmid: LSM identification * @name: attribute name * @value: attribute value * @size: attribute value size
@@ -3873,13 +3873,12 @@ int security_getprocattr(struct task_struct *p, const char *lsm,* * Return: Returns bytes written on success, a negative value otherwise. */ -int security_setprocattr (const char *lsm,const char *name,void *value, -size_t size) +int security_setprocattr (int lsmid,const char *name,void *value,size_t size) {struct security_hook_list *hp;hlist_for_each_entry (hp, &security_hook_heads.setprocattr, list) { -if (lsm !=NULL &&strcmp (lsm, hp->lsmid->name)) +if (lsmid !=0 && lsmid != hp->lsmid->id)continue ;return hp->hook.setprocattr (name, value, size); }
Signature · 1 line
2.41.0
Casey Schaufler
maintainerPATCH v15 4/11 LSM: syscalls for current process attributes
In reply to Casey SchauflerCreate a system call lsm_get_self_attr() to provide the security module maintained attributes of the current process. Create a system call lsm_set_self_attr() to set a security module maintained attribute of the current process. Historically these attributes have been exposed to user space via entries in procfs under /proc/self/attr.
The attribute value is provided in a lsm_ctx structure. The structure identifies the size of the attribute, and the attribute value. The format of the attribute value is defined by the security module. A flags field is included for LSM specific information. It is currently unused and must be 0. The total size of the data, including the lsm_ctx structure and any padding, is maintained as well.
struct lsm_ctx {
__u64 id;
__u64 flags;
__u64 len;
__u64 ctx_len;
__u8 ctx[];
};Two new LSM hooks are used to interface with the LSMs. security_getselfattr() collects the lsm_ctx values from the LSMs that support the hook, accounting for space requirements. security_setselfattr() identifies which LSM the attribute is intended for and passes it along.
--- Documentation/userspace-api/lsm.rst | 70 +++++++++++++ include/linux/lsm_hook_defs.h | 4 + include/linux/lsm_hooks.h | 1 + include/linux/security.h | 19 ++++ include/linux/syscalls.h | 5 + include/uapi/linux/lsm.h | 36 +++++++ kernel/sys_ni.c | 2 + security/Makefile | 1 + security/lsm_syscalls.c | 57 +++++++++++ security/security.c | 152 ++++++++++++++++++++++++++++ 10 files changed, 347 insertions(+) create mode 100644 Documentation/userspace-api/lsm.rst create mode 100644 security/lsm_syscalls.c
Documentation/userspace-api/lsm.rst new file +70 -0
@@ -0,0 +1,70 @@ +.. SPDX-License-Identifier: GPL-2.0 +.. Copyright (C) 2022 Casey Schaufler <[email protected]> +.. Copyright (C) 2022 Intel Corporation + +===================================== +Linux Security Modules +===================================== + +:Author: Casey Schaufler +:Date: July 2023 + +Linux security modules (LSM) provide a mechanism to implement +additional access controls to the Linux security policies. + +The various security modules may support any of these attributes: + +``LSM_ATTR_CURRENT`` is the current, active security context of the +process. +The proc filesystem provides this value in ``/proc/self/attr/current``. +This is supported by the SELinux, Smack and AppArmor security modules. +Smack also provides this value in ``/proc/self/attr/smack/current``. +AppArmor also provides this value in ``/proc/self/attr/apparmor/current``. + +``LSM_ATTR_EXEC`` is the security context of the process at the time the +current image was executed. +The proc filesystem provides this value in ``/proc/self/attr/exec``. +This is supported by the SELinux and AppArmor security modules. +AppArmor also provides this value in ``/proc/self/attr/apparmor/exec``. + +``LSM_ATTR_FSCREATE`` is the security context of the process used when +creating file system objects. +The proc filesystem provides this value in ``/proc/self/attr/fscreate``. +This is supported by the SELinux security module. + +``LSM_ATTR_KEYCREATE`` is the security context of the process used when +creating key objects. +The proc filesystem provides this value in ``/proc/self/attr/keycreate``. +This is supported by the SELinux security module. + +``LSM_ATTR_PREV`` is the security context of the process at the time the +current security context was set. +The proc filesystem provides this value in ``/proc/self/attr/prev``. +This is supported by the SELinux and AppArmor security modules. +AppArmor also provides this value in ``/proc/self/attr/apparmor/prev``. + +``LSM_ATTR_SOCKCREATE`` is the security context of the process used when +creating socket objects. +The proc filesystem provides this value in ``/proc/self/attr/sockcreate``. +This is supported by the SELinux security module. + +Kernel interface +================ + +Set a security attribute of the current process +----------------------------------------------- + +.. kernel-doc:: security/lsm_syscalls.c + :identifiers: sys_lsm_set_self_attr + +Get the specified security attributes of the current process +------------------------------------------------------------ + +.. kernel-doc:: security/lsm_syscalls.c + :identifiers: sys_lsm_get_self_attr + +Additional documentation +======================== + +* Documentation/security/lsm.rst +* Documentation/security/lsm-development.rst
include/linux/lsm_hook_defs.h +4 -0
@@ -262,6 +262,10 @@ LSM_HOOK(int, 0, sem_semop, struct kern_ipc_perm *perm, struct sembuf *sops, LSM_HOOK(int, 0, netlink_send, struct sock *sk, struct sk_buff *skb) LSM_HOOK(void, LSM_RET_VOID, d_instantiate, struct dentry *dentry, struct inode *inode) +LSM_HOOK(int, -EOPNOTSUPP, getselfattr, unsigned int attr, + struct lsm_ctx __user *ctx, size_t *size, u32 flags) +LSM_HOOK(int, -EOPNOTSUPP, setselfattr, unsigned int attr, + struct lsm_ctx *ctx, size_t size, u32 flags) LSM_HOOK(int, -EINVAL, getprocattr, struct task_struct *p, const char *name, char **value) LSM_HOOK(int, -EINVAL, setprocattr, const char *name, void *value, size_t size)
include/linux/lsm_hooks.h +1 -0
@@ -25,6 +25,7 @@#ifndef __LINUX_LSM_HOOKS_H#define __LINUX_LSM_HOOKS_H +#include <uapi/linux/lsm.h> #include <linux/security.h> #include <linux/init.h> #include <linux/rculist.h>
include/linux/security.h +19 -0
@@ -60,6 +60,7 @@ struct fs_parameter;enum fs_value_type ;struct watch ;struct watch_notification ; +struct lsm_ctx ;/* Default (no) options for the capable function */ #define CAP_OPT_NONE 0x0
@@ -472,6 +473,10 @@ int security_sem_semctl(struct kern_ipc_perm *sma, int cmd);int security_sem_semop (struct kern_ipc_perm *sma,struct sembuf *sops,unsigned nsops,int alter);void security_d_instantiate (struct dentry *dentry,struct inode *inode); +int security_getselfattr (unsigned int attr,struct lsm_ctx __user *ctx, +size_t __user *size,u32 flags); +int security_setselfattr (unsigned int attr,struct lsm_ctx __user *ctx, +size_t size,u32 flags);int security_getprocattr (struct task_struct *p,int lsmid,const char *name,char **value);int security_setprocattr (int lsmid,const char *name,void *value,size_t size);
@@ -1338,6 +1343,20 @@ static inline void security_d_instantiate(struct dentry *dentry, struct inode *inode) { } +static inline int security_getselfattr (unsigned int attr, +struct lsm_ctx __user *ctx, +size_t __user *size,u32 flags) +{ +return -EOPNOTSUPP ; +} + +static inline int security_setselfattr (unsigned int attr, +struct lsm_ctx __user *ctx, +size_t size,u32 flags) +{ +return -EOPNOTSUPP ; +} +static inline int security_getprocattr (struct task_struct *p,int lsmid,const char *name,char **value) {
include/linux/syscalls.h +5 -0
@@ -71,6 +71,7 @@ struct clone_args;struct open_how ;struct mount_attr ;struct landlock_ruleset_attr ; +struct lsm_ctx ;enum landlock_rule_type ;struct cachestat_range ;struct cachestat ;
@@ -940,6 +941,10 @@ asmlinkage long sys_cachestat(unsigned int fd,struct cachestat_range __user *cstat_range, struct cachestat __user *cstat, unsigned int flags);asmlinkage long sys_map_shadow_stack (unsigned long addr,unsigned long size,unsigned int flags); +asmlinkage long sys_lsm_get_self_attr (unsigned int attr,struct lsm_ctx *ctx, +size_t *size,__u32 flags); +asmlinkage long sys_lsm_set_self_attr (unsigned int attr,struct lsm_ctx *ctx, +size_t size,__u32 flags);/* * Architecture-specific system calls
include/uapi/linux/lsm.h +36 -0
@@ -9,6 +9,36 @@#ifndef _UAPI_LINUX_LSM_H#define _UAPI_LINUX_LSM_H +#include <linux/types.h> +#include <linux/unistd.h> + +/** +* struct lsm_ctx - LSM context information +* @id: the LSM id number, see LSM_ID_XXX +* @flags: LSM specific flags +* @len: length of the lsm_ctx struct, @ctx and any other data or padding +* @ctx_len: the size of @ctx +* @ctx: the LSM context value +* +* The @len field MUST be equal to the size of the lsm_ctx struct +* plus any additional padding and/or data placed after @ctx. +* +* In all cases @ctx_len MUST be equal to the length of @ctx. +* If @ctx is a string value it should be nul terminated with +* @ctx_len equal to `strlen(@ctx) + 1`. Binary values are +* supported. +* +* The @flags and @ctx fields SHOULD only be interpreted by the +* LSM specified by @id; they MUST be set to zero/0 when not used. +*/ +struct lsm_ctx { +__u64 id; +__u64 flags; +__u64 len; +__u64 ctx_len; +__u8 ctx[]; +}; +/* * ID tokens to identify Linux Security Modules (LSMs) *
@@ -51,4 +81,10 @@#define LSM_ATTR_PREV 104#define LSM_ATTR_SOCKCREATE 105 +/* +* LSM_FLAG_XXX definitions identify special handling instructions +* for the API. +*/ +#define LSM_FLAG_SINGLE 0x0001 +#endif /* _UAPI_LINUX_LSM_H */
kernel/sys_ni.c +2 -0
@@ -170,6 +170,8 @@ COND_SYSCALL(landlock_add_rule);COND_SYSCALL (landlock_restrict_self);COND_SYSCALL (fadvise64_64);COND_SYSCALL_COMPAT (fadvise64_64); +COND_SYSCALL (lsm_get_self_attr); +COND_SYSCALL (lsm_set_self_attr);/* CONFIG_MMU only */ COND_SYSCALL (swapon);
security/Makefile +1 -0
@@ -7,6 +7,7 @@ obj-$(CONFIG_KEYS) += keys/ # always enable default capabilities obj-y += commoncap.o +obj-$(CONFIG_SECURITY) += lsm_syscalls.o obj-$(CONFIG_MMU) += min_addr.o # Object file lists
security/lsm_syscalls.c new file +57 -0
57 lines not on this page · raw message
security/security.c +152 -0
158 lines not on this page · raw message
Signature · 1 line
2.41.0
Mickaël Salaün
maintainerRe: [PATCH v15 04/11] LSM: syscalls for current process attributes
Quoted 94 lines · Casey Schaufler
Create a system call
lsm_get_self_attr()to provide the security module maintained attributes of the current process. Create a system calllsm_set_self_attr()to set a security module maintained attribute of the current process. Historically these attributes have been exposed to user space via entries in procfs under/proc/self/attr.The attribute value is provided in a
lsm_ctxstructure. The structure identifies the size of the attribute, and the attribute value. The format of the attribute value is defined by the security module. A flags field is included for LSM specific information. It is currently unused and must be 0. The total size of the data, including thelsm_ctxstructure and any padding, is maintained as well.struct lsm_ctx { __u64 id; __u64 flags; __u64 len; __u64 ctx_len; __u8 ctx[]; };Two new LSM hooks are used to interface with the LSMs.
security_getselfattr()collects thelsm_ctxvalues from the LSMs that support the hook, accounting for space requirements.security_setselfattr()identifies which LSM the attribute is intended for and passes it along.Signed-off-by Casey Schaufler <[email protected]>Reviewed-by Kees Cook <[email protected]>Reviewed-by Serge Hallyn <[email protected]>Reviewed-by John Johansen <[email protected]>--- Documentation/userspace-api/lsm.rst | 70 +++++++++++++ include/linux/lsm_hook_defs.h | 4 + include/linux/lsm_hooks.h | 1 + include/linux/security.h | 19 ++++ include/linux/syscalls.h | 5 + include/uapi/linux/lsm.h | 36 +++++++ kernel/sys_ni.c | 2 + security/Makefile | 1 + security/lsm_syscalls.c | 57 +++++++++++ security/security.c | 152 ++++++++++++++++++++++++++++ 10 files changed, 347 insertions(+) create mode 100644 Documentation/userspace-api/lsm.rst create mode 100644 security/lsm_syscalls.csecurity/security.c +38
-0@@ -3837,6 +3837,158 @@ void security_d_instantiate(struct dentry *dentry, struct inode *inode) }EXPORT_SYMBOL (security_d_instantiate); +/* +* Please keep this in sync with it's counterpart in security/lsm_syscalls.c +*/ + +/** +* security_getselfattr - Read an LSM attribute of the current process. +* @attr: which attribute to return +* @uctx: the user-space destination for the information, or NULL +* @size: pointer to the size of space available to receive the data +* @flags: special handling options. LSM_FLAG_SINGLE indicates that only +* attributes associated with the LSM identified in the passed @ctx be +* reported. +* +* A NULL value for @uctx can be used to get both the number of attributes +* and the size of the data. +* +* Returns the number of attributes found on success, negative value +* on error. @size is reset to the total size of the data. +* If @size is insufficient to contain the data -E2BIG is returned. +*/ +int security_getselfattr (unsigned int attr,struct lsm_ctx __user *uctx, +size_t __user *size,u32 flags) +{ +struct security_hook_list *hp; +struct lsm_ctx lctx = { .id =LSM_ID_UNDEF , }; +u8 __user *base = (u8 __user *)uctx; +size_t total =0 ; +size_t entrysize; +size_t left; +bool toobig = false; +bool single = false; +int count =0 ; +int rc; + +if (attr ==LSM_ATTR_UNDEF ) +return -EINVAL ; +if (size ==NULL ) +return -EINVAL ;
security/security.c void security_d_instantiate(struct dentry *dentry, struct inode *inode) · line 3887
Quoted 10 lines
security/security.c +10
-0+if (get_user (left, size)) +return -EFAULT ; + +if (flags) { +/* +* Only flag supported is LSM_FLAG_SINGLE +*/ +if (flags !=LSM_FLAG_SINGLE ) +return -EINVAL ; +if (uctx &©_from_user (&lctx, uctx,sizeof (lctx)))
I'm not sure if we should return -EINVAL or -EFAULT when uctx == NULL. Because uctx is optional (when LSM_FLAG_SINGLE is not set), I guess -EINVAL is OK.
Quoted 24 lines
security/security.c +24
-0+return -EFAULT ; +/* +* If the LSM ID isn't specified it is an error. +*/ +if (lctx.id ==LSM_ID_UNDEF ) +return -EINVAL ; + single = true; + } + +/* +* In the usual case gather all the data from the LSMs. +* In the single case only get the data from the LSM specified. +*/ +hlist_for_each_entry (hp, &security_hook_heads.getselfattr, list) { +if (single && lctx.id != hp->lsmid->id) +continue ; + entrysize = left; +if (base) + uctx = (struct lsm_ctx __user *)(base + total); + rc = hp->hook.getselfattr (attr, uctx, &entrysize, flags); +if (rc == -EOPNOTSUPP ) { + rc =0 ; +continue ; + }
security/security.c void security_d_instantiate(struct dentry *dentry, struct inode *inode) · line 3921
Quoted 10 lines
security/security.c +10
-0+if (rc == -E2BIG ) { + toobig = true; + left =0 ; + }else if (rc <0 ) +return rc; +else + left -= entrysize; + + total += entrysize; + count += rc;
There is a bug if rc == -E2BIG
Quoted 11 lines
security/security.c +11
-0+if (single) +break ; + } +if (put_user (total, size)) +return -EFAULT ; +if (toobig) +return -E2BIG ; +if (count ==0 ) +return LSM_RET_DEFAULT (getselfattr); +return count; +}
Paul Moore
maintainerRe: [PATCH v15 04/11] LSM: syscalls for current process attributes
Quoted 47 lines · Mickaël Salaün
Quoted 46 lines · Casey Schaufler
Create a system call
lsm_get_self_attr()to provide the security module maintained attributes of the current process. Create a system calllsm_set_self_attr()to set a security module maintained attribute of the current process. Historically these attributes have been exposed to user space via entries in procfs under/proc/self/attr.The attribute value is provided in a
lsm_ctxstructure. The structure identifies the size of the attribute, and the attribute value. The format of the attribute value is defined by the security module. A flags field is included for LSM specific information. It is currently unused and must be 0. The total size of the data, including thelsm_ctxstructure and any padding, is maintained as well.struct lsm_ctx { __u64 id; __u64 flags; __u64 len; __u64 ctx_len; __u8 ctx[]; };Two new LSM hooks are used to interface with the LSMs.
security_getselfattr()collects thelsm_ctxvalues from the LSMs that support the hook, accounting for space requirements.security_setselfattr()identifies which LSM the attribute is intended for and passes it along.Signed-off-by Casey Schaufler <[email protected]>Reviewed-by Kees Cook <[email protected]>Reviewed-by Serge Hallyn <[email protected]>Reviewed-by John Johansen <[email protected]>--- Documentation/userspace-api/lsm.rst | 70 +++++++++++++ include/linux/lsm_hook_defs.h | 4 + include/linux/lsm_hooks.h | 1 + include/linux/security.h | 19 ++++ include/linux/syscalls.h | 5 + include/uapi/linux/lsm.h | 36 +++++++ kernel/sys_ni.c | 2 + security/Makefile | 1 + security/lsm_syscalls.c | 57 +++++++++++ security/security.c | 152 ++++++++++++++++++++++++++++ 10 files changed, 347 insertions(+) create mode 100644 Documentation/userspace-api/lsm.rst create mode 100644 security/lsm_syscalls.c
...
Quoted 52 lines
Quoted 52 lines
security/security.c +44
-0@@ -3837,6 +3837,158 @@ void security_d_instantiate(struct dentry *dentry, struct inode *inode) }EXPORT_SYMBOL (security_d_instantiate); +/* +* Please keep this in sync with it's counterpart in security/lsm_syscalls.c +*/ + +/** +* security_getselfattr - Read an LSM attribute of the current process. +* @attr: which attribute to return +* @uctx: the user-space destination for the information, or NULL +* @size: pointer to the size of space available to receive the data +* @flags: special handling options. LSM_FLAG_SINGLE indicates that only +* attributes associated with the LSM identified in the passed @ctx be +* reported. +* +* A NULL value for @uctx can be used to get both the number of attributes +* and the size of the data. +* +* Returns the number of attributes found on success, negative value +* on error. @size is reset to the total size of the data. +* If @size is insufficient to contain the data -E2BIG is returned. +*/ +int security_getselfattr (unsigned int attr,struct lsm_ctx __user *uctx, +size_t __user *size,u32 flags) +{ +struct security_hook_list *hp; +struct lsm_ctx lctx = { .id =LSM_ID_UNDEF , }; +u8 __user *base = (u8 __user *)uctx; +size_t total =0 ; +size_t entrysize; +size_t left; +bool toobig = false; +bool single = false; +int count =0 ; +int rc; + +if (attr ==LSM_ATTR_UNDEF ) +return -EINVAL ; +if (size ==NULL ) +return -EINVAL ; +if (get_user (left, size)) +return -EFAULT ; + +if (flags) { +/* +* Only flag supported is LSM_FLAG_SINGLE
Quoted 8 lines
security/security.c void security_d_instantiate(struct dentry *dentry, struct inode *inode) · line 3887
Quoted 4 lines
security/security.c +4
-0+*/ +if (flags !=LSM_FLAG_SINGLE ) +return -EINVAL ; +if (uctx &©_from_user (&lctx, uctx,sizeof (lctx)))I'm not sure if we should return
-EINVALor-EFAULTwhen uctx == NULL. Because uctx is optional (whenLSM_FLAG_SINGLEis not set), I guess-EINVALis OK.
That's a good point, we should probably the error codes here: if uctx is NULL in the LSM_FLAG_SINGLE case we should return -EINVAL, if the copy_from_user() fails we should return -EFAULT.
Quoted 28 lines
Quoted 28 lines
security/security.c +28
-0+return -EFAULT ; +/* +* If the LSM ID isn't specified it is an error. +*/ +if (lctx.id ==LSM_ID_UNDEF ) +return -EINVAL ; + single = true; + } + +/* +* In the usual case gather all the data from the LSMs. +* In the single case only get the data from the LSM specified. +*/ +hlist_for_each_entry (hp, &security_hook_heads.getselfattr, list) { +if (single && lctx.id != hp->lsmid->id) +continue ; + entrysize = left; +if (base) + uctx = (struct lsm_ctx __user *)(base + total); + rc = hp->hook.getselfattr (attr, uctx, &entrysize, flags); +if (rc == -EOPNOTSUPP ) { + rc =0 ; +continue ; + } +if (rc == -E2BIG ) { + toobig = true; + left =0 ; + }else if (rc <0 )
Quoted 8 lines
security/security.c void security_d_instantiate(struct dentry *dentry, struct inode *inode) · line 3921
Quoted 6 lines
security/security.c +6
-0+return rc; + else + left -= entrysize; + + total += entrysize; + count += rc;There is a bug if rc ==
-E2BIG
Can you elaborate a bit more on this? Nothing is jumping out at me as obviously broken... are you talking about @count becoming garbage due to @rc being equal to -E2BIG? If that is the case it should be okay since we explicitly return -E2BIG, not @count, if @toobig is true.
Quoted 11 lines
Quoted 11 lines
security/security.c +11
-0+if (single) +break ; + } +if (put_user (total, size)) +return -EFAULT ; +if (toobig) +return -E2BIG ; +if (count ==0 ) +return LSM_RET_DEFAULT (getselfattr); +return count; +}
Signature · 1 line
paul-moore.com
Mickaël Salaün
maintainerRe: [PATCH v15 04/11] LSM: syscalls for current process attributes
Quoted 153 lines · Paul Moore
Quoted 47 lines · Mickaël Salaün
Quoted 46 lines · Casey Schaufler
Create a system call
lsm_get_self_attr()to provide the security module maintained attributes of the current process. Create a system calllsm_set_self_attr()to set a security module maintained attribute of the current process. Historically these attributes have been exposed to user space via entries in procfs under/proc/self/attr.The attribute value is provided in a
lsm_ctxstructure. The structure identifies the size of the attribute, and the attribute value. The format of the attribute value is defined by the security module. A flags field is included for LSM specific information. It is currently unused and must be 0. The total size of the data, including thelsm_ctxstructure and any padding, is maintained as well.struct lsm_ctx { __u64 id; __u64 flags; __u64 len; __u64 ctx_len; __u8 ctx[]; };Two new LSM hooks are used to interface with the LSMs.
security_getselfattr()collects thelsm_ctxvalues from the LSMs that support the hook, accounting for space requirements.security_setselfattr()identifies which LSM the attribute is intended for and passes it along.Signed-off-by Casey Schaufler <[email protected]>Reviewed-by Kees Cook <[email protected]>Reviewed-by Serge Hallyn <[email protected]>Reviewed-by John Johansen <[email protected]>--- Documentation/userspace-api/lsm.rst | 70 +++++++++++++ include/linux/lsm_hook_defs.h | 4 + include/linux/lsm_hooks.h | 1 + include/linux/security.h | 19 ++++ include/linux/syscalls.h | 5 + include/uapi/linux/lsm.h | 36 +++++++ kernel/sys_ni.c | 2 + security/Makefile | 1 + security/lsm_syscalls.c | 57 +++++++++++ security/security.c | 152 ++++++++++++++++++++++++++++ 10 files changed, 347 insertions(+) create mode 100644 Documentation/userspace-api/lsm.rst create mode 100644 security/lsm_syscalls.c...
Quoted 52 lines
Quoted 52 lines
security/security.c +44
-0@@ -3837,6 +3837,158 @@ void security_d_instantiate(struct dentry *dentry, struct inode *inode) }EXPORT_SYMBOL (security_d_instantiate); +/* +* Please keep this in sync with it's counterpart in security/lsm_syscalls.c +*/ + +/** +* security_getselfattr - Read an LSM attribute of the current process. +* @attr: which attribute to return +* @uctx: the user-space destination for the information, or NULL +* @size: pointer to the size of space available to receive the data +* @flags: special handling options. LSM_FLAG_SINGLE indicates that only +* attributes associated with the LSM identified in the passed @ctx be +* reported. +* +* A NULL value for @uctx can be used to get both the number of attributes +* and the size of the data. +* +* Returns the number of attributes found on success, negative value +* on error. @size is reset to the total size of the data. +* If @size is insufficient to contain the data -E2BIG is returned. +*/ +int security_getselfattr (unsigned int attr,struct lsm_ctx __user *uctx, +size_t __user *size,u32 flags) +{ +struct security_hook_list *hp; +struct lsm_ctx lctx = { .id =LSM_ID_UNDEF , }; +u8 __user *base = (u8 __user *)uctx; +size_t total =0 ; +size_t entrysize; +size_t left; +bool toobig = false; +bool single = false; +int count =0 ; +int rc; + +if (attr ==LSM_ATTR_UNDEF ) +return -EINVAL ; +if (size ==NULL ) +return -EINVAL ; +if (get_user (left, size)) +return -EFAULT ; + +if (flags) { +/* +* Only flag supported is LSM_FLAG_SINGLE Quoted 8 lines
security/security.c void security_d_instantiate(struct dentry *dentry, struct inode *inode) · line 3887
Quoted 4 lines
security/security.c +4
-0+*/ +if (flags !=LSM_FLAG_SINGLE ) +return -EINVAL ; +if (uctx &©_from_user (&lctx, uctx,sizeof (lctx)))I'm not sure if we should return
-EINVALor-EFAULTwhen uctx == NULL. Because uctx is optional (whenLSM_FLAG_SINGLEis not set), I guess-EINVALis OK.That's a good point, we should probably the error codes here: if uctx is NULL in the
LSM_FLAG_SINGLEcase we should return-EINVAL, if thecopy_from_user()fails we should return-EFAULT.Quoted 28 lines
Quoted 28 lines
security/security.c +28
-0+return -EFAULT ; +/* +* If the LSM ID isn't specified it is an error. +*/ +if (lctx.id ==LSM_ID_UNDEF ) +return -EINVAL ; + single = true; + } + +/* +* In the usual case gather all the data from the LSMs. +* In the single case only get the data from the LSM specified. +*/ +hlist_for_each_entry (hp, &security_hook_heads.getselfattr, list) { +if (single && lctx.id != hp->lsmid->id) +continue ; + entrysize = left; +if (base) + uctx = (struct lsm_ctx __user *)(base + total); + rc = hp->hook.getselfattr (attr, uctx, &entrysize, flags); +if (rc == -EOPNOTSUPP ) { + rc =0 ; +continue ; + } +if (rc == -E2BIG ) { + toobig = true; + left =0 ; + }else if (rc <0 )Quoted 8 lines
security/security.c void security_d_instantiate(struct dentry *dentry, struct inode *inode) · line 3921
Quoted 6 lines
security/security.c +6
-0+return rc; + else + left -= entrysize; + + total += entrysize; + count += rc;There is a bug if rc ==
-E2BIG
Quoted 4 lines
Can you elaborate a bit more on this? Nothing is jumping out at me as obviously broken... are you talking about @count becoming garbage due to @rc being equal to
-E2BIG? If that is the case it should be okay since we explicitly return-E2BIG, not @count, if @toobig is true.
Indeed, in this case count will not be returned thanks to toobig. I'd suggest to "continue" if rc == -E2BIG (like for -EOPNOTSUPP) to avoid an inconsistent count value, which could bite us one day.
Quoted 15 lines
Quoted 12 lines
Quoted 12 lines
security/security.c +11
-0+if (single) +break ; + } +if (put_user (total, size)) +return -EFAULT ; +if (toobig) +return -E2BIG ; +if (count ==0 ) +return LSM_RET_DEFAULT (getselfattr); +return count; +}Signature · 1 line
paul-moore.com
Paul Moore
maintainerRe: [PATCH v15 04/11] LSM: syscalls for current process attributes
Quoted 154 lines · Mickaël Salaün
Quoted 153 lines · Paul Moore
Quoted 47 lines · Mickaël Salaün
Quoted 46 lines · Casey Schaufler
Create a system call
lsm_get_self_attr()to provide the security module maintained attributes of the current process. Create a system calllsm_set_self_attr()to set a security module maintained attribute of the current process. Historically these attributes have been exposed to user space via entries in procfs under/proc/self/attr.The attribute value is provided in a
lsm_ctxstructure. The structure identifies the size of the attribute, and the attribute value. The format of the attribute value is defined by the security module. A flags field is included for LSM specific information. It is currently unused and must be 0. The total size of the data, including thelsm_ctxstructure and any padding, is maintained as well.struct lsm_ctx { __u64 id; __u64 flags; __u64 len; __u64 ctx_len; __u8 ctx[]; };Two new LSM hooks are used to interface with the LSMs.
security_getselfattr()collects thelsm_ctxvalues from the LSMs that support the hook, accounting for space requirements.security_setselfattr()identifies which LSM the attribute is intended for and passes it along.Signed-off-by Casey Schaufler <[email protected]>Reviewed-by Kees Cook <[email protected]>Reviewed-by Serge Hallyn <[email protected]>Reviewed-by John Johansen <[email protected]>--- Documentation/userspace-api/lsm.rst | 70 +++++++++++++ include/linux/lsm_hook_defs.h | 4 + include/linux/lsm_hooks.h | 1 + include/linux/security.h | 19 ++++ include/linux/syscalls.h | 5 + include/uapi/linux/lsm.h | 36 +++++++ kernel/sys_ni.c | 2 + security/Makefile | 1 + security/lsm_syscalls.c | 57 +++++++++++ security/security.c | 152 ++++++++++++++++++++++++++++ 10 files changed, 347 insertions(+) create mode 100644 Documentation/userspace-api/lsm.rst create mode 100644 security/lsm_syscalls.c...
Quoted 52 lines
Quoted 52 lines
security/security.c +44
-0@@ -3837,6 +3837,158 @@ void security_d_instantiate(struct dentry *dentry, struct inode *inode) }EXPORT_SYMBOL (security_d_instantiate); +/* +* Please keep this in sync with it's counterpart in security/lsm_syscalls.c +*/ + +/** +* security_getselfattr - Read an LSM attribute of the current process. +* @attr: which attribute to return +* @uctx: the user-space destination for the information, or NULL +* @size: pointer to the size of space available to receive the data +* @flags: special handling options. LSM_FLAG_SINGLE indicates that only +* attributes associated with the LSM identified in the passed @ctx be +* reported. +* +* A NULL value for @uctx can be used to get both the number of attributes +* and the size of the data. +* +* Returns the number of attributes found on success, negative value +* on error. @size is reset to the total size of the data. +* If @size is insufficient to contain the data -E2BIG is returned. +*/ +int security_getselfattr (unsigned int attr,struct lsm_ctx __user *uctx, +size_t __user *size,u32 flags) +{ +struct security_hook_list *hp; +struct lsm_ctx lctx = { .id =LSM_ID_UNDEF , }; +u8 __user *base = (u8 __user *)uctx; +size_t total =0 ; +size_t entrysize; +size_t left; +bool toobig = false; +bool single = false; +int count =0 ; +int rc; + +if (attr ==LSM_ATTR_UNDEF ) +return -EINVAL ; +if (size ==NULL ) +return -EINVAL ; +if (get_user (left, size)) +return -EFAULT ; + +if (flags) { +/* +* Only flag supported is LSM_FLAG_SINGLE Quoted 8 lines
security/security.c void security_d_instantiate(struct dentry *dentry, struct inode *inode) · line 3887
Quoted 4 lines
security/security.c +4
-0+*/ +if (flags !=LSM_FLAG_SINGLE ) +return -EINVAL ; +if (uctx &©_from_user (&lctx, uctx,sizeof (lctx)))I'm not sure if we should return
-EINVALor-EFAULTwhen uctx == NULL. Because uctx is optional (whenLSM_FLAG_SINGLEis not set), I guess-EINVALis OK.That's a good point, we should probably the error codes here: if uctx is NULL in the
LSM_FLAG_SINGLEcase we should return-EINVAL, if thecopy_from_user()fails we should return-EFAULT.Quoted 36 lines
Quoted 24 lines
security/security.c +24
-0+return -EFAULT ; +/* +* If the LSM ID isn't specified it is an error. +*/ +if (lctx.id ==LSM_ID_UNDEF ) +return -EINVAL ; + single = true; + } + +/* +* In the usual case gather all the data from the LSMs. +* In the single case only get the data from the LSM specified. +*/ +hlist_for_each_entry (hp, &security_hook_heads.getselfattr, list) { +if (single && lctx.id != hp->lsmid->id) +continue ; + entrysize = left; +if (base) + uctx = (struct lsm_ctx __user *)(base + total); + rc = hp->hook.getselfattr (attr, uctx, &entrysize, flags); +if (rc == -EOPNOTSUPP ) { + rc =0 ; +continue ; + }security/security.c void security_d_instantiate(struct dentry *dentry, struct inode *inode) · line 3921
Quoted 10 lines
security/security.c +10
-0+if (rc == -E2BIG ) { + toobig = true; + left =0 ; + }else if (rc <0 ) +return rc; +else + left -= entrysize; + + total += entrysize; + count += rc;There is a bug if rc ==
-E2BIG
Quoted 8 lines
Quoted 4 lines
Can you elaborate a bit more on this? Nothing is jumping out at me as obviously broken... are you talking about @count becoming garbage due to @rc being equal to
-E2BIG? If that is the case it should be okay since we explicitly return-E2BIG, not @count, if @toobig is true.Indeed, in this case count will not be returned thanks to toobig. I'd suggest to "continue" if rc ==
-E2BIG(like for-EOPNOTSUPP) to avoid an inconsistent count value, which could bite us one day.
Okay, how about we reset @rc to zero in the -E2BIG case? We don't want to bypass the lower part of the loop in this case as we still need to update @total.
if (rc == -E2BIG) {
rc = 0;
left = 0;
toobig = true;
}Signature · 1 line
paul-moore.com
Mickaël Salaün
maintainerRe: [PATCH v15 04/11] LSM: syscalls for current process attributes
Quoted 168 lines · Paul Moore
Quoted 154 lines · Mickaël Salaün
Quoted 153 lines · Paul Moore
Quoted 47 lines · Mickaël Salaün
Quoted 46 lines · Casey Schaufler
Create a system call
lsm_get_self_attr()to provide the security module maintained attributes of the current process. Create a system calllsm_set_self_attr()to set a security module maintained attribute of the current process. Historically these attributes have been exposed to user space via entries in procfs under/proc/self/attr.The attribute value is provided in a
lsm_ctxstructure. The structure identifies the size of the attribute, and the attribute value. The format of the attribute value is defined by the security module. A flags field is included for LSM specific information. It is currently unused and must be 0. The total size of the data, including thelsm_ctxstructure and any padding, is maintained as well.struct lsm_ctx { __u64 id; __u64 flags; __u64 len; __u64 ctx_len; __u8 ctx[]; };Two new LSM hooks are used to interface with the LSMs.
security_getselfattr()collects thelsm_ctxvalues from the LSMs that support the hook, accounting for space requirements.security_setselfattr()identifies which LSM the attribute is intended for and passes it along.Signed-off-by Casey Schaufler <[email protected]>Reviewed-by Kees Cook <[email protected]>Reviewed-by Serge Hallyn <[email protected]>Reviewed-by John Johansen <[email protected]>--- Documentation/userspace-api/lsm.rst | 70 +++++++++++++ include/linux/lsm_hook_defs.h | 4 + include/linux/lsm_hooks.h | 1 + include/linux/security.h | 19 ++++ include/linux/syscalls.h | 5 + include/uapi/linux/lsm.h | 36 +++++++ kernel/sys_ni.c | 2 + security/Makefile | 1 + security/lsm_syscalls.c | 57 +++++++++++ security/security.c | 152 ++++++++++++++++++++++++++++ 10 files changed, 347 insertions(+) create mode 100644 Documentation/userspace-api/lsm.rst create mode 100644 security/lsm_syscalls.c...
Quoted 52 lines
Quoted 52 lines
security/security.c +44
-0@@ -3837,6 +3837,158 @@ void security_d_instantiate(struct dentry *dentry, struct inode *inode) }EXPORT_SYMBOL (security_d_instantiate); +/* +* Please keep this in sync with it's counterpart in security/lsm_syscalls.c +*/ + +/** +* security_getselfattr - Read an LSM attribute of the current process. +* @attr: which attribute to return +* @uctx: the user-space destination for the information, or NULL +* @size: pointer to the size of space available to receive the data +* @flags: special handling options. LSM_FLAG_SINGLE indicates that only +* attributes associated with the LSM identified in the passed @ctx be +* reported. +* +* A NULL value for @uctx can be used to get both the number of attributes +* and the size of the data. +* +* Returns the number of attributes found on success, negative value +* on error. @size is reset to the total size of the data. +* If @size is insufficient to contain the data -E2BIG is returned. +*/ +int security_getselfattr (unsigned int attr,struct lsm_ctx __user *uctx, +size_t __user *size,u32 flags) +{ +struct security_hook_list *hp; +struct lsm_ctx lctx = { .id =LSM_ID_UNDEF , }; +u8 __user *base = (u8 __user *)uctx; +size_t total =0 ; +size_t entrysize; +size_t left; +bool toobig = false; +bool single = false; +int count =0 ; +int rc; + +if (attr ==LSM_ATTR_UNDEF ) +return -EINVAL ; +if (size ==NULL ) +return -EINVAL ; +if (get_user (left, size)) +return -EFAULT ; + +if (flags) { +/* +* Only flag supported is LSM_FLAG_SINGLE Quoted 8 lines
security/security.c void security_d_instantiate(struct dentry *dentry, struct inode *inode) · line 3887
Quoted 4 lines
security/security.c +4
-0+*/ +if (flags !=LSM_FLAG_SINGLE ) +return -EINVAL ; +if (uctx &©_from_user (&lctx, uctx,sizeof (lctx)))I'm not sure if we should return
-EINVALor-EFAULTwhen uctx == NULL. Because uctx is optional (whenLSM_FLAG_SINGLEis not set), I guess-EINVALis OK.That's a good point, we should probably the error codes here: if uctx is NULL in the
LSM_FLAG_SINGLEcase we should return-EINVAL, if thecopy_from_user()fails we should return-EFAULT.Quoted 36 lines
Quoted 24 lines
security/security.c +24
-0+return -EFAULT ; +/* +* If the LSM ID isn't specified it is an error. +*/ +if (lctx.id ==LSM_ID_UNDEF ) +return -EINVAL ; + single = true; + } + +/* +* In the usual case gather all the data from the LSMs. +* In the single case only get the data from the LSM specified. +*/ +hlist_for_each_entry (hp, &security_hook_heads.getselfattr, list) { +if (single && lctx.id != hp->lsmid->id) +continue ; + entrysize = left; +if (base) + uctx = (struct lsm_ctx __user *)(base + total); + rc = hp->hook.getselfattr (attr, uctx, &entrysize, flags); +if (rc == -EOPNOTSUPP ) { + rc =0 ; +continue ; + }security/security.c void security_d_instantiate(struct dentry *dentry, struct inode *inode) · line 3921
Quoted 10 lines
security/security.c +10
-0+if (rc == -E2BIG ) { + toobig = true; + left =0 ; + }else if (rc <0 ) +return rc; +else + left -= entrysize; + + total += entrysize; + count += rc;There is a bug if rc ==
-E2BIGQuoted 8 lines
Quoted 4 lines
Can you elaborate a bit more on this? Nothing is jumping out at me as obviously broken... are you talking about @count becoming garbage due to @rc being equal to
-E2BIG? If that is the case it should be okay since we explicitly return-E2BIG, not @count, if @toobig is true.Indeed, in this case count will not be returned thanks to toobig. I'd suggest to "continue" if rc ==
-E2BIG(like for-EOPNOTSUPP) to avoid an inconsistent count value, which could bite us one day.Okay, how about we reset @rc to zero in the
-E2BIGcase? We don't want to bypass the lower part of the loop in this case as we still need to update @total.
Quoted 5 lines
if (rc == -E2BIG) {
rc = 0;
left = 0;
toobig = true;
}Indeed, this is better.
To avoid useless calls to getselfattr hooks, we could also patch the last part of the loop:
- if (single)
+ if (single || left <= 0)
break;
Quoted 3 lines
Signature · 2 lines
-- paul-moore.com
Paul Moore
maintainerRe: [PATCH v15 04/11] LSM: syscalls for current process attributes
Quoted 180 lines · Mickaël Salaün
Quoted 168 lines · Paul Moore
Quoted 154 lines · Mickaël Salaün
Quoted 153 lines · Paul Moore
Quoted 47 lines · Mickaël Salaün
Quoted 46 lines · Casey Schaufler
Create a system call
lsm_get_self_attr()to provide the security module maintained attributes of the current process. Create a system calllsm_set_self_attr()to set a security module maintained attribute of the current process. Historically these attributes have been exposed to user space via entries in procfs under/proc/self/attr.The attribute value is provided in a
lsm_ctxstructure. The structure identifies the size of the attribute, and the attribute value. The format of the attribute value is defined by the security module. A flags field is included for LSM specific information. It is currently unused and must be 0. The total size of the data, including thelsm_ctxstructure and any padding, is maintained as well.struct lsm_ctx { __u64 id; __u64 flags; __u64 len; __u64 ctx_len; __u8 ctx[]; };Two new LSM hooks are used to interface with the LSMs.
security_getselfattr()collects thelsm_ctxvalues from the LSMs that support the hook, accounting for space requirements.security_setselfattr()identifies which LSM the attribute is intended for and passes it along.Signed-off-by Casey Schaufler <[email protected]>Reviewed-by Kees Cook <[email protected]>Reviewed-by Serge Hallyn <[email protected]>Reviewed-by John Johansen <[email protected]>--- Documentation/userspace-api/lsm.rst | 70 +++++++++++++ include/linux/lsm_hook_defs.h | 4 + include/linux/lsm_hooks.h | 1 + include/linux/security.h | 19 ++++ include/linux/syscalls.h | 5 + include/uapi/linux/lsm.h | 36 +++++++ kernel/sys_ni.c | 2 + security/Makefile | 1 + security/lsm_syscalls.c | 57 +++++++++++ security/security.c | 152 ++++++++++++++++++++++++++++ 10 files changed, 347 insertions(+) create mode 100644 Documentation/userspace-api/lsm.rst create mode 100644 security/lsm_syscalls.c...
Quoted 52 lines
Quoted 52 lines
security/security.c +44
-0@@ -3837,6 +3837,158 @@ void security_d_instantiate(struct dentry *dentry, struct inode *inode) }EXPORT_SYMBOL (security_d_instantiate); +/* +* Please keep this in sync with it's counterpart in security/lsm_syscalls.c +*/ + +/** +* security_getselfattr - Read an LSM attribute of the current process. +* @attr: which attribute to return +* @uctx: the user-space destination for the information, or NULL +* @size: pointer to the size of space available to receive the data +* @flags: special handling options. LSM_FLAG_SINGLE indicates that only +* attributes associated with the LSM identified in the passed @ctx be +* reported. +* +* A NULL value for @uctx can be used to get both the number of attributes +* and the size of the data. +* +* Returns the number of attributes found on success, negative value +* on error. @size is reset to the total size of the data. +* If @size is insufficient to contain the data -E2BIG is returned. +*/ +int security_getselfattr (unsigned int attr,struct lsm_ctx __user *uctx, +size_t __user *size,u32 flags) +{ +struct security_hook_list *hp; +struct lsm_ctx lctx = { .id =LSM_ID_UNDEF , }; +u8 __user *base = (u8 __user *)uctx; +size_t total =0 ; +size_t entrysize; +size_t left; +bool toobig = false; +bool single = false; +int count =0 ; +int rc; + +if (attr ==LSM_ATTR_UNDEF ) +return -EINVAL ; +if (size ==NULL ) +return -EINVAL ; +if (get_user (left, size)) +return -EFAULT ; + +if (flags) { +/* +* Only flag supported is LSM_FLAG_SINGLE Quoted 8 lines
security/security.c void security_d_instantiate(struct dentry *dentry, struct inode *inode) · line 3887
Quoted 4 lines
security/security.c +4
-0+*/ +if (flags !=LSM_FLAG_SINGLE ) +return -EINVAL ; +if (uctx &©_from_user (&lctx, uctx,sizeof (lctx)))I'm not sure if we should return
-EINVALor-EFAULTwhen uctx == NULL. Because uctx is optional (whenLSM_FLAG_SINGLEis not set), I guess-EINVALis OK.That's a good point, we should probably the error codes here: if uctx is NULL in the
LSM_FLAG_SINGLEcase we should return-EINVAL, if thecopy_from_user()fails we should return-EFAULT.Quoted 36 lines
Quoted 24 lines
security/security.c +24
-0+return -EFAULT ; +/* +* If the LSM ID isn't specified it is an error. +*/ +if (lctx.id ==LSM_ID_UNDEF ) +return -EINVAL ; + single = true; + } + +/* +* In the usual case gather all the data from the LSMs. +* In the single case only get the data from the LSM specified. +*/ +hlist_for_each_entry (hp, &security_hook_heads.getselfattr, list) { +if (single && lctx.id != hp->lsmid->id) +continue ; + entrysize = left; +if (base) + uctx = (struct lsm_ctx __user *)(base + total); + rc = hp->hook.getselfattr (attr, uctx, &entrysize, flags); +if (rc == -EOPNOTSUPP ) { + rc =0 ; +continue ; + }security/security.c void security_d_instantiate(struct dentry *dentry, struct inode *inode) · line 3921
Quoted 10 lines
security/security.c +10
-0+if (rc == -E2BIG ) { + toobig = true; + left =0 ; + }else if (rc <0 ) +return rc; +else + left -= entrysize; + + total += entrysize; + count += rc;There is a bug if rc ==
-E2BIGQuoted 8 lines
Quoted 4 lines
Can you elaborate a bit more on this? Nothing is jumping out at me as obviously broken... are you talking about @count becoming garbage due to @rc being equal to
-E2BIG? If that is the case it should be okay since we explicitly return-E2BIG, not @count, if @toobig is true.Indeed, in this case count will not be returned thanks to toobig. I'd suggest to "continue" if rc ==
-E2BIG(like for-EOPNOTSUPP) to avoid an inconsistent count value, which could bite us one day.Okay, how about we reset @rc to zero in the
-E2BIGcase? We don't want to bypass the lower part of the loop in this case as we still need to update @total.Quoted 5 lines
if (rc == -E2BIG) { rc = 0; left = 0; toobig = true; }Indeed, this is better.
To avoid useless calls to getselfattr hooks, we could also patch the last part of the loop:
Review
Quoted 3 lines
(quoted diff) +1
-1- if (single) + if (single || left <= 0) break;
They aren't useless calls, we keep calling into the LSMs so that we can return a buffer size hint in the @size parameter when the getattr syscall returns -E2BIG.
Signature · 1 line
paul-moore.com
Casey Schaufler
maintainerPATCH v15 5/11 LSM: Create lsm_list_modules system call
In reply to Casey SchauflerCreate a system call to report the list of Linux Security Modules that are active on the system. The list is provided as an array of LSM ID numbers.
The calling application can use this list determine what LSM specific actions it might take. That might include choosing an output format, determining required privilege or bypassing security module specific behavior.
--- Documentation/userspace-api/lsm.rst | 3 +++ include/linux/syscalls.h | 1 + kernel/sys_ni.c | 1 + security/lsm_syscalls.c | 39 +++++++++++++++++++++++++++++ 4 files changed, 44 insertions(+)
Documentation/userspace-api/lsm.rst +3 -0
@@ -63,6 +63,9 @@ Get the specified security attributes of the current process .. kernel-doc:: security/lsm_syscalls.c :identifiers: sys_lsm_get_self_attr +.. kernel-doc:: security/lsm_syscalls.c + :identifiers: sys_lsm_list_modules + Additional documentation ========================
include/linux/syscalls.h +1 -0
@@ -945,6 +945,7 @@ asmlinkage long sys_lsm_get_self_attr(unsigned int attr, struct lsm_ctx *ctx, size_t *size, __u32 flags);asmlinkage long sys_lsm_set_self_attr (unsigned int attr,struct lsm_ctx *ctx,size_t size,__u32 flags); +asmlinkage long sys_lsm_list_modules (u64 *ids,size_t *size,u32 flags);/* * Architecture-specific system calls
kernel/sys_ni.c +1 -0
@@ -172,6 +172,7 @@ COND_SYSCALL(fadvise64_64);COND_SYSCALL_COMPAT (fadvise64_64);COND_SYSCALL (lsm_get_self_attr);COND_SYSCALL (lsm_set_self_attr); +COND_SYSCALL (lsm_list_modules);/* CONFIG_MMU only */ COND_SYSCALL (swapon);
security/lsm_syscalls.c +39 -0
@@ -55,3 +55,42 @@ SYSCALL_DEFINE4(lsm_get_self_attr, unsigned int, attr, struct lsm_ctx __user *, {return security_getselfattr (attr, ctx, size, flags); } + +/** +* sys_lsm_list_modules - Return a list of the active security modules +* @ids: the LSM module ids +* @size: pointer to size of @ids, updated on return +* @flags: reserved for future use, must be zero +* +* Returns a list of the active LSM ids. On success this function +* returns the number of @ids array elements. This value may be zero +* if there are no LSMs active. If @size is insufficient to contain +* the return data -E2BIG is returned and @size is set to the minimum +* required size. In all other cases a negative value indicating the +* error is returned. +*/ +SYSCALL_DEFINE3(lsm_list_modules, u64 __user *, ids, size_t __user *, size, + u32, flags) +{ +size_t total_size = lsm_active_cnt *sizeof (*ids); +size_t usize; +int i; + +if (flags) +return -EINVAL ; + +if (get_user (usize, size)) +return -EFAULT ; + +if (put_user (total_size, size) !=0 ) +return -EFAULT ; + +if (usize < total_size) +return -E2BIG ; + +for (i =0 ; i < lsm_active_cnt; i++) +if (put_user (lsm_idlist[i]->id, ids++)) +return -EFAULT ; + +return lsm_active_cnt; +}
Signature · 1 line
2.41.0
Re: [PATCH v15 05/11] LSM: Create lsm_list_modules system call
Quoted 9 lines · Casey Schaufler
Create a system call to report the list of Linux Security Modules that are active on the system. The list is provided as an array of LSM ID numbers.
The calling application can use this list determine what LSM specific actions it might take. That might include choosing an output format, determining required privilege or bypassing security module specific behavior.
Quoted 4 lines
Signed-off-by Casey Schaufler <[email protected]>Reviewed-by Kees Cook <[email protected]>Reviewed-by Serge Hallyn <[email protected]>Reviewed-by John Johansen <[email protected]>
Quoted 95 lines
--- Documentation/userspace-api/lsm.rst | 3 +++ include/linux/syscalls.h | 1 + kernel/sys_ni.c | 1 + security/lsm_syscalls.c | 39 +++++++++++++++++++++++++++++ 4 files changed, 44 insertions(+)Documentation/userspace-api/lsm.rst +3
-0@@ -63,6 +63,9 @@ Get the specified security attributes of the current process .. kernel-doc:: security/lsm_syscalls.c :identifiers: sys_lsm_get_self_attr +.. kernel-doc:: security/lsm_syscalls.c + :identifiers: sys_lsm_list_modules + Additional documentation ========================include/linux/syscalls.h +1
-0@@ -945,6 +945,7 @@ asmlinkage long sys_lsm_get_self_attr(unsigned int attr, struct lsm_ctx *ctx, size_t *size, __u32 flags);asmlinkage long sys_lsm_set_self_attr (unsigned int attr,struct lsm_ctx *ctx,size_t size,__u32 flags); +asmlinkage long sys_lsm_list_modules (u64 *ids,size_t *size,u32 flags);/* * Architecture-specific system calls kernel/sys_ni.c +1
-0@@ -172,6 +172,7 @@ COND_SYSCALL(fadvise64_64);COND_SYSCALL_COMPAT (fadvise64_64);COND_SYSCALL (lsm_get_self_attr);COND_SYSCALL (lsm_set_self_attr); +COND_SYSCALL (lsm_list_modules);/* CONFIG_MMU only */ COND_SYSCALL (swapon);security/lsm_syscalls.c +39
-0@@ -55,3 +55,42 @@ SYSCALL_DEFINE4(lsm_get_self_attr, unsigned int, attr, struct lsm_ctx __user *, {return security_getselfattr (attr, ctx, size, flags); } + +/** +* sys_lsm_list_modules - Return a list of the active security modules +* @ids: the LSM module ids +* @size: pointer to size of @ids, updated on return +* @flags: reserved for future use, must be zero +* +* Returns a list of the active LSM ids. On success this function +* returns the number of @ids array elements. This value may be zero +* if there are no LSMs active. If @size is insufficient to contain +* the return data -E2BIG is returned and @size is set to the minimum +* required size. In all other cases a negative value indicating the +* error is returned. +*/ +SYSCALL_DEFINE3(lsm_list_modules, u64 __user *, ids, size_t __user *, size, + u32, flags) +{ +size_t total_size = lsm_active_cnt *sizeof (*ids); +size_t usize; +int i; + +if (flags) +return -EINVAL ; + +if (get_user (usize, size)) +return -EFAULT ; + +if (put_user (total_size, size) !=0 ) +return -EFAULT ; + +if (usize < total_size) +return -E2BIG ; + +for (i =0 ; i < lsm_active_cnt; i++) +if (put_user (lsm_idlist[i]->id, ids++)) +return -EFAULT ; + +return lsm_active_cnt; +}Signature · 1 line
2.41.0
Re: [PATCH v15 05/11] LSM: Create lsm_list_modules system call
In reply to Casey SchauflerHi,
On Tue, Sep 12, 2023 at 01:56:50PM -0700, Casey Schaufler wrote:
[...]
Quoted 12 lines
security/lsm_syscalls.c +6
-0@@ -55,3 +55,42 @@ SYSCALL_DEFINE4(lsm_get_self_attr, unsigned int, attr, struct lsm_ctx __user *, {return security_getselfattr (attr, ctx, size, flags); } + +/** +* sys_lsm_list_modules - Return a list of the active security modules +* @ids: the LSM module ids +* @size: pointer to size of @ids, updated on return +* @flags: reserved for future use, must be zero
security/lsm_syscalls.c SYSCALL_DEFINE4(lsm_get_self_attr, unsigned int, attr, struct lsm_ctx __user *, · line 73
Quoted 10 lines
security/lsm_syscalls.c +10
-0+* +* Returns a list of the active LSM ids. On success this function +* returns the number of @ids array elements. This value may be zero +* if there are no LSMs active. If @size is insufficient to contain +* the return data -E2BIG is returned and @size is set to the minimum +* required size. In all other cases a negative value indicating the +* error is returned. +*/ +SYSCALL_DEFINE3(lsm_list_modules, u64 __user *, ids, size_t __user *, size, + u32, flags)
I'm sorry but the size of userspace size_t is different from the kernel one on 32-bit compat architectures.
Looks like there has to be a COMPAT_SYSCALL_DEFINE3(lsm_list_modules, ...) now. Other two added lsm syscalls also have this issue.
Signature · 1 line
ldv
Paul Moore
maintainerRe: [PATCH v15 05/11] LSM: Create lsm_list_modules system call
Quoted 19 lines · Dmitry V. Levin
On Tue, Sep 12, 2023 at 01:56:50PM -0700, Casey Schaufler wrote:
[...]Quoted 17 lines
security/lsm_syscalls.c +11
-0@@ -55,3 +55,42 @@ SYSCALL_DEFINE4(lsm_get_self_attr, unsigned int, attr, struct lsm_ctx __user *, {return security_getselfattr (attr, ctx, size, flags); } + +/** +* sys_lsm_list_modules - Return a list of the active security modules +* @ids: the LSM module ids +* @size: pointer to size of @ids, updated on return +* @flags: reserved for future use, must be zero +* +* Returns a list of the active LSM ids. On success this function +* returns the number of @ids array elements. This value may be zero +* if there are no LSMs active. If @size is insufficient to contain +* the return data -E2BIG is returned and @size is set to the minimum
Quoted 8 lines
security/lsm_syscalls.c SYSCALL_DEFINE4(lsm_get_self_attr, unsigned int, attr, struct lsm_ctx __user *, · line 73
Quoted 5 lines
security/lsm_syscalls.c +5
-0+* required size. In all other cases a negative value indicating the +* error is returned. +*/ +SYSCALL_DEFINE3(lsm_list_modules, u64 __user *, ids, size_t __user *, size, + u32, flags)I'm sorry but the size of userspace
size_tis different from the kernel one on 32-bit compat architectures.
D'oh, yes, thanks for pointing that out. It would have been nice to have caught that before v6.8 was released, but I guess it's better than later.
Quoted 2 lines
Looks like there has to be a
COMPAT_SYSCALL_DEFINE3(lsm_list_modules, ...)now. Other two added lsm syscalls also have this issue.
Considering that Linux v6.8, and by extension these syscalls, are only a few days old, I think I'd rather see us just modify the syscalls and avoid the compat baggage. I'm going to be shocked if anyone has shifted to using the new syscalls yet, and even if they have (!!), moving from a "size_t" type to a "u64" should be mostly transparent for the majority of native 64-bit systems. Those running the absolute latest kernels on 32-bit systems with custom or bleeding edge userspace *may* see a slight hiccup, but I think that user count is in the single digits, if not zero.
Let's fix this quickly with /size_t/u64/ in v6.8.1 and avoid the compat shim if we can.
Casey, do you have time to put together a patch for this (you should fix the call chains below the syscalls too)? If not, please let me know and I'll get a patch out ASAP.
Thanks all.
Signature · 1 line
paul-moore.com
Casey Schaufler
maintainerRe: [PATCH v15 05/11] LSM: Create lsm_list_modules system call
Quoted 43 lines · Paul Moore
Quoted 18 lines · Dmitry V. Levin
On Tue, Sep 12, 2023 at 01:56:50PM -0700, Casey Schaufler wrote:
[...]Quoted 16 lines
security/lsm_syscalls.c +10
-0@@ -55,3 +55,42 @@ SYSCALL_DEFINE4(lsm_get_self_attr, unsigned int, attr, struct lsm_ctx __user *, {return security_getselfattr (attr, ctx, size, flags); } + +/** +* sys_lsm_list_modules - Return a list of the active security modules +* @ids: the LSM module ids +* @size: pointer to size of @ids, updated on return +* @flags: reserved for future use, must be zero +* +* Returns a list of the active LSM ids. On success this function +* returns the number of @ids array elements. This value may be zero +* if there are no LSMs active. If @size is insufficient to contain Quoted 8 lines
security/lsm_syscalls.c SYSCALL_DEFINE4(lsm_get_self_attr, unsigned int, attr, struct lsm_ctx __user *, · line 73
Quoted 6 lines
security/lsm_syscalls.c +6
-0+* the return data -E2BIG is returned and @size is set to the minimum +* required size. In all other cases a negative value indicating the +* error is returned. +*/ +SYSCALL_DEFINE3(lsm_list_modules, u64 __user *, ids, size_t __user *, size, + u32, flags)I'm sorry but the size of userspace
size_tis different from the kernel one on 32-bit compat architectures.D'oh, yes, thanks for pointing that out. It would have been nice to have caught that before v6.8 was released, but I guess it's better than later.
Quoted 2 lines
Looks like there has to be a
COMPAT_SYSCALL_DEFINE3(lsm_list_modules, ...)now. Other two added lsm syscalls also have this issue.Considering that Linux v6.8, and by extension these syscalls, are only a few days old, I think I'd rather see us just modify the syscalls and avoid the compat baggage. I'm going to be shocked if anyone has shifted to using the new syscalls yet, and even if they have (!!), moving from a "
size_t" type to a "u64" should be mostly transparent for the majority of native 64-bit systems. Those running the absolute latest kernels on 32-bit systems with custom or bleeding edge userspace *may* see a slight hiccup, but I think that user count is in the single digits, if not zero.
Quoted 6 lines
Let's fix this quickly with /size_t/u64/ in v6.8.1 and avoid the compat shim if we can.
Casey, do you have time to put together a patch for this (you should fix the call chains below the syscalls too)? If not, please let me know and I'll get a patch out ASAP.
Grumble. Yes, I'll get right on it.
Quoted 3 lines
Thanks all.
Paul Moore
maintainerRe: [PATCH v15 05/11] LSM: Create lsm_list_modules system call
Quoted 44 lines · Casey Schaufler
Quoted 43 lines · Paul Moore
Quoted 18 lines · Dmitry V. Levin
On Tue, Sep 12, 2023 at 01:56:50PM -0700, Casey Schaufler wrote:
[...]Quoted 16 lines
security/lsm_syscalls.c +10
-0@@ -55,3 +55,42 @@ SYSCALL_DEFINE4(lsm_get_self_attr, unsigned int, attr, struct lsm_ctx __user *, {return security_getselfattr (attr, ctx, size, flags); } + +/** +* sys_lsm_list_modules - Return a list of the active security modules +* @ids: the LSM module ids +* @size: pointer to size of @ids, updated on return +* @flags: reserved for future use, must be zero +* +* Returns a list of the active LSM ids. On success this function +* returns the number of @ids array elements. This value may be zero +* if there are no LSMs active. If @size is insufficient to contain Quoted 8 lines
security/lsm_syscalls.c SYSCALL_DEFINE4(lsm_get_self_attr, unsigned int, attr, struct lsm_ctx __user *, · line 73
Quoted 6 lines
security/lsm_syscalls.c +6
-0+* the return data -E2BIG is returned and @size is set to the minimum +* required size. In all other cases a negative value indicating the +* error is returned. +*/ +SYSCALL_DEFINE3(lsm_list_modules, u64 __user *, ids, size_t __user *, size, + u32, flags)I'm sorry but the size of userspace
size_tis different from the kernel one on 32-bit compat architectures.D'oh, yes, thanks for pointing that out. It would have been nice to have caught that before v6.8 was released, but I guess it's better than later.
Quoted 2 lines
Looks like there has to be a
COMPAT_SYSCALL_DEFINE3(lsm_list_modules, ...)now. Other two added lsm syscalls also have this issue.Considering that Linux v6.8, and by extension these syscalls, are only a few days old, I think I'd rather see us just modify the syscalls and avoid the compat baggage. I'm going to be shocked if anyone has shifted to using the new syscalls yet, and even if they have (!!), moving from a "
size_t" type to a "u64" should be mostly transparent for the majority of native 64-bit systems. Those running the absolute latest kernels on 32-bit systems with custom or bleeding edge userspace *may* see a slight hiccup, but I think that user count is in the single digits, if not zero.
Quoted 8 lines
Quoted 6 lines
Let's fix this quickly with /size_t/u64/ in v6.8.1 and avoid the compat shim if we can.
Casey, do you have time to put together a patch for this (you should fix the call chains below the syscalls too)? If not, please let me know and I'll get a patch out ASAP.
Grumble. Yes, I'll get right on it.
Great, thanks Casey.
Signature · 1 line
paul-moore.com
Casey Schaufler
maintainerRe: [PATCH v15 05/11] LSM: Create lsm_list_modules system call
Quoted 45 lines · Paul Moore
Quoted 44 lines · Casey Schaufler
Quoted 43 lines · Paul Moore
Quoted 18 lines · Dmitry V. Levin
On Tue, Sep 12, 2023 at 01:56:50PM -0700, Casey Schaufler wrote:
[...]Quoted 16 lines
security/lsm_syscalls.c +10
-0@@ -55,3 +55,42 @@ SYSCALL_DEFINE4(lsm_get_self_attr, unsigned int, attr, struct lsm_ctx __user *, {return security_getselfattr (attr, ctx, size, flags); } + +/** +* sys_lsm_list_modules - Return a list of the active security modules +* @ids: the LSM module ids +* @size: pointer to size of @ids, updated on return +* @flags: reserved for future use, must be zero +* +* Returns a list of the active LSM ids. On success this function +* returns the number of @ids array elements. This value may be zero +* if there are no LSMs active. If @size is insufficient to contain Quoted 8 lines
security/lsm_syscalls.c SYSCALL_DEFINE4(lsm_get_self_attr, unsigned int, attr, struct lsm_ctx __user *, · line 73
Quoted 6 lines
security/lsm_syscalls.c +6
-0+* the return data -E2BIG is returned and @size is set to the minimum +* required size. In all other cases a negative value indicating the +* error is returned. +*/ +SYSCALL_DEFINE3(lsm_list_modules, u64 __user *, ids, size_t __user *, size, + u32, flags)I'm sorry but the size of userspace
size_tis different from the kernel one on 32-bit compat architectures.D'oh, yes, thanks for pointing that out. It would have been nice to have caught that before v6.8 was released, but I guess it's better than later.
Quoted 2 lines
Looks like there has to be a
COMPAT_SYSCALL_DEFINE3(lsm_list_modules, ..)now. Other two added lsm syscalls also have this issue.Considering that Linux v6.8, and by extension these syscalls, are only a few days old, I think I'd rather see us just modify the syscalls and avoid the compat baggage. I'm going to be shocked if anyone has shifted to using the new syscalls yet, and even if they have (!!), moving from a "
size_t" type to a "u64" should be mostly transparent for the majority of native 64-bit systems. Those running the absolute latest kernels on 32-bit systems with custom or bleeding edge userspace *may* see a slight hiccup, but I think that user count is in the single digits, if not zero.
Quoted 8 lines
Quoted 7 lines
Quoted 6 lines
Let's fix this quickly with /size_t/u64/ in v6.8.1 and avoid the compat shim if we can.
Casey, do you have time to put together a patch for this (you should fix the call chains below the syscalls too)? If not, please let me know and I'll get a patch out ASAP.
Grumble. Yes, I'll get right on it.
Great, thanks Casey.
Look like lsm_get_self_attr() needs the same change. lsm_set_self_attr() doesn't, need it, but I'm tempted to change it as well for consistency. Thoughts?
Quoted 1 line
Paul Moore
maintainerRe: [PATCH v15 05/11] LSM: Create lsm_list_modules system call
Quoted 52 lines · Casey Schaufler
Quoted 51 lines · Paul Moore
Quoted 50 lines · Casey Schaufler
Quoted 49 lines · Paul Moore
Quoted 18 lines · Dmitry V. Levin
On Tue, Sep 12, 2023 at 01:56:50PM -0700, Casey Schaufler wrote:
[...]Quoted 16 lines
security/lsm_syscalls.c +10
-0@@ -55,3 +55,42 @@ SYSCALL_DEFINE4(lsm_get_self_attr, unsigned int, attr, struct lsm_ctx __user *, {return security_getselfattr (attr, ctx, size, flags); } + +/** +* sys_lsm_list_modules - Return a list of the active security modules +* @ids: the LSM module ids +* @size: pointer to size of @ids, updated on return +* @flags: reserved for future use, must be zero +* +* Returns a list of the active LSM ids. On success this function +* returns the number of @ids array elements. This value may be zero +* if there are no LSMs active. If @size is insufficient to contain Quoted 8 lines
security/lsm_syscalls.c SYSCALL_DEFINE4(lsm_get_self_attr, unsigned int, attr, struct lsm_ctx __user *, · line 73
Quoted 6 lines
security/lsm_syscalls.c +6
-0+* the return data -E2BIG is returned and @size is set to the minimum +* required size. In all other cases a negative value indicating the +* error is returned. +*/ +SYSCALL_DEFINE3(lsm_list_modules, u64 __user *, ids, size_t __user *, size, + u32, flags)I'm sorry but the size of userspace
size_tis different from the kernel one on 32-bit compat architectures.D'oh, yes, thanks for pointing that out. It would have been nice to have caught that before v6.8 was released, but I guess it's better than later.
Quoted 2 lines
Looks like there has to be a
COMPAT_SYSCALL_DEFINE3(lsm_list_modules, ..)now. Other two added lsm syscalls also have this issue.Considering that Linux v6.8, and by extension these syscalls, are only a few days old, I think I'd rather see us just modify the syscalls and avoid the compat baggage. I'm going to be shocked if anyone has shifted to using the new syscalls yet, and even if they have (!!), moving from a "
size_t" type to a "u64" should be mostly transparent for the majority of native 64-bit systems. Those running the absolute latest kernels on 32-bit systems with custom or bleeding edge userspace *may* see a slight hiccup, but I think that user count is in the single digits, if not zero.Let's fix this quickly with /size_t/u64/ in v6.8.1 and avoid the compat shim if we can.
Casey, do you have time to put together a patch for this (you should fix the call chains below the syscalls too)? If not, please let me know and I'll get a patch out ASAP.
Quoted 6 lines
Quoted 2 lines
Quoted 1 line
Grumble. Yes, I'll get right on it.
Great, thanks Casey.
Look like
lsm_get_self_attr()needs the same change.lsm_set_self_attr()doesn't, need it, but I'm tempted to change it as well for consistency. Thoughts?
I'd suggest changing both.
Signature · 1 line
paul-moore.com
Re: [PATCH v15 05/11] LSM: Create lsm_list_modules system call
In reply to Casey SchauflerQuoted 52 lines · Casey Schaufler
Quoted 51 lines · Paul Moore
Quoted 50 lines · Casey Schaufler
Quoted 49 lines · Paul Moore
Quoted 18 lines · Dmitry V. Levin
On Tue, Sep 12, 2023 at 01:56:50PM -0700, Casey Schaufler wrote:
[...]Quoted 16 lines
security/lsm_syscalls.c +10
-0@@ -55,3 +55,42 @@ SYSCALL_DEFINE4(lsm_get_self_attr, unsigned int, attr, struct lsm_ctx __user *, {return security_getselfattr (attr, ctx, size, flags); } + +/** +* sys_lsm_list_modules - Return a list of the active security modules +* @ids: the LSM module ids +* @size: pointer to size of @ids, updated on return +* @flags: reserved for future use, must be zero +* +* Returns a list of the active LSM ids. On success this function +* returns the number of @ids array elements. This value may be zero +* if there are no LSMs active. If @size is insufficient to contain Quoted 8 lines
security/lsm_syscalls.c SYSCALL_DEFINE4(lsm_get_self_attr, unsigned int, attr, struct lsm_ctx __user *, · line 73
Quoted 6 lines
security/lsm_syscalls.c +6
-0+* the return data -E2BIG is returned and @size is set to the minimum +* required size. In all other cases a negative value indicating the +* error is returned. +*/ +SYSCALL_DEFINE3(lsm_list_modules, u64 __user *, ids, size_t __user *, size, + u32, flags)I'm sorry but the size of userspace
size_tis different from the kernel one on 32-bit compat architectures.D'oh, yes, thanks for pointing that out. It would have been nice to have caught that before v6.8 was released, but I guess it's better than later.
Quoted 2 lines
Looks like there has to be a
COMPAT_SYSCALL_DEFINE3(lsm_list_modules, ..)now. Other two added lsm syscalls also have this issue.Considering that Linux v6.8, and by extension these syscalls, are only a few days old, I think I'd rather see us just modify the syscalls and avoid the compat baggage. I'm going to be shocked if anyone has shifted to using the new syscalls yet, and even if they have (!!), moving from a "
size_t" type to a "u64" should be mostly transparent for the majority of native 64-bit systems. Those running the absolute latest kernels on 32-bit systems with custom or bleeding edge userspace *may* see a slight hiccup, but I think that user count is in the single digits, if not zero.Let's fix this quickly with /size_t/u64/ in v6.8.1 and avoid the compat shim if we can.
Casey, do you have time to put together a patch for this (you should fix the call chains below the syscalls too)? If not, please let me know and I'll get a patch out ASAP.
Quoted 6 lines
Quoted 2 lines
Quoted 1 line
Grumble. Yes, I'll get right on it.
Great, thanks Casey.
Look like
lsm_get_self_attr()needs the same change.lsm_set_self_attr()doesn't, need it, but I'm tempted to change it as well for consistency. Thoughts?
As lsm_get_self_attr() has the same issue, it needs the same treatment.
lsm_set_self_attr() could be left unchanged. In fact, changing the type of syscall arguments from size_t to an explicit 64-bit type would be problematic because 32-bit syscalls cannot have 64-bit arguments.
Signature · 1 line
ldv
Re: [PATCH v15 05/11] LSM: Create lsm_list_modules system call
Quoted 60 lines · Dmitry V. Levin
Quoted 52 lines · Casey Schaufler
Quoted 51 lines · Paul Moore
Quoted 50 lines · Casey Schaufler
Quoted 49 lines · Paul Moore
Quoted 18 lines · Dmitry V. Levin
On Tue, Sep 12, 2023 at 01:56:50PM -0700, Casey Schaufler wrote:
[...]Quoted 16 lines
security/lsm_syscalls.c +10
-0@@ -55,3 +55,42 @@ SYSCALL_DEFINE4(lsm_get_self_attr, unsigned int, attr, struct lsm_ctx __user *, {return security_getselfattr (attr, ctx, size, flags); } + +/** +* sys_lsm_list_modules - Return a list of the active security modules +* @ids: the LSM module ids +* @size: pointer to size of @ids, updated on return +* @flags: reserved for future use, must be zero +* +* Returns a list of the active LSM ids. On success this function +* returns the number of @ids array elements. This value may be zero +* if there are no LSMs active. If @size is insufficient to contain Quoted 8 lines
security/lsm_syscalls.c SYSCALL_DEFINE4(lsm_get_self_attr, unsigned int, attr, struct lsm_ctx __user *, · line 73
Quoted 6 lines
security/lsm_syscalls.c +6
-0+* the return data -E2BIG is returned and @size is set to the minimum +* required size. In all other cases a negative value indicating the +* error is returned. +*/ +SYSCALL_DEFINE3(lsm_list_modules, u64 __user *, ids, size_t __user *, size, + u32, flags)I'm sorry but the size of userspace
size_tis different from the kernel one on 32-bit compat architectures.D'oh, yes, thanks for pointing that out. It would have been nice to have caught that before v6.8 was released, but I guess it's better than later.
Quoted 2 lines
Looks like there has to be a
COMPAT_SYSCALL_DEFINE3(lsm_list_modules, ..)now. Other two added lsm syscalls also have this issue.Considering that Linux v6.8, and by extension these syscalls, are only a few days old, I think I'd rather see us just modify the syscalls and avoid the compat baggage. I'm going to be shocked if anyone has shifted to using the new syscalls yet, and even if they have (!!), moving from a "
size_t" type to a "u64" should be mostly transparent for the majority of native 64-bit systems. Those running the absolute latest kernels on 32-bit systems with custom or bleeding edge userspace *may* see a slight hiccup, but I think that user count is in the single digits, if not zero.Let's fix this quickly with /size_t/u64/ in v6.8.1 and avoid the compat shim if we can.
Casey, do you have time to put together a patch for this (you should fix the call chains below the syscalls too)? If not, please let me know and I'll get a patch out ASAP.
Quoted 6 lines
Quoted 2 lines
Quoted 1 line
Grumble. Yes, I'll get right on it.
Great, thanks Casey.
Look like
lsm_get_self_attr()needs the same change.lsm_set_self_attr()doesn't, need it, but I'm tempted to change it as well for consistency. Thoughts?
Quoted 5 lines
As
lsm_get_self_attr()has the same issue, it needs the same treatment.
lsm_set_self_attr()could be left unchanged. In fact, changing the type of syscall arguments fromsize_tto an explicit 64-bit type would be problematic because 32-bit syscalls cannot have 64-bit arguments.
Using u32 should be totally fine for both. Nearly ever kernel internal limits sizes to INT_MAX anyway. :)
Signature · 1 line
Kees Cook
Casey Schaufler
maintainerRe: [PATCH v15 05/11] LSM: Create lsm_list_modules system call
Quoted 59 lines · Kees Cook
Quoted 58 lines · Dmitry V. Levin
Quoted 57 lines · Casey Schaufler
Quoted 45 lines · Paul Moore
Quoted 44 lines · Casey Schaufler
Quoted 43 lines · Paul Moore
Quoted 18 lines · Dmitry V. Levin
On Tue, Sep 12, 2023 at 01:56:50PM -0700, Casey Schaufler wrote:
[...]Quoted 16 lines
security/lsm_syscalls.c +10
-0@@ -55,3 +55,42 @@ SYSCALL_DEFINE4(lsm_get_self_attr, unsigned int, attr, struct lsm_ctx __user *, {return security_getselfattr (attr, ctx, size, flags); } + +/** +* sys_lsm_list_modules - Return a list of the active security modules +* @ids: the LSM module ids +* @size: pointer to size of @ids, updated on return +* @flags: reserved for future use, must be zero +* +* Returns a list of the active LSM ids. On success this function +* returns the number of @ids array elements. This value may be zero +* if there are no LSMs active. If @size is insufficient to contain Quoted 8 lines
security/lsm_syscalls.c SYSCALL_DEFINE4(lsm_get_self_attr, unsigned int, attr, struct lsm_ctx __user *, · line 73
Quoted 6 lines
security/lsm_syscalls.c +6
-0+* the return data -E2BIG is returned and @size is set to the minimum +* required size. In all other cases a negative value indicating the +* error is returned. +*/ +SYSCALL_DEFINE3(lsm_list_modules, u64 __user *, ids, size_t __user *, size, + u32, flags)I'm sorry but the size of userspace
size_tis different from the kernel one on 32-bit compat architectures.D'oh, yes, thanks for pointing that out. It would have been nice to have caught that before v6.8 was released, but I guess it's better than later.
Quoted 2 lines
Looks like there has to be a
COMPAT_SYSCALL_DEFINE3(lsm_list_modules, ..)now. Other two added lsm syscalls also have this issue.Considering that Linux v6.8, and by extension these syscalls, are only a few days old, I think I'd rather see us just modify the syscalls and avoid the compat baggage. I'm going to be shocked if anyone has shifted to using the new syscalls yet, and even if they have (!!), moving from a "
size_t" type to a "u64" should be mostly transparent for the majority of native 64-bit systems. Those running the absolute latest kernels on 32-bit systems with custom or bleeding edge userspace *may* see a slight hiccup, but I think that user count is in the single digits, if not zero.Quoted 8 lines
Quoted 7 lines
Quoted 6 lines
Let's fix this quickly with /size_t/u64/ in v6.8.1 and avoid the compat shim if we can.
Casey, do you have time to put together a patch for this (you should fix the call chains below the syscalls too)? If not, please let me know and I'll get a patch out ASAP.
Grumble. Yes, I'll get right on it.
Great, thanks Casey.
Look like
lsm_get_self_attr()needs the same change.lsm_set_self_attr()doesn't, need it, but I'm tempted to change it as well for consistency. Thoughts?
Quoted 7 lines
Quoted 5 lines
As
lsm_get_self_attr()has the same issue, it needs the same treatment.
lsm_set_self_attr()could be left unchanged. In fact, changing the type of syscall arguments fromsize_tto an explicit 64-bit type would be problematic because 32-bit syscalls cannot have 64-bit arguments.Using u32 should be totally fine for both. Nearly ever kernel internal limits sizes to
INT_MAXanyway. :)
My initial patch changes the size_t pointers in lsm_list_modules() and lsm_get_self_attr() to __u64 pointers. I could change them to __u32 pointers and include lsm_set_self_attr() as well. Let's see who screams how loudly.
Paul Moore
maintainerRe: [PATCH v15 05/11] LSM: Create lsm_list_modules system call
In reply to Dmitry V. LevinQuoted 60 lines · Dmitry V. Levin
Quoted 52 lines · Casey Schaufler
Quoted 51 lines · Paul Moore
Quoted 50 lines · Casey Schaufler
Quoted 49 lines · Paul Moore
Quoted 18 lines · Dmitry V. Levin
On Tue, Sep 12, 2023 at 01:56:50PM -0700, Casey Schaufler wrote:
[...]Quoted 16 lines
security/lsm_syscalls.c +10
-0@@ -55,3 +55,42 @@ SYSCALL_DEFINE4(lsm_get_self_attr, unsigned int, attr, struct lsm_ctx __user *, {return security_getselfattr (attr, ctx, size, flags); } + +/** +* sys_lsm_list_modules - Return a list of the active security modules +* @ids: the LSM module ids +* @size: pointer to size of @ids, updated on return +* @flags: reserved for future use, must be zero +* +* Returns a list of the active LSM ids. On success this function +* returns the number of @ids array elements. This value may be zero +* if there are no LSMs active. If @size is insufficient to contain Quoted 8 lines
security/lsm_syscalls.c SYSCALL_DEFINE4(lsm_get_self_attr, unsigned int, attr, struct lsm_ctx __user *, · line 73
Quoted 6 lines
security/lsm_syscalls.c +6
-0+* the return data -E2BIG is returned and @size is set to the minimum +* required size. In all other cases a negative value indicating the +* error is returned. +*/ +SYSCALL_DEFINE3(lsm_list_modules, u64 __user *, ids, size_t __user *, size, + u32, flags)I'm sorry but the size of userspace
size_tis different from the kernel one on 32-bit compat architectures.D'oh, yes, thanks for pointing that out. It would have been nice to have caught that before v6.8 was released, but I guess it's better than later.
Quoted 2 lines
Looks like there has to be a
COMPAT_SYSCALL_DEFINE3(lsm_list_modules, ..)now. Other two added lsm syscalls also have this issue.Considering that Linux v6.8, and by extension these syscalls, are only a few days old, I think I'd rather see us just modify the syscalls and avoid the compat baggage. I'm going to be shocked if anyone has shifted to using the new syscalls yet, and even if they have (!!), moving from a "
size_t" type to a "u64" should be mostly transparent for the majority of native 64-bit systems. Those running the absolute latest kernels on 32-bit systems with custom or bleeding edge userspace *may* see a slight hiccup, but I think that user count is in the single digits, if not zero.Let's fix this quickly with /size_t/u64/ in v6.8.1 and avoid the compat shim if we can.
Casey, do you have time to put together a patch for this (you should fix the call chains below the syscalls too)? If not, please let me know and I'll get a patch out ASAP.
Quoted 6 lines
Quoted 2 lines
Quoted 1 line
Grumble. Yes, I'll get right on it.
Great, thanks Casey.
Look like
lsm_get_self_attr()needs the same change.lsm_set_self_attr()doesn't, need it, but I'm tempted to change it as well for consistency. Thoughts?
Quoted 5 lines
As
lsm_get_self_attr()has the same issue, it needs the same treatment.
lsm_set_self_attr()could be left unchanged. In fact, changing the type of syscall arguments fromsize_tto an explicit 64-bit type would be problematic because 32-bit syscalls cannot have 64-bit arguments.
You might as well convert all of the size_t parameters, pointers or otherwise, in the three syscalls to u32 Casey.
I'd leave the lsm_ctx struct alone, the individual fields are nicely aligned on both 32-bit and 64-bit systems and worst case we have some unused bits.
The 64-bit LSM IDs are perhaps a bit more problematic, but I believe we are okay and I don't think we should change that. With one of the primary motivations behind the LSM syscalls being support for multiple LSMs, I suspect any future LSMs will use an array of LSM IDs (the u64 is hidden behind a pointer) as we do in lsm_list_modules() or the LSM ID will be part of a larger struct like lsm_ctx.
--
paul-moore.com
Casey Schaufler
maintainerRe: [PATCH v15 05/11] LSM: Create lsm_list_modules system call
Quoted 59 lines · Paul Moore
Quoted 58 lines · Dmitry V. Levin
Quoted 57 lines · Casey Schaufler
Quoted 45 lines · Paul Moore
Quoted 44 lines · Casey Schaufler
Quoted 43 lines · Paul Moore
Quoted 18 lines · Dmitry V. Levin
On Tue, Sep 12, 2023 at 01:56:50PM -0700, Casey Schaufler wrote:
[...]Quoted 16 lines
security/lsm_syscalls.c +10
-0@@ -55,3 +55,42 @@ SYSCALL_DEFINE4(lsm_get_self_attr, unsigned int, attr, struct lsm_ctx __user *, {return security_getselfattr (attr, ctx, size, flags); } + +/** +* sys_lsm_list_modules - Return a list of the active security modules +* @ids: the LSM module ids +* @size: pointer to size of @ids, updated on return +* @flags: reserved for future use, must be zero +* +* Returns a list of the active LSM ids. On success this function +* returns the number of @ids array elements. This value may be zero +* if there are no LSMs active. If @size is insufficient to contain Quoted 8 lines
security/lsm_syscalls.c SYSCALL_DEFINE4(lsm_get_self_attr, unsigned int, attr, struct lsm_ctx __user *, · line 73
Quoted 6 lines
security/lsm_syscalls.c +6
-0+* the return data -E2BIG is returned and @size is set to the minimum +* required size. In all other cases a negative value indicating the +* error is returned. +*/ +SYSCALL_DEFINE3(lsm_list_modules, u64 __user *, ids, size_t __user *, size, + u32, flags)I'm sorry but the size of userspace
size_tis different from the kernel one on 32-bit compat architectures.D'oh, yes, thanks for pointing that out. It would have been nice to have caught that before v6.8 was released, but I guess it's better than later.
Quoted 2 lines
Looks like there has to be a
COMPAT_SYSCALL_DEFINE3(lsm_list_modules, ..)now. Other two added lsm syscalls also have this issue.Considering that Linux v6.8, and by extension these syscalls, are only a few days old, I think I'd rather see us just modify the syscalls and avoid the compat baggage. I'm going to be shocked if anyone has shifted to using the new syscalls yet, and even if they have (!!), moving from a "
size_t" type to a "u64" should be mostly transparent for the majority of native 64-bit systems. Those running the absolute latest kernels on 32-bit systems with custom or bleeding edge userspace *may* see a slight hiccup, but I think that user count is in the single digits, if not zero.Quoted 8 lines
Quoted 7 lines
Quoted 6 lines
Let's fix this quickly with /size_t/u64/ in v6.8.1 and avoid the compat shim if we can.
Casey, do you have time to put together a patch for this (you should fix the call chains below the syscalls too)? If not, please let me know and I'll get a patch out ASAP.
Grumble. Yes, I'll get right on it.
Great, thanks Casey.
Look like
lsm_get_self_attr()needs the same change.lsm_set_self_attr()doesn't, need it, but I'm tempted to change it as well for consistency. Thoughts?
Quoted 7 lines
Quoted 5 lines
As
lsm_get_self_attr()has the same issue, it needs the same treatment.
lsm_set_self_attr()could be left unchanged. In fact, changing the type of syscall arguments fromsize_tto an explicit 64-bit type would be problematic because 32-bit syscalls cannot have 64-bit arguments.You might as well convert all of the
size_tparameters, pointers or otherwise, in the three syscalls to u32 Casey.
Well, nuts. So much for that coin flip. V2 coming real soon.
Paul Moore
maintainerRe: [PATCH v15 05/11] LSM: Create lsm_list_modules system call
Quoted 62 lines · Casey Schaufler
Quoted 61 lines · Paul Moore
Quoted 60 lines · Dmitry V. Levin
Quoted 49 lines · Casey Schaufler
Quoted 48 lines · Paul Moore
Quoted 47 lines · Casey Schaufler
Quoted 46 lines · Paul Moore
Quoted 18 lines · Dmitry V. Levin
On Tue, Sep 12, 2023 at 01:56:50PM -0700, Casey Schaufler wrote:
[...]Quoted 16 lines
security/lsm_syscalls.c +10
-0@@ -55,3 +55,42 @@ SYSCALL_DEFINE4(lsm_get_self_attr, unsigned int, attr, struct lsm_ctx __user *, {return security_getselfattr (attr, ctx, size, flags); } + +/** +* sys_lsm_list_modules - Return a list of the active security modules +* @ids: the LSM module ids +* @size: pointer to size of @ids, updated on return +* @flags: reserved for future use, must be zero +* +* Returns a list of the active LSM ids. On success this function +* returns the number of @ids array elements. This value may be zero +* if there are no LSMs active. If @size is insufficient to contain Quoted 8 lines
security/lsm_syscalls.c SYSCALL_DEFINE4(lsm_get_self_attr, unsigned int, attr, struct lsm_ctx __user *, · line 73
Quoted 6 lines
security/lsm_syscalls.c +6
-0+* the return data -E2BIG is returned and @size is set to the minimum +* required size. In all other cases a negative value indicating the +* error is returned. +*/ +SYSCALL_DEFINE3(lsm_list_modules, u64 __user *, ids, size_t __user *, size, + u32, flags)I'm sorry but the size of userspace
size_tis different from the kernel one on 32-bit compat architectures.D'oh, yes, thanks for pointing that out. It would have been nice to have caught that before v6.8 was released, but I guess it's better than later.
Quoted 2 lines
Looks like there has to be a
COMPAT_SYSCALL_DEFINE3(lsm_list_modules, ..)now. Other two added lsm syscalls also have this issue.Considering that Linux v6.8, and by extension these syscalls, are only a few days old, I think I'd rather see us just modify the syscalls and avoid the compat baggage. I'm going to be shocked if anyone has shifted to using the new syscalls yet, and even if they have (!!), moving from a "
size_t" type to a "u64" should be mostly transparent for the majority of native 64-bit systems. Those running the absolute latest kernels on 32-bit systems with custom or bleeding edge userspace *may* see a slight hiccup, but I think that user count is in the single digits, if not zero.Let's fix this quickly with /size_t/u64/ in v6.8.1 and avoid the compat shim if we can.
Quoted 8 lines
Quoted 5 lines
Quoted 4 lines
Quoted 3 lines
Casey, do you have time to put together a patch for this (you should fix the call chains below the syscalls too)? If not, please let me know and I'll get a patch out ASAP.
Grumble. Yes, I'll get right on it.
Great, thanks Casey.
Look like
lsm_get_self_attr()needs the same change.lsm_set_self_attr()doesn't, need it, but I'm tempted to change it as well for consistency. Thoughts?As
lsm_get_self_attr()has the same issue, it needs the same treatment.
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
lsm_set_self_attr()could be left unchanged. In fact, changing the type of syscall arguments fromsize_tto an explicit 64-bit type would be problematic because 32-bit syscalls cannot have 64-bit arguments.You might as well convert all of the
size_tparameters, pointers or otherwise, in the three syscalls to u32 Casey.Well, nuts. So much for that coin flip. V2 coming real soon.
Yeah, sorry for the false starts today ...
Signature · 1 line
paul-moore.com
Casey Schaufler
maintainerPATCH v15 6/11 LSM: wireup Linux Security Module syscalls
In reply to Casey SchauflerWireup lsm_get_self_attr, lsm_set_self_attr and lsm_list_modules system calls.
--- arch/alpha/kernel/syscalls/syscall.tbl | 3 +++ arch/arm/tools/syscall.tbl | 3 +++ arch/arm64/include/asm/unistd.h | 2 +- arch/arm64/include/asm/unistd32.h | 6 ++++++ arch/ia64/kernel/syscalls/syscall.tbl | 3 +++ arch/m68k/kernel/syscalls/syscall.tbl | 3 +++ arch/microblaze/kernel/syscalls/syscall.tbl | 3 +++ arch/mips/kernel/syscalls/syscall_n32.tbl | 3 +++ arch/mips/kernel/syscalls/syscall_n64.tbl | 3 +++ arch/mips/kernel/syscalls/syscall_o32.tbl | 3 +++ arch/parisc/kernel/syscalls/syscall.tbl | 3 +++ arch/powerpc/kernel/syscalls/syscall.tbl | 3 +++ arch/s390/kernel/syscalls/syscall.tbl | 3 +++ arch/sh/kernel/syscalls/syscall.tbl | 3 +++ arch/sparc/kernel/syscalls/syscall.tbl | 3 +++ arch/x86/entry/syscalls/syscall_32.tbl | 3 +++ arch/x86/entry/syscalls/syscall_64.tbl | 3 +++ arch/xtensa/kernel/syscalls/syscall.tbl | 3 +++ include/uapi/asm-generic/unistd.h | 9 ++++++++- tools/perf/arch/mips/entry/syscalls/syscall_n64.tbl | 3 +++ tools/perf/arch/powerpc/entry/syscalls/syscall.tbl | 3 +++ tools/perf/arch/s390/entry/syscalls/syscall.tbl | 3 +++ tools/perf/arch/x86/entry/syscalls/syscall_64.tbl | 3 +++ 23 files changed, 75 insertions(+), 2 deletions(-)
arch/alpha/kernel/syscalls/syscall.tbl +3 -0
@@ -492,3 +492,6 @@ 560 common set_mempolicy_home_node sys_ni_syscall 561 common cachestat sys_cachestat 562 common fchmodat2 sys_fchmodat2 +563 common lsm_get_self_attr sys_lsm_get_self_attr +564 common lsm_set_self_attr sys_lsm_set_self_attr +565 common lsm_list_modules sys_lsm_list_modules
arch/arm/tools/syscall.tbl +3 -0
@@ -466,3 +466,6 @@ 450 common set_mempolicy_home_node sys_set_mempolicy_home_node 451 common cachestat sys_cachestat 452 common fchmodat2 sys_fchmodat2 +453 common lsm_get_self_attr sys_lsm_get_self_attr +454 common lsm_set_self_attr sys_lsm_set_self_attr +455 common lsm_list_modules sys_lsm_list_modules
arch/arm64/include/asm/unistd.h +1 -1
@@ -39,7 +39,7 @@#define __ARM_NR_compat_set_tls (__ARM_NR_COMPAT_BASE + 5)#define __ARM_NR_COMPAT_END (__ARM_NR_COMPAT_BASE + 0x800) -#define __NR_compat_syscalls 453 +#define __NR_compat_syscalls 456#endif #define __ARCH_WANT_SYS_CLONE
arch/arm64/include/asm/unistd32.h +6 -0
@@ -911,6 +911,12 @@ __SYSCALL(__NR_set_mempolicy_home_node, sys_set_mempolicy_home_node) __SYSCALL(__NR_cachestat, sys_cachestat)#define __NR_fchmodat2 452 __SYSCALL(__NR_fchmodat2, sys_fchmodat2) +#define __NR_lsm_get_self_attr 453 +__SYSCALL(__NR_lsm_get_self_attr, sys_lsm_get_self_attr) +#define __NR_lsm_set_self_attr 454 +__SYSCALL(__NR_lsm_set_self_attr, sys_lsm_set_self_attr) +#define __NR_lsm_list_modules 455 +__SYSCALL (__NR_lsm_list_modules, sys_lsm_list_modules)/* * Please add new compat syscalls above this comment and update
arch/ia64/kernel/syscalls/syscall.tbl +3 -0
@@ -373,3 +373,6 @@ 450 common set_mempolicy_home_node sys_set_mempolicy_home_node 451 common cachestat sys_cachestat 452 common fchmodat2 sys_fchmodat2 +453 common lsm_get_self_attr sys_lsm_get_self_attr +454 common lsm_set_self_attr sys_lsm_set_self_attr +455 common lsm_list_modules sys_lsm_list_modules
arch/m68k/kernel/syscalls/syscall.tbl +3 -0
@@ -452,3 +452,6 @@ 450 common set_mempolicy_home_node sys_set_mempolicy_home_node 451 common cachestat sys_cachestat 452 common fchmodat2 sys_fchmodat2 +453 common lsm_get_self_attr sys_lsm_get_self_attr +454 common lsm_set_self_attr sys_lsm_set_self_attr +455 common lsm_list_modules sys_lsm_list_modules
arch/microblaze/kernel/syscalls/syscall.tbl +3 -0
@@ -458,3 +458,6 @@ 450 common set_mempolicy_home_node sys_set_mempolicy_home_node 451 common cachestat sys_cachestat 452 common fchmodat2 sys_fchmodat2 +453 common lsm_get_self_attr sys_lsm_get_self_attr +454 common lsm_set_self_attr sys_lsm_set_self_attr +455 common lsm_list_modules sys_lsm_list_modules
arch/mips/kernel/syscalls/syscall_n32.tbl +3 -0
@@ -391,3 +391,6 @@ 450 n32 set_mempolicy_home_node sys_set_mempolicy_home_node 451 n32 cachestat sys_cachestat 452 n32 fchmodat2 sys_fchmodat2 +453 n32 lsm_get_self_attr sys_lsm_get_self_attr +454 n32 lsm_set_self_attr sys_lsm_set_self_attr +455 n32 lsm_list_modules sys_lsm_list_modules
arch/mips/kernel/syscalls/syscall_n64.tbl +3 -0
@@ -367,3 +367,6 @@ 450 common set_mempolicy_home_node sys_set_mempolicy_home_node 451 n64 cachestat sys_cachestat 452 n64 fchmodat2 sys_fchmodat2 +453 n64 lsm_get_self_attr sys_lsm_get_self_attr +454 n64 lsm_set_self_attr sys_lsm_set_self_attr +455 n64 lsm_list_modules sys_lsm_list_modules
arch/mips/kernel/syscalls/syscall_o32.tbl +3 -0
@@ -440,3 +440,6 @@ 450 o32 set_mempolicy_home_node sys_set_mempolicy_home_node 451 o32 cachestat sys_cachestat 452 o32 fchmodat2 sys_fchmodat2 +453 o32 lsm_get_self_attr sys_lsm_get_self_attr +454 032 lsm_set_self_attr sys_lsm_set_self_attr +455 o32 lsm_list_modules sys_lsm_list_modules
arch/parisc/kernel/syscalls/syscall.tbl +3 -0
@@ -451,3 +451,6 @@ 450 common set_mempolicy_home_node sys_set_mempolicy_home_node 451 common cachestat sys_cachestat 452 common fchmodat2 sys_fchmodat2 +453 common lsm_get_self_attr sys_lsm_get_self_attr +454 common lsm_set_self_attr sys_lsm_set_self_attr +455 common lsm_list_modules sys_lsm_list_modules
arch/powerpc/kernel/syscalls/syscall.tbl +3 -0
@@ -539,3 +539,6 @@ 450 nospu set_mempolicy_home_node sys_set_mempolicy_home_node 451 common cachestat sys_cachestat 452 common fchmodat2 sys_fchmodat2 +453 common lsm_get_self_attr sys_lsm_get_self_attr +454 common lsm_set_self_attr sys_lsm_set_self_attr +455 common lsm_list_modules sys_lsm_list_modules
arch/s390/kernel/syscalls/syscall.tbl +3 -0
@@ -455,3 +455,6 @@ 450 common set_mempolicy_home_node sys_set_mempolicy_home_node sys_set_mempolicy_home_node 451 common cachestat sys_cachestat sys_cachestat 452 common fchmodat2 sys_fchmodat2 sys_fchmodat2 +453 common lsm_get_self_attr sys_lsm_get_self_attr sys_lsm_get_self_attr +454 common lsm_set_self_attr sys_lsm_set_self_attr sys_lsm_set_self_attr +455 common lsm_list_modules sys_lsm_list_modules sys_lsm_list_modules
arch/sh/kernel/syscalls/syscall.tbl +3 -0
@@ -455,3 +455,6 @@ 450 common set_mempolicy_home_node sys_set_mempolicy_home_node 451 common cachestat sys_cachestat 452 common fchmodat2 sys_fchmodat2 +453 common lsm_get_self_attr sys_lsm_get_self_attr +454 common lsm_set_self_attr sys_lsm_set_self_attr +455 common lsm_list_modules sys_lsm_list_modules
arch/sparc/kernel/syscalls/syscall.tbl +3 -0
@@ -498,3 +498,6 @@ 450 common set_mempolicy_home_node sys_set_mempolicy_home_node 451 common cachestat sys_cachestat 452 common fchmodat2 sys_fchmodat2 +453 common lsm_get_self_attr sys_lsm_get_self_attr +454 common lsm_set_self_attr sys_lsm_set_self_attr +455 common lsm_list_modules sys_lsm_list_modules
arch/x86/entry/syscalls/syscall_32.tbl +3 -0
@@ -457,3 +457,6 @@ 450 i386 set_mempolicy_home_node sys_set_mempolicy_home_node 451 i386 cachestat sys_cachestat 452 i386 fchmodat2 sys_fchmodat2 +453 i386 lsm_get_self_attr sys_lsm_get_self_attr +454 i386 lsm_set_self_attr sys_lsm_set_self_attr +455 i386 lsm_list_modules sys_lsm_list_modules
arch/x86/entry/syscalls/syscall_64.tbl +3 -0
@@ -375,6 +375,9 @@ 451 common cachestat sys_cachestat 452 common fchmodat2 sys_fchmodat2 453 64 map_shadow_stack sys_map_shadow_stack +454 common lsm_get_self_attr sys_lsm_get_self_attr +455 common lsm_set_self_attr sys_lsm_set_self_attr +456 common lsm_list_modules sys_lsm_list_modules # # Due to a historical design error, certain syscalls are numbered differently
arch/xtensa/kernel/syscalls/syscall.tbl +3 -0
@@ -423,3 +423,6 @@ 450 common set_mempolicy_home_node sys_set_mempolicy_home_node 451 common cachestat sys_cachestat 452 common fchmodat2 sys_fchmodat2 +453 common lsm_get_self_attr sys_lsm_get_self_attr +454 common lsm_set_self_attr sys_lsm_set_self_attr +455 common lsm_list_modules sys_lsm_list_modules
include/uapi/asm-generic/unistd.h +8 -1
@@ -823,8 +823,15 @@ __SYSCALL(__NR_cachestat, sys_cachestat)#define __NR_fchmodat2 452 __SYSCALL(__NR_fchmodat2, sys_fchmodat2) +#define __NR_lsm_get_self_attr 453 +__SYSCALL(__NR_lsm_get_self_attr, sys_lsm_get_self_attr) +#define __NR_lsm_set_self_attr 454 +__SYSCALL(__NR_lsm_set_self_attr, sys_lsm_set_self_attr) +#define __NR_lsm_list_modules 455 +__SYSCALL(__NR_lsm_list_modules, sys_lsm_list_modules) +#undef __NR_syscalls -#define __NR_syscalls 453 +#define __NR_syscalls 456/* * 32 bit systems traditionally used different
tools/perf/arch/mips/entry/syscalls/syscall_n64.tbl +3 -0
@@ -366,3 +366,6 @@ 449 n64 futex_waitv sys_futex_waitv 450 common set_mempolicy_home_node sys_set_mempolicy_home_node 451 n64 cachestat sys_cachestat +453 n64 lsm_get_self_attr sys_lsm_get_self_attr +454 n64 lsm_set_self_attr sys_lsm_set_self_attr +455 n64 lsm_list_modules sys_lsm_list_modules
tools/perf/arch/powerpc/entry/syscalls/syscall.tbl +3 -0
@@ -538,3 +538,6 @@ 449 common futex_waitv sys_futex_waitv 450 nospu set_mempolicy_home_node sys_set_mempolicy_home_node 451 common cachestat sys_cachestat +453 common lsm_get_self_attr sys_lsm_get_self_attr +454 common lsm_set_self_attr sys_lsm_set_self_attr +455 common lsm_list_modules sys_lsm_list_modules
tools/perf/arch/s390/entry/syscalls/syscall.tbl +3 -0
@@ -454,3 +454,6 @@ 449 common futex_waitv sys_futex_waitv sys_futex_waitv 450 common set_mempolicy_home_node sys_set_mempolicy_home_node sys_set_mempolicy_home_node 451 common cachestat sys_cachestat sys_cachestat +453 common lsm_get_self_attr sys_lsm_get_self_attr sys_lsm_get_self_attr +454 common lsm_set_self_attr sys_lsm_set_self_attr sys_lsm_set_self_attr +455 common lsm_list_modules sys_lsm_list_modules sys_lsm_list_modules
tools/perf/arch/x86/entry/syscalls/syscall_64.tbl +3 -0
@@ -373,6 +373,9 @@ 449 common futex_waitv sys_futex_waitv 450 common set_mempolicy_home_node sys_set_mempolicy_home_node 451 common cachestat sys_cachestat +453 common lsm_get_self_attr sys_lsm_get_self_attr +454 common lsm_set_self_attr sys_lsm_set_self_attr +455 common lsm_list_modules sys_lsm_list_modules # # Due to a historical design error, certain syscalls are numbered differently
Signature · 1 line
2.41.0
Re: [PATCH v15 06/11] LSM: wireup Linux Security Module syscalls
Quoted 5 lines · Casey Schaufler
Wireup
lsm_get_self_attr,lsm_set_self_attrandlsm_list_modulessystem calls.Signed-off-by Casey Schaufler <[email protected]>Reviewed-by Kees Cook <[email protected]>
Quoted 309 lines
Acked-by Arnd Bergmann <[email protected]>--- arch/alpha/kernel/syscalls/syscall.tbl | 3 +++ arch/arm/tools/syscall.tbl | 3 +++ arch/arm64/include/asm/unistd.h | 2 +- arch/arm64/include/asm/unistd32.h | 6 ++++++ arch/ia64/kernel/syscalls/syscall.tbl | 3 +++ arch/m68k/kernel/syscalls/syscall.tbl | 3 +++ arch/microblaze/kernel/syscalls/syscall.tbl | 3 +++ arch/mips/kernel/syscalls/syscall_n32.tbl | 3 +++ arch/mips/kernel/syscalls/syscall_n64.tbl | 3 +++ arch/mips/kernel/syscalls/syscall_o32.tbl | 3 +++ arch/parisc/kernel/syscalls/syscall.tbl | 3 +++ arch/powerpc/kernel/syscalls/syscall.tbl | 3 +++ arch/s390/kernel/syscalls/syscall.tbl | 3 +++ arch/sh/kernel/syscalls/syscall.tbl | 3 +++ arch/sparc/kernel/syscalls/syscall.tbl | 3 +++ arch/x86/entry/syscalls/syscall_32.tbl | 3 +++ arch/x86/entry/syscalls/syscall_64.tbl | 3 +++ arch/xtensa/kernel/syscalls/syscall.tbl | 3 +++ include/uapi/asm-generic/unistd.h | 9 ++++++++- tools/perf/arch/mips/entry/syscalls/syscall_n64.tbl | 3 +++ tools/perf/arch/powerpc/entry/syscalls/syscall.tbl | 3 +++ tools/perf/arch/s390/entry/syscalls/syscall.tbl | 3 +++ tools/perf/arch/x86/entry/syscalls/syscall_64.tbl | 3 +++ 23 files changed, 75 insertions(+), 2 deletions(-)arch/alpha/kernel/syscalls/syscall.tbl +3
-0@@ -492,3 +492,6 @@ 560 common set_mempolicy_home_node sys_ni_syscall 561 common cachestat sys_cachestat 562 common fchmodat2 sys_fchmodat2 +563 common lsm_get_self_attr sys_lsm_get_self_attr +564 common lsm_set_self_attr sys_lsm_set_self_attr +565 common lsm_list_modules sys_lsm_list_modulesarch/arm/tools/syscall.tbl +3
-0@@ -466,3 +466,6 @@ 450 common set_mempolicy_home_node sys_set_mempolicy_home_node 451 common cachestat sys_cachestat 452 common fchmodat2 sys_fchmodat2 +453 common lsm_get_self_attr sys_lsm_get_self_attr +454 common lsm_set_self_attr sys_lsm_set_self_attr +455 common lsm_list_modules sys_lsm_list_modulesarch/arm64/include/asm/unistd.h +1
-1@@ -39,7 +39,7 @@#define __ARM_NR_compat_set_tls (__ARM_NR_COMPAT_BASE + 5)#define __ARM_NR_COMPAT_END (__ARM_NR_COMPAT_BASE + 0x800) -#define __NR_compat_syscalls 453 +#define __NR_compat_syscalls 456#endif #define __ARCH_WANT_SYS_CLONEarch/arm64/include/asm/unistd32.h +6
-0@@ -911,6 +911,12 @@ __SYSCALL(__NR_set_mempolicy_home_node, sys_set_mempolicy_home_node) __SYSCALL(__NR_cachestat, sys_cachestat)#define __NR_fchmodat2 452 __SYSCALL(__NR_fchmodat2, sys_fchmodat2) +#define __NR_lsm_get_self_attr 453 +__SYSCALL(__NR_lsm_get_self_attr, sys_lsm_get_self_attr) +#define __NR_lsm_set_self_attr 454 +__SYSCALL(__NR_lsm_set_self_attr, sys_lsm_set_self_attr) +#define __NR_lsm_list_modules 455 +__SYSCALL (__NR_lsm_list_modules, sys_lsm_list_modules)/* * Please add new compat syscalls above this comment and update arch/ia64/kernel/syscalls/syscall.tbl +3
-0@@ -373,3 +373,6 @@ 450 common set_mempolicy_home_node sys_set_mempolicy_home_node 451 common cachestat sys_cachestat 452 common fchmodat2 sys_fchmodat2 +453 common lsm_get_self_attr sys_lsm_get_self_attr +454 common lsm_set_self_attr sys_lsm_set_self_attr +455 common lsm_list_modules sys_lsm_list_modulesarch/m68k/kernel/syscalls/syscall.tbl +3
-0@@ -452,3 +452,6 @@ 450 common set_mempolicy_home_node sys_set_mempolicy_home_node 451 common cachestat sys_cachestat 452 common fchmodat2 sys_fchmodat2 +453 common lsm_get_self_attr sys_lsm_get_self_attr +454 common lsm_set_self_attr sys_lsm_set_self_attr +455 common lsm_list_modules sys_lsm_list_modulesarch/microblaze/kernel/syscalls/syscall.tbl +3
-0@@ -458,3 +458,6 @@ 450 common set_mempolicy_home_node sys_set_mempolicy_home_node 451 common cachestat sys_cachestat 452 common fchmodat2 sys_fchmodat2 +453 common lsm_get_self_attr sys_lsm_get_self_attr +454 common lsm_set_self_attr sys_lsm_set_self_attr +455 common lsm_list_modules sys_lsm_list_modulesarch/mips/kernel/syscalls/syscall_n32.tbl +3
-0@@ -391,3 +391,6 @@ 450 n32 set_mempolicy_home_node sys_set_mempolicy_home_node 451 n32 cachestat sys_cachestat 452 n32 fchmodat2 sys_fchmodat2 +453 n32 lsm_get_self_attr sys_lsm_get_self_attr +454 n32 lsm_set_self_attr sys_lsm_set_self_attr +455 n32 lsm_list_modules sys_lsm_list_modulesarch/mips/kernel/syscalls/syscall_n64.tbl +3
-0@@ -367,3 +367,6 @@ 450 common set_mempolicy_home_node sys_set_mempolicy_home_node 451 n64 cachestat sys_cachestat 452 n64 fchmodat2 sys_fchmodat2 +453 n64 lsm_get_self_attr sys_lsm_get_self_attr +454 n64 lsm_set_self_attr sys_lsm_set_self_attr +455 n64 lsm_list_modules sys_lsm_list_modulesarch/mips/kernel/syscalls/syscall_o32.tbl +3
-0@@ -440,3 +440,6 @@ 450 o32 set_mempolicy_home_node sys_set_mempolicy_home_node 451 o32 cachestat sys_cachestat 452 o32 fchmodat2 sys_fchmodat2 +453 o32 lsm_get_self_attr sys_lsm_get_self_attr +454 032 lsm_set_self_attr sys_lsm_set_self_attr +455 o32 lsm_list_modules sys_lsm_list_modulesarch/parisc/kernel/syscalls/syscall.tbl +3
-0@@ -451,3 +451,6 @@ 450 common set_mempolicy_home_node sys_set_mempolicy_home_node 451 common cachestat sys_cachestat 452 common fchmodat2 sys_fchmodat2 +453 common lsm_get_self_attr sys_lsm_get_self_attr +454 common lsm_set_self_attr sys_lsm_set_self_attr +455 common lsm_list_modules sys_lsm_list_modulesarch/powerpc/kernel/syscalls/syscall.tbl +3
-0@@ -539,3 +539,6 @@ 450 nospu set_mempolicy_home_node sys_set_mempolicy_home_node 451 common cachestat sys_cachestat 452 common fchmodat2 sys_fchmodat2 +453 common lsm_get_self_attr sys_lsm_get_self_attr +454 common lsm_set_self_attr sys_lsm_set_self_attr +455 common lsm_list_modules sys_lsm_list_modulesarch/s390/kernel/syscalls/syscall.tbl +3
-0@@ -455,3 +455,6 @@ 450 common set_mempolicy_home_node sys_set_mempolicy_home_node sys_set_mempolicy_home_node 451 common cachestat sys_cachestat sys_cachestat 452 common fchmodat2 sys_fchmodat2 sys_fchmodat2 +453 common lsm_get_self_attr sys_lsm_get_self_attr sys_lsm_get_self_attr +454 common lsm_set_self_attr sys_lsm_set_self_attr sys_lsm_set_self_attr +455 common lsm_list_modules sys_lsm_list_modules sys_lsm_list_modulesarch/sh/kernel/syscalls/syscall.tbl +3
-0@@ -455,3 +455,6 @@ 450 common set_mempolicy_home_node sys_set_mempolicy_home_node 451 common cachestat sys_cachestat 452 common fchmodat2 sys_fchmodat2 +453 common lsm_get_self_attr sys_lsm_get_self_attr +454 common lsm_set_self_attr sys_lsm_set_self_attr +455 common lsm_list_modules sys_lsm_list_modulesarch/sparc/kernel/syscalls/syscall.tbl +3
-0@@ -498,3 +498,6 @@ 450 common set_mempolicy_home_node sys_set_mempolicy_home_node 451 common cachestat sys_cachestat 452 common fchmodat2 sys_fchmodat2 +453 common lsm_get_self_attr sys_lsm_get_self_attr +454 common lsm_set_self_attr sys_lsm_set_self_attr +455 common lsm_list_modules sys_lsm_list_modulesarch/x86/entry/syscalls/syscall_32.tbl +3
-0@@ -457,3 +457,6 @@ 450 i386 set_mempolicy_home_node sys_set_mempolicy_home_node 451 i386 cachestat sys_cachestat 452 i386 fchmodat2 sys_fchmodat2 +453 i386 lsm_get_self_attr sys_lsm_get_self_attr +454 i386 lsm_set_self_attr sys_lsm_set_self_attr +455 i386 lsm_list_modules sys_lsm_list_modulesarch/x86/entry/syscalls/syscall_64.tbl +3
-0@@ -375,6 +375,9 @@ 451 common cachestat sys_cachestat 452 common fchmodat2 sys_fchmodat2 453 64 map_shadow_stack sys_map_shadow_stack +454 common lsm_get_self_attr sys_lsm_get_self_attr +455 common lsm_set_self_attr sys_lsm_set_self_attr +456 common lsm_list_modules sys_lsm_list_modules # # Due to a historical design error, certain syscalls are numbered differentlyarch/xtensa/kernel/syscalls/syscall.tbl +3
-0@@ -423,3 +423,6 @@ 450 common set_mempolicy_home_node sys_set_mempolicy_home_node 451 common cachestat sys_cachestat 452 common fchmodat2 sys_fchmodat2 +453 common lsm_get_self_attr sys_lsm_get_self_attr +454 common lsm_set_self_attr sys_lsm_set_self_attr +455 common lsm_list_modules sys_lsm_list_modulesinclude/uapi/asm-generic/unistd.h +8
-1@@ -823,8 +823,15 @@ __SYSCALL(__NR_cachestat, sys_cachestat)#define __NR_fchmodat2 452 __SYSCALL(__NR_fchmodat2, sys_fchmodat2) +#define __NR_lsm_get_self_attr 453 +__SYSCALL(__NR_lsm_get_self_attr, sys_lsm_get_self_attr) +#define __NR_lsm_set_self_attr 454 +__SYSCALL(__NR_lsm_set_self_attr, sys_lsm_set_self_attr) +#define __NR_lsm_list_modules 455 +__SYSCALL(__NR_lsm_list_modules, sys_lsm_list_modules) +#undef __NR_syscalls -#define __NR_syscalls 453 +#define __NR_syscalls 456/* * 32 bit systems traditionally used different tools/perf/arch/mips/entry/syscalls/syscall_n64.tbl +3
-0@@ -366,3 +366,6 @@ 449 n64 futex_waitv sys_futex_waitv 450 common set_mempolicy_home_node sys_set_mempolicy_home_node 451 n64 cachestat sys_cachestat +453 n64 lsm_get_self_attr sys_lsm_get_self_attr +454 n64 lsm_set_self_attr sys_lsm_set_self_attr +455 n64 lsm_list_modules sys_lsm_list_modulestools/perf/arch/powerpc/entry/syscalls/syscall.tbl +3
-0@@ -538,3 +538,6 @@ 449 common futex_waitv sys_futex_waitv 450 nospu set_mempolicy_home_node sys_set_mempolicy_home_node 451 common cachestat sys_cachestat +453 common lsm_get_self_attr sys_lsm_get_self_attr +454 common lsm_set_self_attr sys_lsm_set_self_attr +455 common lsm_list_modules sys_lsm_list_modulestools/perf/arch/s390/entry/syscalls/syscall.tbl +3
-0@@ -454,3 +454,6 @@ 449 common futex_waitv sys_futex_waitv sys_futex_waitv 450 common set_mempolicy_home_node sys_set_mempolicy_home_node sys_set_mempolicy_home_node 451 common cachestat sys_cachestat sys_cachestat +453 common lsm_get_self_attr sys_lsm_get_self_attr sys_lsm_get_self_attr +454 common lsm_set_self_attr sys_lsm_set_self_attr sys_lsm_set_self_attr +455 common lsm_list_modules sys_lsm_list_modules sys_lsm_list_modulestools/perf/arch/x86/entry/syscalls/syscall_64.tbl +3
-0@@ -373,6 +373,9 @@ 449 common futex_waitv sys_futex_waitv 450 common set_mempolicy_home_node sys_set_mempolicy_home_node 451 common cachestat sys_cachestat +453 common lsm_get_self_attr sys_lsm_get_self_attr +454 common lsm_set_self_attr sys_lsm_set_self_attr +455 common lsm_list_modules sys_lsm_list_modules # # Due to a historical design error, certain syscalls are numbered differentlySignature · 1 line
2.41.0
Casey Schaufler
maintainerPATCH v15 7/11 LSM: Helpers for attribute names and filling lsm_ctx
In reply to Casey SchauflerAdd lsm_name_to_attr(), which translates a text string to a LSM_ATTR value if one is available.
Add lsm_fill_user_ctx(), which fills a struct lsm_ctx, including the trailing attribute value.
Both are used in module specific components of LSM system calls.
--- include/linux/security.h | 14 ++++++++++++++ security/lsm_syscalls.c | 24 +++++++++++++++++++++++ security/security.c | 41 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 79 insertions(+)
include/linux/security.h +14 -0
@@ -32,6 +32,7 @@#include <linux/string.h> #include <linux/mm.h> #include <linux/sockptr.h> +#include <uapi/linux/lsm.h> struct linux_binprm ;struct cred ;
@@ -264,6 +265,7 @@ int unregister_blocking_lsm_notifier(struct notifier_block *nb);/* prototypes */ extern int security_init (void );extern int early_security_init (void ); +extern u64 lsm_name_to_attr (const char *name);/* Security operations */ int security_binder_set_context_mgr (const struct cred *mgr);
@@ -490,6 +492,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); +int lsm_fill_user_ctx (struct lsm_ctx __user *ctx,void *context, +size_t context_size,u64 id,u64 flags);#else /* CONFIG_SECURITY */ static inline int call_blocking_lsm_notifier (enum lsm_event event,void *data)
@@ -507,6 +511,11 @@ static inline int unregister_blocking_lsm_notifier(struct notifier_block *nb)return 0 ; } +static inline u64 lsm_name_to_attr (const char *name) +{ +return LSM_ATTR_UNDEF ; +} +static inline void security_free_mnt_opts (void **mnt_opts) { }
@@ -1415,6 +1424,11 @@ static inline int security_locked_down(enum lockdown_reason what) {return 0 ; } +static inline int lsm_fill_user_ctx (struct lsm_ctx __user *ctx,void *context, +size_t context_size,u64 id,u64 flags) +{ +return -EOPNOTSUPP ; +}#endif /* CONFIG_SECURITY */ #if defined(CONFIG_SECURITY ) && defined(CONFIG_WATCH_QUEUE )
security/lsm_syscalls.c +24 -0
@@ -17,6 +17,30 @@#include <linux/lsm_hooks.h> #include <uapi/linux/lsm.h> +/** +* lsm_name_to_attr - map an LSM attribute name to its ID +* @name: name of the attribute +* +* Returns the LSM attribute value associated with @name, or 0 if +* there is no mapping. +*/ +u64 lsm_name_to_attr (const char *name) +{ +if (!strcmp (name,"current" )) +return LSM_ATTR_CURRENT ; +if (!strcmp (name,"exec" )) +return LSM_ATTR_EXEC ; +if (!strcmp (name,"fscreate" )) +return LSM_ATTR_FSCREATE ; +if (!strcmp (name,"keycreate" )) +return LSM_ATTR_KEYCREATE ; +if (!strcmp (name,"prev" )) +return LSM_ATTR_PREV ; +if (!strcmp (name,"sockcreate" )) +return LSM_ATTR_SOCKCREATE ; +return LSM_ATTR_UNDEF ; +} +/** * sys_lsm_set_self_attr - Set current task's security module attribute * @attr: which attribute to set
security/security.c +41 -0
47 lines not on this page · raw message
Signature · 1 line
2.41.0
Re: [PATCH v15 07/11] LSM: Helpers for attribute names and filling lsm_ctx
Quoted 11 lines · Casey Schaufler
Add
lsm_name_to_attr(), which translates a text string to aLSM_ATTRvalue if one is available.Add
lsm_fill_user_ctx(), which fills a structlsm_ctx, including the trailing attribute value.Both are used in module specific components of LSM system calls.
Signed-off-by Casey Schaufler <[email protected]>Reviewed-by John Johansen <[email protected]>Reviewed-by Serge Hallyn <[email protected]>
Quoted 149 lines
--- include/linux/security.h | 14 ++++++++++++++ security/lsm_syscalls.c | 24 +++++++++++++++++++++++ security/security.c | 41 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 79 insertions(+)include/linux/security.h +14
-0@@ -32,6 +32,7 @@#include <linux/string.h> #include <linux/mm.h> #include <linux/sockptr.h> +#include <uapi/linux/lsm.h> struct linux_binprm ;struct cred ;@@ -264,6 +265,7 @@ int unregister_blocking_lsm_notifier(struct notifier_block *nb);/* prototypes */ extern int security_init (void );extern int early_security_init (void ); +extern u64 lsm_name_to_attr (const char *name);/* Security operations */ int security_binder_set_context_mgr (const struct cred *mgr);@@ -490,6 +492,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); +int lsm_fill_user_ctx (struct lsm_ctx __user *ctx,void *context, +size_t context_size,u64 id,u64 flags);#else /* CONFIG_SECURITY */ static inline int call_blocking_lsm_notifier (enum lsm_event event,void *data)@@ -507,6 +511,11 @@ static inline int unregister_blocking_lsm_notifier(struct notifier_block *nb)return 0 ; } +static inline u64 lsm_name_to_attr (const char *name) +{ +return LSM_ATTR_UNDEF ; +} +static inline void security_free_mnt_opts (void **mnt_opts) { }@@ -1415,6 +1424,11 @@ static inline int security_locked_down(enum lockdown_reason what) {return 0 ; } +static inline int lsm_fill_user_ctx (struct lsm_ctx __user *ctx,void *context, +size_t context_size,u64 id,u64 flags) +{ +return -EOPNOTSUPP ; +}#endif /* CONFIG_SECURITY */ #if defined(CONFIG_SECURITY ) && defined(CONFIG_WATCH_QUEUE )security/lsm_syscalls.c +24
-0@@ -17,6 +17,30 @@#include <linux/lsm_hooks.h> #include <uapi/linux/lsm.h> +/** +* lsm_name_to_attr - map an LSM attribute name to its ID +* @name: name of the attribute +* +* Returns the LSM attribute value associated with @name, or 0 if +* there is no mapping. +*/ +u64 lsm_name_to_attr (const char *name) +{ +if (!strcmp (name,"current" )) +return LSM_ATTR_CURRENT ; +if (!strcmp (name,"exec" )) +return LSM_ATTR_EXEC ; +if (!strcmp (name,"fscreate" )) +return LSM_ATTR_FSCREATE ; +if (!strcmp (name,"keycreate" )) +return LSM_ATTR_KEYCREATE ; +if (!strcmp (name,"prev" )) +return LSM_ATTR_PREV ; +if (!strcmp (name,"sockcreate" )) +return LSM_ATTR_SOCKCREATE ; +return LSM_ATTR_UNDEF ; +} +/** * sys_lsm_set_self_attr - Set current task's security module attribute * @attr: which attribute to set security/security.c +41
-0@@ -771,6 +771,47 @@ static int lsm_superblock_alloc(struct super_block *sb)return 0 ; } +/** +* lsm_fill_user_ctx - Fill a user space lsm_ctx structure +* @ctx: an LSM context to be filled +* @context: the new context value +* @context_size: the size of the new context value +* @id: LSM id +* @flags: LSM defined flags +* +* Fill all of the fields in a user space lsm_ctx structure. +* Caller is assumed to have verified that @ctx has enough space +* for @context. +* +* Returns 0 on success, -EFAULT on a copyout error, -ENOMEM +* if memory can't be allocated. +*/ +int lsm_fill_user_ctx (struct lsm_ctx __user *ctx,void *context, +size_t context_size,u64 id,u64 flags) +{ +struct lsm_ctx *lctx; +size_t locallen =struct_size (lctx, ctx, context_size); +int rc =0 ; + + lctx =kzalloc (locallen,GFP_KERNEL ); +if (lctx ==NULL ) +return -ENOMEM ; + + lctx->id = id; + lctx->flags = flags; + lctx->ctx_len = context_size; + lctx->len = locallen; + +memcpy (lctx->ctx, context, context_size); + +if (copy_to_user (ctx, lctx, locallen)) + rc = -EFAULT ; + +kfree (lctx); + +return rc; +} +/* * The default value of the LSM hook is defined in linux/lsm_hook_defs.h and * can be accessed with: Signature · 1 line
2.41.0
Casey Schaufler
maintainerPATCH v15 8/11 Smack: implement setselfattr and getselfattr hooks
In reply to Casey SchauflerImplement Smack support for security_[gs]etselfattr. Refactor the setprocattr hook to avoid code duplication.
--- security/smack/smack_lsm.c | 95 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 90 insertions(+), 5 deletions(-)
security/smack/smack_lsm.c +90 -5
@@ -3626,6 +3626,46 @@ static void smack_d_instantiate(struct dentry *opt_dentry, struct inode *inode)return ; } +/** +* smack_getselfattr - Smack current process attribute +* @attr: which attribute to fetch +* @ctx: buffer to receive the result +* @size: available size in, actual size out +* @flags: unused +* +* Fill the passed user space @ctx with the details of the requested +* attribute. +* +* Returns the number of attributes on success, an error code otherwise. +* There will only ever be one attribute. +*/ +static int smack_getselfattr (unsigned int attr,struct lsm_ctx __user *ctx, +size_t *size,u32 flags) +{ +struct smack_known *skp =smk_of_current (); +int total; +int slen; +int rc; + +if (attr !=LSM_ATTR_CURRENT ) +return -EOPNOTSUPP ; + + slen =strlen (skp->smk_known) +1 ; + total =ALIGN (slen +sizeof (*ctx),8 ); +if (total > *size) + rc = -E2BIG ; +else if (ctx) + rc =lsm_fill_user_ctx (ctx, skp->smk_known, slen,LSM_ID_SMACK , +0 ); +else + rc =1 ; + + *size = total; +if (rc >=0 ) +return 1 ; +return rc; +} +/** * smack_getprocattr - Smack process attribute access * @p: the object task
@@ -3655,8 +3695,8 @@ static int smack_getprocattr(struct task_struct *p, const char *name, char **val }/** -* smack_setprocattr - Smack process attribute setting -* @name: the name of the attribute in /proc/.../attr +* do_setattr - Smack process attribute setting +* @attr: the ID of the attribute * @value: the value to set * @size: the size of the value *
@@ -3665,7 +3705,7 @@ static int smack_getprocattr(struct task_struct *p, const char *name, char **val* * Returns the length of the smack label or an error code */ -static int smack_setprocattr (const char *name,void *value,size_t size) +static int do_setattr (u64 attr,void *value,size_t size) {struct task_smack *tsp =smack_cred (current_cred ());struct cred *new;
@@ -3679,8 +3719,8 @@ static int smack_setprocattr(const char *name, void *value, size_t size)if (value ==NULL || size ==0 || size >=SMK_LONGLABEL )return -EINVAL ; -if (strcmp (name,"current" ) !=0 ) -return -EINVAL ; +if (attr !=LSM_ATTR_CURRENT ) +return -EOPNOTSUPP ; skp =smk_import_entry (value, size);if (IS_ERR (skp))
@@ -3719,6 +3759,49 @@ static int smack_setprocattr(const char *name, void *value, size_t size)return size; } +/** +* smack_setselfattr - Set a Smack process attribute +* @attr: which attribute to set +* @ctx: buffer containing the data +* @size: size of @ctx +* @flags: unused +* +* Fill the passed user space @ctx with the details of the requested +* attribute. +* +* Returns 0 on success, an error code otherwise. +*/ +static int smack_setselfattr (unsigned int attr,struct lsm_ctx *ctx, +size_t size,u32 flags) +{ +int rc; + + rc =do_setattr (attr, ctx->ctx, ctx->ctx_len); +if (rc >0 ) +return 0 ; +return rc; +} + +/** +* smack_setprocattr - Smack process attribute setting +* @name: the name of the attribute in /proc/.../attr +* @value: the value to set +* @size: the size of the value +* +* Sets the Smack value of the task. Only setting self +* is permitted and only with privilege +* +* Returns the length of the smack label or an error code +*/ +static int smack_setprocattr (const char *name,void *value,size_t size) +{ +int attr =lsm_name_to_attr (name); + +if (attr !=LSM_ATTR_UNDEF ) +return do_setattr (attr, value, size); +return -EINVAL ; +} +/** * smack_unix_stream_connect - Smack access on UDS * @sock: one sock
@@ -5033,6 +5116,8 @@ static struct security_hook_list smack_hooks[] __ro_after_init = {LSM_HOOK_INIT (d_instantiate, smack_d_instantiate), +LSM_HOOK_INIT (getselfattr, smack_getselfattr), +LSM_HOOK_INIT (setselfattr, smack_setselfattr),LSM_HOOK_INIT (getprocattr, smack_getprocattr), LSM_HOOK_INIT(setprocattr, smack_setprocattr),
Signature · 1 line
2.41.0
Mickaël Salaün
maintainerRe: [PATCH v15 08/11] Smack: implement setselfattr and getselfattr hooks
Quoted 42 lines · Casey Schaufler
Implement Smack support for security_[gs]etselfattr. Refactor the setprocattr hook to avoid code duplication.
Signed-off-by Casey Schaufler <[email protected]>Reviewed-by John Johansen <[email protected]>--- security/smack/smack_lsm.c | 95 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 90 insertions(+), 5 deletions(-)security/smack/smack_lsm.c +25
-0@@ -3626,6 +3626,46 @@ static void smack_d_instantiate(struct dentry *opt_dentry, struct inode *inode)return ; } +/** +* smack_getselfattr - Smack current process attribute +* @attr: which attribute to fetch +* @ctx: buffer to receive the result +* @size: available size in, actual size out +* @flags: unused +* +* Fill the passed user space @ctx with the details of the requested +* attribute. +* +* Returns the number of attributes on success, an error code otherwise. +* There will only ever be one attribute. +*/ +static int smack_getselfattr (unsigned int attr,struct lsm_ctx __user *ctx, +size_t *size,u32 flags) +{ +struct smack_known *skp =smk_of_current (); +int total; +int slen; +int rc; + +if (attr !=LSM_ATTR_CURRENT ) +return -EOPNOTSUPP ; + + slen =strlen (skp->smk_known) +1 ;
security/smack/smack_lsm.c static void smack_d_instantiate(struct dentry *opt_dentry, struct inode *inode) · line 3663
Quoted 10 lines
security/smack/smack_lsm.c +8
-0+ total =ALIGN (slen +sizeof (*ctx),8 ); +if (total > *size) + rc = -E2BIG ; +else if (ctx) + rc =lsm_fill_user_ctx (ctx, skp->smk_known, slen,LSM_ID_SMACK , +0 ); +else + rc =1 ;
Can we move these checks into lsm_fill_user_ctx()? They are similar for AppArmor and SELinux.
Quoted 6 lines
security/smack/smack_lsm.c +6
-0+ + *size = total; +if (rc >=0 ) +return 1 ; +return rc; +}
Casey Schaufler
maintainerRe: [PATCH v15 08/11] Smack: implement setselfattr and getselfattr hooks
Quoted 61 lines · Mickaël Salaün
Quoted 41 lines · Casey Schaufler
Implement Smack support for security_[gs]etselfattr. Refactor the setprocattr hook to avoid code duplication.
Signed-off-by Casey Schaufler <[email protected]>Reviewed-by John Johansen <[email protected]>--- security/smack/smack_lsm.c | 95 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 90 insertions(+), 5 deletions(-)security/smack/smack_lsm.c +24
-0@@ -3626,6 +3626,46 @@ static void smack_d_instantiate(struct dentry *opt_dentry, struct inode *inode)return ; } +/** +* smack_getselfattr - Smack current process attribute +* @attr: which attribute to fetch +* @ctx: buffer to receive the result +* @size: available size in, actual size out +* @flags: unused +* +* Fill the passed user space @ctx with the details of the requested +* attribute. +* +* Returns the number of attributes on success, an error code otherwise. +* There will only ever be one attribute. +*/ +static int smack_getselfattr (unsigned int attr,struct lsm_ctx __user *ctx, +size_t *size,u32 flags) +{ +struct smack_known *skp =smk_of_current (); +int total; +int slen; +int rc; + +if (attr !=LSM_ATTR_CURRENT ) +return -EOPNOTSUPP ; +security/smack/smack_lsm.c static void smack_d_instantiate(struct dentry *opt_dentry, struct inode *inode) · line 3662
Quoted 10 lines
security/smack/smack_lsm.c +9
-0+ slen =strlen (skp->smk_known) +1 ; + total =ALIGN (slen +sizeof (*ctx),8 ); +if (total > *size) + rc = -E2BIG ; +else if (ctx) + rc =lsm_fill_user_ctx (ctx, skp->smk_known, slen,LSM_ID_SMACK , +0 ); +else + rc =1 ;Can we move these checks into
lsm_fill_user_ctx()? They are similar for AppArmor and SELinux.Quoted 6 lines
security/smack/smack_lsm.c +6
-0+ + *size = total; +if (rc >=0 ) +return 1 ; +return rc; +}
Casey Schaufler
maintainerRe: [PATCH v15 08/11] Smack: implement setselfattr and getselfattr hooks
In reply to Mickaël SalaünQuoted 44 lines · Mickaël Salaün
Quoted 42 lines · Casey Schaufler
Implement Smack support for security_[gs]etselfattr. Refactor the setprocattr hook to avoid code duplication.
Signed-off-by Casey Schaufler <[email protected]>Reviewed-by John Johansen <[email protected]>--- security/smack/smack_lsm.c | 95 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 90 insertions(+), 5 deletions(-)security/smack/smack_lsm.c +25
-0@@ -3626,6 +3626,46 @@ static void smack_d_instantiate(struct dentry *opt_dentry, struct inode *inode)return ; } +/** +* smack_getselfattr - Smack current process attribute +* @attr: which attribute to fetch +* @ctx: buffer to receive the result +* @size: available size in, actual size out +* @flags: unused +* +* Fill the passed user space @ctx with the details of the requested +* attribute. +* +* Returns the number of attributes on success, an error code otherwise. +* There will only ever be one attribute. +*/ +static int smack_getselfattr (unsigned int attr,struct lsm_ctx __user *ctx, +size_t *size,u32 flags) +{ +struct smack_known *skp =smk_of_current (); +int total; +int slen; +int rc; + +if (attr !=LSM_ATTR_CURRENT ) +return -EOPNOTSUPP ; + + slen =strlen (skp->smk_known) +1 ;
Quoted 10 lines
security/smack/smack_lsm.c static void smack_d_instantiate(struct dentry *opt_dentry, struct inode *inode) · line 3661
Quoted 8 lines
security/smack/smack_lsm.c +8
-0+ total =ALIGN (slen +sizeof (*ctx),8 ); +if (total > *size) + rc = -E2BIG ; +else if (ctx) + rc =lsm_fill_user_ctx (ctx, skp->smk_known, slen,LSM_ID_SMACK , +0 ); +else + rc =1 ;Can we move these checks into
lsm_fill_user_ctx()? They are similar for AppArmor and SELinux.
Possibly, but that would make lsm_fill_user_ctx() into lsm_validiate_and_fill_user_ctx(), and I don't want to do that.
Quoted 7 lines
Quoted 7 lines
security/smack/smack_lsm.c +6
-0+ + *size = total; +if (rc >=0 ) +return 1 ; +return rc; +}
Casey Schaufler
maintainerPATCH v15 9/11 AppArmor: Add selfattr hooks
In reply to Casey SchauflerAdd hooks for setselfattr and getselfattr. These hooks are not very different from their setprocattr and getprocattr equivalents, and much of the code is shared.
--- security/apparmor/include/procattr.h | 2 +- security/apparmor/lsm.c | 91 ++++++++++++++++++++++++++-- security/apparmor/procattr.c | 10 +-- 3 files changed, 92 insertions(+), 11 deletions(-)
security/apparmor/include/procattr.h +1 -1
@@ -11,7 +11,7 @@#ifndef __AA_PROCATTR_H#define __AA_PROCATTR_H -int aa_getprocattr (struct aa_label *label,char **string); +int aa_getprocattr (struct aa_label *label,char **string,bool newline);int aa_setprocattr_changehat (char *args,size_t size,int flags);#endif /* __AA_PROCATTR_H */
security/apparmor/lsm.c +85 -6
139 lines not on this page · raw message
security/apparmor/procattr.c +6 -4
@@ -20,6 +20,7 @@* aa_getprocattr - Return the label information for @label * @label: the label to print label info about (NOT NULL) * @string: Returns - string containing the label info (NOT NULL) +* @newline: indicates that a newline should be added * * Requires: label != NULL && string != NULL *
@@ -27,7 +28,7 @@* * Returns: size of string placed in @string else error code on failure */ -int aa_getprocattr (struct aa_label *label,char **string) +int aa_getprocattr (struct aa_label *label,char **string,bool newline) {struct aa_ns *ns =labels_ns (label);struct aa_ns *current_ns =aa_get_current_ns ();
@@ -57,11 +58,12 @@ int aa_getprocattr(struct aa_label *label, char **string)return len; } - (*string)[len] ='\n' ; - (*string)[len +1 ] =0 ; +if (newline) + (*string)[len++] ='\n' ; + (*string)[len] =0 ;aa_put_ns (current_ns); -return len +1 ; +return len; }/**
Signature · 1 line
2.41.0
Casey Schaufler
maintainerPATCH v15 10/11 SELinux: Add selfattr hooks
In reply to Casey SchauflerAdd hooks for setselfattr and getselfattr. These hooks are not very different from their setprocattr and getprocattr equivalents, and much of the code is shared.
--- security/selinux/hooks.c | 134 +++++++++++++++++++++++++++++++-------- 1 file changed, 107 insertions(+), 27 deletions(-)
security/selinux/hooks.c +107 -27
@@ -6279,8 +6279,8 @@ static void selinux_d_instantiate(struct dentry *dentry, struct inode *inode)inode_doinit_with_dentry (inode, dentry); } -static int selinux_getprocattr (struct task_struct *p, -const char *name,char **value) +static int selinux_lsm_getattr (unsigned int attr,struct task_struct *p, +char **value) {const struct task_security_struct *__tsec;u32 sid;
@@ -6297,20 +6297,27 @@ static int selinux_getprocattr(struct task_struct *p, goto bad; } -if (!strcmp (name,"current" )) +switch (attr) { +case LSM_ATTR_CURRENT : sid = __tsec->sid; -else if (!strcmp (name,"prev" )) +break ; +case LSM_ATTR_PREV : sid = __tsec->osid; -else if (!strcmp (name,"exec" )) +break ; +case LSM_ATTR_EXEC : sid = __tsec->exec_sid; -else if (!strcmp (name,"fscreate" )) +break ; +case LSM_ATTR_FSCREATE : sid = __tsec->create_sid; -else if (!strcmp (name,"keycreate" )) +break ; +case LSM_ATTR_KEYCREATE : sid = __tsec->keycreate_sid; -else if (!strcmp (name,"sockcreate" )) +break ; +case LSM_ATTR_SOCKCREATE : sid = __tsec->sockcreate_sid; -else { - error = -EINVAL ; +break ; +default : + error = -EOPNOTSUPP ; goto bad; }rcu_read_unlock ();
@@ -6328,7 +6335,7 @@ static int selinux_getprocattr(struct task_struct *p,return error; } -static int selinux_setprocattr (const char *name,void *value,size_t size) +static int selinux_lsm_setattr (u64 attr,void *value,size_t size) {struct task_security_struct *tsec;struct cred *new;
@@ -6339,23 +6346,31 @@ static int selinux_setprocattr(const char *name, void *value, size_t size)/* * Basic control over ability to set these attributes at all. */ -if (!strcmp (name,"exec" )) +switch (attr) { +case LSM_ATTR_EXEC : error =avc_has_perm (mysid, mysid,SECCLASS_PROCESS ,PROCESS__SETEXEC ,NULL ); -else if (!strcmp (name,"fscreate" )) +break ; +case LSM_ATTR_FSCREATE : error =avc_has_perm (mysid, mysid,SECCLASS_PROCESS ,PROCESS__SETFSCREATE ,NULL ); -else if (!strcmp (name,"keycreate" )) +break ; +case LSM_ATTR_KEYCREATE : error =avc_has_perm (mysid, mysid,SECCLASS_PROCESS ,PROCESS__SETKEYCREATE ,NULL ); -else if (!strcmp (name,"sockcreate" )) +break ; +case LSM_ATTR_SOCKCREATE : error =avc_has_perm (mysid, mysid,SECCLASS_PROCESS ,PROCESS__SETSOCKCREATE ,NULL ); -else if (!strcmp (name,"current" )) +break ; +case LSM_ATTR_CURRENT : error =avc_has_perm (mysid, mysid,SECCLASS_PROCESS ,PROCESS__SETCURRENT ,NULL ); -else - error = -EINVAL ; +break ; +default : + error = -EOPNOTSUPP ; +break ; + }if (error)return error;
@@ -6367,13 +6382,14 @@ static int selinux_setprocattr(const char *name, void *value, size_t size) } error =security_context_to_sid (value, size, &sid,GFP_KERNEL ); -if (error == -EINVAL && !strcmp (name,"fscreate" )) { +if (error == -EINVAL && attr ==LSM_ATTR_FSCREATE ) {if (!has_cap_mac_admin (true)) {struct audit_buffer *ab;size_t audit_size; -/* We strip a nul only if it is at the end, otherwise the -* context contains a nul and we should audit that */ +/* We strip a nul only if it is at the end, +* otherwise the context contains a nul and +* we should audit that */ if (str[size -1 ] =='\0' ) audit_size = size -1 ;else
@@ -6384,7 +6400,8 @@ static int selinux_setprocattr(const char *name, void *value, size_t size)if (!ab)return error;audit_log_format (ab,"op=fscreate invalid_context=" ); -audit_log_n_untrustedstring (ab, value, audit_size); +audit_log_n_untrustedstring (ab, value, + audit_size);audit_log_end (ab);return error;
@@ -6407,11 +6424,11 @@ static int selinux_setprocattr(const char *name, void *value, size_t size)checks and may_create for the file creation checks. The operation will then fail if the context is not permitted. */ tsec =selinux_cred (new); -if (!strcmp (name,"exec" )) { +if (attr ==LSM_ATTR_EXEC ) { tsec->exec_sid = sid; - }else if (!strcmp (name,"fscreate" )) { + }else if (attr ==LSM_ATTR_FSCREATE ) { tsec->create_sid = sid; - }else if (!strcmp (name,"keycreate" )) { + }else if (attr ==LSM_ATTR_KEYCREATE ) {if (sid) { error =avc_has_perm (mysid, sid,SECCLASS_KEY ,KEY__CREATE ,NULL );
@@ -6419,9 +6436,9 @@ static int selinux_setprocattr(const char *name, void *value, size_t size) goto abort_change; } tsec->keycreate_sid = sid; - }else if (!strcmp (name,"sockcreate" )) { + }else if (attr ==LSM_ATTR_SOCKCREATE ) { tsec->sockcreate_sid = sid; - }else if (!strcmp (name,"current" )) { + }else if (attr ==LSM_ATTR_CURRENT ) { error = -EINVAL ;if (sid ==0 ) goto abort_change;
@@ -6463,6 +6480,67 @@ static int selinux_setprocattr(const char *name, void *value, size_t size)return error; } +static int selinux_getselfattr (unsigned int attr,struct lsm_ctx __user *ctx, +size_t *size,u32 flags) +{ +char *value; +size_t total_len; +int len; +int rc =0 ; + + len =selinux_lsm_getattr (attr, current, &value); +if (len <0 ) +return len; + + total_len =ALIGN (struct_size (ctx, ctx, len),8 ); + +if (total_len > *size) + rc = -E2BIG ; +else if (ctx) + rc =lsm_fill_user_ctx (ctx, value, len,LSM_ID_SELINUX ,0 ); + +kfree (value); + *size = total_len; +if (rc <0 ) +return rc; +return 1 ; +} + +static int selinux_setselfattr (unsigned int attr,struct lsm_ctx *ctx, +size_t size,u32 flags) +{ +int rc; + + rc =selinux_lsm_setattr (attr, ctx->ctx, ctx->ctx_len); +if (rc >0 ) +return 0 ; +return rc; +} + +static int selinux_getprocattr (struct task_struct *p, +const char *name,char **value) +{ +unsigned int attr =lsm_name_to_attr (name); +int rc; + +if (attr) { + rc =selinux_lsm_getattr (attr, p, value); +if (rc != -EOPNOTSUPP ) +return rc; + } + +return -EINVAL ; +} + +static int selinux_setprocattr (const char *name,void *value,size_t size) +{ +int attr =lsm_name_to_attr (name); + +if (attr) +return selinux_lsm_setattr (attr, value, size); +return -EINVAL ; +} +static int selinux_ismaclabel (const char *name) {return (strcmp (name,XATTR_SELINUX_SUFFIX ) ==0 );
@@ -7091,6 +7169,8 @@ static struct security_hook_list selinux_hooks[] __ro_after_init = {LSM_HOOK_INIT (d_instantiate, selinux_d_instantiate), +LSM_HOOK_INIT (getselfattr, selinux_getselfattr), +LSM_HOOK_INIT (setselfattr, selinux_setselfattr),LSM_HOOK_INIT (getprocattr, selinux_getprocattr), LSM_HOOK_INIT(setprocattr, selinux_setprocattr),
Signature · 1 line
2.41.0
Casey Schaufler
maintainerPATCH v15 11/11 LSM: selftests for Linux Security Module syscalls
In reply to Casey SchauflerAdd selftests for the three system calls supporting the LSM infrastructure. This set of tests is limited by the differences in access policy enforced by the existing security modules.
--- MAINTAINERS | 1 + tools/testing/selftests/Makefile | 1 + tools/testing/selftests/lsm/.gitignore | 1 + tools/testing/selftests/lsm/Makefile | 17 ++ tools/testing/selftests/lsm/common.c | 89 ++++++ tools/testing/selftests/lsm/common.h | 33 +++ tools/testing/selftests/lsm/config | 3 + .../selftests/lsm/lsm_get_self_attr_test.c | 275 ++++++++++++++++++ .../selftests/lsm/lsm_list_modules_test.c | 140 +++++++++ .../selftests/lsm/lsm_set_self_attr_test.c | 74 +++++ 10 files changed, 634 insertions(+) create mode 100644 tools/testing/selftests/lsm/.gitignore create mode 100644 tools/testing/selftests/lsm/Makefile create mode 100644 tools/testing/selftests/lsm/common.c create mode 100644 tools/testing/selftests/lsm/common.h create mode 100644 tools/testing/selftests/lsm/config create mode 100644 tools/testing/selftests/lsm/lsm_get_self_attr_test.c create mode 100644 tools/testing/selftests/lsm/lsm_list_modules_test.c create mode 100644 tools/testing/selftests/lsm/lsm_set_self_attr_test.c
MAINTAINERS +1 -0
@@ -19309,6 +19309,7 @@ W: http://kernsec.org/ T: git git://git.kernel.org/pub/scm/linux/kernel/git/pcmoore/lsm.git F: include/uapi/linux/lsm.h F: security/ +F: tools/testing/selftests/lsm/ X: security/selinux/ SELINUX SECURITY MODULE
tools/testing/selftests/Makefile +1 -0
@@ -42,6 +42,7 @@ TARGETS += landlock TARGETS += lib TARGETS += livepatch TARGETS += lkdtm +TARGETS += lsm TARGETS += membarrier TARGETS += memfd TARGETS += memory-hotplug
tools/testing/selftests/lsm/.gitignore new file +1 -0
@@ -0,0 +1 @@ +/*_test
tools/testing/selftests/lsm/Makefile new file +17 -0
@@ -0,0 +1,17 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# First run: make -C ../../../.. headers_install + +CFLAGS += -Wall -O2 $(KHDR_INCLUDES) +LOCAL_HDRS += common.h + +TEST_GEN_PROGS := lsm_get_self_attr_test lsm_list_modules_test \ + lsm_set_self_attr_test + +include ../lib.mk + +$(OUTPUT)/lsm_get_self_attr_test: lsm_get_self_attr_test.c common.c +$(OUTPUT)/lsm_set_self_attr_test: lsm_set_self_attr_test.c common.c +$(OUTPUT)/lsm_list_modules_test: lsm_list_modules_test.c common.c + +EXTRA_CLEAN = $(OUTPUT)/common.o
tools/testing/selftests/lsm/common.c new file +89 -0
89 lines not on this page · raw message
tools/testing/selftests/lsm/common.h new file +33 -0
@@ -0,0 +1,33 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Linux Security Module infrastructure tests +* +* Copyright © 2023 Casey Schaufler <[email protected]> +*/ + +#ifndef lsm_get_self_attr +static inline int lsm_get_self_attr (unsigned int attr,struct lsm_ctx *ctx, +size_t *size,__u32 flags) +{ +return syscall (__NR_lsm_get_self_attr, attr, ctx, size, flags); +} +#endif + +#ifndef lsm_set_self_attr +static inline int lsm_set_self_attr (unsigned int attr,struct lsm_ctx *ctx, +size_t size,__u32 flags) +{ +return syscall (__NR_lsm_set_self_attr, attr, ctx, size, flags); +} +#endif + +#ifndef lsm_list_modules +static inline int lsm_list_modules (__u64 *ids,size_t *size,__u32 flags) +{ +return syscall (__NR_lsm_list_modules, ids, size, flags); +} +#endif + +extern int read_proc_attr (const char *attr,char *value,size_t size); +extern int read_sysfs_lsms (char *lsms,size_t size); +int attr_lsm_count (void );
tools/testing/selftests/lsm/config new file +3 -0
@@ -0,0 +1,3 @@ +CONFIG_SYSFS=y +CONFIG_SECURITY=y +CONFIG_SECURITYFS=y
tools/testing/selftests/lsm/lsm_get_self_attr_test.c new file +275 -0
275 lines not on this page · raw message
tools/testing/selftests/lsm/lsm_list_modules_test.c new file +140 -0
140 lines not on this page · raw message
tools/testing/selftests/lsm/lsm_set_self_attr_test.c new file +74 -0
74 lines not on this page · raw message
Signature · 1 line
2.41.0
Re: [PATCH v15 11/11] LSM: selftests for Linux Security Module syscalls
Quoted 5 lines · Casey Schaufler
Add selftests for the three system calls supporting the LSM infrastructure. This set of tests is limited by the differences in access policy enforced by the existing security modules.
Signed-off-by Casey Schaufler <[email protected]>
I'd like more corner case tests, but these are good. Thanks for writing them!
Quoted 728 lines
--- MAINTAINERS | 1 + tools/testing/selftests/Makefile | 1 + tools/testing/selftests/lsm/.gitignore | 1 + tools/testing/selftests/lsm/Makefile | 17 ++ tools/testing/selftests/lsm/common.c | 89 ++++++ tools/testing/selftests/lsm/common.h | 33 +++ tools/testing/selftests/lsm/config | 3 + .../selftests/lsm/lsm_get_self_attr_test.c | 275 ++++++++++++++++++ .../selftests/lsm/lsm_list_modules_test.c | 140 +++++++++ .../selftests/lsm/lsm_set_self_attr_test.c | 74 +++++ 10 files changed, 634 insertions(+) create mode 100644 tools/testing/selftests/lsm/.gitignore create mode 100644 tools/testing/selftests/lsm/Makefile create mode 100644 tools/testing/selftests/lsm/common.c create mode 100644 tools/testing/selftests/lsm/common.h create mode 100644 tools/testing/selftests/lsm/config create mode 100644 tools/testing/selftests/lsm/lsm_get_self_attr_test.c create mode 100644 tools/testing/selftests/lsm/lsm_list_modules_test.c create mode 100644 tools/testing/selftests/lsm/lsm_set_self_attr_test.cMAINTAINERS +1
-0@@ -19309,6 +19309,7 @@ W: http://kernsec.org/ T: git git://git.kernel.org/pub/scm/linux/kernel/git/pcmoore/lsm.git F: include/uapi/linux/lsm.h F: security/ +F: tools/testing/selftests/lsm/ X: security/selinux/ SELINUX SECURITY MODULEtools/testing/selftests/Makefile +1
-0@@ -42,6 +42,7 @@ TARGETS += landlock TARGETS += lib TARGETS += livepatch TARGETS += lkdtm +TARGETS += lsm TARGETS += membarrier TARGETS += memfd TARGETS += memory-hotplugtools/testing/selftests/lsm/.gitignore new file +1
-0@@ -0,0 +1 @@ +/*_testtools/testing/selftests/lsm/Makefile new file +17
-0@@ -0,0 +1,17 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# First run: make -C ../../../.. headers_install + +CFLAGS += -Wall -O2 $(KHDR_INCLUDES) +LOCAL_HDRS += common.h + +TEST_GEN_PROGS := lsm_get_self_attr_test lsm_list_modules_test \ + lsm_set_self_attr_test + +include ../lib.mk + +$(OUTPUT)/lsm_get_self_attr_test: lsm_get_self_attr_test.c common.c +$(OUTPUT)/lsm_set_self_attr_test: lsm_set_self_attr_test.c common.c +$(OUTPUT)/lsm_list_modules_test: lsm_list_modules_test.c common.c + +EXTRA_CLEAN = $(OUTPUT)/common.otools/testing/selftests/lsm/common.c new file +89
-0@@ -0,0 +1,89 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Linux Security Module infrastructure tests +* +* Copyright © 2023 Casey Schaufler <[email protected]> +*/ + +#define _GNU_SOURCE +#include <linux/lsm.h> +#include <fcntl.h> +#include <string.h> +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <sys/types.h> +#include "common.h" + +#define PROCATTR "/proc/self/attr/" + +int read_proc_attr (const char *attr,char *value,size_t size) +{ +int fd; +int len; +char *path; + + len =strlen (PROCATTR ) +strlen (attr) +1 ; + path =calloc (len,1 ); +if (path ==NULL ) +return -1 ; +sprintf (path,"%s%s" ,PROCATTR , attr); + + fd =open (path,O_RDONLY ); +free (path); + +if (fd <0 ) +return -1 ; + len =read (fd, value, size); + +close (fd); + +/* Ensure value is terminated */ +if (len <=0 || len == size) +return -1 ; + value[len] ='\0' ; + + path =strchr (value,'\n' ); +if (path) + *path ='\0' ; + +return 0 ; +} + +int read_sysfs_lsms (char *lsms,size_t size) +{ +FILE *fp; +size_t red; + + fp =fopen ("/sys/kernel/security/lsm" ,"r" ); +if (fp ==NULL ) +return -1 ; + red =fread (lsms,1 , size, fp); +fclose (fp); + +if (red <=0 || red == size) +return -1 ; + lsms[red] ='\0' ; +return 0 ; +} + +int attr_lsm_count (void ) +{ +char *names =calloc (sysconf (_SC_PAGESIZE),1 ); +int count =0 ; + +if (!names) +return 0 ; + +if (read_sysfs_lsms (names,sysconf (_SC_PAGESIZE))) +return 0 ; + +if (strstr (names,"selinux" )) + count++; +if (strstr (names,"smack" )) + count++; +if (strstr (names,"apparmor" )) + count++; + +return count; +}tools/testing/selftests/lsm/common.h new file +33
-0@@ -0,0 +1,33 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Linux Security Module infrastructure tests +* +* Copyright © 2023 Casey Schaufler <[email protected]> +*/ + +#ifndef lsm_get_self_attr +static inline int lsm_get_self_attr (unsigned int attr,struct lsm_ctx *ctx, +size_t *size,__u32 flags) +{ +return syscall (__NR_lsm_get_self_attr, attr, ctx, size, flags); +} +#endif + +#ifndef lsm_set_self_attr +static inline int lsm_set_self_attr (unsigned int attr,struct lsm_ctx *ctx, +size_t size,__u32 flags) +{ +return syscall (__NR_lsm_set_self_attr, attr, ctx, size, flags); +} +#endif + +#ifndef lsm_list_modules +static inline int lsm_list_modules (__u64 *ids,size_t *size,__u32 flags) +{ +return syscall (__NR_lsm_list_modules, ids, size, flags); +} +#endif + +extern int read_proc_attr (const char *attr,char *value,size_t size); +extern int read_sysfs_lsms (char *lsms,size_t size); +int attr_lsm_count (void );tools/testing/selftests/lsm/config new file +3
-0@@ -0,0 +1,3 @@ +CONFIG_SYSFS=y +CONFIG_SECURITY=y +CONFIG_SECURITYFS=ytools/testing/selftests/lsm/lsm_get_self_attr_test.c new file +275
-0@@ -0,0 +1,275 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Linux Security Module infrastructure tests +* Tests for the lsm_get_self_attr system call +* +* Copyright © 2022 Casey Schaufler <[email protected]> +*/ + +#define _GNU_SOURCE +#include <linux/lsm.h> +#include <fcntl.h> +#include <string.h> +#include <stdio.h> +#include <unistd.h> +#include <sys/types.h> +#include "../kselftest_harness.h" +#include "common.h" + +static struct lsm_ctx *next_ctx (struct lsm_ctx *ctxp) +{ +void *vp; + + vp = (void *)ctxp +sizeof (*ctxp) + ctxp->ctx_len; +return (struct lsm_ctx *)vp; +} + +TEST (size_null_lsm_get_self_attr) +{ +const long page_size =sysconf (_SC_PAGESIZE); +struct lsm_ctx *ctx =calloc (page_size,1 ); + +ASSERT_NE (NULL , ctx); + errno =0 ; +ASSERT_EQ (-1 ,lsm_get_self_attr (LSM_ATTR_CURRENT , ctx,NULL ,0 )); +ASSERT_EQ (EINVAL , errno); + +free (ctx); +} + +TEST (ctx_null_lsm_get_self_attr) +{ +const long page_size =sysconf (_SC_PAGESIZE); +size_t size = page_size; +int rc; + + rc =lsm_get_self_attr (LSM_ATTR_CURRENT ,NULL , &size,0 ); + +if (attr_lsm_count ()) { +ASSERT_NE (-1 , rc); +ASSERT_NE (1 , size); + }else { +ASSERT_EQ (-1 , rc); + } +} + +TEST (size_too_small_lsm_get_self_attr) +{ +const long page_size =sysconf (_SC_PAGESIZE); +struct lsm_ctx *ctx =calloc (page_size,1 ); +size_t size =1 ; + +ASSERT_NE (NULL , ctx); + errno =0 ; +ASSERT_EQ (-1 ,lsm_get_self_attr (LSM_ATTR_CURRENT , ctx, &size,0 )); +if (attr_lsm_count ()) { +ASSERT_EQ (E2BIG , errno); + }else { +ASSERT_EQ (EOPNOTSUPP , errno); + } +ASSERT_NE (1 , size); + +free (ctx); +} + +TEST (flags_zero_lsm_get_self_attr) +{ +const long page_size =sysconf (_SC_PAGESIZE); +struct lsm_ctx *ctx =calloc (page_size,1 ); +__u64 *syscall_lsms =calloc (page_size,1 ); +size_t size; +int lsmcount; +int i; + +ASSERT_NE (NULL , ctx); + errno =0 ; + size = page_size; +ASSERT_EQ (-1 ,lsm_get_self_attr (LSM_ATTR_CURRENT , ctx, &size, +LSM_FLAG_SINGLE )); +ASSERT_EQ (EINVAL , errno); +ASSERT_EQ (page_size, size); + + lsmcount =syscall (__NR_lsm_list_modules, syscall_lsms, &size,0 ); +ASSERT_LE (1 , lsmcount); +ASSERT_NE (NULL , syscall_lsms); + +for (i =0 ; i < lsmcount; i++) { + errno =0 ; + size = page_size; + ctx->id = syscall_lsms[i]; + +if (syscall_lsms[i] ==LSM_ID_SELINUX || + syscall_lsms[i] ==LSM_ID_SMACK || + syscall_lsms[i] ==LSM_ID_APPARMOR ) { +ASSERT_EQ (1 ,lsm_get_self_attr (LSM_ATTR_CURRENT , ctx, + &size,LSM_FLAG_SINGLE )); + }else { +ASSERT_EQ (-1 ,lsm_get_self_attr (LSM_ATTR_CURRENT , ctx, + &size, +LSM_FLAG_SINGLE )); + } + } + +free (ctx); +} + +TEST (flags_overset_lsm_get_self_attr) +{ +const long page_size =sysconf (_SC_PAGESIZE); +struct lsm_ctx *ctx =calloc (page_size,1 ); +size_t size; + +ASSERT_NE (NULL , ctx); + + errno =0 ; + size = page_size; +ASSERT_EQ (-1 ,lsm_get_self_attr (LSM_ATTR_CURRENT |LSM_ATTR_PREV , ctx, + &size,0 )); +ASSERT_EQ (EOPNOTSUPP , errno); + + errno =0 ; + size = page_size; +ASSERT_EQ (-1 ,lsm_get_self_attr (LSM_ATTR_CURRENT , ctx, &size, +LSM_FLAG_SINGLE | + (LSM_FLAG_SINGLE <<1 ))); +ASSERT_EQ (EINVAL , errno); + +free (ctx); +} + +TEST (basic_lsm_get_self_attr) +{ +const long page_size =sysconf (_SC_PAGESIZE); +size_t size = page_size; +struct lsm_ctx *ctx =calloc (page_size,1 ); +struct lsm_ctx *tctx =NULL ; +__u64 *syscall_lsms =calloc (page_size,1 ); +char *attr =calloc (page_size,1 ); +int cnt_current =0 ; +int cnt_exec =0 ; +int cnt_fscreate =0 ; +int cnt_keycreate =0 ; +int cnt_prev =0 ; +int cnt_sockcreate =0 ; +int lsmcount; +int count; +int i; + +ASSERT_NE (NULL , ctx); +ASSERT_NE (NULL , syscall_lsms); + + lsmcount =syscall (__NR_lsm_list_modules, syscall_lsms, &size,0 ); +ASSERT_LE (1 , lsmcount); + +for (i =0 ; i < lsmcount; i++) { +switch (syscall_lsms[i]) { +case LSM_ID_SELINUX : + cnt_current++; + cnt_exec++; + cnt_fscreate++; + cnt_keycreate++; + cnt_prev++; + cnt_sockcreate++; +break ; +case LSM_ID_SMACK : + cnt_current++; +break ; +case LSM_ID_APPARMOR : + cnt_current++; + cnt_exec++; + cnt_prev++; +break ; +default : +break ; + } + } + +if (cnt_current) { + size = page_size; + count =lsm_get_self_attr (LSM_ATTR_CURRENT , ctx, &size,0 ); +ASSERT_EQ (cnt_current, count); + tctx = ctx; +ASSERT_EQ (0 ,read_proc_attr ("current" , attr, page_size)); +ASSERT_EQ (0 ,strcmp ((char *)tctx->ctx, attr)); +for (i =1 ; i < count; i++) { + tctx =next_ctx (tctx); +ASSERT_NE (0 ,strcmp ((char *)tctx->ctx, attr)); + } + } +if (cnt_exec) { + size = page_size; + count =lsm_get_self_attr (LSM_ATTR_EXEC , ctx, &size,0 ); +ASSERT_GE (cnt_exec, count); +if (count >0 ) { + tctx = ctx; +if (read_proc_attr ("exec" , attr, page_size) ==0 ) +ASSERT_EQ (0 ,strcmp ((char *)tctx->ctx, attr)); + } +for (i =1 ; i < count; i++) { + tctx =next_ctx (tctx); +ASSERT_NE (0 ,strcmp ((char *)tctx->ctx, attr)); + } + } +if (cnt_fscreate) { + size = page_size; + count =lsm_get_self_attr (LSM_ATTR_FSCREATE , ctx, &size,0 ); +ASSERT_GE (cnt_fscreate, count); +if (count >0 ) { + tctx = ctx; +if (read_proc_attr ("fscreate" , attr, page_size) ==0 ) +ASSERT_EQ (0 ,strcmp ((char *)tctx->ctx, attr)); + } +for (i =1 ; i < count; i++) { + tctx =next_ctx (tctx); +ASSERT_NE (0 ,strcmp ((char *)tctx->ctx, attr)); + } + } +if (cnt_keycreate) { + size = page_size; + count =lsm_get_self_attr (LSM_ATTR_KEYCREATE , ctx, &size,0 ); +ASSERT_GE (cnt_keycreate, count); +if (count >0 ) { + tctx = ctx; +if (read_proc_attr ("keycreate" , attr, page_size) ==0 ) +ASSERT_EQ (0 ,strcmp ((char *)tctx->ctx, attr)); + } +for (i =1 ; i < count; i++) { + tctx =next_ctx (tctx); +ASSERT_NE (0 ,strcmp ((char *)tctx->ctx, attr)); + } + } +if (cnt_prev) { + size = page_size; + count =lsm_get_self_attr (LSM_ATTR_PREV , ctx, &size,0 ); +ASSERT_GE (cnt_prev, count); +if (count >0 ) { + tctx = ctx; +ASSERT_EQ (0 ,read_proc_attr ("prev" , attr, page_size)); +ASSERT_EQ (0 ,strcmp ((char *)tctx->ctx, attr)); +for (i =1 ; i < count; i++) { + tctx =next_ctx (tctx); +ASSERT_NE (0 ,strcmp ((char *)tctx->ctx, attr)); + } + } + } +if (cnt_sockcreate) { + size = page_size; + count =lsm_get_self_attr (LSM_ATTR_SOCKCREATE , ctx, &size,0 ); +ASSERT_GE (cnt_sockcreate, count); +if (count >0 ) { + tctx = ctx; +if (read_proc_attr ("sockcreate" , attr, page_size) ==0 ) +ASSERT_EQ (0 ,strcmp ((char *)tctx->ctx, attr)); + } +for (i =1 ; i < count; i++) { + tctx =next_ctx (tctx); +ASSERT_NE (0 ,strcmp ((char *)tctx->ctx, attr)); + } + } + +free (ctx); +free (attr); +free (syscall_lsms); +} + +TEST_HARNESS_MAIN tools/testing/selftests/lsm/lsm_list_modules_test.c new file +140
-0@@ -0,0 +1,140 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Linux Security Module infrastructure tests +* Tests for the lsm_list_modules system call +* +* Copyright © 2022 Casey Schaufler <[email protected]> +*/ + +#define _GNU_SOURCE +#include <linux/lsm.h> +#include <string.h> +#include <stdio.h> +#include <unistd.h> +#include <sys/types.h> +#include "../kselftest_harness.h" +#include "common.h" + +TEST (size_null_lsm_list_modules) +{ +const long page_size =sysconf (_SC_PAGESIZE); +__u64 *syscall_lsms =calloc (page_size,1 ); + +ASSERT_NE (NULL , syscall_lsms); + errno =0 ; +ASSERT_EQ (-1 ,lsm_list_modules (syscall_lsms,NULL ,0 )); +ASSERT_EQ (EFAULT , errno); + +free (syscall_lsms); +} + +TEST (ids_null_lsm_list_modules) +{ +const long page_size =sysconf (_SC_PAGESIZE); +size_t size = page_size; + + errno =0 ; +ASSERT_EQ (-1 ,lsm_list_modules (NULL , &size,0 )); +ASSERT_EQ (EFAULT , errno); +ASSERT_NE (1 , size); +} + +TEST (size_too_small_lsm_list_modules) +{ +const long page_size =sysconf (_SC_PAGESIZE); +__u64 *syscall_lsms =calloc (page_size,1 ); +size_t size =1 ; + +ASSERT_NE (NULL , syscall_lsms); + errno =0 ; +ASSERT_EQ (-1 ,lsm_list_modules (syscall_lsms, &size,0 )); +ASSERT_EQ (E2BIG , errno); +ASSERT_NE (1 , size); + +free (syscall_lsms); +} + +TEST (flags_set_lsm_list_modules) +{ +const long page_size =sysconf (_SC_PAGESIZE); +__u64 *syscall_lsms =calloc (page_size,1 ); +size_t size = page_size; + +ASSERT_NE (NULL , syscall_lsms); + errno =0 ; +ASSERT_EQ (-1 ,lsm_list_modules (syscall_lsms, &size,7 )); +ASSERT_EQ (EINVAL , errno); +ASSERT_EQ (page_size, size); + +free (syscall_lsms); +} + +TEST (correct_lsm_list_modules) +{ +const long page_size =sysconf (_SC_PAGESIZE); +size_t size = page_size; +__u64 *syscall_lsms =calloc (page_size,1 ); +char *sysfs_lsms =calloc (page_size,1 ); +char *name; +char *cp; +int count; +int i; + +ASSERT_NE (NULL , sysfs_lsms); +ASSERT_NE (NULL , syscall_lsms); +ASSERT_EQ (0 ,read_sysfs_lsms (sysfs_lsms, page_size)); + + count =lsm_list_modules (syscall_lsms, &size,0 ); +ASSERT_LE (1 , count); + cp = sysfs_lsms; +for (i =0 ; i < count; i++) { +switch (syscall_lsms[i]) { +case LSM_ID_CAPABILITY : + name ="capability" ; +break ; +case LSM_ID_SELINUX : + name ="selinux" ; +break ; +case LSM_ID_SMACK : + name ="smack" ; +break ; +case LSM_ID_TOMOYO : + name ="tomoyo" ; +break ; +case LSM_ID_IMA : + name ="ima" ; +break ; +case LSM_ID_APPARMOR : + name ="apparmor" ; +break ; +case LSM_ID_YAMA : + name ="yama" ; +break ; +case LSM_ID_LOADPIN : + name ="loadpin" ; +break ; +case LSM_ID_SAFESETID : + name ="safesetid" ; +break ; +case LSM_ID_LOCKDOWN : + name ="lockdown" ; +break ; +case LSM_ID_BPF : + name ="bpf" ; +break ; +case LSM_ID_LANDLOCK : + name ="landlock" ; +break ; +default : + name ="INVALID" ; +break ; + } +ASSERT_EQ (0 ,strncmp (cp, name,strlen (name))); + cp +=strlen (name) +1 ; + } + +free (sysfs_lsms); +free (syscall_lsms); +} + +TEST_HARNESS_MAIN tools/testing/selftests/lsm/lsm_set_self_attr_test.c new file +74
-0@@ -0,0 +1,74 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Linux Security Module infrastructure tests +* Tests for the lsm_set_self_attr system call +* +* Copyright © 2022 Casey Schaufler <[email protected]> +*/ + +#define _GNU_SOURCE +#include <linux/lsm.h> +#include <string.h> +#include <stdio.h> +#include <unistd.h> +#include <sys/types.h> +#include "../kselftest_harness.h" +#include "common.h" + +TEST (ctx_null_lsm_set_self_attr) +{ +ASSERT_EQ (-1 ,lsm_set_self_attr (LSM_ATTR_CURRENT ,NULL , +sizeof (struct lsm_ctx ),0 )); +} + +TEST (size_too_small_lsm_set_self_attr) +{ +const long page_size =sysconf (_SC_PAGESIZE); +struct lsm_ctx *ctx =calloc (page_size,1 ); +size_t size = page_size; + +ASSERT_NE (NULL , ctx); +if (attr_lsm_count ()) { +ASSERT_LE (1 ,lsm_get_self_attr (LSM_ATTR_CURRENT , ctx, &size, +0 )); + } +ASSERT_EQ (-1 ,lsm_set_self_attr (LSM_ATTR_CURRENT , ctx,1 ,0 )); + +free (ctx); +} + +TEST (flags_zero_lsm_set_self_attr) +{ +const long page_size =sysconf (_SC_PAGESIZE); +struct lsm_ctx *ctx =calloc (page_size,1 ); +size_t size = page_size; + +ASSERT_NE (NULL , ctx); +if (attr_lsm_count ()) { +ASSERT_LE (1 ,lsm_get_self_attr (LSM_ATTR_CURRENT , ctx, &size, +0 )); + } +ASSERT_EQ (-1 ,lsm_set_self_attr (LSM_ATTR_CURRENT , ctx, size,1 )); + +free (ctx); +} + +TEST (flags_overset_lsm_set_self_attr) +{ +const long page_size =sysconf (_SC_PAGESIZE); +char *ctx =calloc (page_size,1 ); +size_t size = page_size; +struct lsm_ctx *tctx = (struct lsm_ctx *)ctx; + +ASSERT_NE (NULL , ctx); +if (attr_lsm_count ()) { +ASSERT_LE (1 ,lsm_get_self_attr (LSM_ATTR_CURRENT , tctx, &size, +0 )); + } +ASSERT_EQ (-1 ,lsm_set_self_attr (LSM_ATTR_CURRENT |LSM_ATTR_PREV , tctx, + size,0 )); + +free (ctx); +} + +TEST_HARNESS_MAIN Signature · 1 line
2.41.0
Paul Moore
maintainerRe: [PATCH v15 00/11] LSM: Three basic syscalls
In reply to Casey SchauflerQuoted 2 lines · Casey Schaufler
Add three system calls for the Linux Security Module ABI ...
First off, a big thank you to Casey who took it upon himself to turn my pseudo-code syscall suggestion into a proper patchset and saw it through 15 revisions. Thanks also go out to everyone that has helped review and comment on this effort; I know everyone is busy, but these reviews are important.
I'm happy to say that I think we're in a good place with this revision of the LSM syscall patchset. I only see two outstanding issues, and neither of those are bugs/showstoppers that affect the API, they are simply areas where the implementation could be improved. With the understanding that Casey is busy for the rest of the month, and my desire to make sure this patchset gets a full dev cycle in linux-next, I'm going to suggest merging this into the lsm/next-queue branch soon (likely tomorrow) in preparation for merging it into lsm/next once the upcoming merge window closes. Those who want to help improve the implementation, as suggested in the feedback on this revision or otherwise, are welcome to submit patches against the lsm/next-queue branch and I will merge them into that branch once they pass review.
If I don't hear any objections I'll plan on merging this patchset tomorrow, I'll send a follow-up reply to this email when it's done.
Signature · 1 line
paul-moore.com
Paul Moore
maintainerRe: [PATCH v15 00/11] LSM: Three basic syscalls
Quoted 24 lines · Paul Moore
Quoted 2 lines · Casey Schaufler
Add three system calls for the Linux Security Module ABI ...
First off, a big thank you to Casey who took it upon himself to turn my pseudo-code syscall suggestion into a proper patchset and saw it through 15 revisions. Thanks also go out to everyone that has helped review and comment on this effort; I know everyone is busy, but these reviews are important.
I'm happy to say that I think we're in a good place with this revision of the LSM syscall patchset. I only see two outstanding issues, and neither of those are bugs/showstoppers that affect the API, they are simply areas where the implementation could be improved. With the understanding that Casey is busy for the rest of the month, and my desire to make sure this patchset gets a full dev cycle in linux-next, I'm going to suggest merging this into the lsm/next-queue branch soon (likely tomorrow) in preparation for merging it into lsm/next once the upcoming merge window closes. Those who want to help improve the implementation, as suggested in the feedback on this revision or otherwise, are welcome to submit patches against the lsm/next-queue branch and I will merge them into that branch once they pass review.
Quoted 2 lines
If I don't hear any objections I'll plan on merging this patchset tomorrow, I'll send a follow-up reply to this email when it's done.
Since it's been *almost* a full 24 hours and no objections I went ahead and merged this patchset into lsm/next-queue with the intention of bringing them into lsm/next after the upcoming merge window closes. For those of you who have suggested changes, please feel free to submit patches against the lsm/next-queue branch and we can get them queued up along with these patches.
Thanks everyone!
Signature · 1 line
paul-moore.com
Re: [PATCH v15 00/11] LSM: Three basic syscalls
Quoted 28 lines · Paul Moore
Quoted 24 lines · Paul Moore
Quoted 2 lines · Casey Schaufler
Add three system calls for the Linux Security Module ABI ...
First off, a big thank you to Casey who took it upon himself to turn my pseudo-code syscall suggestion into a proper patchset and saw it through 15 revisions. Thanks also go out to everyone that has helped review and comment on this effort; I know everyone is busy, but these reviews are important.
I'm happy to say that I think we're in a good place with this revision of the LSM syscall patchset. I only see two outstanding issues, and neither of those are bugs/showstoppers that affect the API, they are simply areas where the implementation could be improved. With the understanding that Casey is busy for the rest of the month, and my desire to make sure this patchset gets a full dev cycle in linux-next, I'm going to suggest merging this into the lsm/next-queue branch soon (likely tomorrow) in preparation for merging it into lsm/next once the upcoming merge window closes. Those who want to help improve the implementation, as suggested in the feedback on this revision or otherwise, are welcome to submit patches against the lsm/next-queue branch and I will merge them into that branch once they pass review.
Quoted 2 lines
If I don't hear any objections I'll plan on merging this patchset tomorrow, I'll send a follow-up reply to this email when it's done.
Quoted 6 lines
Since it's been *almost* a full 24 hours and no objections I went ahead and merged this patchset into lsm/next-queue with the intention of bringing them into lsm/next after the upcoming merge window closes. For those of you who have suggested changes, please feel free to submit patches against the lsm/next-queue branch and we can get them queued up along with these patches.
Sorry, I just noticed LSM_ID_IMA. Since we have the 'integrity' LSM, I think it should be LSM_ID_INTEGRITY.
Mimi, all, do you agree? If yes, I send a patch shortly.
Thanks
Roberto
Paul Moore
maintainerRe: [PATCH v15 00/11] LSM: Three basic syscalls
Quoted 5 lines · Roberto Sassu
Sorry, I just noticed
LSM_ID_IMA. Since we have the 'integrity' LSM, I think it should beLSM_ID_INTEGRITY.Mimi, all, do you agree? If yes, I send a patch shortly.
I believe LSM_ID_IMA is the better option, despite "integrity" already being present in Kconfig and possibly other areas. "IMA" is a specific thing/LSM whereas "integrity" is a property, principle, or quality. Especially as we move forward with promoting IMA as a full and proper LSM, we should work towards referring to it as "IMA" and not "integrity".
If anything we should be working to support "IMA" in places where we currently have "integrity" so that we can eventually deprecate "integrity".
Signature · 1 line
paul-moore.com
Re: [PATCH v15 00/11] LSM: Three basic syscalls
Quoted 15 lines · Paul Moore
Quoted 5 lines · Roberto Sassu
Sorry, I just noticed
LSM_ID_IMA. Since we have the 'integrity' LSM, I think it should beLSM_ID_INTEGRITY.Mimi, all, do you agree? If yes, I send a patch shortly.
I believe
LSM_ID_IMAis the better option, despite "integrity" already being present inKconfigand possibly other areas. "IMA" is a specific thing/LSM whereas "integrity" is a property, principle, or quality. Especially as we move forward with promoting IMA as a full and proper LSM, we should work towards referring to it as "IMA" and not "integrity".
Quoted 3 lines
If anything we should be working to support "IMA" in places where we currently have "integrity" so that we can eventually deprecate "integrity".
Hi Paul
I fully understand your argument. However, 'integrity' has been the word to identify the integrity subsystem since long time ago.
Reducing the scope to 'ima' would create some confusion since, while 'ima' is associated to integrity, it would not encompass EVM.
The term 'integrity', although it is a property, it precisely identifies in the kernel context the scope and goals of the subsystem, and is general enough to encompass new projects going in a similar direction (such as my integrity digest cache).
From a technical perspective, at the moment it is not possible to split 'integrity' in two standalone LSMs 'ima' and 'evm', as IMA and EVM work on shared integrity metadata. Also my integrity digest cache is using the same metadata.
In addition, making IMA and EVM as standalone LSMs would require a much longer development cycle to make them use disjoint metadata and to define proper communication interfaces. It would be not anymore a technical move of function calls from a place to another, like for the current patch set, but would require substantial time to validate the new design.
To submit my patch set in the current state, the only thing I need is to have LSM_ID_INTEGRITY defined.
Roberto
Paul Moore
maintainerRe: [PATCH v15 00/11] LSM: Three basic syscalls
Quoted 20 lines · Roberto Sassu
Quoted 15 lines · Paul Moore
Quoted 5 lines · Roberto Sassu
Sorry, I just noticed
LSM_ID_IMA. Since we have the 'integrity' LSM, I think it should beLSM_ID_INTEGRITY.Mimi, all, do you agree? If yes, I send a patch shortly.
I believe
LSM_ID_IMAis the better option, despite "integrity" already being present inKconfigand possibly other areas. "IMA" is a specific thing/LSM whereas "integrity" is a property, principle, or quality. Especially as we move forward with promoting IMA as a full and proper LSM, we should work towards referring to it as "IMA" and not "integrity".Quoted 3 lines
If anything we should be working to support "IMA" in places where we currently have "integrity" so that we can eventually deprecate "integrity".
Quoted 7 lines
Hi Paul
I fully understand your argument. However, 'integrity' has been the word to identify the integrity subsystem since long time ago.
Reducing the scope to 'ima' would create some confusion since, while 'ima' is associated to integrity, it would not encompass EVM.
Using LSM_ID_IMA to reference the combination of IMA+EVM makes much more sense to me than using LSM_ID_INTEGRITY, especially as we move towards promoting IMA+EVM and adopting LSM hooks for integrity verification, opening the door for other integrity focused LSMs.
Signature · 1 line
paul-moore.com
Re: [PATCH v15 00/11] LSM: Three basic syscalls
Quoted 27 lines · Paul Moore
Quoted 25 lines · Roberto Sassu
Quoted 15 lines · Paul Moore
Quoted 5 lines · Roberto Sassu
Sorry, I just noticed
LSM_ID_IMA. Since we have the 'integrity' LSM, I think it should beLSM_ID_INTEGRITY.Mimi, all, do you agree? If yes, I send a patch shortly.
I believe
LSM_ID_IMAis the better option, despite "integrity" already being present inKconfigand possibly other areas. "IMA" is a specific thing/LSM whereas "integrity" is a property, principle, or quality. Especially as we move forward with promoting IMA as a full and proper LSM, we should work towards referring to it as "IMA" and not "integrity".Quoted 3 lines
If anything we should be working to support "IMA" in places where we currently have "integrity" so that we can eventually deprecate "integrity".
Hi Paul
I fully understand your argument. However, 'integrity' has been the word to identify the integrity subsystem since long time ago.
Quoted 7 lines
Quoted 2 lines
Reducing the scope to 'ima' would create some confusion since, while 'ima' is associated to integrity, it would not encompass EVM.
Using
LSM_ID_IMAto reference the combination of IMA+EVM makes much more sense to me than usingLSM_ID_INTEGRITY, especially as we move towards promoting IMA+EVM and adopting LSM hooks for integrity verification, opening the door for other integrity focused LSMs.
+ Mimi, linux-integrity
Ok, just to understand before posting v4, the code looks like this:
+const struct lsm_id integrity_lsmid = {
+ .name = "integrity",
+ .id = LSM_ID_IMA,
+};
+
DEFINE_LSM(integrity) = {
.name = "integrity",
- .init = integrity_iintcache_init,
+ .init = integrity_lsm_init,
.order = LSM_ORDER_LAST,
};
Is it ok?
Thanks
Roberto
Re: [PATCH v15 00/11] LSM: Three basic syscalls
Quoted 31 lines · Roberto Sassu
Quoted 30 lines · Paul Moore
Quoted 27 lines · Roberto Sassu
Quoted 15 lines · Paul Moore
Quoted 5 lines · Roberto Sassu
Sorry, I just noticed
LSM_ID_IMA. Since we have the 'integrity' LSM, I think it should beLSM_ID_INTEGRITY.Mimi, all, do you agree? If yes, I send a patch shortly.
I believe
LSM_ID_IMAis the better option, despite "integrity" already being present inKconfigand possibly other areas. "IMA" is a specific thing/LSM whereas "integrity" is a property, principle, or quality. Especially as we move forward with promoting IMA as a full and proper LSM, we should work towards referring to it as "IMA" and not "integrity".Quoted 3 lines
If anything we should be working to support "IMA" in places where we currently have "integrity" so that we can eventually deprecate "integrity".
Hi Paul
I fully understand your argument. However, 'integrity' has been the word to identify the integrity subsystem since long time ago.
Reducing the scope to 'ima' would create some confusion since, while 'ima' is associated to integrity, it would not encompass EVM.
Quoted 8 lines
Quoted 4 lines
Using
LSM_ID_IMAto reference the combination of IMA+EVM makes much more sense to me than usingLSM_ID_INTEGRITY, especially as we move towards promoting IMA+EVM and adopting LSM hooks for integrity verification, opening the door for other integrity focused LSMs.+ Mimi, linux-integrity
Ok, just to understand before posting v4, the code looks like this:
I worked on a new proposal. Let me know what you think. It is available here:
https://github.com/robertosassu/linux/tree/ima-evm-lsms-v4-devel-v6
I made IMA and EVM as standalone LSMs and removed 'integrity'. They maintain the same properties of 'integrity', i.e. they are the last and always enabled.
During initialization, 'ima' and 'evm' call integrity_iintcache_init(), so that they can get integrity metadata. I added a check to ensure that this function is called only once. I also added the lsmid parameter so that the integrity-specific functions are added under the LSM ID of the caller.
I added a new LSM ID for EVM, does not look good that IMA and EVM are represented by LSM_ID_IMA.
Finally, I had to drop the patch to remove the rbtree, because without the 'integrity' LSM, space in the security blob cannot be reserved. Since integrity metadata is shared, it cannot be reserved by 'ima' or 'evm'.
An intermediate solution would be to keep the 'integrity' LSM just to reserve space in the security blob. Or, we remove the rbtree if/when IMA and EVM use disjoint integrity metadata.
Roberto
Mimi Zohar
maintainerRe: [PATCH v15 00/11] LSM: Three basic syscalls
Quoted 60 lines · Roberto Sassu
Quoted 31 lines · Roberto Sassu
Quoted 30 lines · Paul Moore
Quoted 27 lines · Roberto Sassu
Quoted 15 lines · Paul Moore
Quoted 5 lines · Roberto Sassu
Sorry, I just noticed
LSM_ID_IMA. Since we have the 'integrity' LSM, I think it should beLSM_ID_INTEGRITY.Mimi, all, do you agree? If yes, I send a patch shortly.
I believe
LSM_ID_IMAis the better option, despite "integrity" already being present inKconfigand possibly other areas. "IMA" is a specific thing/LSM whereas "integrity" is a property, principle, or quality. Especially as we move forward with promoting IMA as a full and proper LSM, we should work towards referring to it as "IMA" and not "integrity".Quoted 3 lines
If anything we should be working to support "IMA" in places where we currently have "integrity" so that we can eventually deprecate "integrity".
Hi Paul
I fully understand your argument. However, 'integrity' has been the word to identify the integrity subsystem since long time ago.
Reducing the scope to 'ima' would create some confusion since, while 'ima' is associated to integrity, it would not encompass EVM.
Quoted 8 lines
Quoted 4 lines
Using
LSM_ID_IMAto reference the combination of IMA+EVM makes much more sense to me than usingLSM_ID_INTEGRITY, especially as we move towards promoting IMA+EVM and adopting LSM hooks for integrity verification, opening the door for other integrity focused LSMs.+ Mimi, linux-integrity
Ok, just to understand before posting v4, the code looks like this:
I worked on a new proposal. Let me know what you think. It is available here:
https://github.com/robertosassu/linux/tree/ima-evm-lsms-v4-devel-v6
I made IMA and EVM as standalone LSMs and removed 'integrity'. They maintain the same properties of 'integrity', i.e. they are the last and always enabled.
During initialization, 'ima' and 'evm' call
integrity_iintcache_init(), so that they can get integrity metadata. I added a check to ensure that this function is called only once. I also added the lsmid parameter so that the integrity-specific functions are added under the LSM ID of the caller.I added a new LSM ID for EVM, does not look good that IMA and EVM are represented by
LSM_ID_IMA.
Quoted 8 lines
Finally, I had to drop the patch to remove the rbtree, because without the 'integrity' LSM, space in the security blob cannot be reserved. Since integrity metadata is shared, it cannot be reserved by 'ima' or 'evm'.
An intermediate solution would be to keep the 'integrity' LSM just to reserve space in the security blob. Or, we remove the rbtree if/when IMA and EVM use disjoint integrity metadata.
One of the major benefits for making IMA and EVM LSMs was removing the rbtree and replacing it with the ability of using i_security.
I agree with Roberto. All three should be defined: LSM_ID_INTEGRITY, LSM_ID_IMA, LSM_ID_EVM.
Signature · 3 lines
thanks, Mimi
Re: [PATCH v15 00/11] LSM: Three basic syscalls
Quoted 70 lines · Mimi Zohar
Quoted 60 lines · Roberto Sassu
Quoted 31 lines · Roberto Sassu
Quoted 30 lines · Paul Moore
Quoted 27 lines · Roberto Sassu
Quoted 15 lines · Paul Moore
Quoted 5 lines · Roberto Sassu
Sorry, I just noticed
LSM_ID_IMA. Since we have the 'integrity' LSM, I think it should beLSM_ID_INTEGRITY.Mimi, all, do you agree? If yes, I send a patch shortly.
I believe
LSM_ID_IMAis the better option, despite "integrity" already being present inKconfigand possibly other areas. "IMA" is a specific thing/LSM whereas "integrity" is a property, principle, or quality. Especially as we move forward with promoting IMA as a full and proper LSM, we should work towards referring to it as "IMA" and not "integrity".Quoted 3 lines
If anything we should be working to support "IMA" in places where we currently have "integrity" so that we can eventually deprecate "integrity".
Hi Paul
I fully understand your argument. However, 'integrity' has been the word to identify the integrity subsystem since long time ago.
Reducing the scope to 'ima' would create some confusion since, while 'ima' is associated to integrity, it would not encompass EVM.
Quoted 8 lines
Quoted 4 lines
Using
LSM_ID_IMAto reference the combination of IMA+EVM makes much more sense to me than usingLSM_ID_INTEGRITY, especially as we move towards promoting IMA+EVM and adopting LSM hooks for integrity verification, opening the door for other integrity focused LSMs.+ Mimi, linux-integrity
Ok, just to understand before posting v4, the code looks like this:
I worked on a new proposal. Let me know what you think. It is available here:
https://github.com/robertosassu/linux/tree/ima-evm-lsms-v4-devel-v6
I made IMA and EVM as standalone LSMs and removed 'integrity'. They maintain the same properties of 'integrity', i.e. they are the last and always enabled.
During initialization, 'ima' and 'evm' call
integrity_iintcache_init(), so that they can get integrity metadata. I added a check to ensure that this function is called only once. I also added the lsmid parameter so that the integrity-specific functions are added under the LSM ID of the caller.I added a new LSM ID for EVM, does not look good that IMA and EVM are represented by
LSM_ID_IMA.Quoted 8 lines
Finally, I had to drop the patch to remove the rbtree, because without the 'integrity' LSM, space in the security blob cannot be reserved. Since integrity metadata is shared, it cannot be reserved by 'ima' or 'evm'.
An intermediate solution would be to keep the 'integrity' LSM just to reserve space in the security blob. Or, we remove the rbtree if/when IMA and EVM use disjoint integrity metadata.
Quoted 5 lines
One of the major benefits for making IMA and EVM LSMs was removing the rbtree and replacing it with the ability of using
i_security.I agree with Roberto. All three should be defined:
LSM_ID_INTEGRITY,LSM_ID_IMA,LSM_ID_EVM.
I did not try yet, but the 'integrity' LSM does not need an LSM ID. With the last version adding hooks to 'ima' or 'evm', it should be sufficient to keep DEFINE_LSM(integrity) with the request to store a pointer in the security blob (even the init function can be a dummy function).
Roberto
Paul Moore
maintainerRe: [PATCH v15 00/11] LSM: Three basic syscalls
Quoted 1 line · Roberto Sassu
On 10/18/2023 3:09 PM, Mimi Zohar wrote:
...
Quoted 7 lines
Quoted 2 lines
I agree with Roberto. All three should be defined:
LSM_ID_INTEGRITY,LSM_ID_IMA,LSM_ID_EVM.I did not try yet, but the 'integrity' LSM does not need an LSM ID. With the last version adding hooks to 'ima' or 'evm', it should be sufficient to keep
DEFINE_LSM(integrity)with the request to store a pointer in the security blob (even the init function can be a dummy function).
First off, this *really* should have been brought up way, way, *way* before now. This patchset has been discussed for months, and bringing up concerns in the eleventh hour is borderline rude.
At least we haven't shipped this in a tagged release from Linus yet, so there is that.
If you want to add a unique LSM ID for both IMA and EVM, I'm okay with that, but if we do that I don't see the need for a dedicated ID for "integrity". Roberto, Mimi, one of you please send me a patch on top of lsm/next-queue that updates the LSM ID to look like the following (I believe EVM was added between AppArmor and Yama, yes?):
#define LSM_ID_UNDEF 0 #define LSM_ID_CAPABILITY 100 #define LSM_ID_SELINUX 101 #define LSM_ID_SMACK 102 #define LSM_ID_TOMOYO 103 #define LSM_ID_IMA 104 #define LSM_ID_APPARMOR 105 #define LSM_ID_EVM 106 #define LSM_ID_YAMA 107 #define LSM_ID_LOADPIN 108 #define LSM_ID_SAFESETID 109 #define LSM_ID_LOCKDOWN 110 #define LSM_ID_BPF 111 #define LSM_ID_LANDLOCK 112
... and also update the LSM registration code for IMA/EVM/etc. to do the right thing.
Also, just to be clear, you should get this patch out ASAP.
Signature · 1 line
paul-moore.com
Mimi Zohar
maintainerRe: [PATCH v15 00/11] LSM: Three basic syscalls
Quoted 9 lines · Paul Moore
Quoted 1 line · Roberto Sassu
On 10/18/2023 3:09 PM, Mimi Zohar wrote:
...
Quoted 3 lines
Quoted 2 lines
I agree with Roberto. All three should be defined:
LSM_ID_INTEGRITY,LSM_ID_IMA,LSM_ID_EVM.
Quoted 8 lines
Quoted 4 lines
I did not try yet, but the 'integrity' LSM does not need an LSM ID. With the last version adding hooks to 'ima' or 'evm', it should be sufficient to keep
DEFINE_LSM(integrity)with the request to store a pointer in the security blob (even the init function can be a dummy function).First off, this *really* should have been brought up way, way, *way* before now. This patchset has been discussed for months, and bringing up concerns in the eleventh hour is borderline rude.
As everyone knows IMA and EVM are not LSMs at this point.
So the only thing that is "rude" is the way you're responding in this thread.
Quoted 3 lines
At least we haven't shipped this in a tagged release from Linus yet, so there is that.
What does that have to do with anything?! Code changes.
Mimi
Paul Moore
maintainerRe: [PATCH v15 00/11] LSM: Three basic syscalls
Quoted 15 lines · Mimi Zohar
Quoted 14 lines · Paul Moore
Quoted 1 line · Roberto Sassu
On 10/18/2023 3:09 PM, Mimi Zohar wrote:
...
Quoted 7 lines
Quoted 2 lines
I agree with Roberto. All three should be defined:
LSM_ID_INTEGRITY,LSM_ID_IMA,LSM_ID_EVM.I did not try yet, but the 'integrity' LSM does not need an LSM ID. With the last version adding hooks to 'ima' or 'evm', it should be sufficient to keep
DEFINE_LSM(integrity)with the request to store a pointer in the security blob (even the init function can be a dummy function).
Quoted 5 lines
Quoted 3 lines
First off, this *really* should have been brought up way, way, *way* before now. This patchset has been discussed for months, and bringing up concerns in the eleventh hour is borderline rude.
As everyone knows IMA and EVM are not LSMs at this point.
Considering all the work Roberto has been doing to make that happen, not to mention the discussions we've had on this topic, that's an awfully small technicality to use as the basis of an argument.
Quoted 2 lines
So the only thing that is "rude" is the way you're responding in this thread.
Agree to disagree.
Quoted 4 lines
Quoted 2 lines
At least we haven't shipped this in a tagged release from Linus yet, so there is that.
What does that have to do with anything?! Code changes.
Code can change, Linux kernel APIs should not change.
Signature · 1 line
paul-moore.com
Re: [PATCH v15 00/11] LSM: Three basic syscalls
Quoted 20 lines · Paul Moore
Quoted 19 lines · Mimi Zohar
Quoted 17 lines · Paul Moore
Quoted 1 line · Roberto Sassu
On 10/18/2023 3:09 PM, Mimi Zohar wrote:
...
Quoted 7 lines
Quoted 2 lines
I agree with Roberto. All three should be defined:
LSM_ID_INTEGRITY,LSM_ID_IMA,LSM_ID_EVM.I did not try yet, but the 'integrity' LSM does not need an LSM ID. With the last version adding hooks to 'ima' or 'evm', it should be sufficient to keep
DEFINE_LSM(integrity)with the request to store a pointer in the security blob (even the init function can be a dummy function).First off, this *really* should have been brought up way, way, *way* before now. This patchset has been discussed for months, and bringing up concerns in the eleventh hour is borderline rude.
Quoted 5 lines
Quoted 1 line
As everyone knows IMA and EVM are not LSMs at this point.
Considering all the work Roberto has been doing to make that happen, not to mention the discussions we've had on this topic, that's an awfully small technicality to use as the basis of an argument.
Sorry Paul, but I've been working on this patch set for a long time and you were also involved in the prerequisites (like making the 'integrity' LSM as the last).
I thought it was clear at this point that we were going to add the hooks to the 'integrity' LSM.
I really have no problem to rebase my work on top of other work, but I was very surprised to see LSM_ID_IMA instead of LSM_ID_INTEGRITY, and at minimum this should have been agreed with Mimi. And also, I was not convinced with the argument that LSM_ID_IMA should represent IMA+EVM.
Roberto
Casey Schaufler
maintainerRe: [PATCH v15 00/11] LSM: Three basic syscalls
Quoted 21 lines · Roberto Sassu
Quoted 13 lines · Paul Moore
Quoted 12 lines · Mimi Zohar
Quoted 11 lines · Paul Moore
Quoted 1 line · Roberto Sassu
On 10/18/2023 3:09 PM, Mimi Zohar wrote:
...
Quoted 6 lines
Quoted 2 lines
I agree with Roberto. All three should be defined:
LSM_ID_INTEGRITY,LSM_ID_IMA,LSM_ID_EVM.I did not try yet, but the 'integrity' LSM does not need an LSM ID. With the last version adding hooks to 'ima' or 'evm', it should be sufficient to keep
DEFINE_LSM(integrity)with the request to store a pointer in the security blob (even the init function can be a dummy function).Quoted 7 lines
Quoted 4 lines
Quoted 3 lines
First off, this *really* should have been brought up way, way, *way* before now. This patchset has been discussed for months, and bringing up concerns in the eleventh hour is borderline rude.
As everyone knows IMA and EVM are not LSMs at this point.
Considering all the work Roberto has been doing to make that happen, not to mention the discussions we've had on this topic, that's an awfully small technicality to use as the basis of an argument.
Quoted 6 lines
Sorry Paul, but I've been working on this patch set for a long time and you were also involved in the prerequisites (like making the 'integrity' LSM as the last).
I thought it was clear at this point that we were going to add the hooks to the 'integrity' LSM.
There's a chicken/egg issue here. You can hold up the syscalls patch forever if you insist on it accommodating every patch set that's in the pipeline. I understand that you've been working on the integrity rework for some time. I understand that it's frustrating when things change out from under you. Believe me, I do.
Quoted 8 lines
I really have no problem to rebase my work on top of other work, but I was very surprised to see
LSM_ID_IMAinstead ofLSM_ID_INTEGRITY, and at minimum this should have been agreed with Mimi. And also, I was not convinced with the argument thatLSM_ID_IMAshould represent IMA+EVM.Roberto
Re: [PATCH v15 00/11] LSM: Three basic syscalls
In reply to Roberto SassuQuoted 74 lines · Roberto Sassu
Quoted 73 lines · Mimi Zohar
Quoted 60 lines · Roberto Sassu
Quoted 31 lines · Roberto Sassu
Quoted 30 lines · Paul Moore
Quoted 27 lines · Roberto Sassu
Quoted 15 lines · Paul Moore
Quoted 5 lines · Roberto Sassu
Sorry, I just noticed
LSM_ID_IMA. Since we have the 'integrity' LSM, I think it should beLSM_ID_INTEGRITY.Mimi, all, do you agree? If yes, I send a patch shortly.
I believe
LSM_ID_IMAis the better option, despite "integrity" already being present inKconfigand possibly other areas. "IMA" is a specific thing/LSM whereas "integrity" is a property, principle, or quality. Especially as we move forward with promoting IMA as a full and proper LSM, we should work towards referring to it as "IMA" and not "integrity".Quoted 3 lines
If anything we should be working to support "IMA" in places where we currently have "integrity" so that we can eventually deprecate "integrity".
Hi Paul
I fully understand your argument. However, 'integrity' has been the word to identify the integrity subsystem since long time ago.
Reducing the scope to 'ima' would create some confusion since, while 'ima' is associated to integrity, it would not encompass EVM.
Quoted 8 lines
Quoted 4 lines
Using
LSM_ID_IMAto reference the combination of IMA+EVM makes much more sense to me than usingLSM_ID_INTEGRITY, especially as we move towards promoting IMA+EVM and adopting LSM hooks for integrity verification, opening the door for other integrity focused LSMs.+ Mimi, linux-integrity
Ok, just to understand before posting v4, the code looks like this:
I worked on a new proposal. Let me know what you think. It is available here:
https://github.com/robertosassu/linux/tree/ima-evm-lsms-v4-devel-v6
I made IMA and EVM as standalone LSMs and removed 'integrity'. They maintain the same properties of 'integrity', i.e. they are the last and always enabled.
During initialization, 'ima' and 'evm' call
integrity_iintcache_init(), so that they can get integrity metadata. I added a check to ensure that this function is called only once. I also added the lsmid parameter so that the integrity-specific functions are added under the LSM ID of the caller.I added a new LSM ID for EVM, does not look good that IMA and EVM are represented by
LSM_ID_IMA.Quoted 8 lines
Finally, I had to drop the patch to remove the rbtree, because without the 'integrity' LSM, space in the security blob cannot be reserved. Since integrity metadata is shared, it cannot be reserved by 'ima' or 'evm'.
An intermediate solution would be to keep the 'integrity' LSM just to reserve space in the security blob. Or, we remove the rbtree if/when IMA and EVM use disjoint integrity metadata.
One of the major benefits for making IMA and EVM LSMs was removing the rbtree and replacing it with the ability of using
i_security.
Quoted 7 lines
Quoted 2 lines
I agree with Roberto. All three should be defined:
LSM_ID_INTEGRITY,LSM_ID_IMA,LSM_ID_EVM.I did not try yet, but the 'integrity' LSM does not need an LSM ID. With the last version adding hooks to 'ima' or 'evm', it should be sufficient to keep
DEFINE_LSM(integrity)with the request to store a pointer in the security blob (even the init function can be a dummy function).
Ok, I rebased on top of Paul's 'lsm: drop LSM_ID_IMA', made IMA and EVM as standalone LSMs, and assigned LSM IDs to them in the correct chronological order.
Still left DEFINE_LSM(integrity) to reserve space for the integrity_iint_cache pointer, but it does not register any LSM hook, then no LSM ID required.
In the future, we might be able to make IMA and EVM use disjoint metadata, so they will reserve space in the security blob and register appropriate hooks for the metadata management.
With this intermediate solution, I can keep the rbtree patch, which will provide performance improvements due to searching metadata in constant time.
If you want to have a look before I send the patch set, the code is available here:
https://github.com/robertosassu/linux/commits/ima-evm-lsms-v4-devel-v7
It passes all IMA tests:
https://github.com/robertosassu/ima-evm-utils/actions/runs/6571587570
Roberto
Paul Moore
maintainerRe: [PATCH v15 00/11] LSM: Three basic syscalls
In reply to Casey SchauflerQuoted 201 lines · Casey Schaufler
Add three system calls for the Linux Security Module ABI.
lsm_get_self_attr()provides the security module specific attributes that have previously been visible in the/proc/self/attrdirectory. For each security module that uses the specified attribute on the current process the system call will return an LSM identifier and the value of the attribute. The LSM and attribute identifier values are defined ininclude/uapi/linux/lsm.hLSM identifiers are simple integers and reflect the order in which the LSM was added to the mainline kernel. This is a convention, not a promise of the API. LSM identifiers below the value of 100 are reserved for unspecified future uses. That could include information about the security infrastructure itself, or about how multiple LSMs might interact with each other.
A new LSM hook
security_getselfattr()is introduced to get the required information from the security modules. This is similar to the existingsecurity_getprocattr()hook, but specifies the format in which string data is returned and requires the module to put the information into a userspace destination.
lsm_set_self_attr()changes the specified LSM attribute. Only one attribute can be changed at a time, and then only if the specified security module allows the change.A new LSM hook
security_setselfattr()is introduced to set the required information in the security modules. This is similar to the existingsecurity_setprocattr()hook, but specifies the format in which string data is presented and requires the module to get the information from a userspace destination.
lsm_list_modules()provides the LSM identifiers, in order, of the security modules that are active on the system. This has been available in the securityfs file/sys/kernel/security/lsm.Patch 0001 changes the LSM registration from passing the name of the module to passing a
lsm_idstructure that contains the name of the module, an LSM identifier number and an attribute identifier.
Patch 0002 adds the registeredlsm_idsto a table.
Patch 0003 changes security_[gs]etprocattr() to use LSM IDs instead of LSM names.
Patch 0004 implementslsm_get_self_attr()andlsm_set_self_attr(). New LSM hookssecurity_getselfattr()andsecurity_setselfattr()are defined.
Patch 0005 implementslsm_list_modules().
Patch 0006 wires up the syscalls.
Patch 0007 implements helper functions to make it easier for security modules to uselsm_ctxstructures.
Patch 0008 provides the Smack implementation for [gs]etselfattr(). Patch 0009 provides the AppArmor implementation for [gs]etselfattr(). Patch 0010 provides the SELinux implementation for [gs]etselfattr(). Patch 0011 implements selftests for the three new syscalls.https://github.com/cschaufler/lsm-stacking.git#syscalls-6.5-rc7-v14
v15: Rebased on 6.6-rc1.
Adopt suggested improvements tosecurity_getprocattr, making the code easier to read.
Squash a code fix from 0011 to 0004.
v14: Make the handling ofLSM_FLAG_SINGLEeasier to understand.
Tighten the comments and documentation.
Better use of const, static, and__ro_after_init. Add selftests forLSM_FLAG_SINGLEcases.
v13: Change the setselfattr code to do a single user copy.
Make the self tests more robust.
Improve use of const.
Change syscall numbers to reflect upstream additions.
v12: Repair a registration time overflow check.
v11: Remove redundent alignment code
Improve a few comments.
UseLSM_ATTR_UNDEFin place of 0 in a few places. Correct a return of-EINVALto-E2BIG.
v10: Correct use of__user.
Improve a few comments.
Revert unnecessary changes in module initialization.
v9: Support a flagLSM_FLAG_SINGLEinlsm_get_self_attr()that
instructs the call to provide only the attribute for the LSM identified in the referencedlsm_ctxstructure.
Fix a typing error.
Change some coding style.
v8: Allow an LSM to provide more than one instance of an attribute,
even though none of the existing modules do so.
Pad the data returned bylsm_get_self_attr()to the size of the structlsm_ctx.
Change some displeasing varilable names.
v7: Pass the attribute desired to lsm_[gs]et_self_attr in its own
parameter rather than encoding it in the flags. Change the flags parameters to u32.
Don't shortcut out of calling LSM specific code in the infrastructure, let the LSM report that doesn't support an attribute instead. With that it is not necessary to maintain a set of supported attributes in thelsm_idstructure. Fix a typing error.
v6: Switch from reusing security_[gs]procattr() to using new
security_[gs]selfattr() hooks. Use explicit sized data types in thelsm_ctxstructure.v5: Correct syscall parameter data types.
v4: Restore "reserved" LSM ID values. Add explaination.
Squash patches that introduce fields inlsm_id. Correct a wireup error.v3: Add
lsm_set_self_attr().
Renamelsm_self_attr()tolsm_get_self_attr(). Provide the values only for a specifed attribute inlsm_get_self_attr().
Add selftests for the three new syscalls. Correct some parameter checking.v2: Use user-interface safe data types.
Remove "reserved" LSM ID values.
Improve kerneldoc comments
Include copyright dates
Use more descriptive name for LSM counter
Add documentation
Correct wireup errorsCasey Schaufler (11):
LSM: Identify modules by more than name
LSM: Maintain a table of LSM attribute data
proc: Use lsmids instead of lsm names for attrs
LSM: syscalls for current process attributes
LSM: Createlsm_list_modulessystem call
LSM: wireup Linux Security Module syscalls
LSM: Helpers for attribute names and fillinglsm_ctx
Smack: implement setselfattr and getselfattr hooks
AppArmor: Add selfattr hooks
SELinux: Add selfattr hooks
LSM: selftests for Linux Security Module syscallsDocumentation/userspace-api/index.rst | 1 + Documentation/userspace-api/lsm.rst | 73 +++++ MAINTAINERS | 2 + arch/alpha/kernel/syscalls/syscall.tbl | 3 + arch/arm/tools/syscall.tbl | 3 + arch/arm64/include/asm/unistd.h | 2 +- arch/arm64/include/asm/unistd32.h | 6 + arch/ia64/kernel/syscalls/syscall.tbl | 3 + arch/m68k/kernel/syscalls/syscall.tbl | 3 + arch/microblaze/kernel/syscalls/syscall.tbl | 3 + arch/mips/kernel/syscalls/syscall_n32.tbl | 3 + arch/mips/kernel/syscalls/syscall_n64.tbl | 3 + arch/mips/kernel/syscalls/syscall_o32.tbl | 3 + arch/parisc/kernel/syscalls/syscall.tbl | 3 + arch/powerpc/kernel/syscalls/syscall.tbl | 3 + arch/s390/kernel/syscalls/syscall.tbl | 3 + arch/sh/kernel/syscalls/syscall.tbl | 3 + arch/sparc/kernel/syscalls/syscall.tbl | 3 + arch/x86/entry/syscalls/syscall_32.tbl | 3 + arch/x86/entry/syscalls/syscall_64.tbl | 3 + arch/xtensa/kernel/syscalls/syscall.tbl | 3 + fs/proc/base.c | 29 +- fs/proc/internal.h | 2 +- include/linux/lsm_hook_defs.h | 4 + include/linux/lsm_hooks.h | 17 +- include/linux/security.h | 46 ++- include/linux/syscalls.h | 6 + include/uapi/asm-generic/unistd.h | 9 +- include/uapi/linux/lsm.h | 90 ++++++ kernel/sys_ni.c | 3 + security/Makefile | 1 + security/apparmor/include/procattr.h | 2 +- security/apparmor/lsm.c | 99 ++++++- security/apparmor/procattr.c | 10 +- security/bpf/hooks.c | 9 +- security/commoncap.c | 8 +- security/landlock/cred.c | 2 +- security/landlock/fs.c | 2 +- security/landlock/ptrace.c | 2 +- security/landlock/setup.c | 6 + security/landlock/setup.h | 1 + security/loadpin/loadpin.c | 9 +- security/lockdown/lockdown.c | 8 +- security/lsm_syscalls.c | 120 ++++++++ security/safesetid/lsm.c | 9 +- security/security.c | 253 +++++++++++++++- security/selinux/hooks.c | 143 +++++++-- security/smack/smack_lsm.c | 103 ++++++- security/tomoyo/tomoyo.c | 9 +- security/yama/yama_lsm.c | 8 +- .../arch/mips/entry/syscalls/syscall_n64.tbl | 3 + .../arch/powerpc/entry/syscalls/syscall.tbl | 3 + .../perf/arch/s390/entry/syscalls/syscall.tbl | 3 + .../arch/x86/entry/syscalls/syscall_64.tbl | 3 + tools/testing/selftests/Makefile | 1 + tools/testing/selftests/lsm/.gitignore | 1 + tools/testing/selftests/lsm/Makefile | 17 ++ tools/testing/selftests/lsm/common.c | 89 ++++++ tools/testing/selftests/lsm/common.h | 33 +++ tools/testing/selftests/lsm/config | 3 + .../selftests/lsm/lsm_get_self_attr_test.c | 275 ++++++++++++++++++ .../selftests/lsm/lsm_list_modules_test.c | 140 +++++++++ .../selftests/lsm/lsm_set_self_attr_test.c | 74 +++++ 63 files changed, 1694 insertions(+), 93 deletions(-) create mode 100644 Documentation/userspace-api/lsm.rst create mode 100644 include/uapi/linux/lsm.h create mode 100644 security/lsm_syscalls.c
Quoted 8 lines
create mode 100644 tools/testing/selftests/lsm/.gitignore create mode 100644 tools/testing/selftests/lsm/Makefile create mode 100644 tools/testing/selftests/lsm/common.c create mode 100644 tools/testing/selftests/lsm/common.h create mode 100644 tools/testing/selftests/lsm/config create mode 100644 tools/testing/selftests/lsm/lsm_get_self_attr_test.c create mode 100644 tools/testing/selftests/lsm/lsm_list_modules_test.c create mode 100644 tools/testing/selftests/lsm/lsm_set_self_attr_test.c
This patchset is now in lsm/dev, thanks everyone!
Signature · 1 line
paul-moore.com