Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1765624AbXFEULq (ORCPT ); Tue, 5 Jun 2007 16:11:46 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1761044AbXFEULh (ORCPT ); Tue, 5 Jun 2007 16:11:37 -0400 Received: from 74-93-104-97-Washington.hfc.comcastbusiness.net ([74.93.104.97]:56544 "EHLO sunset.davemloft.net" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1758446AbXFEULh (ORCPT ); Tue, 5 Jun 2007 16:11:37 -0400 Date: Tue, 05 Jun 2007 13:11:51 -0700 (PDT) Message-Id: <20070605.131151.82049948.davem@davemloft.net> To: miklos@szeredi.hu Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] fix race in AF_UNIX From: David Miller In-Reply-To: References: <20070605.000247.18308209.davem@davemloft.net> X-Mailer: Mew version 5.1.52 on Emacs 21.4 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1479 Lines: 35 From: Miklos Szeredi Date: Tue, 05 Jun 2007 09:42:41 +0200 > From: Miklos Szeredi > > A recv() on an AF_UNIX, SOCK_STREAM socket can race with a > send()+close() on the peer, causing recv() to return zero, even though > the sent data should be received. > > This happens if the send() and the close() is performed between > skb_dequeue() and checking sk->sk_shutdown in unix_stream_recvmsg(): > > process A skb_dequeue() returns NULL, there's no data in the socket queue > process B new data is inserted onto the queue by unix_stream_sendmsg() > process B sk->sk_shutdown is set to SHUTDOWN_MASK by unix_release_sock() > process A sk->sk_shutdown is checked, unix_release_sock() returns zero > > I'm surprised nobody noticed this, it's not hard to trigger. Maybe > it's just (un)luck with the timing. > > It's possible to work around this bug in userspace, by retrying the > recv() once in case of a zero return value. > > Signed-off-by: Miklos Szeredi Looks good, applied. Another way to fix this would have been to take the u->readlock in unix_release() and unix_shutdown(), but that would have hurt unix_dgram_recvmsg() which doesn't need to handle this race. - 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/