From: Eiichi Tsukata <eiichi.tsukata@nutanix.com>
To: Paul Moore <paul@paul-moore.com>
Cc: "eparis@redhat.com" <eparis@redhat.com>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"audit@vger.kernel.org" <audit@vger.kernel.org>
Subject: Re: [PATCH 0/4] audit: refactor and fix for potential deadlock
Date: Wed, 10 May 2023 08:09:05 +0000 [thread overview]
Message-ID: <0BA588DC-1E53-4BCE-B124-77C5C730C267@nutanix.com> (raw)
In-Reply-To: <506299C8-B1D0-457D-881B-BF639224A3AD@nutanix.com>
> On May 9, 2023, at 10:34, Eiichi Tsukata <eiichi.tsukata@nutanix.com> wrote:
>
>
>
>> On May 8, 2023, at 23:07, Paul Moore <paul@paul-moore.com> wrote:
>>
>> On Mon, May 8, 2023 at 3:58 AM Eiichi Tsukata
>> <eiichi.tsukata@nutanix.com> wrote:
>>> 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().
>>
>> Have you seen this occur in practice?
>
> Yes, we hit this issue multiple times, though it’s pretty rare as you are mentioning.
> In our case, sshd got stuck in audit_log_user_message(), which caused SSH connection
> timeout.
>
I found another case.
kauditd_thread issues wake_up(&audit_backlog_wait) once after wake up.
As waiter side is using add_wait_queue_exclusive() it only wakes up one process at once.
If kauditd wakes up a process which is sleeping in audit_log_start(), then the process will
queue skb and issue wake_up_interruptible(&kauditd_wait). No problem.
But if kauditd wakes up a process which is sleeping in audit_receive(), then the process
won’t try to wake up kauditd. In this case other processes sleeping in audit_log_start()
keep sleeping even if kauditd have flushed the queue.
At this point I’m planning to use non-exclusive wait in audit_receive() in v2.
Let me know if we should use wake_up_all() in kauditd or you have better solution.
Eiichi
next prev parent reply other threads:[~2023-05-10 8:09 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-08 7:58 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 ` [PATCH 4/4] audit: check if queue is full after prepare_to_wait_exclusive() Eiichi Tsukata
2023-05-08 17:13 ` 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 [this message]
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=0BA588DC-1E53-4BCE-B124-77C5C730C267@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®