Re: [PATCH v3] selinux: avoid sk_socket dereference in selinux_sctp_bind_connect()
From: Paul Moore
Date: Wed Jul 01 2026 - 18:23:50 EST
On Jun 25, 2026 Tristan Madani <tristmd@xxxxxxxxx> wrote:
>
> selinux_sctp_bind_connect() dereferences sk->sk_socket to pass a
> struct socket * to selinux_socket_bind() and
> selinux_socket_connect_helper(). However, when the hook is invoked
> from the ASCONF softirq path (sctp_process_asconf), there is no file
> reference guaranteeing that sk->sk_socket is non-NULL. The setsockopt
> callers (bindx, connectx, set_primary, sendmsg connect) hold a file
> reference and are not affected.
>
> Both selinux_socket_bind() and selinux_socket_connect_helper()
> immediately resolve sock->sk, never using the struct socket * for
> anything else. Refactor the inner logic into helpers that take a
> struct sock * directly so that selinux_sctp_bind_connect() never needs
> to touch sk->sk_socket at all.
>
> Suggested-by: Stephen Smalley <stephen.smalley.work@xxxxxxxxx>
> Fixes: d452930fd3b9 ("selinux: Add SCTP support")
> Cc: stable@xxxxxxxxxxxxxxx
> Signed-off-by: Tristan Madani <tristan@xxxxxxxxxxxxxxxxxxx>
> Reviewed-by: Stephen Smalley <stephen.smalley.work@xxxxxxxxx>
> Tested-by: Stephen Smalley <stephen.smalley.work@xxxxxxxxx>
> ---
> Changes in v3:
> - Keep comment describing IPv4/IPv6 address processing loop
> (Stephen Smalley).
>
> Changes in v2:
> - Refactor selinux_socket_bind() and selinux_socket_connect_helper()
> into sk-based inner helpers instead of adding a NULL check on
> sk->sk_socket (Stephen Smalley).
>
> security/selinux/hooks.c | 19 ++++++++++---------
> 1 file changed, 10 insertions(+), 9 deletions(-)
Thanks, this looks good to me, I'm going to merge it into
selinux/stable-7.2 now.
However, there is another issue relating to the SCTP softirq code paths:
the fact that we call into sock_has_perm() in both
__selinux_socket_bind() and selinux_socket_connect_helper(). The
sock_has_perm() function uses current_sid() as the subject in the
avc_has_perm() call, and in the softirq case that is not what we want.
It's been few years since I spent any serious time with SCTP so it isn't
immediately clear to me what the solution is to this problem, but if you
wanted to look into this and come up with some ideas that would be a big
help!
--
paul-moore.com