]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
apparmor: fix NULL sock in aa_sock_file_perm
authorJohn Johansen <john.johansen@canonical.com>
Mon, 24 Nov 2025 23:07:42 +0000 (15:07 -0800)
committerJohn Johansen <john.johansen@canonical.com>
Thu, 22 Jan 2026 12:51:55 +0000 (04:51 -0800)
Deal with the potential that sock and sock-sk can be NULL during
socket setup or teardown. This could lead to an oops. The fix for NULL
pointer dereference in __unix_needs_revalidation shows this is at
least possible for af_unix sockets. While the fix for af_unix sockets
applies for newer mediation this is still the fall back path for older
af_unix mediation and other sockets, so ensure it is covered.

Fixes: 56974a6fcfef6 ("apparmor: add base infastructure for socket mediation")
Reviewed-by: Georgia Garcia <georgia.garcia@canonical.com>
Signed-off-by: John Johansen <john.johansen@canonical.com>
security/apparmor/net.c

index 45cf25605c345b07d318e9c07a1580c6b2154f7e..44c04102062f3d50317b5f9ce20f7441abdbbd83 100644 (file)
@@ -326,8 +326,10 @@ int aa_sock_file_perm(const struct cred *subj_cred, struct aa_label *label,
        struct socket *sock = (struct socket *) file->private_data;
 
        AA_BUG(!label);
-       AA_BUG(!sock);
-       AA_BUG(!sock->sk);
+
+       /* sock && sock->sk can be NULL for sockets being set up or torn down */
+       if (!sock || !sock->sk)
+               return 0;
 
        if (sock->sk->sk_family == PF_UNIX)
                return aa_unix_file_perm(subj_cred, label, op, request, file);