af_unix: Guard against other == sk in unix_dgram_sendmsg
authorRainer Weikusat <rweikusat@mobileactivedefense.com>
Thu, 11 Feb 2016 19:37:27 +0000 (19:37 +0000)
committerWinnie Hsu <whsu@nvidia.com>
Thu, 19 Apr 2018 17:00:17 +0000 (10:00 -0700)
commit0326da267324009a4315517832d81f134264a9ca
tree4c4211458644df288a97258eb86db29e615bb8b7
parent0a3d1f1c16c59e79146478d937eca72e1bc49e32
af_unix: Guard against other == sk in unix_dgram_sendmsg

The unix_dgram_sendmsg routine use the following test

if (unlikely(unix_peer(other) != sk && unix_recvq_full(other))) {

to determine if sk and other are in an n:1 association (either
established via connect or by using sendto to send messages to an
unrelated socket identified by address). This isn't correct as the
specified address could have been bound to the sending socket itself or
because this socket could have been connected to itself by the time of
the unix_peer_get but disconnected before the unix_state_lock(other). In
both cases, the if-block would be entered despite other == sk which
might either block the sender unintentionally or lead to trying to unlock
the same spin lock twice for a non-blocking send. Add a other != sk
check to guard against this.

Bug 1823317

Change-Id: I5b8f74348f82b4a84a3e01a93c58c49829b26efa
Fixes: 7d267278a9ec ("unix: avoid use-after-free in ep_remove_wait_queue")
Reported-By: Philipp Hahn <pmhahn@pmhahn.de>
Signed-off-by: Rainer Weikusat <rweikusat@mobileactivedefense.com>
Tested-by: Philipp Hahn <pmhahn@pmhahn.de>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Gagan Grover <ggrover@nvidia.com>
Reviewed-on: http://git-master/r/1259949
(cherry picked from commit 68a171695a57acd9b63c18ef2700e74ce0713993)
Reviewed-on: https://git-master.nvidia.com/r/1689516
GVS: Gerrit_Virtual_Submit
Reviewed-by: Bibek Basu <bbasu@nvidia.com>
Tested-by: Amulya Yarlagadda <ayarlagadda@nvidia.com>
Reviewed-by: Winnie Hsu <whsu@nvidia.com>
net/unix/af_unix.c