From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.5 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_PASS,USER_AGENT_MUTT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 916CFC10F01 for ; Mon, 18 Feb 2019 21:32:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 608652084D for ; Mon, 18 Feb 2019 21:32:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730652AbfBRVcu (ORCPT ); Mon, 18 Feb 2019 16:32:50 -0500 Received: from zeniv.linux.org.uk ([195.92.253.2]:53566 "EHLO ZenIV.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726955AbfBRVcu (ORCPT ); Mon, 18 Feb 2019 16:32:50 -0500 Received: from viro by ZenIV.linux.org.uk with local (Exim 4.91 #2 (Red Hat Linux)) id 1gvqWt-0001wJ-09; Mon, 18 Feb 2019 21:32:47 +0000 Date: Mon, 18 Feb 2019 21:32:46 +0000 From: Al Viro To: Sasha Levin Cc: netdev@vger.kernel.org, David Miller , stable@kernel.org, stable@vger.kernel.org Subject: Re: [PATCH][unix] missing barriers in some of unix_sock ->addr and ->path accesses Message-ID: <20190218213246.GV2217@ZenIV.linux.org.uk> References: <20190215200934.GM2217@ZenIV.linux.org.uk> <20190218211434.05DF121773@mail.kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190218211434.05DF121773@mail.kernel.org> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org On Mon, Feb 18, 2019 at 09:14:33PM +0000, Sasha Levin wrote: > Hi, > > [This is an automated email] > > This commit has been processed because it contains a -stable tag. Ugh... Should've removed Cc; stable from netdev posting; my apologies. > How should we proceed with this patch? Wait for it to get into davem's tree, for starters? Sorry about that, again... FWIW, further adventures in net/unix land: unix_dgram_poll() contains /* connection hasn't started yet? */ if (sk->sk_state == TCP_SYN_SENT) return mask; and nothing in there sets TCP_SYN_SENT state (not that it would've made any sense of AF_UNIX). unix_poll() contains /* Connection-based need to check for termination and startup */ if ((sk->sk_type == SOCK_STREAM || sk->sk_type == SOCK_SEQPACKET) && sk->sk_state == TCP_CLOSE) while it can only be called as ->poll of unix_stream_ops, which means that sk->sk_type can't be anything other that SOCK_STREAM in there. static void scan_children(struct sock *x, void (*func)(struct unix_sock *), struct sk_buff_head *hitlist) { if (x->sk_state != TCP_LISTEN) { scan_inflight(x, func, hitlist); } else { ... has no exclusion or barriers to deal with the store of TCP_LISTEN into ->sk_state inside unix_listen(). That one's potentially nasty - we won't find SCM_RIGHTS already queued to embrios in x's queue until we notice that x->sk_state == TCP_LISTEN, which can happen between two calls of scan_children() in the same unix_gc() run. The race is narrow, but not impossible, AFAICS. Reasonably easy to fix - lift locking the queue out of scan_inflight(), grab the queue lock before checking if it's a listener and have unix_listen() either grab the queue lock around the assignment to ->sk_state, or pump it up and down before dropping unix_state_lock() (at which point connect() might be able to find it, etc.) Al, still digging through net/unix...