selinux: fix a sock regression in selinux_ip_postroute_compat()
authorPaul Moore <paul@paul-moore.com>
Tue, 19 Oct 2021 16:19:44 +0000 (12:19 -0400)
committerPaul Moore <paul@paul-moore.com>
Tue, 19 Oct 2021 16:35:18 +0000 (12:35 -0400)
Unfortunately we can't rely on nf_hook_state->sk being the proper
originating socket so revert to using skb_to_full_sk(skb).

Fixes: 1d1e1ded1356 ("selinux: make better use of the nf_hook_state passed to the NF hooks")
Reported-by: Linux Kernel Functional Testing <lkft@linaro.org>
Suggested-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Paul Moore <paul@paul-moore.com>
security/selinux/hooks.c

index b4a1bde20261653f1ecdf399d74eb7e5158f9176..6f08cd2fc6a89c442d898f6226505367d46e430e 100644 (file)
@@ -5778,9 +5778,9 @@ static unsigned int selinux_ip_postroute_compat(struct sk_buff *skb,
        struct lsm_network_audit net = {0,};
        u8 proto;
 
-       if (state->sk == NULL)
-               return NF_ACCEPT;
        sk = skb_to_full_sk(skb);
+       if (sk == NULL)
+               return NF_ACCEPT;
        sksec = sk->sk_security;
 
        ad.type = LSM_AUDIT_DATA_NET;