Skip to content

Commit 6441998

Browse files
committed
Merge tag 'audit-pr-20211216' of git://git.kernel.org/pub/scm/linux/kernel/git/pcmoore/audit
Pull audit fix from Paul Moore: "A single patch to fix a problem where the audit queue could grow unbounded when the audit daemon is forcibly stopped" * tag 'audit-pr-20211216' of git://git.kernel.org/pub/scm/linux/kernel/git/pcmoore/audit: audit: improve robustness of the audit queue handling
2 parents 180f3bc + f4b3ee3 commit 6441998

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)