Audit system development
 help / color / mirror / Atom feed
From: Ricardo Robaina <rrobaina@redhat.com>
To: wangchi@kylinos.cn
Cc: paul@paul-moore.com, eparis@redhat.com, audit@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	Ricardo Robaina <rrobaina@redhat.com>
Subject: Re: [PATCH] audit: Fix data race in audit_log_start()
Date: Thu, 18 Jun 2026 10:40:05 -0300	[thread overview]
Message-ID: <20260618134004.3398831-2-rrobaina@redhat.com> (raw)
In-Reply-To: <20260617130038.57465-1-wangchi@kylinos.cn>

Hi Chi,

Good catch, the patch looks good to me.

However, I found three additional instances of the same pattern that
should be included in this patch for completeness:

  1. Line 953 in kauditd_thread():
     wait_event_freezable(kauditd_wait,
                          (skb_queue_len(&audit_queue) ? 1 : 0));

  2. Line 1286 in audit_receive_msg() (AUDIT_GET handler):
     s.backlog = skb_queue_len(&audit_queue);

  3. Line 1630 in audit_receive():
     if (audit_backlog_limit &&
         (skb_queue_len(&audit_queue) > audit_backlog_limit)) {

All three read audit_queue.qlen without synchronization while the queue
is concurrently modified.

diff --git a/kernel/audit.c b/kernel/audit.c
index dcc657d35776..c074c3717946 100644
--- a/kernel/audit.c
+++ b/kernel/audit.c
@@ -950,7 +950,7 @@ static int kauditd_thread(void *dummy)
                 *       do the multicast send and rotate records from the
                 *       main queue to the retry/hold queues */
                wait_event_freezable(kauditd_wait,
-                                    (skb_queue_len(&audit_queue) ? 1 : 0));
+                                    (skb_queue_len_lockless(&audit_queue) ? 1 : 0));
        }
 
        return 0;
@@ -1283,7 +1283,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh,
                s.rate_limit               = audit_rate_limit;
                s.backlog_limit            = audit_backlog_limit;
                s.lost                     = atomic_read(&audit_lost);
-               s.backlog                  = skb_queue_len(&audit_queue);
+               s.backlog                  = skb_queue_len_lockless(&audit_queue);
                s.feature_bitmap           = AUDIT_FEATURE_BITMAP_ALL;
                s.backlog_wait_time        = audit_backlog_wait_time;
                s.backlog_wait_time_actual = atomic_read(&audit_backlog_wait_time_actual);
@@ -1627,7 +1627,7 @@ static void audit_receive(struct sk_buff *skb)
 
        /* can't block with the ctrl lock, so penalize the sender now */
        if (audit_backlog_limit &&
-           (skb_queue_len(&audit_queue) > audit_backlog_limit)) {
+           (skb_queue_len_lockless(&audit_queue) > audit_backlog_limit)) {
                DECLARE_WAITQUEUE(wait, current);
 
                /* wake kauditd to try and flush the queue */

Reviewed-by: Ricardo Robaina <rrobaina@redhat.com>

I hope it helps!
-Ricardo


  reply	other threads:[~2026-06-18 13:40 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-17 13:00 [PATCH] audit: Fix data race in audit_log_start() Chi Wang
2026-06-18 13:40 ` Ricardo Robaina [this message]
2026-06-19  7:42 ` [PATCH v2] audit: Fix data races of skb_queue_len() readers on audit_queue Chi Wang
2026-06-30 20:15   ` Paul Moore
  -- strict thread matches above, loose matches on Subject: below --
2026-06-17 12:15 [PATCH] audit: Fix data race in audit_log_start() Chi Wang

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=20260618134004.3398831-2-rrobaina@redhat.com \
    --to=rrobaina@redhat.com \
    --cc=audit@vger.kernel.org \
    --cc=eparis@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=paul@paul-moore.com \
    --cc=wangchi@kylinos.cn \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox