Skip to contentSkip to conversation

selinux: fix a sock regression in selinux_ip_postroute_compat()

PATCH Applied Paul Moore 2 participants 4 messages Oct 19, 2021 – Oct 20, 2021 SELinux security module

lore
Share & tools
lore

Paul Moore

author maintainer
#0 lore raw

PATCH 1/1 selinux: fix a sock regression in selinux_ip_postroute_compat()

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 ("1d1e1ded13568be81a0e19d228e310a48997bec8")
---
 security/selinux/hooks.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
security/selinux/hooks.c +2 -2
index b4a1bde20261..6f08cd2fc6a8 100644
@@ -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;
#1 lore raw
Quoted 4 lines · Paul Moore

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 ("1d1e1ded13568be81a0e19d228e310a48997bec8")

This doesn't seem right :)

Quoted 24 lines
---
 security/selinux/hooks.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
security/selinux/hooks.c +2 -2
index b4a1bde20261..6f08cd2fc6a8 100644
@@ -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;
Signature · 3 lines
Ondrej Mosnacek
Software Engineer, Linux Security - SELinux kernel
Red Hat, Inc.
author maintainer
#2 lore raw
Quoted 8 lines · Ondrej Mosnacek
Quoted 4 lines · Paul Moore

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 ("1d1e1ded13568be81a0e19d228e310a48997bec8")

This doesn't seem right :)

It does seem a little off, doesn't it? Thanks for catching this, I fixed it up in my local tree.

In case anyone is interested in my long winded excuse ... I replaced my old trusty mouse this morning (one of the buttons was starting to become decidedly un-trusty) and while switching between my Linux system and my Windows system (employer VPN box) I learned that my new mouse actually gets reprogrammed on-the-fly by the Windows driver/config-software such that my middle mouse button was non-functional when returning the Linux and hence my usual workflow of "highlight and middle-click" was temporarily replaced with ctrl-c and crtl-v which was awkward and resulted in some copy-n-paste snafus. I wanted to get the patch posted to the list so I did that before finding a solution to my mouse problems, perhaps that wasn't the best order :)

Signature · 2 lines
paul moore
www.paul-moore.com
author maintainer Applied
#3 lore raw
In reply to Paul Moore
Quoted 11 lines · Paul Moore

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 ("1d1e1ded13568be81a0e19d228e310a48997bec8")
---
 security/selinux/hooks.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Merged into selinux/next, with the corrected Fixes line that Ondrej pointed out.

Signature · 2 lines
paul moore
www.paul-moore.com