[PATCH v30 00/28] LSM: Module stacking for AppArmor

2021-11-23 Thread Casey Schaufler
This patchset provides the changes required for the AppArmor security module to stack safely with any other. v30: Rebase to 5.16-rc1 Replace the integrity sub-system reuse of the audit subsystem event matching functions with IMA specific functions. This is done because audit needs

[PATCH v30 03/28] LSM: Add the lsmblob data structure.

2021-11-23 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

[PATCH v30 05/28] IMA: avoid label collisions with stacked LSMs

2021-11-23 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

[PATCH v30 06/28] LSM: Use lsmblob in security_audit_rule_match

2021-11-23 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()

[PATCH v30 08/28] LSM: Use lsmblob in security_secctx_to_secid

2021-11-23 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

[PATCH v30 09/28] LSM: Use lsmblob in security_secid_to_secctx

2021-11-23 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 v30 13/28] LSM: Use lsmblob in security_cred_getsecid

2021-11-23 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:

[PATCH v30 15/28] LSM: Ensure the correct LSM context releaser

2021-11-23 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

[PATCH v30 22/28] Audit: Keep multiple LSM data in audit_names

2021-11-23 Thread Casey Schaufler
Replace the osid field in the audit_names structure with a lsmblob structure. This accomodates the use of an lsmblob in security_audit_rule_match() and security_inode_getsecid(). Signed-off-by: Casey Schaufler --- kernel/audit.h | 2 +- kernel/auditsc.c | 22 -- 2 files

[PATCH v30 26/28] Audit: Add record for multiple object security contexts

2021-11-23 Thread Casey Schaufler
Create a new audit record AUDIT_MAC_OBJ_CONTEXTS. An example of the MAC_OBJ_CONTEXTS (1421) record is: type=UNKNOWN[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=" field

[PATCH v30 25/28] Audit: Add record for multiple task security contexts

2021-11-23 Thread Casey Schaufler
Create a new audit record AUDIT_MAC_TASK_CONTEXTS. An example of the MAC_TASK_CONTEXTS (1420) record is: type=UNKNOWN[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 in

[PATCH v30 07/28] LSM: Use lsmblob in security_kernel_act_as

2021-11-23 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

[PATCH v30 11/28] LSM: Use lsmblob in security_task_getsecid

2021-11-23 Thread Casey Schaufler
Change the security_task_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

[PATCH v30 12/28] LSM: Use lsmblob in security_inode_getsecid

2021-11-23 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:

[PATCH v30 17/28] LSM: Use lsmcontext in security_inode_getsecctx

2021-11-23 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

[PATCH v30 19/28] NET: Store LSM netlabel data in a lsmblob

2021-11-23 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

[PATCH v30 18/28] LSM: security_secid_to_secctx in netlink netfilter

2021-11-23 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:

[PATCH v30 16/28] LSM: Use lsmcontext in security_secid_to_secctx

2021-11-23 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

[PATCH v30 20/28] binder: Pass LSM identifier for confirmation

2021-11-23 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 ---

[PATCH v30 24/28] Audit: Add framework for auxiliary records

2021-11-23 Thread Casey Schaufler
Add a list for auxiliary record data to the audit_buffer structure. 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 currently

[PATCH v30 23/28] Audit: Create audit_stamp structure

2021-11-23 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 --- kernel/audit.c | 17 + kernel/audit.h | 12 +--- kernel/auditsc.c | 22 +- 3 files changed, 27

[PATCH v30 02/28] LSM: Infrastructure management of the sock security

2021-11-23 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 v30 01/28] integrity: disassociate ima_filter_rule from security_audit_rule

2021-11-23 Thread Casey Schaufler
Create real functions for the ima_filter_rule interfaces. These replace #defines that obscure the reuse of audit interfaces. The new fuctions are put in security.c because they use security module registered hooks that we don't want exported. Signed-off-by: Casey Schaufler ---

[PATCH v30 04/28] LSM: provide lsm name and id slot mappings

2021-11-23 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 v30 10/28] LSM: Use lsmblob in security_ipc_getsecid

2021-11-23 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

[PATCH v30 14/28] LSM: Specify which LSM to display

2021-11-23 Thread Casey Schaufler
Create a new entry "interface_lsm" in the procfs attr directory for controlling which LSM security information is displayed for a process. A process can only read or write its own display value. The name of an active LSM that supplies hooks for human readable data may be written to

[PATCH v30 21/28] LSM: Extend security_secid_to_secctx to include module selection

2021-11-23 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

[PATCH v30 27/28] LSM: Add /proc attr entry for full LSM context

2021-11-23 Thread Casey Schaufler
Add an entry /proc/.../attr/context which displays the full process security "context" in compound format: lsm1\0value\0lsm2\0value\0... This entry is not writable. A security module may decide that its policy does not allow this information to be displayed. In this case none of the

[PATCH v30 28/28] AppArmor: Remove the exclusive flag

2021-11-23 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