Re: [PATCH] unix: avoid use-after-free in ep_remove_wait_queue
From: Jason Baron <jbaron@akamai.com>
Date: 2015-11-17 16:08:24
Also in:
linux-fsdevel, lkml
On 11/15/2015 01:32 PM, Rainer Weikusat wrote:
That was my original idea. The problem with this is that the code starting after the _lock and running until the main code path unlock has to be executed in one go with the other lock held as the results of the tests above this one may become invalid as soon as the other lock is released. This means instead of continuing execution with the send code proper after the block in case other became receive-ready between the first and the second test (possible because _dgram_recvmsg does not take the unix state lock), the whole procedure starting with acquiring the other lock would need to be restarted. Given sufficiently unfavorable circumstances, this could even turn into an endless loop which couldn't be interrupted. (unless code for this was added).
hmmm - I think we can avoid it by doing the wakeup from the write path
in the rare case that the queue has emptied - and avoid the double lock. IE:
unix_state_unlock(other);
unix_state_lock(sk);
err = -EAGAIN;
if (unix_peer(sk) == other) {
unix_dgram_peer_wake_connect(sk, other);
if (skb_queue_len(&other->sk_receive_queue) == 0)
need_wakeup = true;
}
unix_state_unlock(sk);
if (need_wakeup)
wake_up_interruptible_poll(sk_sleep(sk), POLLOUT
| POLLWRNORM | POLLWRBAND);
goto out_free;
Thanks,
-Jason