This is a note to let you know that I've just added the patch titled audit: don't take task_lock() in audit_exe_compare() code path to the 5.4-stable tree which can be found at: http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary The filename of the patch is: audit-don-t-take-task_lock-in-audit_exe_compare-code-path.patch and it can be found in the queue-5.4 subdirectory. If you, or anyone else, feels it should not be added to the stable tree, please let <stable@xxxxxxxxxxxxxxx> know about it. >From 47846d51348dd62e5231a83be040981b17c955fa Mon Sep 17 00:00:00 2001 From: Paul Moore <paul@xxxxxxxxxxxxxx> Date: Mon, 9 Oct 2023 13:18:49 -0400 Subject: audit: don't take task_lock() in audit_exe_compare() code path From: Paul Moore <paul@xxxxxxxxxxxxxx> commit 47846d51348dd62e5231a83be040981b17c955fa upstream. The get_task_exe_file() function locks the given task with task_lock() which when used inside audit_exe_compare() can cause deadlocks on systems that generate audit records when the task_lock() is held. We resolve this problem with two changes: ignoring those cases where the task being audited is not the current task, and changing our approach to obtaining the executable file struct to not require task_lock(). With the intent of the audit exe filter being to filter on audit events generated by processes started by the specified executable, it makes sense that we would only want to use the exe filter on audit records associated with the currently executing process, e.g. @current. If we are asked to filter records using a non-@current task_struct we can safely ignore the exe filter without negatively impacting the admin's expectations for the exe filter. Knowing that we only have to worry about filtering the currently executing task in audit_exe_compare() we can do away with the task_lock() and call get_mm_exe_file() with @current->mm directly. Cc: <stable@xxxxxxxxxxxxxxx> Fixes: 5efc244346f9 ("audit: fix exe_file access in audit_exe_compare") Reported-by: Andreas Steinmetz <anstein99@xxxxxxxxxxxxxx> Reviewed-by: John Johansen <john.johanse@xxxxxxxxxxxxx> Reviewed-by: Mateusz Guzik <mjguzik@xxxxxxxxx> Signed-off-by: Paul Moore <paul@xxxxxxxxxxxxxx> Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> --- kernel/audit_watch.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) --- a/kernel/audit_watch.c +++ b/kernel/audit_watch.c @@ -542,11 +542,18 @@ int audit_exe_compare(struct task_struct unsigned long ino; dev_t dev; - exe_file = get_task_exe_file(tsk); + /* only do exe filtering if we are recording @current events/records */ + if (tsk != current) + return 0; + + if (WARN_ON_ONCE(!current->mm)) + return 0; + exe_file = get_mm_exe_file(current->mm); if (!exe_file) return 0; ino = file_inode(exe_file)->i_ino; dev = file_inode(exe_file)->i_sb->s_dev; fput(exe_file); + return audit_mark_compare(mark, ino, dev); } Patches currently in stable-queue which might be from paul@xxxxxxxxxxxxxx are queue-5.4/audit-don-t-warn_on_once-current-mm-in-audit_exe_compare.patch queue-5.4/audit-don-t-take-task_lock-in-audit_exe_compare-code-path.patch