netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Al Viro <viro@ZenIV.linux.org.uk>
To: Jason Baron <jbaron@akamai.com>
Cc: Eric Dumazet <edumazet@google.com>,
	Dmitry Vyukov <dvyukov@google.com>,
	Benjamin LaHaise <bcrl@kvack.org>,
	"David S. Miller" <davem@davemloft.net>,
	Hannes Frederic Sowa <hannes@stressinduktion.org>,
	David Howells <dhowells@redhat.com>,
	Ying Xue <ying.xue@windriver.com>,
	"Eric W. Biederman" <ebiederm@xmission.com>,
	Rainer Weikusat <rweikusat@mobileactivedefense.com>,
	netdev <netdev@vger.kernel.org>,
	LKML <linux-kernel@vger.kernel.org>,
	syzkaller <syzkaller@googlegroups.com>,
	Kostya Serebryany <kcc@google.com>,
	Alexander Potapenko <glider@google.com>,
	Sasha Levin <sasha.levin@oracle.com>
Subject: Re: use-after-free in sock_wake_async
Date: Tue, 24 Nov 2015 21:40:36 +0000	[thread overview]
Message-ID: <20151124214036.GP22011@ZenIV.linux.org.uk> (raw)
In-Reply-To: <5654D6D9.1050108@akamai.com>

On Tue, Nov 24, 2015 at 04:30:01PM -0500, Jason Baron wrote:

> So looking at this trace I think its the other->sk_socket that gets
> freed and then we call sk_wake_async() on it.
> 
> We could I think grab the socket reference there with unix_state_lock(),
> since that is held by unix_release_sock() before the final iput() is called.
> 
> So something like below might work (compile tested only):

Ewww...

> +struct socket *unix_peer_get_socket(struct sock *s)
> +{
> +	struct socket *peer;
> +
> +	unix_state_lock(s);
> +	peer = s->sk_socket;
> +	if (peer)
> +		__iget(SOCK_INODE(s->sk_socket));
> +	unix_state_unlock(s);
> +
> +	return peer;

>  out_err:
> +	if (other_socket)
> +		iput(SOCK_INODE(other_socket));
>  	scm_destroy(&scm);
>  	return sent ? : err;
>  }

Interplay between socket, file and inode lifetimes is already too convoluted,
and this just makes it nastier.  I don't have a ready solution at the moment,
but this one is too ugly to live.

Al, digging through RTFS(net/unix/af_unix.c) right now...

  reply	other threads:[~2015-11-24 21:40 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-24 14:18 use-after-free in sock_wake_async Dmitry Vyukov
2015-11-24 15:21 ` Eric Dumazet
2015-11-24 15:39   ` Eric Dumazet
2015-11-24 21:30   ` Jason Baron
2015-11-24 21:40     ` Al Viro [this message]
2015-11-24 21:45     ` Benjamin LaHaise
2015-11-24 22:03       ` Eric Dumazet
2015-11-24 22:12         ` Eric Dumazet
2015-11-24 23:34   ` Rainer Weikusat
2015-11-24 23:43     ` Eric Dumazet
2015-11-25  1:10       ` Rainer Weikusat
2015-11-25  1:16         ` Rainer Weikusat
2015-11-25  1:18         ` Eric Dumazet
2015-11-25  2:28           ` Eric Dumazet
2015-11-25  5:43             ` Eric Dumazet
2015-11-25 14:18               ` Eric Dumazet
2015-11-25 16:43           ` Rainer Weikusat
2015-11-25 17:11             ` Eric Dumazet
2015-11-25 17:30               ` Rainer Weikusat
2015-11-25 17:51                 ` Eric Dumazet
2015-11-25 18:24                   ` Rainer Weikusat
2015-11-25 18:39                     ` Eric Dumazet
2015-11-25 19:38                       ` Rainer Weikusat
2015-11-25 19:50                         ` Eric Dumazet
2015-11-25 20:23                           ` Eric Dumazet
2015-11-25 20:57                             ` Rainer Weikusat
2015-11-25 22:09                               ` Eric Dumazet
2015-11-25 22:32                                 ` Hannes Frederic Sowa
2015-11-25 22:43                                   ` Eric Dumazet
2015-11-25 22:52                                     ` Hannes Frederic Sowa
2015-11-26 13:32                                       ` Hannes Frederic Sowa
2015-11-26 14:31                                         ` Hannes Frederic Sowa
2015-11-26 15:51                                         ` Eric Dumazet
2015-11-26 17:03                                           ` Hannes Frederic Sowa
2015-11-26 17:09                                             ` Eric Dumazet
2015-11-26 17:15                                               ` Hannes Frederic Sowa
2015-11-26 17:29                                             ` Eric Dumazet

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20151124214036.GP22011@ZenIV.linux.org.uk \
    --to=viro@zeniv.linux.org.uk \
    --cc=bcrl@kvack.org \
    --cc=davem@davemloft.net \
    --cc=dhowells@redhat.com \
    --cc=dvyukov@google.com \
    --cc=ebiederm@xmission.com \
    --cc=edumazet@google.com \
    --cc=glider@google.com \
    --cc=hannes@stressinduktion.org \
    --cc=jbaron@akamai.com \
    --cc=kcc@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=rweikusat@mobileactivedefense.com \
    --cc=sasha.levin@oracle.com \
    --cc=syzkaller@googlegroups.com \
    --cc=ying.xue@windriver.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).