summaryrefslogtreecommitdiff
path: root/security
diff options
context:
space:
mode:
authorJohn Johansen <john.johansen@canonical.com>2025-11-24 15:07:42 -0800
committerSasha Levin <sashal@kernel.org>2026-03-04 07:20:40 -0500
commit3852eb9a0392eb435c03dcb47d581bcfe6a9a95b (patch)
treed9e4ac6f4b184b482d26bb22274647f93aaaf13b /security
parent77d2e4d03db670783af7dad18998a13892c4fa8d (diff)
apparmor: fix NULL sock in aa_sock_file_perm
[ Upstream commit 00b67657535dfea56e84d11492f5c0f61d0af297 ] 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> Signed-off-by: Sasha Levin <sashal@kernel.org>
Diffstat (limited to 'security')
-rw-r--r--security/apparmor/net.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/security/apparmor/net.c b/security/apparmor/net.c
index 77413a519117..f6f749191f60 100644
--- a/security/apparmor/net.c
+++ b/security/apparmor/net.c
@@ -190,8 +190,10 @@ int aa_sock_file_perm(const struct cred *subj_cred, struct aa_label *label,
const char *op, u32 request, struct socket *sock)
{
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;
return aa_label_sk_perm(subj_cred, label, op, request, sock->sk);
}