diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c index 21e03380dd86..4c69259b62f1 100644 --- a/security/apparmor/lsm.c +++ b/security/apparmor/lsm.c @@ -1035,6 +1035,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); }