Skip to content

Commit f4b3ee3

Browse files
committed
audit: improve robustness of the audit queue handling
If the audit daemon were ever to get stuck in a stopped state the kernel's kauditd_thread() could get blocked attempting to send audit records to the userspace audit daemon. With the kernel thread blocked it is possible that the audit queue could grow unbounded as certain audit record generating events must be exempt from the queue limits else the system enter a deadlock state. This patch resolves this problem by lowering the kernel thread's socket sending timeout from MAX_SCHEDULE_TIMEOUT to HZ/10 and tweaks the kauditd_send_queue() function to better manage the various audit queues when connection problems occur between the kernel and the audit daemon. With this patch, the backlog may temporarily grow beyond the defined limits when the audit daemon is stopped and the system is under heavy audit pressure, but kauditd_thread() will continue to make progress and drain the queues as it would for other connection problems. For example, with the audit daemon put into a stopped state and the system configured to audit every syscall it was still possible to shutdown the system without a kernel panic, deadlock, etc.; granted, the system was slow to shutdown but that is to be expected given the extreme pressure of recording every syscall. The timeout value of HZ/10 was chosen primarily through experimentation and this developer's "gut feeling". There is likely no one perfect value, but as this scenario is limited in scope (root privileges would be needed to send SIGSTOP to the audit daemon), it is likely not worth exposing this as a tunable at present. This can always be done at a later date if it proves necessary. Cc: [email protected] Fixes: 5b52330 ("audit: fix auditd/kernel connection state tracking") Reported-by: Gaosheng Cui <[email protected]> Tested-by: Gaosheng Cui <[email protected]> Reviewed-by: Richard Guy Briggs <[email protected]> Signed-off-by: Paul Moore <[email protected]>
1 parent d9516f3 commit f4b3ee3

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

kernel/audit.c

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,7 @@ static int kauditd_send_queue(struct sock *sk, u32 portid,
718718
{
719719
int rc = 0;
720720
struct sk_buff *skb;
721-
static unsigned int failed = 0;
721+
unsigned int failed = 0;
722722

723723
/* NOTE: kauditd_thread takes care of all our locking, we just use
724724
* the netlink info passed to us (e.g. sk and portid) */
@@ -735,32 +735,30 @@ static int kauditd_send_queue(struct sock *sk, u32 portid,
735735
continue;
736736
}
737737

738+
retry:
738739
/* grab an extra skb reference in case of error */
739740
skb_get(skb);
740741
rc = netlink_unicast(sk, skb, portid, 0);
741742
if (rc < 0) {
742-
/* fatal failure for our queue flush attempt? */
743+
/* send failed - try a few times unless fatal error */
743744
if (++failed >= retry_limit ||
744745
rc == -ECONNREFUSED || rc == -EPERM) {
745-
/* yes - error processing for the queue */
746746
sk = NULL;
747747
if (err_hook)
748748
(*err_hook)(skb);
749-
if (!skb_hook)
750-
goto out;
751-
/* keep processing with the skb_hook */
749+
if (rc == -EAGAIN)
750+
rc = 0;
751+
/* continue to drain the queue */
752752
continue;
753753
} else
754-
/* no - requeue to preserve ordering */
755-
skb_queue_head(queue, skb);
754+
goto retry;
756755
} else {
757-
/* it worked - drop the extra reference and continue */
756+
/* skb sent - drop the extra reference and continue */
758757
consume_skb(skb);
759758
failed = 0;
760759
}
761760
}
762761

763-
out:
764762
return (rc >= 0 ? 0 : rc);
765763
}
766764

@@ -1609,7 +1607,8 @@ static int __net_init audit_net_init(struct net *net)
16091607
audit_panic("cannot initialize netlink socket in namespace");
16101608
return -ENOMEM;
16111609
}
1612-
aunet->sk->sk_sndtimeo = MAX_SCHEDULE_TIMEOUT;
1610+
/* limit the timeout in case auditd is blocked/stopped */
1611+
aunet->sk->sk_sndtimeo = HZ / 10;
16131612

16141613
return 0;
16151614
}

0 commit comments

Comments
 (0)