Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1271370

Re: [PATCH] unix: avoid use-after-free in ep_remove_wait_queue (w/ Fixes:)

From Jason Baron <jbaron@akamai.com>
Newsgroups linux.kernel
Subject Re: [PATCH] unix: avoid use-after-free in ep_remove_wait_queue (w/ Fixes:)
Date 2015-11-17 17:20 +0100
Message-ID <qvR97-7kN-5@gated-at.bofh.it> (permalink)
References (7 earlier) <qsVVE-7IC-11@gated-at.bofh.it> <qtp7j-2b1-1@gated-at.bofh.it> <qurJM-1FS-9@gated-at.bofh.it> <qvAhX-4Jx-7@gated-at.bofh.it> <qvArE-4ME-13@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw



On 11/16/2015 05:28 PM, Rainer Weikusat wrote:
> An AF_UNIX datagram socket being the client in an n:1 association with
> some server socket is only allowed to send messages to the server if the
> receive queue of this socket contains at most sk_max_ack_backlog
> datagrams. This implies that prospective writers might be forced to go
> to sleep despite none of the message presently enqueued on the server
> receive queue were sent by them. In order to ensure that these will be
> woken up once space becomes again available, the present unix_dgram_poll
> routine does a second sock_poll_wait call with the peer_wait wait queue
> of the server socket as queue argument (unix_dgram_recvmsg does a wake
> up on this queue after a datagram was received). This is inherently
> problematic because the server socket is only guaranteed to remain alive
> for as long as the client still holds a reference to it. In case the
> connection is dissolved via connect or by the dead peer detection logic
> in unix_dgram_sendmsg, the server socket may be freed despite "the
> polling mechanism" (in particular, epoll) still has a pointer to the
> corresponding peer_wait queue. There's no way to forcibly deregister a
> wait queue with epoll.
> 
> Based on an idea by Jason Baron, the patch below changes the code such
> that a wait_queue_t belonging to the client socket is enqueued on the
> peer_wait queue of the server whenever the peer receive queue full
> condition is detected by either a sendmsg or a poll. A wake up on the
> peer queue is then relayed to the ordinary wait queue of the client
> socket via wake function. The connection to the peer wait queue is again
> dissolved if either a wake up is about to be relayed or the client
> socket reconnects or a dead peer is detected or the client socket is
> itself closed. This enables removing the second sock_poll_wait from
> unix_dgram_poll, thus avoiding the use-after-free, while still ensuring
> that no blocked writer sleeps forever.
> 
> Signed-off-by: Rainer Weikusat <rweikusat@mobileactivedefense.com>
> Fixes: ec0d215f9420 ("af_unix: fix 'poll for write'/connected DGRAM sockets")
> ---
> 
> Additional remark about "5456f09aaf88/ af_unix: fix unix_dgram_poll()
> behavior for EPOLLOUT event": This shouldn't be an issue anymore with
> this change despite it restores the "only when writable" behaviour" as
> the wake up relay will also be set up once _dgram_sendmsg returned
> EAGAIN for a send attempt on a n:1 connected socket.
> 
> 

Hi,

My only comment was about potentially avoiding the double lock in the
write path, otherwise this looks ok to me.

Thanks,

-Jason
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Re: [PATCH] unix: avoid use-after-free in ep_remove_wait_queue Rainer Weikusat <rweikusat@mobileactivedefense.com> - 2015-11-16 23:20 +0100
  Re: [PATCH] unix: avoid use-after-free in ep_remove_wait_queue (w/ Fixes:) Rainer Weikusat <rweikusat@mobileactivedefense.com> - 2015-11-16 23:30 +0100
    Re: [PATCH] unix: avoid use-after-free in ep_remove_wait_queue (w/  Fixes:) Jason Baron <jbaron@akamai.com> - 2015-11-17 17:20 +0100
    Re: [PATCH] unix: avoid use-after-free in ep_remove_wait_queue (w/  Fixes:) David Miller <davem@davemloft.net> - 2015-11-17 21:20 +0100
      Re: [PATCH] unix: avoid use-after-free in ep_remove_wait_queue (w/ Fixes:) Rainer Weikusat <rweikusat@mobileactivedefense.com> - 2015-11-17 22:40 +0100
        Re: [PATCH] unix: avoid use-after-free in ep_remove_wait_queue (w/ Fixes:) Rainer Weikusat <rweikusat@mobileactivedefense.com> - 2015-11-17 23:20 +0100
          Re: [PATCH] unix: avoid use-after-free in ep_remove_wait_queue (w/ Fixes:) Rainer Weikusat <rweikusat@mobileactivedefense.com> - 2015-11-20 00:50 +0100
        Re: [PATCH] unix: avoid use-after-free in ep_remove_wait_queue (w/ Fixes:) Rainer Weikusat <rweikusat@mobileactivedefense.com> - 2015-11-17 23:50 +0100
      Re: [PATCH] unix: avoid use-after-free in ep_remove_wait_queue (w/ Fixes:) Rainer Weikusat <rweikusat@mobileactivedefense.com> - 2015-11-18 19:20 +0100
        more statistics (was: [PATCH] unix: avoid use-after-free in ep_remove_wait_queue (w/ Fixes:)) Rainer Weikusat <rweikusat@mobileactivedefense.com> - 2015-11-19 00:50 +0100
    Re: [PATCH] unix: avoid use-after-free in ep_remove_wait_queue (w/ Fixes:) Rainer Weikusat <rweikusat@mobileactivedefense.com> - 2015-11-20 01:00 +0100
      Re: [PATCH] unix: avoid use-after-free in ep_remove_wait_queue (w/  Fixes:) Jason Baron <jbaron@akamai.com> - 2015-11-20 17:10 +0100
        Re: [PATCH] unix: avoid use-after-free in ep_remove_wait_queue (w/ Fixes:) Rainer Weikusat <rweikusat@mobileactivedefense.com> - 2015-11-20 17:30 +0100
      Re: [PATCH] unix: avoid use-after-free in ep_remove_wait_queue Rainer Weikusat <rweikusat@mobileactivedefense.com> - 2015-11-20 23:10 +0100
        Re: [PATCH] unix: avoid use-after-free in ep_remove_wait_queue Jason Baron <jbaron@akamai.com> - 2015-11-23 17:30 +0100
        Re: [PATCH] unix: avoid use-after-free in ep_remove_wait_queue David Miller <davem@davemloft.net> - 2015-11-23 18:40 +0100
          Re: [PATCH] unix: avoid use-after-free in ep_remove_wait_queue Rainer Weikusat <rweikusat@mobileactivedefense.com> - 2015-11-23 22:40 +0100
            Re: [PATCH] unix: avoid use-after-free in ep_remove_wait_queue Rainer Weikusat <rweikusat@mobileactivedefense.com> - 2015-11-24 00:10 +0100

csiph-web