audit: drop BUG_ON() calls
cover audit: drop BUG_ON() calls
This series drops two BUG_ON() calls from audit_add_to_parent() and audit_signal_info_syscall(), replacing them with alternatives that avoid panicking the kernel for conditions that are either debug-only assertions or defensive invariant checks.
Ricardo Robaina (2):
audit: drop BUG_ON() from audit_add_to_parent()
audit: drop BUG_ON() from audit_signal_info_syscall()
kernel/audit_watch.c | 2 +- kernel/auditsc.c | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-)
Signature · 1 line
2.53.0
PATCH 1/2 audit: drop BUG_ON() from audit_add_to_parent()
The BUG_ON(!mutex_is_locked(&audit_filter_mutex)) check in audit_add_to_parent() will panic the kernel if the mutex is not held, which is too severe for this situation.
Replace it with lockdep_assert_held(), instead.
--- kernel/audit_watch.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/audit_watch.c +1 -1
@@ -372,7 +372,7 @@ static void audit_add_to_parent(struct audit_krule *krule,struct audit_watch *w, *watch = krule->watch;int watch_found =0 ; -BUG_ON (!mutex_is_locked (&audit_filter_mutex)); +lockdep_assert_held (&audit_filter_mutex);list_for_each_entry (w, &parent->watches, wlist) {if (strcmp (watch->path, w->path))
Signature · 1 line
2.53.0
Re: [PATCH 1/2] audit: drop BUG_ON() from audit_add_to_parent()
Quoted 11 lines · On Jul 28, 2026 Ricardo Robaina <[email protected]> wrote:
The BUG_ON(!mutex_is_locked(&audit_filter_mutex)) check in
audit_add_to_parent()will panic the kernel if the mutex is not held, which is too severe for this situation.Replace it with
lockdep_assert_held(), instead.Signed-off-by Ricardo Robaina <[email protected]>--- kernel/audit_watch.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Merged into audit/dev, thanks.
--
paul-moore.com
Re: [PATCH 1/2] audit: drop BUG_ON() from audit_add_to_parent()
Quoted 14 lines · Paul Moore
Quoted 11 lines · On Jul 28, 2026 Ricardo Robaina <[email protected]> wrote:
The BUG_ON(!mutex_is_locked(&audit_filter_mutex)) check in
audit_add_to_parent()will panic the kernel if the mutex is not held, which is too severe for this situation.Replace it with
lockdep_assert_held(), instead.Signed-off-by Ricardo Robaina <[email protected]>--- kernel/audit_watch.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 5 lines
Merged into audit/dev, thanks.
--
paul-moore.com
Thanks, Paul!
PATCH 2/2 audit: drop BUG_ON() from audit_signal_info_syscall()
In reply to Ricardo RobainaThe BUG_ON(axp->pid_count >= AUDIT_AUX_PIDS) check in audit_signal_info_syscall() will panic the kernel if the signal target pid array overflows, which is too severe for this situation.
Replace it with a WARN_ON_ONCE() and return of -EINVAL, instead.
--- kernel/auditsc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
kernel/auditsc.c +2 -1
@@ -2712,7 +2712,8 @@ int audit_signal_info_syscall(struct task_struct *t) axp->d.next = ctx->aux_pids; ctx->aux_pids = (void *)axp; } -BUG_ON (axp->pid_count >=AUDIT_AUX_PIDS ); +if (WARN_ON_ONCE (axp->pid_count >=AUDIT_AUX_PIDS )) +return -EINVAL ; axp->target_pid[axp->pid_count] =task_tgid_nr (t); axp->target_auid[axp->pid_count] =audit_get_loginuid (t);
Signature · 1 line
2.53.0
Re: [PATCH 2/2] audit: drop BUG_ON() from audit_signal_info_syscall()
Quoted 17 lines · On Jul 28, 2026 Ricardo Robaina <[email protected]> wrote:
The
BUG_ON(axp->pid_count >= AUDIT_AUX_PIDS)check inaudit_signal_info_syscall()will panic the kernel if the signal target pid array overflows, which is too severe for this situation.Replace it with a
WARN_ON_ONCE()and return of-EINVAL, instead.Signed-off-by Ricardo Robaina <[email protected]>--- kernel/auditsc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)kernel/auditsc.c +0
-0
kernel/auditsc.c int audit_signal_info_syscall(struct task_struct *t) · line 2716
Quoted 6 lines
kernel/auditsc.c +2
-1@@ -2712,7 +2712,8 @@ int audit_signal_info_syscall(struct task_struct *t) axp->d.next = ctx->aux_pids; ctx->aux_pids = (void *)axp; } -BUG_ON (axp->pid_count >=AUDIT_AUX_PIDS ); +if (WARN_ON_ONCE (axp->pid_count >=AUDIT_AUX_PIDS )) +return -EINVAL ;
Part of me wonders if the WARN_ON_ONCE() should be a pr_err(), possibly ratelimited, but given that I don't recall ever seeing this BUG_ON() trigger I think this is fine. We can always change the WARN_ON_ONCE() later if needed, getting rid of the BUG_ON() is the big win.
Merged into audit/dev, thanks.
Quoted 4 lines
kernel/auditsc.c +0
-0axp->target_pid[axp->pid_count] =task_tgid_nr (t); axp->target_auid[axp->pid_count] =audit_get_loginuid (t);Signature · 1 line
2.53.0
--
paul-moore.com
Re: [PATCH 2/2] audit: drop BUG_ON() from audit_signal_info_syscall()
Quoted 31 lines · Paul Moore
Quoted 17 lines · On Jul 28, 2026 Ricardo Robaina <[email protected]> wrote:
The
BUG_ON(axp->pid_count >= AUDIT_AUX_PIDS)check inaudit_signal_info_syscall()will panic the kernel if the signal target pid array overflows, which is too severe for this situation.Replace it with a
WARN_ON_ONCE()and return of-EINVAL, instead.Signed-off-by Ricardo Robaina <[email protected]>--- kernel/auditsc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)kernel/auditsc.c +0
-0kernel/auditsc.c int audit_signal_info_syscall(struct task_struct *t) · line 2716
Quoted 6 lines
kernel/auditsc.c +2
-1@@ -2712,7 +2712,8 @@ int audit_signal_info_syscall(struct task_struct *t) axp->d.next = ctx->aux_pids; ctx->aux_pids = (void *)axp; } -BUG_ON (axp->pid_count >=AUDIT_AUX_PIDS ); +if (WARN_ON_ONCE (axp->pid_count >=AUDIT_AUX_PIDS )) +return -EINVAL ;Part of me wonders if the
WARN_ON_ONCE()should be apr_err(), possibly ratelimited, but given that I don't recall ever seeing thisBUG_ON()trigger I think this is fine. We can always change theWARN_ON_ONCE()later if needed, getting rid of theBUG_ON()is the big win.
Quoted 1 line
Merged into audit/dev, thanks.
Makes sense. Thanks, Paul!
Quoted 9 lines
Quoted 5 lines
kernel/auditsc.c +0
-1axp->target_pid[axp->pid_count] =task_tgid_nr (t); axp->target_auid[axp->pid_count] =audit_get_loginuid (t); --2.53.0
--
paul-moore.com