]> git.baikalelectronics.ru Git - kernel.git/commit
net: do not allow changing SO_REUSEADDR/SO_REUSEPORT on bound sockets
authorMaciej Żenczykowski <maze@google.com>
Sun, 3 Jun 2018 17:47:05 +0000 (10:47 -0700)
committerDavid S. Miller <davem@davemloft.net>
Mon, 4 Jun 2018 21:14:22 +0000 (17:14 -0400)
commit059cad2e18936d52880a7b627927ec43ea0623e5
tree0de99698fcb5b64fde318ceea9a1fab5e81bff02
parente7ceba69a3c8f9f011851cc73b8d1167a3e3ed9e
net: do not allow changing SO_REUSEADDR/SO_REUSEPORT on bound sockets

It is not safe to do so because such sockets are already in the
hash tables and changing these options can result in invalidating
the tb->fastreuse(port) caching.

This can have later far reaching consequences wrt. bind conflict checks
which rely on these caches (for optimization purposes).

Not to mention that you can currently end up with two identical
non-reuseport listening sockets bound to the same local ip:port
by clearing reuseport on them after they've already both been bound.

There is unfortunately no EISBOUND error or anything similar,
and EISCONN seems to be misleading for a bound-but-not-connected
socket, so use EUCLEAN 'Structure needs cleaning' which AFAICT
is the closest you can get to meaning 'socket in bad state'.
(although perhaps EINVAL wouldn't be a bad choice either?)

This does unfortunately run the risk of breaking buggy
userspace programs...

Signed-off-by: Maciej Żenczykowski <maze@google.com>
Cc: Eric Dumazet <edumazet@google.com>
Change-Id: I77c2b3429b2fdf42671eee0fa7a8ba721c94963b
Reviewed-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/core/sock.c