audit: init ab->skb_list earlier in audit_buffer_alloc()

syzbot found a bug in audit_buffer_alloc() if nlmsg_new() returns NULL.

We need to initialize ab->skb_list before calling audit_buffer_free()
which will use both the skb_list spinlock and list pointers.

Fixes: eb59d494ee ("audit: add record for multiple task security contexts")
Reported-by: syzbot+bb185b018a51f8d91fd2@syzkaller.appspotmail.com
Closes: https://lore.kernel.org/lkml/68b93e3c.a00a0220.eb3d.0000.GAE@google.com/T/#u
Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Casey Schaufler <casey@schaufler-ca.com>
Cc: Paul Moore <paul@paul-moore.com>
Cc: Eric Paris <eparis@redhat.com>
Cc: audit@vger.kernel.org
Signed-off-by: Paul Moore <paul@paul-moore.com>
pull/1354/merge
Eric Dumazet 2025-09-04 07:25:37 +00:00 committed by Paul Moore
parent 0ffbc876d0
commit 2aef21a6a6
1 changed files with 2 additions and 1 deletions

View File

@ -1831,11 +1831,12 @@ static struct audit_buffer *audit_buffer_alloc(struct audit_context *ctx,
if (!ab)
return NULL;
skb_queue_head_init(&ab->skb_list);
ab->skb = nlmsg_new(AUDIT_BUFSIZ, gfp_mask);
if (!ab->skb)
goto err;
skb_queue_head_init(&ab->skb_list);
skb_queue_tail(&ab->skb_list, ab->skb);
if (!nlmsg_put(ab->skb, 0, 0, type, 0, 0))