diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c index 1e2f40db15c5..97389b9c4129 100644 --- a/security/apparmor/lsm.c +++ b/security/apparmor/lsm.c @@ -1081,6 +1081,13 @@ static int apparmor_socket_sock_rcv_skb(struct sock *sk, struct sk_buff *skb) if (!skb->secmark) return 0; + /* + * If reach here before socket_post_create hook is called, in which + * case label is null, drop the packet. + */ + if (!ctx->label) + return -EACCES; + return apparmor_secmark_check(ctx->label, OP_RECVMSG, AA_MAY_RECEIVE, skb->secmark, sk); }