]> git.baikalelectronics.ru Git - kernel.git/commit
af_unix: fix races in sk_peer_pid and sk_peer_cred accesses
authorEric Dumazet <edumazet@google.com>
Wed, 29 Sep 2021 22:57:50 +0000 (15:57 -0700)
committerDavid S. Miller <davem@davemloft.net>
Thu, 30 Sep 2021 13:18:40 +0000 (14:18 +0100)
commit97276a24b7684b8c32eb908c746fe92080fd2ece
treef01ff49d4c08b6e5465f1ad535264518d1885bdc
parenta90e014895d40d461b3dcf3e528b23b9c67b80bd
af_unix: fix races in sk_peer_pid and sk_peer_cred accesses

Jann Horn reported that SO_PEERCRED and SO_PEERGROUPS implementations
are racy, as af_unix can concurrently change sk_peer_pid and sk_peer_cred.

In order to fix this issue, this patch adds a new spinlock that needs
to be used whenever these fields are read or written.

Jann also pointed out that l2cap_sock_get_peer_pid_cb() is currently
reading sk->sk_peer_pid which makes no sense, as this field
is only possibly set by AF_UNIX sockets.
We will have to clean this in a separate patch.
This could be done by reverting 5269259fa95b "Bluetooth: L2CAP: Add get_peer_pid callback"
or implementing what was truly expected.

Fixes: 03d643b24db0 ("af_unix: Allow SO_PEERCRED to work across namespaces.")
Signed-off-by: Eric Dumazet <edumazet@google.com>
Reported-by: Jann Horn <jannh@google.com>
Cc: Eric W. Biederman <ebiederm@xmission.com>
Cc: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
Cc: Marcel Holtmann <marcel@holtmann.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/net/sock.h
net/core/sock.c
net/unix/af_unix.c