Re: LSM stacking in next for 6.1?

2022-09-27 Thread Paul Moore
On Tue, Sep 27, 2022 at 4:54 PM Casey Schaufler wrote: > > On 9/14/2022 6:42 AM, Paul Moore wrote: > > On Thu, Sep 8, 2022 at 6:56 PM Casey Schaufler > > wrote: > >> I am going to start playing with these syscalls. Please help me understand > >> where I have suggested something stoopid. > > Than

Re: LSM stacking in next for 6.1?

2022-09-27 Thread Casey Schaufler
On 9/14/2022 6:42 AM, Paul Moore wrote: > On Thu, Sep 8, 2022 at 6:56 PM Casey Schaufler wrote: >> I am going to start playing with these syscalls. Please help me understand >> where I have suggested something stoopid. > Thanks for posting an initial patch that we can use for further > discussion.

[PATCH v38 39/39] LSM: Create lsm_module_list system call

2022-09-27 Thread 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. Signed-off-by: Casey Schaufler --- arch/x86/entry/syscalls/syscall_64.tbl | 1 + include/linux/syscalls.h | 1 + include/uapi/asm-g

[PATCH v38 31/39] LSM: Add a function to report multiple LSMs

2022-09-27 Thread Casey Schaufler
Add a new boolean function lsm_multiple_contexts() to identify when multiple security modules provide security context strings. Signed-off-by: Casey Schaufler Acked-by: Paul Moore Reviewed-by: John Johansen --- include/linux/security.h | 9 + 1 file changed, 9 insertions(+) diff --git

[PATCH v38 38/39] AppArmor: Remove the exclusive flag

2022-09-27 Thread Casey Schaufler
With the inclusion of the interface LSM process attribute mechanism AppArmor no longer needs to be treated as an "exclusive" security module. Remove the flag that indicates it is exclusive. Remove the stub getpeersec_dgram AppArmor hook as it has no effect in the single LSM case and interferes in t

[PATCH v38 37/39] LSM: Removed scaffolding function lsmcontext_init

2022-09-27 Thread Casey Schaufler
The scaffolding function lsmcontext_init() is no longer used. Remove it. Signed-off-by: Casey Schaufler --- include/linux/security.h | 19 --- 1 file changed, 19 deletions(-) diff --git a/include/linux/security.h b/include/linux/security.h index c190b9189287..f6a247033556 100644

[PATCH v38 36/39] netlabel: Use a struct lsmblob in audit data

2022-09-27 Thread Casey Schaufler
Remove scaffolding in netlabel audit by keeping subject lsm information in an lsmblob structure instead of a secid. Acked-by: Paul Moore Signed-off-by: Casey Schaufler --- include/net/netlabel.h| 2 +- net/netlabel/netlabel_unlabeled.c | 4 +--- net/netlabel/netlabel_user.c | 4

[PATCH v38 34/39] audit: multiple subject lsm values for netlabel

2022-09-27 Thread Casey Schaufler
Refactor audit_log_task_context(), creating a new audit_log_subject_context(). This is used in netlabel auditing to provide multiple subject security contexts as necessary. Acked-by: Paul Moore Signed-off-by: Casey Schaufler --- include/linux/audit.h| 7 +++ kernel/audit.c

[PATCH v38 35/39] Audit: Add record for multiple object contexts

2022-09-27 Thread Casey Schaufler
Create a new audit record AUDIT_MAC_OBJ_CONTEXTS. An example of the MAC_OBJ_CONTEXTS (1421) record is: type=MAC_OBJ_CONTEXTS[1421] msg=audit(1601152467.009:1050): obj_selinux=unconfined_u:object_r:user_home_t:s0 When an audit event includes a AUDIT_MAC_OBJ_CONTEXTS record the "obj=" f

[PATCH v38 33/39] Audit: Add record for multiple task security contexts

2022-09-27 Thread Casey Schaufler
Create a new audit record AUDIT_MAC_TASK_CONTEXTS. An example of the MAC_TASK_CONTEXTS (1420) record is: type=MAC_TASK_CONTEXTS[1420] msg=audit(1600880931.832:113) subj_apparmor=unconfined subj_smack=_ When an audit event includes a AUDIT_MAC_TASK_CONTEXTS record the "subj=" field

[PATCH v38 32/39] Audit: Allow multiple records in an audit_buffer

2022-09-27 Thread Casey Schaufler
Replace the single skb pointer in an audit_buffer with a list of skb pointers. Add the audit_stamp information to the audit_buffer as there's no guarantee that there will be an audit_context containing the stamp associated with the event. At audit_log_end() time create auxiliary records (none are c

[PATCH v38 30/39] Audit: Create audit_stamp structure

2022-09-27 Thread Casey Schaufler
Replace the timestamp and serial number pair used in audit records with a structure containing the two elements. Signed-off-by: Casey Schaufler Acked-by: Paul Moore --- kernel/audit.c | 17 + kernel/audit.h | 13 + kernel/auditsc.c | 22 +- 3

[PATCH v38 29/39] Audit: Keep multiple LSM data in audit_names

2022-09-27 Thread Casey Schaufler
Replace the osid field in the audit_names structure with a lsmblob structure. This accommodates the use of an lsmblob in security_audit_rule_match() and security_inode_getsecid(). Signed-off-by: Casey Schaufler Acked-by: Paul Moore --- kernel/audit.h | 2 +- kernel/auditsc.c | 22 ---

[PATCH v38 28/39] LSM: security_secid_to_secctx module selection

2022-09-27 Thread Casey Schaufler
Add a parameter to security_secid_to_secctx() to identify which of the security modules that may be active should provide the security context. If the parameter is greater than or equal to zero, the security module associated with that LSM "slot" is used. If the value is LSMBLOB_DISPLAY the "interf

[PATCH v38 27/39] binder: Pass LSM identifier for confirmation

2022-09-27 Thread Casey Schaufler
Send an identifier for the security module interface_lsm along with the security context. This allows the receiver to verify that the receiver and the sender agree on which security module's context is being used. If they don't agree the message is rejected. Signed-off-by: Casey Schaufler --- dr

[PATCH v38 25/39] LSM: security_secid_to_secctx in netlink netfilter

2022-09-27 Thread Casey Schaufler
Change netlink netfilter interfaces to use lsmcontext pointers, and remove scaffolding. Reviewed-by: Kees Cook Reviewed-by: John Johansen Acked-by: Paul Moore Acked-by: Stephen Smalley Acked-by: Pablo Neira Ayuso Signed-off-by: Casey Schaufler Cc: net...@vger.kernel.org Cc: netfilter-de...@v

[PATCH v38 26/39] NET: Store LSM netlabel data in a lsmblob

2022-09-27 Thread Casey Schaufler
Netlabel uses LSM interfaces requiring an lsmblob and the internal storage is used to pass information between these interfaces, so change the internal data from a secid to a lsmblob. Update the netlabel interfaces and their callers to accommodate the change. This requires that the modules using ne

[PATCH v38 24/39] Use lsmcontext in security_dentry_init_security

2022-09-27 Thread Casey Schaufler
Replace the (secctx,seclen) pointer pair with a single lsmcontext pointer to allow return of the LSM identifier along with the context and context length. This allows security_release_secctx() to know how to release the context. Callers have been modified to use or save the returned data from the n

[PATCH v38 22/39] LSM: Use lsmcontext in security_secid_to_secctx

2022-09-27 Thread Casey Schaufler
Replace the (secctx,seclen) pointer pair with a single lsmcontext pointer to allow return of the LSM identifier along with the context and context length. This allows security_release_secctx() to know how to release the context. Callers have been modified to use or save the returned data from the n

[PATCH v38 21/39] LSM: Ensure the correct LSM context releaser

2022-09-27 Thread Casey Schaufler
Add a new lsmcontext data structure to hold all the information about a "security context", including the string, its size and which LSM allocated the string. The allocation information is necessary because LSMs have different policies regarding the lifecycle of these strings. SELinux allocates and

[PATCH v38 23/39] LSM: Use lsmcontext in security_inode_getsecctx

2022-09-27 Thread Casey Schaufler
Change the security_inode_getsecctx() interface to fill a lsmcontext structure instead of data and length pointers. This provides the information about which LSM created the context so that security_release_secctx() can use the correct hook. Acked-by: Stephen Smalley Acked-by: Paul Moore Acked-b

[PATCH v38 18/39] LSM: Use lsmblob in security_inode_getsecid

2022-09-27 Thread Casey Schaufler
Change the security_inode_getsecid() interface to fill in a lsmblob structure instead of a u32 secid. This allows for its callers to gather data from all registered LSMs. Data is provided for IMA and audit. Reviewed-by: Kees Cook Reviewed-by: John Johansen Acked-by: Stephen Smalley Acked-by: Pa

[PATCH v38 19/39] LSM: Use lsmblob in security_cred_getsecid

2022-09-27 Thread Casey Schaufler
Change the security_cred_getsecid() interface to fill in a lsmblob instead of a u32 secid. The associated data elements in the audit sub-system are changed from a secid to a lsmblob to accommodate multiple possible LSM audit users. Reviewed-by: Kees Cook Reviewed-by: John Johansen Acked-by: Step

[PATCH v38 20/39] LSM: Specify which LSM to display

2022-09-27 Thread Casey Schaufler
Create two new prctl() options PR_LSM_ATTR_SET and PR_LSM_ATTR_GET which change and report the Interface LSM respectively. The LSM ID number of an active LSM that supplies hooks for human readable data may be passed in the arg2 value with the PR_LSM_ATTR_SET option. The PR_LSM_ATT_GET option retur

[PATCH v38 17/39] LSM: Use lsmblob in security_current_getsecid

2022-09-27 Thread Casey Schaufler
Change the security_current_getsecid_subj() and security_task_getsecid_obj() interfaces to fill in a lsmblob structure instead of a u32 secid in support of LSM stacking. Audit interfaces will need to collect all possible secids for possible reporting. Reviewed-by: Kees Cook Reviewed-by: John Joha

[PATCH v38 16/39] LSM: Use lsmblob in security_ipc_getsecid

2022-09-27 Thread Casey Schaufler
There may be more than one LSM that provides IPC data for auditing. Change security_ipc_getsecid() to fill in a lsmblob structure instead of the u32 secid. The audit data structure containing the secid will be updated later, so there is a bit of scaffolding here. Reviewed-by: Kees Cook Reviewed-b

[PATCH v38 15/39] LSM: Use lsmblob in security_secid_to_secctx

2022-09-27 Thread Casey Schaufler
Change security_secid_to_secctx() to take a lsmblob as input instead of a u32 secid. It will then call the LSM hooks using the lsmblob element allocated for that module. The callers have been updated as well. This allows for the possibility that more than one module may be called upon to translate

[PATCH v38 14/39] LSM: Use lsmblob in security_secctx_to_secid

2022-09-27 Thread Casey Schaufler
Change the security_secctx_to_secid interface to use a lsmblob structure in place of the single u32 secid in support of module stacking. Change its callers to do the same. The security module hook is unchanged, still passing back a secid. The infrastructure passes the correct entry from the lsmblo

[PATCH v38 13/39] LSM: Use lsmblob in security_kernel_act_as

2022-09-27 Thread Casey Schaufler
Change the security_kernel_act_as interface to use a lsmblob structure in place of the single u32 secid in support of module stacking. Change its only caller, set_security_override, to do the same. Change that one's only caller, set_security_override_from_ctx, to call it with the new parameter type

[PATCH v38 12/39] LSM: Use lsmblob in security_audit_rule_match

2022-09-27 Thread Casey Schaufler
Change the secid parameter of security_audit_rule_match to a lsmblob structure pointer. Pass the entry from the lsmblob structure for the approprite slot to the LSM hook. Change the users of security_audit_rule_match to use the lsmblob instead of a u32. The scaffolding function lsmblob_init() fill

[PATCH v38 11/39] IMA: avoid label collisions with stacked LSMs

2022-09-27 Thread Casey Schaufler
Integrity measurement may filter on security module information and needs to be clear in the case of multiple active security modules which applies. Provide a boot option ima_rules_lsm= to allow the user to specify an active security module to apply filters to. If not specified, use the first regis

[PATCH v38 10/39] LSM: provide lsm name and id slot mappings

2022-09-27 Thread Casey Schaufler
Provide interfaces to map LSM slot numbers and LSM names. Update the LSM registration code to save this information. Acked-by: Paul Moore Reviewed-by: Kees Cook Signed-off-by: Casey Schaufler --- include/linux/security.h | 4 security/security.c | 45

[PATCH v38 09/39] LSM: Add the lsmblob data structure.

2022-09-27 Thread Casey Schaufler
When more than one security module is exporting data to audit and networking sub-systems a single 32 bit integer is no longer sufficient to represent the data. Add a structure to be used instead. The lsmblob structure is currently an array of u32 "secids". There is an entry for each of the securit

[PATCH v38 08/39] LSM: Infrastructure management of the sock security

2022-09-27 Thread Casey Schaufler
Move management of the sock->sk_security blob out of the individual security modules and into the security infrastructure. Instead of allocating the blobs from within the modules the modules tell the infrastructure how much space is required, and the space is allocated there. Acked-by: Paul Moore

[PATCH v38 06/39] LSM: lsm_self_attr syscall for LSM self attributes

2022-09-27 Thread Casey Schaufler
Create a system call lsm_self_attr() to provide the security module maintained attributes of the current process. Historically these attributes have been exposed to user space via entries in procfs under /proc/self/attr. Attributes are provided as a collection of lsm_ctx structures which are place

[PATCH v38 07/39] integrity: disassociate ima_filter_rule from security_audit_rule

2022-09-27 Thread Casey Schaufler
Create real functions for the ima_filter_rule interfaces. These replace #defines that obscure the reuse of audit interfaces. The new functions are put in security.c because they use security module registered hooks that we don't want exported. Acked-by: Paul Moore Reviewed-by: John Johansen Sign

[PATCH v38 05/39] proc: Use lsmids instead of lsm names for attrs

2022-09-27 Thread Casey Schaufler
Use 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 pr

[PATCH v38 04/39] LSM: Maintain a table of LSM attribute data

2022-09-27 Thread Casey Schaufler
As LSMs are registered add their lsm_id pointers to a table. This will be used later for attribute reporting. Signed-off-by: Casey Schaufler --- include/linux/security.h | 17 + security/security.c | 18 ++ 2 files changed, 35 insertions(+) diff --git a/incl

[PATCH v38 03/39] LSM: Identify the process attributes for each module

2022-09-27 Thread Casey Schaufler
Add an integer member "features" to the struct lsm_id which identifies the API related data associated with each security module. The initial set of features maps to information that has traditionaly been available in /proc/self/attr. Signed-off-by: Casey Schaufler --- include/linux/lsm_hooks.h

[PATCH v38 01/39] LSM: Identify modules by more than name

2022-09-27 Thread Casey Schaufler
Create a struct lsm_id to contain identifying information about Linux Security Modules (LSMs). At inception this contains a single member, which is the name of the module. Change the security_add_hooks() interface to use this structure. Change the individual modules to maintain their own struct lsm

[PATCH v38 02/39] LSM: Add an LSM identifier for external use

2022-09-27 Thread Casey Schaufler
Add an integer member "id" to the struct lsm_id. This value is a unique identifier associated with each security module. The values are defined in a new UAPI header file. Each existing LSM has been updated to include it's LSMID in the lsm_id. Signed-off-by: Casey Schaufler --- include/linux/lsm_

[PATCH v38 00/39] LSM: Module stacking for AppArmor

2022-09-27 Thread Casey Schaufler
This patchset provides the changes required for the AppArmor security module to stack safely with any other. There are additional changes required for SELinux and Smack to coexist. These are primarily in the networking code and will be addressed after these changes are upstream. v38: Rebase to 6.0