Re: [RFC PATCH] audit: drop BUG_ON() from audit_log_XXX()

Ricardo Robaina <[email protected]> Wed, 1 Jul 2026 10:19:54 -0300
Newsgroups org.kernel.vger.audit
Message-ID <CAABTaaCG9xrLXsYoAx9QD85t8xkpveMXi_sBndz-7mbCmpZgBw@mail.gmail.com>
On Tue, Jun 30, 2026 at 4:53=E2=80=AFPM Paul Moore <[email protected]> wr=
ote:
>
> We can easily drop the BUG_ON()s from the audit_log_XXX() helpers and
> simply return to the caller as we do if we are passed a NULL
> audit_buffer.
>
> Signed-off-by: Paul Moore <[email protected]>
> ---
>  kernel/audit.c | 9 +++------
>  1 file changed, 3 insertions(+), 6 deletions(-)
>
> diff --git a/kernel/audit.c b/kernel/audit.c
> index dcc657d35776..d05c92d74361 100644
> --- a/kernel/audit.c
> +++ b/kernel/audit.c
> @@ -2016,10 +2016,9 @@ void audit_log_vformat(struct audit_buffer *ab, co=
nst char *fmt, va_list args)
>         struct sk_buff *skb;
>         va_list args2;
>
> -       if (!ab)
> +       if (!ab || !ab->skb)
>                 return;
>
> -       BUG_ON(!ab->skb);
>         skb =3D ab->skb;
>         avail =3D skb_tailroom(skb);
>         if (avail =3D=3D 0) {
> @@ -2084,10 +2083,9 @@ void audit_log_n_hex(struct audit_buffer *ab, cons=
t unsigned char *buf,
>         unsigned char *ptr;
>         struct sk_buff *skb;
>
> -       if (!ab)
> +       if (!ab || !ab->skb)
>                 return;
>
> -       BUG_ON(!ab->skb);
>         skb =3D ab->skb;
>         avail =3D skb_tailroom(skb);
>         new_len =3D len<<1;
> @@ -2117,10 +2115,9 @@ void audit_log_n_string(struct audit_buffer *ab, c=
onst char *string,
>         unsigned char *ptr;
>         struct sk_buff *skb;
>
> -       if (!ab)
> +       if (!ab || !ab->skb)
>                 return;
>
> -       BUG_ON(!ab->skb);
>         skb =3D ab->skb;
>         avail =3D skb_tailroom(skb);
>         new_len =3D slen + 3;     /* enclosing quotes + null terminator *=
/
> --
> 2.55.0
>
>

Hi Paul,

It looks good to me. I agree that it was not worth panicking the
kernel in these cases.
Reviewed-by: Ricardo Robaina <[email protected]>

I was taking a look at other BUG_ON instances and noticed a couple
that might benefit from similar treatment:

  1. In audit_add_to_parent() at kernel/audit_watch.c:375:
     BUG_ON(!mutex_is_locked(&audit_filter_mutex));

     Couldn't we use lockdep_assert_held() instead?

  2. In __audit_log_bprm_fcaps() at kernel/auditsc.c:2715:
     BUG_ON(axp->pid_count >=3D AUDIT_AUX_PIDS);

     This could gracefully return an error instead of panicking.

I can send patches for these if you think they're worthwhile.

-Ricardo