linux-stable/net/unix
Eric Dumazet 0512a9aede af_unix: fix races in sk_peer_pid and sk_peer_cred accesses
[ Upstream commit 35306eb238 ]

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 b48596d1dc "Bluetooth: L2CAP: Add get_peer_pid callback"
or implementing what was truly expected.

Fixes: 109f6e39fa ("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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2021-10-06 15:31:24 +02:00
..
af_unix.c af_unix: fix races in sk_peer_pid and sk_peer_cred accesses 2021-10-06 15:31:24 +02:00
diag.c missing barriers in some of unix_sock ->addr and ->path accesses 2019-03-19 13:12:41 +01:00
garbage.c net: split out functions related to registering inflight socket files 2021-07-31 08:22:37 +02:00
Kconfig net: split out functions related to registering inflight socket files 2021-07-31 08:22:37 +02:00
Makefile net: split out functions related to registering inflight socket files 2021-07-31 08:22:37 +02:00
scm.c net: split out functions related to registering inflight socket files 2021-07-31 08:22:37 +02:00
scm.h net: split out functions related to registering inflight socket files 2021-07-31 08:22:37 +02:00
sysctl_net_unix.c