]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
apparmor: lift kernel socket check out of critical section
authorJohn Johansen <john.johansen@canonical.com>
Wed, 10 Apr 2024 21:49:43 +0000 (14:49 -0700)
committerJohn Johansen <john.johansen@canonical.com>
Sat, 18 Jan 2025 14:47:12 +0000 (06:47 -0800)
There is no need for the kern check to be in the critical section,
it only complicates the code and slows down the case where the
socket is being created by the kernel.

Lifting it out will also allow socket_create to share common template
code, with other socket_permission checks.

Signed-off-by: John Johansen <john.johansen@canonical.com>
security/apparmor/lsm.c

index 1246115b7435bd0d4e57f0d0ff02f02c36b277ee..f7b2d4bb1d978b74c857a7e05162f6521c1c7db7 100644 (file)
@@ -1095,10 +1095,14 @@ static int apparmor_socket_create(int family, int type, int protocol, int kern)
 
        AA_BUG(in_interrupt());
 
+       if (kern)
+               return 0;
+
        label = begin_current_label_crit_section();
-       if (!(kern || unconfined(label)))
+       if (!unconfined(label)) {
                error = aa_af_perm(current_cred(), label, OP_CREATE,
                                   AA_MAY_CREATE, family, type, protocol);
+       }
        end_current_label_crit_section(label);
 
        return error;