Skip to content

Commit 032e70a

Browse files
chenzongyao200127pcmoore
authored andcommitted
selinux: use sk blob accessor in socket permission helpers
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. Fixes: d1d991e ("selinux: Add netlink xperm support") Cc: stable@vger.kernel.org # v6.13+ Signed-off-by: Zongyao Chen <ZongYao.Chen@linux.alibaba.com> Signed-off-by: Paul Moore <paul@paul-moore.com>
1 parent 254f496 commit 032e70a

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

security/selinux/hooks.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4920,7 +4920,7 @@ static bool sock_skip_has_perm(u32 sid)
49204920

49214921
static int sock_has_perm(struct sock *sk, u32 perms)
49224922
{
4923-
struct sk_security_struct *sksec = sk->sk_security;
4923+
struct sk_security_struct *sksec = selinux_sock(sk);
49244924
struct common_audit_data ad;
49254925
struct lsm_network_audit net;
49264926

@@ -6227,7 +6227,7 @@ static unsigned int selinux_ip_postroute(void *priv,
62276227

62286228
static int nlmsg_sock_has_extended_perms(struct sock *sk, u32 perms, u16 nlmsg_type)
62296229
{
6230-
struct sk_security_struct *sksec = sk->sk_security;
6230+
struct sk_security_struct *sksec = selinux_sock(sk);
62316231
struct common_audit_data ad;
62326232
u8 driver;
62336233
u8 xperm;

0 commit comments

Comments
 (0)