Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756245AbdCGWHU (ORCPT ); Tue, 7 Mar 2017 17:07:20 -0500 Received: from mail-wm0-f54.google.com ([74.125.82.54]:35522 "EHLO mail-wm0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751093AbdCGWHT (ORCPT ); Tue, 7 Mar 2017 17:07:19 -0500 MIME-Version: 1.0 In-Reply-To: References: From: Cong Wang Date: Tue, 7 Mar 2017 14:04:38 -0800 Message-ID: Subject: Re: net: BUG in unix_notinflight To: Dmitry Vyukov Cc: David Miller , Hannes Frederic Sowa , Willy Tarreau , netdev , LKML , Eric Dumazet , Al Viro , syzkaller Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1235 Lines: 32 On Tue, Mar 7, 2017 at 12:37 AM, Dmitry Vyukov wrote: > On Mon, Mar 6, 2017 at 11:34 PM, Cong Wang wrote: >> The problem here is there is no lock protecting concurrent unix_detach_fds() >> even though unix_notinflight() is already serialized, if we call >> unix_notinflight() >> twice on the same file pointer, we trigger this bug... >> >> I don't know what is the right lock here to serialize it. > > > What exactly here needs to be protected? > > 1484 static void unix_detach_fds(struct scm_cookie *scm, struct sk_buff *skb) > 1485 { > 1486 int i; > 1487 > 1488 scm->fp = UNIXCB(skb).fp; > 1489 UNIXCB(skb).fp = NULL; > 1490 > 1491 for (i = scm->fp->count-1; i >= 0; i--) > 1492 unix_notinflight(scm->fp->user, scm->fp->fp[i]); > 1493 } > > Whole unix_notinflight happens under global unix_gc_lock. > > Is it that 2 threads call unix_detach_fds for the same skb, and then > call unix_notinflight for the same fd twice? Not the same skb, but their UNIXCB(skb).fp points to the same place, therefore we call unix_notinflight() twice on the same fp->user and fp->fp[i], although we have refcounting but still able to trigger this warning.