From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758336AbdCUWg6 (ORCPT ); Tue, 21 Mar 2017 18:36:58 -0400 Received: from shards.monkeyblade.net ([184.105.139.130]:57840 "EHLO shards.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757046AbdCUWgy (ORCPT ); Tue, 21 Mar 2017 18:36:54 -0400 Date: Tue, 21 Mar 2017 15:27:40 -0700 (PDT) Message-Id: <20170321.152740.423576909432306907.davem@davemloft.net> To: andreyu@google.com Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] net: unix: properly re-increment inflight counter of GC discarded candidates From: David Miller In-Reply-To: <20170315031642.19576-1-andreyu@google.com> References: <20170315031642.19576-1-andreyu@google.com> X-Mailer: Mew version 6.7 on Emacs 24.5 / Mule 6.0 (HANACHIRUSATO) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.5.12 (shards.monkeyblade.net [149.20.54.216]); Tue, 21 Mar 2017 15:27:43 -0700 (PDT) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Andrey Ulanov Date: Tue, 14 Mar 2017 20:16:42 -0700 > Dmitry has reported that a BUG_ON() condition in unix_notinflight() > may be triggered by a simple code that forwards unix socket in an > SCM_RIGHTS message. > That is caused by incorrect unix socket GC implementation in unix_gc(). > > The GC first collects list of candidates, then (a) decrements their > "children's" inflight counter, (b) checks which inflight counters are > now 0, and then (c) increments all inflight counters back. > (a) and (c) are done by calling scan_children() with inc_inflight or > dec_inflight as the second argument. > > Commit 6209344f5a37 ("net: unix: fix inflight counting bug in garbage > collector") changed scan_children() such that it no longer considers > sockets that do not have UNIX_GC_CANDIDATE flag. It also added a block > of code that that unsets this flag _before_ invoking > scan_children(, dec_iflight, ). This may lead to incorrect inflight > counters for some sockets. > > This change fixes this bug by changing order of operations: > UNIX_GC_CANDIDATE is now unset only after all inflight counters are > restored to the original state. > > kernel BUG at net/unix/garbage.c:149! > RIP: 0010:[] [] > unix_notinflight+0x3b4/0x490 net/unix/garbage.c:149 > Call Trace: > [] unix_detach_fds.isra.19+0xff/0x170 net/unix/af_unix.c:1487 > [] unix_destruct_scm+0xf9/0x210 net/unix/af_unix.c:1496 > [] skb_release_head_state+0x101/0x200 net/core/skbuff.c:655 > [] skb_release_all+0x1a/0x60 net/core/skbuff.c:668 > [] __kfree_skb+0x1a/0x30 net/core/skbuff.c:684 > [] kfree_skb+0x184/0x570 net/core/skbuff.c:705 > [] unix_release_sock+0x5b5/0xbd0 net/unix/af_unix.c:559 > [] unix_release+0x49/0x90 net/unix/af_unix.c:836 > [] sock_release+0x92/0x1f0 net/socket.c:570 > [] sock_close+0x1b/0x20 net/socket.c:1017 > [] __fput+0x34e/0x910 fs/file_table.c:208 > [] ____fput+0x1a/0x20 fs/file_table.c:244 > [] task_work_run+0x1a0/0x280 kernel/task_work.c:116 > [< inline >] exit_task_work include/linux/task_work.h:21 > [] do_exit+0x183a/0x2640 kernel/exit.c:828 > [] do_group_exit+0x14e/0x420 kernel/exit.c:931 > [] get_signal+0x663/0x1880 kernel/signal.c:2307 > [] do_signal+0xc5/0x2190 arch/x86/kernel/signal.c:807 > [] exit_to_usermode_loop+0x1ea/0x2d0 > arch/x86/entry/common.c:156 > [< inline >] prepare_exit_to_usermode arch/x86/entry/common.c:190 > [] syscall_return_slowpath+0x4d3/0x570 > arch/x86/entry/common.c:259 > [] entry_SYSCALL_64_fastpath+0xc4/0xc6 > > Link: https://lkml.org/lkml/2017/3/6/252 > Signed-off-by: Andrey Ulanov > Reported-by: Dmitry Vyukov > Fixes: 6209344 ("net: unix: fix inflight counting bug in garbage collector") Applied and queued up for -stable, thanks.