Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1268221
| From | Rainer Weikusat <rweikusat@mobileactivedefense.com> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | Re: [PATCH] unix: avoid use-after-free in ep_remove_wait_queue |
| Date | 2015-11-12 20:20 +0100 |
| Message-ID | <qu5zz-4wv-13@gated-at.bofh.it> (permalink) |
| References | (5 earlier) <qrQEG-5PE-15@gated-at.bofh.it> <qrQY1-6bv-3@gated-at.bofh.it> <qsVVE-7IC-11@gated-at.bofh.it> <qtp7j-2b1-1@gated-at.bofh.it> <qtHxg-5NS-19@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
Jason Baron <jbaron@akamai.com> writes:
>> +
>> +/* Needs sk unix state lock. After recv_ready indicated not ready,
>> + * establish peer_wait connection if still needed.
>> + */
>> +static int unix_dgram_peer_wake_me(struct sock *sk, struct sock *other)
>> +{
>> + int connected;
>> +
>> + connected = unix_dgram_peer_wake_connect(sk, other);
>> +
>> + if (unix_recvq_full(other))
>> + return 1;
>> +
>> + if (connected)
>> + unix_dgram_peer_wake_disconnect(sk, other);
>> +
>> + return 0;
>> +}
>> +
>
> So the comment above this function says 'needs unix state lock', however
> the usage in unix_dgram_sendmsg() has the 'other' lock, while the usage
> in unix_dgram_poll() has the 'sk' lock. So this looks racy.
That's one thing which is broken with this patch. Judging from a 'quick'
look at the _dgram_sendmsg code, the unix_state_lock(other) will need to
be turned into a unix_state_double_lock(sk, other) and the remaining
code changed accordingly (since all of the checks must be done without
unlocking other).
There's also something else seriously wrong with the present patch: Some
code in unix_dgram_connect presently (with this change) looks like this:
/*
* If it was connected, reconnect.
*/
if (unix_peer(sk)) {
struct sock *old_peer = unix_peer(sk);
unix_peer(sk) = other;
if (unix_dgram_peer_wake_disconnect(sk, other))
wake_up_interruptible_poll(sk_sleep(sk),
POLLOUT |
POLLWRNORM |
POLLWRBAND);
unix_state_double_unlock(sk, other);
if (other != old_peer)
unix_dgram_disconnected(sk, old_peer);
sock_put(old_peer);
and trying to disconnect from a peer the socket is just being
connected to is - of course - "flowering tomfoolery" (literal
translation of the German "bluehender Bloedsinn") --- it needs to
disconnect from old_peer instead.
I'll address the suggestion and send an updated patch "later today" (may
become "early tomorrow"). I have some code addressing both issues but
that's part of a release of 'our' kernel fork, ie, 3.2.54-based I'll
need to do 'soon'.
--
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 | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Re: Use-after-free in ep_remove_wait_queue Dmitry Vyukov <dvyukov@google.com> - 2015-11-06 14:10 +0100
Re: Use-after-free in ep_remove_wait_queue Jason Baron <jbaron@akamai.com> - 2015-11-06 16:00 +0100
Re: Use-after-free in ep_remove_wait_queue Rainer Weikusat <rweikusat@mobileactivedefense.com> - 2015-11-06 16:20 +0100
[PATCH] unix: avoid use-after-free in ep_remove_wait_queue Rainer Weikusat <rweikusat@mobileactivedefense.com> - 2015-11-09 15:50 +0100
Re: [PATCH] unix: avoid use-after-free in ep_remove_wait_queue David Miller <davem@davemloft.net> - 2015-11-09 19:30 +0100
Re: [PATCH] unix: avoid use-after-free in ep_remove_wait_queue Rainer Weikusat <rweikusat@mobileactivedefense.com> - 2015-11-10 18:20 +0100
Re: [PATCH] unix: avoid use-after-free in ep_remove_wait_queue Jason Baron <jbaron@akamai.com> - 2015-11-09 23:50 +0100
Re: [PATCH] unix: avoid use-after-free in ep_remove_wait_queue Rainer Weikusat <rweikusat@mobileactivedefense.com> - 2015-11-10 18:40 +0100
Re: [PATCH] unix: avoid use-after-free in ep_remove_wait_queue Rainer Weikusat <rweikusat@mobileactivedefense.com> - 2015-11-10 23:00 +0100
Re: [PATCH] unix: avoid use-after-free in ep_remove_wait_queue Hannes Frederic Sowa <hannes@stressinduktion.org> - 2015-11-11 13:30 +0100
Re: [PATCH] unix: avoid use-after-free in ep_remove_wait_queue Rainer Weikusat <rweikusat@mobileactivedefense.com> - 2015-11-11 17:20 +0100
Re: [PATCH] unix: avoid use-after-free in ep_remove_wait_queue Hannes Frederic Sowa <hannes@stressinduktion.org> - 2015-11-11 20:00 +0100
Re: [PATCH] unix: avoid use-after-free in ep_remove_wait_queue Rainer Weikusat <rweikusat@mobileactivedefense.com> - 2015-11-13 20:10 +0100
Re: [PATCH] unix: avoid use-after-free in ep_remove_wait_queue Jason Baron <jbaron@akamai.com> - 2015-11-11 18:40 +0100
Re: [PATCH] unix: avoid use-after-free in ep_remove_wait_queue Rainer Weikusat <rweikusat@mobileactivedefense.com> - 2015-11-12 20:20 +0100
Re: [PATCH] unix: avoid use-after-free in ep_remove_wait_queue Rainer Weikusat <rweikusat@mobileactivedefense.com> - 2015-11-13 20:00 +0100
Re: [PATCH] unix: avoid use-after-free in ep_remove_wait_queue Jason Baron <jbaron@akamai.com> - 2015-11-13 23:20 +0100
Re: [PATCH] unix: avoid use-after-free in ep_remove_wait_queue Rainer Weikusat <rweikusat@mobileactivedefense.com> - 2015-11-15 19:40 +0100
csiph-web