Skip to content

Commit c645c11

Browse files
committed
Merge tag 'audit-pr-20221003' of git://git.kernel.org/pub/scm/linux/kernel/git/pcmoore/audit
Pull audit updates from Paul Moore: "Six audit patches for v6.1, most are pretty trivial, but a quick list of the highlights are below: - Only free the audit proctitle information on task exit. This allows us to cache the information and improve performance slightly. - Use the time_after() macro to do time comparisons instead of doing it directly and potentially causing ourselves problems when the timer wraps. - Convert an audit_context state comparison from a relative enum comparison, e.g. (x < y), to a not-equal comparison to ensure that we are not caught out at some unknown point in the future by an enum shuffle. - A handful of small cleanups such as tidying up comments and removing unused declarations" * tag 'audit-pr-20221003' of git://git.kernel.org/pub/scm/linux/kernel/git/pcmoore/audit: audit: remove selinux_audit_rule_update() declaration audit: use time_after to compare time audit: free audit_proctitle only on task exit audit: explicitly check audit_context->context enum value audit: audit_context pid unused, context enum comment fix audit: fix repeated words in comments
2 parents 3eba620 + 934f70d commit c645c11

File tree

3 files changed

+9
-13
lines changed

3 files changed

+9
-13
lines changed

kernel/audit.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,6 @@ static inline int audit_rate_check(void)
321321
static DEFINE_SPINLOCK(lock);
322322
unsigned long flags;
323323
unsigned long now;
324-
unsigned long elapsed;
325324
int retval = 0;
326325

327326
if (!audit_rate_limit) return 1;
@@ -330,9 +329,8 @@ static inline int audit_rate_check(void)
330329
if (++messages < audit_rate_limit) {
331330
retval = 1;
332331
} else {
333-
now = jiffies;
334-
elapsed = now - last_check;
335-
if (elapsed > HZ) {
332+
now = jiffies;
333+
if (time_after(now, last_check + HZ)) {
336334
last_check = now;
337335
messages = 0;
338336
retval = 1;
@@ -366,7 +364,7 @@ void audit_log_lost(const char *message)
366364
if (!print) {
367365
spin_lock_irqsave(&lock, flags);
368366
now = jiffies;
369-
if (now - last_msg > HZ) {
367+
if (time_after(now, last_msg + HZ)) {
370368
print = 1;
371369
last_msg = now;
372370
}

kernel/audit.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ struct audit_context {
133133
struct sockaddr_storage *sockaddr;
134134
size_t sockaddr_len;
135135
/* Save things to print about task_struct */
136-
pid_t pid, ppid;
136+
pid_t ppid;
137137
kuid_t uid, euid, suid, fsuid;
138138
kgid_t gid, egid, sgid, fsgid;
139139
unsigned long personality;
@@ -245,8 +245,6 @@ struct audit_netlink_list {
245245

246246
int audit_send_list_thread(void *_dest);
247247

248-
extern int selinux_audit_rule_update(void);
249-
250248
extern struct mutex audit_filter_mutex;
251249
extern int audit_del_rule(struct audit_entry *entry);
252250
extern void audit_free_rule_rcu(struct rcu_head *head);

kernel/auditsc.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -965,7 +965,7 @@ static void audit_reset_context(struct audit_context *ctx)
965965
if (!ctx)
966966
return;
967967

968-
/* if ctx is non-null, reset the "ctx->state" regardless */
968+
/* if ctx is non-null, reset the "ctx->context" regardless */
969969
ctx->context = AUDIT_CTX_UNUSED;
970970
if (ctx->dummy)
971971
return;
@@ -1002,7 +1002,7 @@ static void audit_reset_context(struct audit_context *ctx)
10021002
kfree(ctx->sockaddr);
10031003
ctx->sockaddr = NULL;
10041004
ctx->sockaddr_len = 0;
1005-
ctx->pid = ctx->ppid = 0;
1005+
ctx->ppid = 0;
10061006
ctx->uid = ctx->euid = ctx->suid = ctx->fsuid = KUIDT_INIT(0);
10071007
ctx->gid = ctx->egid = ctx->sgid = ctx->fsgid = KGIDT_INIT(0);
10081008
ctx->personality = 0;
@@ -1016,7 +1016,6 @@ static void audit_reset_context(struct audit_context *ctx)
10161016
WARN_ON(!list_empty(&ctx->killed_trees));
10171017
audit_free_module(ctx);
10181018
ctx->fds[0] = -1;
1019-
audit_proctitle_free(ctx);
10201019
ctx->type = 0; /* reset last for audit_free_*() */
10211020
}
10221021

@@ -1077,6 +1076,7 @@ static inline void audit_free_context(struct audit_context *context)
10771076
{
10781077
/* resetting is extra work, but it is likely just noise */
10791078
audit_reset_context(context);
1079+
audit_proctitle_free(context);
10801080
free_tree_refs(context);
10811081
kfree(context->filterkey);
10821082
kfree(context);
@@ -1833,7 +1833,7 @@ void __audit_free(struct task_struct *tsk)
18331833

18341834
/* We are called either by do_exit() or the fork() error handling code;
18351835
* in the former case tsk == current and in the latter tsk is a
1836-
* random task_struct that doesn't doesn't have any meaningful data we
1836+
* random task_struct that doesn't have any meaningful data we
18371837
* need to log via audit_log_exit().
18381838
*/
18391839
if (tsk == current && !context->dummy) {
@@ -2069,7 +2069,7 @@ void __audit_syscall_exit(int success, long return_code)
20692069
/* run through both filters to ensure we set the filterkey properly */
20702070
audit_filter_syscall(current, context);
20712071
audit_filter_inodes(current, context);
2072-
if (context->current_state < AUDIT_STATE_RECORD)
2072+
if (context->current_state != AUDIT_STATE_RECORD)
20732073
goto out;
20742074

20752075
audit_log_exit();

0 commit comments

Comments
 (0)