Skip to content

Commit 2115bb2

Browse files
deepa-hubpcmoore
authored andcommitted
audit: Use timespec64 to represent audit timestamps
struct timespec is not y2038 safe. Audit timestamps are recorded in string format into an audit buffer for a given context. These mark the entry timestamps for the syscalls. Use y2038 safe struct timespec64 to represent the times. The log strings can handle this transition as strings can hold upto 1024 characters. Signed-off-by: Deepa Dinamani <deepa.kernel@gmail.com> Reviewed-by: Arnd Bergmann <arnd@arndb.de> Acked-by: Paul Moore <paul@paul-moore.com> Acked-by: Richard Guy Briggs <rgb@redhat.com> Signed-off-by: Paul Moore <paul@paul-moore.com>
1 parent b6c7c11 commit 2115bb2

4 files changed

Lines changed: 11 additions & 11 deletions

File tree

‎include/linux/audit.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ static inline void audit_ptrace(struct task_struct *t)
331331
/* Private API (for audit.c only) */
332332
extern unsigned int audit_serial(void);
333333
extern int auditsc_get_stamp(struct audit_context *ctx,
334-
struct timespec *t, unsigned int *serial);
334+
struct timespec64 *t, unsigned int *serial);
335335
extern int audit_set_loginuid(kuid_t loginuid);
336336

337337
static inline kuid_t audit_get_loginuid(struct task_struct *tsk)
@@ -510,7 +510,7 @@ static inline void __audit_seccomp(unsigned long syscall, long signr, int code)
510510
static inline void audit_seccomp(unsigned long syscall, long signr, int code)
511511
{ }
512512
static inline int auditsc_get_stamp(struct audit_context *ctx,
513-
struct timespec *t, unsigned int *serial)
513+
struct timespec64 *t, unsigned int *serial)
514514
{
515515
return 0;
516516
}

‎kernel/audit.c‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1638,10 +1638,10 @@ unsigned int audit_serial(void)
16381638
}
16391639

16401640
static inline void audit_get_stamp(struct audit_context *ctx,
1641-
struct timespec *t, unsigned int *serial)
1641+
struct timespec64 *t, unsigned int *serial)
16421642
{
16431643
if (!ctx || !auditsc_get_stamp(ctx, t, serial)) {
1644-
*t = CURRENT_TIME;
1644+
ktime_get_real_ts64(t);
16451645
*serial = audit_serial();
16461646
}
16471647
}
@@ -1665,7 +1665,7 @@ struct audit_buffer *audit_log_start(struct audit_context *ctx, gfp_t gfp_mask,
16651665
int type)
16661666
{
16671667
struct audit_buffer *ab;
1668-
struct timespec t;
1668+
struct timespec64 t;
16691669
unsigned int uninitialized_var(serial);
16701670

16711671
if (audit_initialized != AUDIT_INITIALIZED)
@@ -1718,8 +1718,8 @@ struct audit_buffer *audit_log_start(struct audit_context *ctx, gfp_t gfp_mask,
17181718
}
17191719

17201720
audit_get_stamp(ab->ctx, &t, &serial);
1721-
audit_log_format(ab, "audit(%lu.%03lu:%u): ",
1722-
t.tv_sec, t.tv_nsec/1000000, serial);
1721+
audit_log_format(ab, "audit(%llu.%03lu:%u): ",
1722+
(unsigned long long)t.tv_sec, t.tv_nsec/1000000, serial);
17231723

17241724
return ab;
17251725
}

‎kernel/audit.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ struct audit_context {
112112
enum audit_state state, current_state;
113113
unsigned int serial; /* serial number for record */
114114
int major; /* syscall number */
115-
struct timespec ctime; /* time of syscall entry */
115+
struct timespec64 ctime; /* time of syscall entry */
116116
unsigned long argv[4]; /* syscall arguments */
117117
long return_code;/* syscall return code */
118118
u64 prio;

‎kernel/auditsc.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1532,7 +1532,7 @@ void __audit_syscall_entry(int major, unsigned long a1, unsigned long a2,
15321532
return;
15331533

15341534
context->serial = 0;
1535-
context->ctime = CURRENT_TIME;
1535+
ktime_get_real_ts64(&context->ctime);
15361536
context->in_syscall = 1;
15371537
context->current_state = state;
15381538
context->ppid = 0;
@@ -1941,13 +1941,13 @@ EXPORT_SYMBOL_GPL(__audit_inode_child);
19411941
/**
19421942
* auditsc_get_stamp - get local copies of audit_context values
19431943
* @ctx: audit_context for the task
1944-
* @t: timespec to store time recorded in the audit_context
1944+
* @t: timespec64 to store time recorded in the audit_context
19451945
* @serial: serial value that is recorded in the audit_context
19461946
*
19471947
* Also sets the context as auditable.
19481948
*/
19491949
int auditsc_get_stamp(struct audit_context *ctx,
1950-
struct timespec *t, unsigned int *serial)
1950+
struct timespec64 *t, unsigned int *serial)
19511951
{
19521952
if (!ctx->in_syscall)
19531953
return 0;

0 commit comments

Comments
 (0)