selinux: use sk blob accessor in socket permission helpers
PATCH 1/1 selinux: use sk blob accessor in socket permission helpers
From: Zongyao Chen <[email protected]>
SELinux socket state lives in the composite LSM socket blob.
sock_has_perm() and nlmsg_sock_has_extended_perms() currently dereference sk->sk_security directly, which assumes the SELinux socket blob is at offset zero.
In stacked configurations that assumption does not hold. If another LSM allocates socket blob storage before SELinux, these helpers may read the wrong blob and feed invalid SID and class values into AVC checks.
Use selinux_sock() instead of accessing sk->sk_security directly.
--- security/selinux/hooks.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
security/selinux/hooks.c +2 -2
@@ -4920,7 +4920,7 @@ static bool sock_skip_has_perm(u32 sid)static int sock_has_perm (struct sock *sk,u32 perms) { -struct sk_security_struct *sksec = sk->sk_security; +struct sk_security_struct *sksec =selinux_sock (sk);struct common_audit_data ad;struct lsm_network_audit net;
@@ -6227,7 +6227,7 @@ static unsigned int selinux_ip_postroute(void *priv,static int nlmsg_sock_has_extended_perms (struct sock *sk,u32 perms,u16 nlmsg_type) { -struct sk_security_struct *sksec = sk->sk_security; +struct sk_security_struct *sksec =selinux_sock (sk);struct common_audit_data ad;u8 driver;u8 xperm;
base-commit: dd6c438c3e64a5ff0b5d7e78f7f9be547803ef1b
Signature · 1 line
2.47.3
Paul Moore
maintainerQuoted 11 lines · On Apr 24, 2026 [email protected] wrote:
SELinux socket state lives in the composite LSM socket blob.
sock_has_perm()andnlmsg_sock_has_extended_perms()currently dereferencesk->sk_securitydirectly, which assumes the SELinux socket blob is at offset zero.In stacked configurations that assumption does not hold. If another LSM allocates socket blob storage before SELinux, these helpers may read the wrong blob and feed invalid SID and class values into AVC checks.
Quoted 8 lines
Use
selinux_sock()instead of accessingsk->sk_securitydirectly.Fixes d1d991efaf34 ("selinux: Add netlink xperm support")Cc [email protected] # v6.13+Signed-off-by Zongyao Chen <[email protected]>--- security/selinux/hooks.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
Nice catch, thanks. Merged into selinux/stable-7.1 and I'll send it up to Linus later this week.
Quoted 23 lines
security/selinux/hooks.c +2
-2@@ -4920,7 +4920,7 @@ static bool sock_skip_has_perm(u32 sid)static int sock_has_perm (struct sock *sk,u32 perms) { -struct sk_security_struct *sksec = sk->sk_security; +struct sk_security_struct *sksec =selinux_sock (sk);struct common_audit_data ad;struct lsm_network_audit net;@@ -6227,7 +6227,7 @@ static unsigned int selinux_ip_postroute(void *priv,static int nlmsg_sock_has_extended_perms (struct sock *sk,u32 perms,u16 nlmsg_type) { -struct sk_security_struct *sksec = sk->sk_security; +struct sk_security_struct *sksec =selinux_sock (sk);struct common_audit_data ad;u8 driver;u8 xperm;
Quoted 3 lines
base-commit:
dd6c438c3e64a5ff0b5d7e78f7f9be547803ef1bSignature · 1 line
2.47.3
--
paul-moore.com