Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755250AbbKXVk4 (ORCPT ); Tue, 24 Nov 2015 16:40:56 -0500 Received: from zeniv.linux.org.uk ([195.92.253.2]:56570 "EHLO ZenIV.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755100AbbKXVkv (ORCPT ); Tue, 24 Nov 2015 16:40:51 -0500 Date: Tue, 24 Nov 2015 21:40:36 +0000 From: Al Viro To: Jason Baron Cc: Eric Dumazet , Dmitry Vyukov , Benjamin LaHaise , "David S. Miller" , Hannes Frederic Sowa , David Howells , Ying Xue , "Eric W. Biederman" , Rainer Weikusat , netdev , LKML , syzkaller , Kostya Serebryany , Alexander Potapenko , Sasha Levin Subject: Re: use-after-free in sock_wake_async Message-ID: <20151124214036.GP22011@ZenIV.linux.org.uk> References: <5654D6D9.1050108@akamai.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <5654D6D9.1050108@akamai.com> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1268 Lines: 41 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... -- 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/