On Mon, Mar 10, 2025 at 3:53 PM Stephen Smalley <stephen.smalley.work@xxxxxxxxx> wrote: > On Sat, Mar 8, 2025 at 11:55 PM Edward Adam Davis <eadavis@xxxxxx> wrote: > > > > syzbot reported a data-race in selinux_socket_post_create / > > selinux_socket_sock_rcv_skb. [1] > > > > When creating the socket path and receiving the network data packet path, > > effective data access protection is not performed when reading and writing > > the sid, resulting in a race condition. > > > > Add a lock to synchronize the two. ... > > Reported-by: syzbot+00c633585760c05507c3@xxxxxxxxxxxxxxxxxxxxxxxxx > > Closes: https://syzkaller.appspot.com/bug?extid=00c633585760c05507c3 > > Signed-off-by: Edward Adam Davis <eadavis@xxxxxx> > > --- > > security/selinux/hooks.c | 7 ++++++- > > 1 file changed, 6 insertions(+), 1 deletion(-) > > > > diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c > > index 7b867dfec88b..ea5d0273f9d5 100644 > > --- a/security/selinux/hooks.c > > +++ b/security/selinux/hooks.c > > @@ -4677,8 +4677,10 @@ static int selinux_socket_post_create(struct socket *sock, int family, > > > > if (sock->sk) { > > sksec = selinux_sock(sock->sk); > > + spin_lock(&sksec->lock); > > You didn't include the diff that adds this lock field to > sk_security_struct, but aside from that, I would suggest something > lighter-weight like READ_ONCE/WRITE_ONCE if possible. Yes, please don't add a spinlock to something that is potentially going to be hit on every packet entering the system. -- paul-moore.com