All of lore.kernel.org
 help / color / mirror / Atom feed
From: Casey Schaufler <casey@schaufler-ca.com>
To: casey.schaufler@intel.com, jmorris@namei.org,
	linux-security-module@vger.kernel.org, selinux@vger.kernel.org
Cc: casey@schaufler-ca.com, linux-audit@redhat.com,
	keescook@chromium.org, john.johansen@canonical.com,
	penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com,
	sds@tycho.nsa.gov, linux-kernel@vger.kernel.org
Subject: [PATCH v30 23/28] Audit: Create audit_stamp structure
Date: Tue, 23 Nov 2021 17:43:27 -0800	[thread overview]
Message-ID: <20211124014332.36128-24-casey@schaufler-ca.com> (raw)
In-Reply-To: <20211124014332.36128-1-casey@schaufler-ca.com>

Replace the timestamp and serial number pair used in audit records
with a structure containing the two elements.

Signed-off-by: Casey Schaufler <casey@schaufler-ca.com>
---
 kernel/audit.c   | 17 +++++++++--------
 kernel/audit.h   | 12 +++++++++---
 kernel/auditsc.c | 22 +++++++++-------------
 3 files changed, 27 insertions(+), 24 deletions(-)

diff --git a/kernel/audit.c b/kernel/audit.c
index 3c6e88a9ff62..069cd4c81a61 100644
--- a/kernel/audit.c
+++ b/kernel/audit.c
@@ -1786,11 +1786,11 @@ unsigned int audit_serial(void)
 }
 
 static inline void audit_get_stamp(struct audit_context *ctx,
-				   struct timespec64 *t, unsigned int *serial)
+				   struct audit_stamp *stamp)
 {
-	if (!ctx || !auditsc_get_stamp(ctx, t, serial)) {
-		ktime_get_coarse_real_ts64(t);
-		*serial = audit_serial();
+	if (!ctx || !auditsc_get_stamp(ctx, stamp)) {
+		ktime_get_coarse_real_ts64(&stamp->ctime);
+		stamp->serial = audit_serial();
 	}
 }
 
@@ -1813,8 +1813,7 @@ struct audit_buffer *audit_log_start(struct audit_context *ctx, gfp_t gfp_mask,
 				     int type)
 {
 	struct audit_buffer *ab;
-	struct timespec64 t;
-	unsigned int serial;
+	struct audit_stamp stamp;
 
 	if (audit_initialized != AUDIT_INITIALIZED)
 		return NULL;
@@ -1867,12 +1866,14 @@ struct audit_buffer *audit_log_start(struct audit_context *ctx, gfp_t gfp_mask,
 		return NULL;
 	}
 
-	audit_get_stamp(ab->ctx, &t, &serial);
+	audit_get_stamp(ab->ctx, &stamp);
 	/* cancel dummy context to enable supporting records */
 	if (ctx)
 		ctx->dummy = 0;
 	audit_log_format(ab, "audit(%llu.%03lu:%u): ",
-			 (unsigned long long)t.tv_sec, t.tv_nsec/1000000, serial);
+			 (unsigned long long)stamp.ctime.tv_sec,
+			 stamp.ctime.tv_nsec/1000000,
+			 stamp.serial);
 
 	return ab;
 }
diff --git a/kernel/audit.h b/kernel/audit.h
index a2fca1134519..56560846f3b0 100644
--- a/kernel/audit.h
+++ b/kernel/audit.h
@@ -99,6 +99,12 @@ struct audit_proctitle {
 	char	*value;	/* the cmdline field */
 };
 
+/* A timestamp/serial pair to identify an event */
+struct audit_stamp {
+	struct timespec64	ctime;	/* time of syscall entry */
+	unsigned int		serial;	/* serial number for record */
+};
+
 /* The per-task audit context. */
 struct audit_context {
 	int		    dummy;	/* must be the first element */
@@ -108,10 +114,10 @@ struct audit_context {
 		AUDIT_CTX_URING,	/* in use by io_uring */
 	} context;
 	enum audit_state    state, current_state;
+	struct audit_stamp  stamp;	/* event identifier */
 	unsigned int	    serial;     /* serial number for record */
 	int		    major;      /* syscall number */
 	int		    uring_op;   /* uring operation */
-	struct timespec64   ctime;      /* time of syscall entry */
 	unsigned long	    argv[4];    /* syscall arguments */
 	long		    return_code;/* syscall return code */
 	u64		    prio;
@@ -261,7 +267,7 @@ extern void audit_put_tty(struct tty_struct *tty);
 #ifdef CONFIG_AUDITSYSCALL
 extern unsigned int audit_serial(void);
 extern int auditsc_get_stamp(struct audit_context *ctx,
-			      struct timespec64 *t, unsigned int *serial);
+			     struct audit_stamp *stamp);
 
 extern void audit_put_watch(struct audit_watch *watch);
 extern void audit_get_watch(struct audit_watch *watch);
@@ -302,7 +308,7 @@ extern void audit_filter_inodes(struct task_struct *tsk,
 				struct audit_context *ctx);
 extern struct list_head *audit_killed_trees(void);
 #else /* CONFIG_AUDITSYSCALL */
-#define auditsc_get_stamp(c, t, s) 0
+#define auditsc_get_stamp(c, s) 0
 #define audit_put_watch(w) do { } while (0)
 #define audit_get_watch(w) do { } while (0)
 #define audit_to_watch(k, p, l, o) (-EINVAL)
diff --git a/kernel/auditsc.c b/kernel/auditsc.c
index 0d0351dc0c52..e6868d072648 100644
--- a/kernel/auditsc.c
+++ b/kernel/auditsc.c
@@ -983,10 +983,10 @@ static void audit_reset_context(struct audit_context *ctx)
 	 */
 
 	ctx->current_state = ctx->state;
-	ctx->serial = 0;
+	ctx->stamp.serial = 0;
 	ctx->major = 0;
 	ctx->uring_op = 0;
-	ctx->ctime = (struct timespec64){ .tv_sec = 0, .tv_nsec = 0 };
+	ctx->stamp.ctime = (struct timespec64){ .tv_sec = 0, .tv_nsec = 0 };
 	memset(ctx->argv, 0, sizeof(ctx->argv));
 	ctx->return_code = 0;
 	ctx->prio = (ctx->state == AUDIT_STATE_RECORD ? ~0ULL : 0);
@@ -1889,7 +1889,7 @@ void __audit_uring_entry(u8 op)
 
 	ctx->context = AUDIT_CTX_URING;
 	ctx->current_state = ctx->state;
-	ktime_get_coarse_real_ts64(&ctx->ctime);
+	ktime_get_coarse_real_ts64(&ctx->stamp.ctime);
 }
 
 /**
@@ -2005,7 +2005,7 @@ void __audit_syscall_entry(int major, unsigned long a1, unsigned long a2,
 	context->argv[3]    = a4;
 	context->context = AUDIT_CTX_SYSCALL;
 	context->current_state  = state;
-	ktime_get_coarse_real_ts64(&context->ctime);
+	ktime_get_coarse_real_ts64(&context->stamp.ctime);
 }
 
 /**
@@ -2474,21 +2474,17 @@ EXPORT_SYMBOL_GPL(__audit_inode_child);
 /**
  * auditsc_get_stamp - get local copies of audit_context values
  * @ctx: audit_context for the task
- * @t: timespec64 to store time recorded in the audit_context
- * @serial: serial value that is recorded in the audit_context
+ * @stamp: timestamp to record
  *
  * Also sets the context as auditable.
  */
-int auditsc_get_stamp(struct audit_context *ctx,
-		       struct timespec64 *t, unsigned int *serial)
+int auditsc_get_stamp(struct audit_context *ctx, struct audit_stamp *stamp)
 {
 	if (ctx->context == AUDIT_CTX_UNUSED)
 		return 0;
-	if (!ctx->serial)
-		ctx->serial = audit_serial();
-	t->tv_sec  = ctx->ctime.tv_sec;
-	t->tv_nsec = ctx->ctime.tv_nsec;
-	*serial    = ctx->serial;
+	if (!ctx->stamp.serial)
+		ctx->stamp.serial = audit_serial();
+	*stamp = ctx->stamp;
 	if (!ctx->prio) {
 		ctx->prio = 1;
 		ctx->current_state = AUDIT_STATE_RECORD;
-- 
2.31.1


WARNING: multiple messages have this Message-ID (diff)
From: Casey Schaufler <casey@schaufler-ca.com>
To: casey.schaufler@intel.com, jmorris@namei.org,
	linux-security-module@vger.kernel.org, selinux@vger.kernel.org
Cc: john.johansen@canonical.com, linux-kernel@vger.kernel.org,
	linux-audit@redhat.com, sds@tycho.nsa.gov
Subject: [PATCH v30 23/28] Audit: Create audit_stamp structure
Date: Tue, 23 Nov 2021 17:43:27 -0800	[thread overview]
Message-ID: <20211124014332.36128-24-casey@schaufler-ca.com> (raw)
In-Reply-To: <20211124014332.36128-1-casey@schaufler-ca.com>

Replace the timestamp and serial number pair used in audit records
with a structure containing the two elements.

Signed-off-by: Casey Schaufler <casey@schaufler-ca.com>
---
 kernel/audit.c   | 17 +++++++++--------
 kernel/audit.h   | 12 +++++++++---
 kernel/auditsc.c | 22 +++++++++-------------
 3 files changed, 27 insertions(+), 24 deletions(-)

diff --git a/kernel/audit.c b/kernel/audit.c
index 3c6e88a9ff62..069cd4c81a61 100644
--- a/kernel/audit.c
+++ b/kernel/audit.c
@@ -1786,11 +1786,11 @@ unsigned int audit_serial(void)
 }
 
 static inline void audit_get_stamp(struct audit_context *ctx,
-				   struct timespec64 *t, unsigned int *serial)
+				   struct audit_stamp *stamp)
 {
-	if (!ctx || !auditsc_get_stamp(ctx, t, serial)) {
-		ktime_get_coarse_real_ts64(t);
-		*serial = audit_serial();
+	if (!ctx || !auditsc_get_stamp(ctx, stamp)) {
+		ktime_get_coarse_real_ts64(&stamp->ctime);
+		stamp->serial = audit_serial();
 	}
 }
 
@@ -1813,8 +1813,7 @@ struct audit_buffer *audit_log_start(struct audit_context *ctx, gfp_t gfp_mask,
 				     int type)
 {
 	struct audit_buffer *ab;
-	struct timespec64 t;
-	unsigned int serial;
+	struct audit_stamp stamp;
 
 	if (audit_initialized != AUDIT_INITIALIZED)
 		return NULL;
@@ -1867,12 +1866,14 @@ struct audit_buffer *audit_log_start(struct audit_context *ctx, gfp_t gfp_mask,
 		return NULL;
 	}
 
-	audit_get_stamp(ab->ctx, &t, &serial);
+	audit_get_stamp(ab->ctx, &stamp);
 	/* cancel dummy context to enable supporting records */
 	if (ctx)
 		ctx->dummy = 0;
 	audit_log_format(ab, "audit(%llu.%03lu:%u): ",
-			 (unsigned long long)t.tv_sec, t.tv_nsec/1000000, serial);
+			 (unsigned long long)stamp.ctime.tv_sec,
+			 stamp.ctime.tv_nsec/1000000,
+			 stamp.serial);
 
 	return ab;
 }
diff --git a/kernel/audit.h b/kernel/audit.h
index a2fca1134519..56560846f3b0 100644
--- a/kernel/audit.h
+++ b/kernel/audit.h
@@ -99,6 +99,12 @@ struct audit_proctitle {
 	char	*value;	/* the cmdline field */
 };
 
+/* A timestamp/serial pair to identify an event */
+struct audit_stamp {
+	struct timespec64	ctime;	/* time of syscall entry */
+	unsigned int		serial;	/* serial number for record */
+};
+
 /* The per-task audit context. */
 struct audit_context {
 	int		    dummy;	/* must be the first element */
@@ -108,10 +114,10 @@ struct audit_context {
 		AUDIT_CTX_URING,	/* in use by io_uring */
 	} context;
 	enum audit_state    state, current_state;
+	struct audit_stamp  stamp;	/* event identifier */
 	unsigned int	    serial;     /* serial number for record */
 	int		    major;      /* syscall number */
 	int		    uring_op;   /* uring operation */
-	struct timespec64   ctime;      /* time of syscall entry */
 	unsigned long	    argv[4];    /* syscall arguments */
 	long		    return_code;/* syscall return code */
 	u64		    prio;
@@ -261,7 +267,7 @@ extern void audit_put_tty(struct tty_struct *tty);
 #ifdef CONFIG_AUDITSYSCALL
 extern unsigned int audit_serial(void);
 extern int auditsc_get_stamp(struct audit_context *ctx,
-			      struct timespec64 *t, unsigned int *serial);
+			     struct audit_stamp *stamp);
 
 extern void audit_put_watch(struct audit_watch *watch);
 extern void audit_get_watch(struct audit_watch *watch);
@@ -302,7 +308,7 @@ extern void audit_filter_inodes(struct task_struct *tsk,
 				struct audit_context *ctx);
 extern struct list_head *audit_killed_trees(void);
 #else /* CONFIG_AUDITSYSCALL */
-#define auditsc_get_stamp(c, t, s) 0
+#define auditsc_get_stamp(c, s) 0
 #define audit_put_watch(w) do { } while (0)
 #define audit_get_watch(w) do { } while (0)
 #define audit_to_watch(k, p, l, o) (-EINVAL)
diff --git a/kernel/auditsc.c b/kernel/auditsc.c
index 0d0351dc0c52..e6868d072648 100644
--- a/kernel/auditsc.c
+++ b/kernel/auditsc.c
@@ -983,10 +983,10 @@ static void audit_reset_context(struct audit_context *ctx)
 	 */
 
 	ctx->current_state = ctx->state;
-	ctx->serial = 0;
+	ctx->stamp.serial = 0;
 	ctx->major = 0;
 	ctx->uring_op = 0;
-	ctx->ctime = (struct timespec64){ .tv_sec = 0, .tv_nsec = 0 };
+	ctx->stamp.ctime = (struct timespec64){ .tv_sec = 0, .tv_nsec = 0 };
 	memset(ctx->argv, 0, sizeof(ctx->argv));
 	ctx->return_code = 0;
 	ctx->prio = (ctx->state == AUDIT_STATE_RECORD ? ~0ULL : 0);
@@ -1889,7 +1889,7 @@ void __audit_uring_entry(u8 op)
 
 	ctx->context = AUDIT_CTX_URING;
 	ctx->current_state = ctx->state;
-	ktime_get_coarse_real_ts64(&ctx->ctime);
+	ktime_get_coarse_real_ts64(&ctx->stamp.ctime);
 }
 
 /**
@@ -2005,7 +2005,7 @@ void __audit_syscall_entry(int major, unsigned long a1, unsigned long a2,
 	context->argv[3]    = a4;
 	context->context = AUDIT_CTX_SYSCALL;
 	context->current_state  = state;
-	ktime_get_coarse_real_ts64(&context->ctime);
+	ktime_get_coarse_real_ts64(&context->stamp.ctime);
 }
 
 /**
@@ -2474,21 +2474,17 @@ EXPORT_SYMBOL_GPL(__audit_inode_child);
 /**
  * auditsc_get_stamp - get local copies of audit_context values
  * @ctx: audit_context for the task
- * @t: timespec64 to store time recorded in the audit_context
- * @serial: serial value that is recorded in the audit_context
+ * @stamp: timestamp to record
  *
  * Also sets the context as auditable.
  */
-int auditsc_get_stamp(struct audit_context *ctx,
-		       struct timespec64 *t, unsigned int *serial)
+int auditsc_get_stamp(struct audit_context *ctx, struct audit_stamp *stamp)
 {
 	if (ctx->context == AUDIT_CTX_UNUSED)
 		return 0;
-	if (!ctx->serial)
-		ctx->serial = audit_serial();
-	t->tv_sec  = ctx->ctime.tv_sec;
-	t->tv_nsec = ctx->ctime.tv_nsec;
-	*serial    = ctx->serial;
+	if (!ctx->stamp.serial)
+		ctx->stamp.serial = audit_serial();
+	*stamp = ctx->stamp;
 	if (!ctx->prio) {
 		ctx->prio = 1;
 		ctx->current_state = AUDIT_STATE_RECORD;
-- 
2.31.1

--
Linux-audit mailing list
Linux-audit@redhat.com
https://listman.redhat.com/mailman/listinfo/linux-audit


  parent reply	other threads:[~2021-11-24  2:09 UTC|newest]

Thread overview: 85+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20211124014332.36128-1-casey.ref@schaufler-ca.com>
2021-11-24  1:43 ` [PATCH v30 00/28] LSM: Module stacking for AppArmor Casey Schaufler
2021-11-24  1:43   ` Casey Schaufler
2021-11-24  1:43   ` [PATCH v30 01/28] integrity: disassociate ima_filter_rule from security_audit_rule Casey Schaufler
2021-11-24  1:43     ` Casey Schaufler
2021-12-06  2:43     ` Paul Moore
2021-12-06  2:43       ` Paul Moore
2021-11-24  1:43   ` [PATCH v30 02/28] LSM: Infrastructure management of the sock security Casey Schaufler
2021-11-24  1:43     ` Casey Schaufler
2021-11-24  1:43   ` [PATCH v30 03/28] LSM: Add the lsmblob data structure Casey Schaufler
2021-11-24  1:43     ` Casey Schaufler
2021-12-06  2:44     ` Paul Moore
2021-12-06  2:44       ` Paul Moore
2021-11-24  1:43   ` [PATCH v30 04/28] LSM: provide lsm name and id slot mappings Casey Schaufler
2021-11-24  1:43     ` Casey Schaufler
2021-11-24  1:43   ` [PATCH v30 05/28] IMA: avoid label collisions with stacked LSMs Casey Schaufler
2021-11-24  1:43     ` Casey Schaufler
2021-11-24  1:43   ` [PATCH v30 06/28] LSM: Use lsmblob in security_audit_rule_match Casey Schaufler
2021-11-24  1:43     ` Casey Schaufler
2021-11-24 13:19     ` kernel test robot
2021-11-24 13:19       ` kernel test robot
2021-11-24 13:19       ` kernel test robot
2021-12-06  2:44     ` Paul Moore
2021-12-06  2:44       ` Paul Moore
2021-11-24  1:43   ` [PATCH v30 07/28] LSM: Use lsmblob in security_kernel_act_as Casey Schaufler
2021-11-24  1:43     ` Casey Schaufler
2021-11-24  1:43   ` [PATCH v30 08/28] LSM: Use lsmblob in security_secctx_to_secid Casey Schaufler
2021-11-24  1:43     ` Casey Schaufler
2021-11-24  1:43   ` [PATCH v30 09/28] LSM: Use lsmblob in security_secid_to_secctx Casey Schaufler
2021-11-24  1:43     ` Casey Schaufler
2021-11-24  1:43   ` [PATCH v30 10/28] LSM: Use lsmblob in security_ipc_getsecid Casey Schaufler
2021-11-24  1:43     ` Casey Schaufler
2021-11-24  1:43   ` [PATCH v30 11/28] LSM: Use lsmblob in security_task_getsecid Casey Schaufler
2021-11-24  1:43     ` Casey Schaufler
2021-11-24  1:43   ` [PATCH v30 12/28] LSM: Use lsmblob in security_inode_getsecid Casey Schaufler
2021-11-24  1:43     ` Casey Schaufler
2021-11-24  1:43   ` [PATCH v30 13/28] LSM: Use lsmblob in security_cred_getsecid Casey Schaufler
2021-11-24  1:43     ` Casey Schaufler
2021-11-24  1:43   ` [PATCH v30 14/28] LSM: Specify which LSM to display Casey Schaufler
2021-11-24  1:43     ` Casey Schaufler
2021-11-24 18:28     ` Christian Göttsche
2021-11-24 20:21       ` Casey Schaufler
2021-11-24  1:43   ` [PATCH v30 15/28] LSM: Ensure the correct LSM context releaser Casey Schaufler
2021-11-24  1:43     ` Casey Schaufler
2021-11-24  1:43   ` [PATCH v30 16/28] LSM: Use lsmcontext in security_secid_to_secctx Casey Schaufler
2021-11-24  1:43     ` Casey Schaufler
2021-11-24  1:43   ` [PATCH v30 17/28] LSM: Use lsmcontext in security_inode_getsecctx Casey Schaufler
2021-11-24  1:43     ` Casey Schaufler
2021-11-24  1:43   ` [PATCH v30 18/28] LSM: security_secid_to_secctx in netlink netfilter Casey Schaufler
2021-11-24  1:43     ` Casey Schaufler
2021-11-24  1:43   ` [PATCH v30 19/28] NET: Store LSM netlabel data in a lsmblob Casey Schaufler
2021-11-24  1:43     ` Casey Schaufler
2021-11-24  1:43   ` [PATCH v30 20/28] binder: Pass LSM identifier for confirmation Casey Schaufler
2021-11-24  1:43     ` Casey Schaufler
2021-11-24  1:43   ` [PATCH v30 21/28] LSM: Extend security_secid_to_secctx to include module selection Casey Schaufler
2021-11-24  1:43     ` Casey Schaufler
2021-11-24  1:43   ` [PATCH v30 22/28] Audit: Keep multiple LSM data in audit_names Casey Schaufler
2021-11-24  1:43     ` Casey Schaufler
2021-12-06  2:44     ` Paul Moore
2021-12-06  2:44       ` Paul Moore
2021-11-24  1:43   ` Casey Schaufler [this message]
2021-11-24  1:43     ` [PATCH v30 23/28] Audit: Create audit_stamp structure Casey Schaufler
2021-12-06  2:44     ` Paul Moore
2021-12-06  2:44       ` Paul Moore
2021-11-24  1:43   ` [PATCH v30 24/28] Audit: Add framework for auxiliary records Casey Schaufler
2021-11-24  1:43     ` Casey Schaufler
2021-12-06  2:45     ` Paul Moore
2021-12-06  2:45       ` Paul Moore
2021-11-24  1:43   ` [PATCH v30 25/28] Audit: Add record for multiple task security contexts Casey Schaufler
2021-11-24  1:43     ` Casey Schaufler
2021-12-06  2:45     ` Paul Moore
2021-12-06  2:45       ` Paul Moore
2021-11-24  1:43   ` [PATCH v30 26/28] Audit: Add record for multiple object " Casey Schaufler
2021-11-24  1:43     ` Casey Schaufler
2021-11-24  7:41     ` kernel test robot
2021-11-24  7:41       ` kernel test robot
2021-11-24  7:41       ` kernel test robot
2021-11-24 13:40     ` kernel test robot
2021-11-24 13:40       ` kernel test robot
2021-11-24 13:40       ` kernel test robot
2021-12-06  2:45     ` Paul Moore
2021-12-06  2:45       ` Paul Moore
2021-11-24  1:43   ` [PATCH v30 27/28] LSM: Add /proc attr entry for full LSM context Casey Schaufler
2021-11-24  1:43     ` Casey Schaufler
2021-11-24  1:43   ` [PATCH v30 28/28] AppArmor: Remove the exclusive flag Casey Schaufler
2021-11-24  1:43     ` 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=20211124014332.36128-24-casey@schaufler-ca.com \
    --to=casey@schaufler-ca.com \
    --cc=casey.schaufler@intel.com \
    --cc=jmorris@namei.org \
    --cc=john.johansen@canonical.com \
    --cc=keescook@chromium.org \
    --cc=linux-audit@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=paul@paul-moore.com \
    --cc=penguin-kernel@i-love.sakura.ne.jp \
    --cc=sds@tycho.nsa.gov \
    --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.