Skip to content

Commit 00b6765

Browse files
committed
apparmor: fix NULL sock in aa_sock_file_perm
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: 56974a6 ("apparmor: add base infastructure for socket mediation") Reviewed-by: Georgia Garcia <[email protected]> Signed-off-by: John Johansen <[email protected]>
1 parent e2938ad commit 00b6765

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

security/apparmor/net.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,8 +326,10 @@ int aa_sock_file_perm(const struct cred *subj_cred, struct aa_label *label,
326326
struct socket *sock = (struct socket *) file->private_data;
327327

328328
AA_BUG(!label);
329-
AA_BUG(!sock);
330-
AA_BUG(!sock->sk);
329+
330+
/* sock && sock->sk can be NULL for sockets being set up or torn down */
331+
if (!sock || !sock->sk)
332+
return 0;
331333

332334
if (sock->sk->sk_family == PF_UNIX)
333335
return aa_unix_file_perm(subj_cred, label, op, request, file);

0 commit comments

Comments
 (0)