From: Eiichi Tsukata <eiichi.tsukata@nutanix.com>
To: paul@paul-moore.com, eparis@redhat.com,
linux-kernel@vger.kernel.org, audit@vger.kernel.org
Cc: Eiichi Tsukata <eiichi.tsukata@nutanix.com>
Subject: [PATCH v2 4/5] audit: check if audit_queue is full after prepare_to_wait_exclusive()
Date: Thu, 11 May 2023 05:21:15 +0000 [thread overview]
Message-ID: <20230511052116.19452-5-eiichi.tsukata@nutanix.com> (raw)
In-Reply-To: <20230511052116.19452-1-eiichi.tsukata@nutanix.com>
Commit 7ffb8e317bae ("audit: we don't need to
__set_current_state(TASK_RUNNING)") accidentally moved queue full check
before add_wait_queue_exclusive() which introduced the following race:
CPU1 CPU2
======== ========
(in audit_log_start()) (in kauditd_thread())
@audit_queue is full
wake_up(&audit_backlog_wait)
wait_event_freezable()
add_wait_queue_exclusive()
...
schedule_timeout()
Once this happens, both audit_log_start() and kauditd_thread() can cause
deadlock for up to backlog_wait_time waiting for each other. To prevent
the race, this patch adds @audit_queue full check after
prepare_to_wait_exclusive() and call schedule_timeout() only if the
queue is full.
Fixes: 7ffb8e317bae ("audit: we don't need to __set_current_state(TASK_RUNNING)")
Signed-off-by: Eiichi Tsukata <eiichi.tsukata@nutanix.com>
---
kernel/audit.c | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/kernel/audit.c b/kernel/audit.c
index bcbb0ba33c84..6b0cc0459984 100644
--- a/kernel/audit.c
+++ b/kernel/audit.c
@@ -644,8 +644,16 @@ static long wait_for_kauditd(long stime)
prepare_to_wait_exclusive(&audit_backlog_wait, &wait,
TASK_UNINTERRUPTIBLE);
- rtime = schedule_timeout(stime);
- atomic_add(stime - rtime, &audit_backlog_wait_time_actual);
+
+ /* need to check if the queue is full again because kauditd might have
+ * flushed the queue and went to sleep after prepare_to_wait_exclusive()
+ */
+ if (audit_queue_full(&audit_queue)) {
+ rtime = schedule_timeout(stime);
+ atomic_add(stime - rtime, &audit_backlog_wait_time_actual);
+ } else {
+ rtime = 0;
+ }
finish_wait(&audit_backlog_wait, &wait);
return rtime;
--
2.40.0
next prev parent reply other threads:[~2023-05-11 5:22 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-11 5:21 [PATCH v2 0/5] audit: refactors and fixes for potential deadlocks Eiichi Tsukata
2023-05-11 5:21 ` [PATCH v2 1/5] audit: refactor queue full checks Eiichi Tsukata
2023-05-19 20:54 ` Paul Moore
2023-05-22 4:19 ` Eiichi Tsukata
2023-05-11 5:21 ` [PATCH v2 2/5] audit: account backlog waiting time in audit_receive() Eiichi Tsukata
2023-05-19 20:54 ` Paul Moore
2023-05-22 4:22 ` Eiichi Tsukata
2023-05-23 20:55 ` Paul Moore
2023-05-11 5:21 ` [PATCH v2 3/5] audit: convert DECLARE_WAITQUEUE to DEFINE_WAIT Eiichi Tsukata
2023-05-19 20:54 ` Paul Moore
2023-05-11 5:21 ` Eiichi Tsukata [this message]
2023-05-19 20:54 ` [PATCH v2 4/5] audit: check if audit_queue is full after prepare_to_wait_exclusive() Paul Moore
2023-05-22 4:28 ` Eiichi Tsukata
2023-05-23 21:02 ` Paul Moore
2023-05-11 5:21 ` [PATCH v2 5/5] audit: do not use exclusive wait in audit_receive() Eiichi Tsukata
2023-05-19 20:54 ` Paul Moore
2023-05-22 4:44 ` Eiichi Tsukata
2023-05-23 3:58 ` Eiichi Tsukata
2023-05-23 21:07 ` Paul Moore
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=20230511052116.19452-5-eiichi.tsukata@nutanix.com \
--to=eiichi.tsukata@nutanix.com \
--cc=audit@vger.kernel.org \
--cc=eparis@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=paul@paul-moore.com \
/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
all inboxes | Powered by JetHome®