]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commit - net/compat.c
sock: Make sock->sk_stamp thread-safe
authorDeepa Dinamani <deepa.kernel@gmail.com>
Fri, 28 Dec 2018 02:55:09 +0000 (18:55 -0800)
committerKleber Sacilotto de Souza <kleber.souza@canonical.com>
Wed, 14 Aug 2019 09:18:49 +0000 (11:18 +0200)
commit2bdc9211bcd9c7172d408e425cdf7b526cd629fb
tree892988de6307441fb2aef7dd0ccfd5da48b84f2d
parent7ab8fdad6abad7548fa2ce1331e0ee51a0d5ebca
sock: Make sock->sk_stamp thread-safe

BugLink: https://bugs.launchpad.net/bugs/1837257
[ Upstream commit 3a0ed3e9619738067214871e9cb826fa23b2ddb9 ]

Al Viro mentioned (Message-ID
<20170626041334.GZ10672@ZenIV.linux.org.uk>)
that there is probably a race condition
lurking in accesses of sk_stamp on 32-bit machines.

sock->sk_stamp is of type ktime_t which is always an s64.
On a 32 bit architecture, we might run into situations of
unsafe access as the access to the field becomes non atomic.

Use seqlocks for synchronization.
This allows us to avoid using spinlocks for readers as
readers do not need mutual exclusion.

Another approach to solve this is to require sk_lock for all
modifications of the timestamps. The current approach allows
for timestamps to have their own lock: sk_stamp_lock.
This allows for the patch to not compete with already
existing critical sections, and side effects are limited
to the paths in the patch.

The addition of the new field maintains the data locality
optimizations from
commit 9115e8cd2a0c ("net: reorganize struct sock for better data
locality")

Note that all the instances of the sk_stamp accesses
are either through the ioctl or the syscall recvmsg.

Signed-off-by: Deepa Dinamani <deepa.kernel@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Andrea Righi <andrea.righi@canonical.com>
Signed-off-by: Khalid Elmously <khalid.elmously@canonical.com>
include/net/sock.h
net/compat.c
net/core/sock.c
net/sunrpc/svcsock.c