All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stephen Smalley <sds@tycho.nsa.gov>
To: Casey Schaufler <casey@schaufler-ca.com>,
	casey.schaufler@intel.com, jmorris@namei.org,
	linux-security-module@vger.kernel.org, selinux@vger.kernel.org
Cc: keescook@chromium.org, john.johansen@canonical.com,
	penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com
Subject: Re: [PATCH v12 22/25] Audit: Include object data for all security modules
Date: Wed, 18 Dec 2019 13:02:35 -0500	[thread overview]
Message-ID: <2a22d682-3293-d684-dc79-cb2d5aba4610@tycho.nsa.gov> (raw)
In-Reply-To: <20191216223621.5127-23-casey@schaufler-ca.com>

On 12/16/19 5:36 PM, Casey Schaufler wrote:
> When there is more than one context displaying security
> module extend what goes into the audit record by supplimenting
> the "obj=" with an "obj_<lsm>=" for each such security
> module.
> 
> Signed-off-by: Casey Schaufler <casey@schaufler-ca.com>

Disclaimer: requires ack by audit maintainers.  For me,
Acked-by: Stephen Smalley <sds@tycho.nsa.gov>

> ---
>   kernel/audit.h   |   4 +-
>   kernel/auditsc.c | 110 ++++++++++++++++++++++++-----------------------
>   2 files changed, 58 insertions(+), 56 deletions(-)
> 
> diff --git a/kernel/audit.h b/kernel/audit.h
> index af9bc09e656c..c9f1e1641542 100644
> --- a/kernel/audit.h
> +++ b/kernel/audit.h
> @@ -78,7 +78,7 @@ struct audit_names {
>   	kuid_t			uid;
>   	kgid_t			gid;
>   	dev_t			rdev;
> -	u32			osid;
> +	struct lsmblob		oblob;
>   	struct audit_cap_data	fcap;
>   	unsigned int		fcap_ver;
>   	unsigned char		type;		/* record type */
> @@ -152,7 +152,7 @@ struct audit_context {
>   			kuid_t			uid;
>   			kgid_t			gid;
>   			umode_t			mode;
> -			u32			osid;
> +			struct lsmblob		oblob;
>   			int			has_perm;
>   			uid_t			perm_uid;
>   			gid_t			perm_gid;
> diff --git a/kernel/auditsc.c b/kernel/auditsc.c
> index e0dd643e9b13..0c071947c2b3 100644
> --- a/kernel/auditsc.c
> +++ b/kernel/auditsc.c
> @@ -659,17 +659,15 @@ static int audit_filter_rules(struct task_struct *tsk,
>   			if (f->lsm_rule) {
>   				/* Find files that match */
>   				if (name) {
> -					lsmblob_init(&blob, name->osid);
>   					result = security_audit_rule_match(
> -								&blob,
> +								&name->oblob,
>   								f->type,
>   								f->op,
>   								f->lsm_rule);
>   				} else if (ctx) {
>   					list_for_each_entry(n, &ctx->names_list, list) {
> -						lsmblob_init(&blob, n->osid);
>   						if (security_audit_rule_match(
> -								&blob,
> +								&n->oblob,
>   								f->type,
>   								f->op,
>   								f->lsm_rule)) {
> @@ -681,8 +679,7 @@ static int audit_filter_rules(struct task_struct *tsk,
>   				/* Find ipc objects that match */
>   				if (!ctx || ctx->type != AUDIT_IPC)
>   					break;
> -				lsmblob_init(&blob, ctx->ipc.osid);
> -				if (security_audit_rule_match(&blob,
> +				if (security_audit_rule_match(&ctx->ipc.oblob,
>   							      f->type, f->op,
>   							      f->lsm_rule))
>   					++result;
> @@ -956,13 +953,57 @@ static inline void audit_free_context(struct audit_context *context)
>   	kfree(context);
>   }
>   
> +static int audit_log_object_context(struct audit_buffer *ab,
> +				    struct lsmblob *blob)
> +{
> +	struct lsmcontext context;
> +	const char *lsm;
> +	int i;
> +
> +	/*
> +	 * None of the installed modules have object labels.
> +	 */
> +	if (security_lsm_slot_name(0) == NULL)
> +		return 0;
> +
> +	if (blob->secid[0] != 0) {
> +		if (security_secid_to_secctx(blob, &context, 0)) {
> +			audit_log_format(ab, " obj=?");
> +			return 1;
> +		}
> +		audit_log_format(ab, " obj=%s", context.context);
> +		security_release_secctx(&context);
> +	}
> +
> +	/*
> +	 * Don't do anything more unless there is more than one LSM
> +	 * with a security context to report.
> +	 */
> +	if (security_lsm_slot_name(1) == NULL)
> +		return 0;
> +
> +	for (i = 0; i < LSMBLOB_ENTRIES; i++) {
> +		lsm = security_lsm_slot_name(i);
> +		if (lsm == NULL)
> +			break;
> +		if (blob->secid[i] == 0)
> +			continue;
> +		if (security_secid_to_secctx(blob, &context, i)) {
> +			audit_log_format(ab, " obj_%s=?", lsm);
> +			continue;
> +		}
> +		audit_log_format(ab, " obj_%s=%s", lsm, context.context);
> +		security_release_secctx(&context);
> +	}
> +	return 0;
> +}
> +
>   static int audit_log_pid_context(struct audit_context *context, pid_t pid,
>   				 kuid_t auid, kuid_t uid,
>   				 unsigned int sessionid,
>   				 struct lsmblob *blob, char *comm)
>   {
>   	struct audit_buffer *ab;
> -	struct lsmcontext lsmctx;
>   	int rc = 0;
>   
>   	ab = audit_log_start(context, GFP_KERNEL, AUDIT_OBJ_PID);
> @@ -972,15 +1013,7 @@ static int audit_log_pid_context(struct audit_context *context, pid_t pid,
>   	audit_log_format(ab, "opid=%d oauid=%d ouid=%d oses=%d", pid,
>   			 from_kuid(&init_user_ns, auid),
>   			 from_kuid(&init_user_ns, uid), sessionid);
> -	if (lsmblob_is_set(blob)) {
> -		if (security_secid_to_secctx(blob, &lsmctx, LSMBLOB_FIRST)) {
> -			audit_log_format(ab, " obj=(none)");
> -			rc = 1;
> -		} else {
> -			audit_log_format(ab, " obj=%s", lsmctx.context);
> -			security_release_secctx(&lsmctx);
> -		}
> -	}
> +	rc = audit_log_object_context(ab, blob);
>   	audit_log_format(ab, " ocomm=");
>   	audit_log_untrustedstring(ab, comm);
>   	audit_log_end(ab);
> @@ -1207,26 +1240,14 @@ static void show_special(struct audit_context *context, int *call_panic)
>   				context->socketcall.args[i]);
>   		break; }
>   	case AUDIT_IPC: {
> -		u32 osid = context->ipc.osid;
> +		struct lsmblob *oblob = & context->ipc.oblob;
>   
>   		audit_log_format(ab, "ouid=%u ogid=%u mode=%#ho",
>   				 from_kuid(&init_user_ns, context->ipc.uid),
>   				 from_kgid(&init_user_ns, context->ipc.gid),
>   				 context->ipc.mode);
> -		if (osid) {
> -			struct lsmcontext lsmcxt;
> -			struct lsmblob blob;
> -
> -			lsmblob_init(&blob, osid);
> -			if (security_secid_to_secctx(&blob, &lsmcxt,
> -						     LSMBLOB_FIRST)) {
> -				audit_log_format(ab, " osid=%u", osid);
> -				*call_panic = 1;
> -			} else {
> -				audit_log_format(ab, " obj=%s", lsmcxt.context);
> -				security_release_secctx(&lsmcxt);
> -			}
> -		}
> +		if (audit_log_object_context(ab, oblob))
> +			*call_panic = 1;
>   		if (context->ipc.has_perm) {
>   			audit_log_end(ab);
>   			ab = audit_log_start(context, GFP_KERNEL,
> @@ -1366,20 +1387,8 @@ static void audit_log_name(struct audit_context *context, struct audit_names *n,
>   				 from_kgid(&init_user_ns, n->gid),
>   				 MAJOR(n->rdev),
>   				 MINOR(n->rdev));
> -	if (n->osid != 0) {
> -		struct lsmblob blob;
> -		struct lsmcontext lsmctx;
> -
> -		lsmblob_init(&blob, n->osid);
> -		if (security_secid_to_secctx(&blob, &lsmctx, LSMBLOB_FIRST)) {
> -			audit_log_format(ab, " osid=%u", n->osid);
> -			if (call_panic)
> -				*call_panic = 2;
> -		} else {
> -			audit_log_format(ab, " obj=%s", lsmctx.context);
> -			security_release_secctx(&lsmctx);
> -		}
> -	}
> +	if (audit_log_object_context(ab, &n->oblob) && call_panic)
> +		*call_panic = 2;
>   
>   	/* log the audit_names record type */
>   	switch (n->type) {
> @@ -1929,17 +1938,13 @@ static void audit_copy_inode(struct audit_names *name,
>   			     const struct dentry *dentry,
>   			     struct inode *inode, unsigned int flags)
>   {
> -	struct lsmblob blob;
> -
>   	name->ino   = inode->i_ino;
>   	name->dev   = inode->i_sb->s_dev;
>   	name->mode  = inode->i_mode;
>   	name->uid   = inode->i_uid;
>   	name->gid   = inode->i_gid;
>   	name->rdev  = inode->i_rdev;
> -	security_inode_getsecid(inode, &blob);
> -	/* scaffolding until osid is updated */
> -	name->osid = blob.secid[0];
> +	security_inode_getsecid(inode, &name->oblob);
>   	if (flags & AUDIT_INODE_NOEVAL) {
>   		name->fcap_ver = -1;
>   		return;
> @@ -2285,14 +2290,11 @@ void __audit_mq_getsetattr(mqd_t mqdes, struct mq_attr *mqstat)
>   void __audit_ipc_obj(struct kern_ipc_perm *ipcp)
>   {
>   	struct audit_context *context = audit_context();
> -	struct lsmblob blob;
>   	context->ipc.uid = ipcp->uid;
>   	context->ipc.gid = ipcp->gid;
>   	context->ipc.mode = ipcp->mode;
>   	context->ipc.has_perm = 0;
> -	security_ipc_getsecid(ipcp, &blob);
> -	/* scaffolding on the [0] - change "osid" to a lsmblob */
> -	context->ipc.osid = blob.secid[0];
> +	security_ipc_getsecid(ipcp, &context->ipc.oblob);
>   	context->type = AUDIT_IPC;
>   }
>   
> 


  reply	other threads:[~2019-12-18 18:02 UTC|newest]

Thread overview: 70+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20191216223621.5127-1-casey.ref@schaufler-ca.com>
2019-12-16 22:35 ` [PATCH v12 00/25] LSM: Module stacking for AppArmor Casey Schaufler
2019-12-16 22:35   ` [PATCH v12 01/25] LSM: Infrastructure management of the sock security Casey Schaufler
2019-12-17 17:23     ` Stephen Smalley
2019-12-16 22:35   ` [PATCH v12 02/25] LSM: Create and manage the lsmblob data structure Casey Schaufler
2019-12-17 17:30     ` Stephen Smalley
2019-12-19 21:11     ` Mimi Zohar
2019-12-19 21:44       ` Casey Schaufler
2019-12-16 22:35   ` [PATCH v12 03/25] LSM: Use lsmblob in security_audit_rule_match Casey Schaufler
2019-12-17 17:34     ` Stephen Smalley
2019-12-17 22:01       ` Casey Schaufler
2019-12-17 23:47         ` Kees Cook
2019-12-18  0:28           ` Casey Schaufler
2019-12-18 13:16             ` Stephen Smalley
2019-12-16 22:36   ` [PATCH v12 04/25] LSM: Use lsmblob in security_kernel_act_as Casey Schaufler
2019-12-17 17:37     ` Stephen Smalley
2019-12-16 22:36   ` [PATCH v12 05/25] net: Prepare UDS for security module stacking Casey Schaufler
2019-12-17 17:41     ` Stephen Smalley
2019-12-16 22:36   ` [PATCH v12 06/25] LSM: Use lsmblob in security_secctx_to_secid Casey Schaufler
2019-12-17 17:51     ` Stephen Smalley
2019-12-16 22:36   ` [PATCH v12 07/25] LSM: Use lsmblob in security_secid_to_secctx Casey Schaufler
2019-12-17 18:01     ` Stephen Smalley
2019-12-16 22:36   ` [PATCH v12 08/25] LSM: Use lsmblob in security_ipc_getsecid Casey Schaufler
2019-12-17 18:02     ` Stephen Smalley
2019-12-16 22:36   ` [PATCH v12 09/25] LSM: Use lsmblob in security_task_getsecid Casey Schaufler
2019-12-17 18:11     ` Stephen Smalley
2019-12-17 18:26       ` Casey Schaufler
2019-12-16 22:36   ` [PATCH v12 10/25] LSM: Use lsmblob in security_inode_getsecid Casey Schaufler
2019-12-17 18:13     ` Stephen Smalley
2019-12-16 22:36   ` [PATCH v12 11/25] LSM: Use lsmblob in security_cred_getsecid Casey Schaufler
2019-12-17 18:23     ` Stephen Smalley
2019-12-16 22:36   ` [PATCH v12 12/25] IMA: Change internal interfaces to use lsmblobs Casey Schaufler
2019-12-17 18:26     ` Stephen Smalley
2019-12-16 22:36   ` [PATCH v12 13/25] LSM: Specify which LSM to display Casey Schaufler
2019-12-18 15:17     ` Stephen Smalley
2019-12-18 16:32       ` Casey Schaufler
2019-12-16 22:36   ` [PATCH v12 14/25] LSM: Ensure the correct LSM context releaser Casey Schaufler
2019-12-18 15:53     ` Stephen Smalley
2019-12-16 22:36   ` [PATCH v12 15/25] LSM: Use lsmcontext in security_secid_to_secctx Casey Schaufler
2019-12-18 16:06     ` Stephen Smalley
2019-12-18 19:33     ` Stephen Smalley
2019-12-16 22:36   ` [PATCH v12 16/25] LSM: Use lsmcontext in security_dentry_init_security Casey Schaufler
2019-12-18 16:16     ` Stephen Smalley
2019-12-16 22:36   ` [PATCH v12 17/25] LSM: Use lsmcontext in security_inode_getsecctx Casey Schaufler
2019-12-18 17:02     ` Stephen Smalley
2019-12-16 22:36   ` [PATCH v12 18/25] LSM: security_secid_to_secctx in netlink netfilter Casey Schaufler
2019-12-18 17:10     ` Stephen Smalley
2019-12-16 22:36   ` [PATCH v12 19/25] NET: Store LSM netlabel data in a lsmblob Casey Schaufler
2019-12-18 17:41     ` Stephen Smalley
2019-12-16 22:36   ` [PATCH v12 20/25] LSM: Verify LSM display sanity in binder Casey Schaufler
2019-12-18 17:43     ` Stephen Smalley
2019-12-16 22:36   ` [PATCH v12 21/25] Audit: Add subj_LSM fields when necessary Casey Schaufler
2019-12-18 17:55     ` Stephen Smalley
2019-12-16 22:36   ` [PATCH v12 22/25] Audit: Include object data for all security modules Casey Schaufler
2019-12-18 18:02     ` Stephen Smalley [this message]
2019-12-16 22:36   ` [PATCH v12 23/25] NET: Add SO_PEERCONTEXT for multiple LSMs Casey Schaufler
2019-12-18 18:28     ` Stephen Smalley
2019-12-18 19:12       ` Stephen Smalley
2019-12-18 20:50         ` Stephen Smalley
2019-12-19 12:19           ` Simon McVittie
2019-12-19 13:47             ` Stephen Smalley
2019-12-19 15:00               ` Stephen Smalley
2019-12-19 16:48                 ` Simon McVittie
2019-12-19 17:02                   ` Stephen Smalley
2019-12-19 19:27                     ` John Johansen
2019-12-19 20:51                       ` Casey Schaufler
2019-12-19 21:41                         ` John Johansen
2019-12-19 19:21                   ` John Johansen
2019-12-16 22:36   ` [PATCH v12 24/25] LSM: Add /proc attr entry for full LSM context Casey Schaufler
2019-12-16 22:36   ` [PATCH v12 25/25] AppArmor: Remove the exclusive flag Casey Schaufler
2019-12-24 23:18 [PATCH v12 00/25] LSM: Module stacking for AppArmor Casey Schaufler
2019-12-24 23:19 ` [PATCH v12 22/25] Audit: Include object data for all security modules Casey Schaufler

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2a22d682-3293-d684-dc79-cb2d5aba4610@tycho.nsa.gov \
    --to=sds@tycho.nsa.gov \
    --cc=casey.schaufler@intel.com \
    --cc=casey@schaufler-ca.com \
    --cc=jmorris@namei.org \
    --cc=john.johansen@canonical.com \
    --cc=keescook@chromium.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=paul@paul-moore.com \
    --cc=penguin-kernel@i-love.sakura.ne.jp \
    --cc=selinux@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.