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 4/4] audit: check if queue is full after prepare_to_wait_exclusive()
Date: Mon, 8 May 2023 07:58:12 +0000 [thread overview]
Message-ID: <20230508075812.76077-5-eiichi.tsukata@nutanix.com> (raw)
In-Reply-To: <20230508075812.76077-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())
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 queue full check after
prepare_to_wait_exclusive().
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 | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/kernel/audit.c b/kernel/audit.c
index bcbb0ba33c84..d37a3a045230 100644
--- a/kernel/audit.c
+++ b/kernel/audit.c
@@ -644,8 +644,14 @@ 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);
+ }
finish_wait(&audit_backlog_wait, &wait);
return rtime;
--
2.40.0
next prev parent reply other threads:[~2023-05-08 7:59 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-08 7:58 [PATCH 0/4] audit: refactor and fix for potential deadlock Eiichi Tsukata
2023-05-08 7:58 ` [PATCH 1/4] audit: refactor queue full checks Eiichi Tsukata
2023-05-10 6:54 ` Rinat Gadelshin
2023-05-10 7:17 ` Eiichi Tsukata
2023-05-10 7:28 ` Rinat Gadelshin
2023-05-08 7:58 ` [PATCH 2/4] audit: account backlog waiting time in audit_receive() Eiichi Tsukata
2023-05-08 7:58 ` [PATCH 3/4] audit: convert DECLARE_WAITQUEUE to DEFINE_WAIT Eiichi Tsukata
2023-05-08 7:58 ` Eiichi Tsukata [this message]
2023-05-08 17:13 ` [PATCH 4/4] audit: check if queue is full after prepare_to_wait_exclusive() kernel test robot
2023-05-09 1:44 ` Eiichi Tsukata
2023-05-08 14:07 ` [PATCH 0/4] audit: refactor and fix for potential deadlock Paul Moore
2023-05-09 1:34 ` Eiichi Tsukata
2023-05-10 8:09 ` Eiichi Tsukata
2023-05-17 16:15 ` Paul Moore
2023-05-17 16:03 ` 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=20230508075812.76077-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®