Received: by 10.223.176.5 with SMTP id f5csp387726wra; Wed, 7 Feb 2018 00:44:17 -0800 (PST) X-Google-Smtp-Source: AH8x227m+artU9KHXRBGDewyqY8qFd1mWLaNm96/NM02s0iiJRcmlJgb7NeQY/+S2Vt2grSuWh9A X-Received: by 10.98.223.80 with SMTP id u77mr5315408pfg.186.1517993057444; Wed, 07 Feb 2018 00:44:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517993057; cv=none; d=google.com; s=arc-20160816; b=RLv7pkCskoxoNEV4A5vmaUJWU9/rbga8TeoRJYTQn0u+ujOzOJFTtNaDwdGgyJRQm9 PAQSzLrbaRlsPJ1RNjGx2H51ohAMaVmlSUHYNx3jf+wQVQ7oZ9Y2GtzO6yyTp3n2eiin elkNYiMtTvU56PlKe1aUlaPY4TUCqeprXWMJCC/u+9EqLIZpiay3YKv1o8MrwBpKh0fw hyKifb3BnRykJxjef7fZuUkqfmBy/DQz2YRni4om29T5J41ORBqx3JjDdiO+AkMnVqef UabXLmJzAJ2/UsXylUoQBMl9lvYfcIqb6bWk7ZUtS7/6GarLZE8Hmeg/96a3d+CsN4Qy G7Dw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:date:cc:to:from:subject:message-id :arc-authentication-results; bh=65VbcpOiiKryr2v8ub6oztR/P1HpxF41vzCO3nvckNM=; b=Qz+hfK3ABzABgjAALMXweaS1Ksi793jD8eju7TGA8yqB8n1mrPWWzGvHscnQSBtvw+ sPecqYXneN/a+4npqDJZ0RZ5jLngv65C6P4xjbrUp+vb1oRvsPPkpN0yjnAJyd273Bse 7m/F3fmJDVx+V2LvtNqR/USQWO7yvVMtrnJAY/ZiAQjFCLS8nAXonOkvcbJ0C+Ih3A0w /YlxFxYrcAB2Dgtrs/Y1G6vk4fRYVpZoJYSeNGK/GeIy9xnMw5fIyg+4WTCGK/wbadRW OHdKS0TXCsfsUWaC/9fBEXJM8pKf3sKRVcljCCPc+2QPzoGK5o3TK693+cWm862qoKsx CQ9g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v68si792836pfb.292.2018.02.07.00.44.03; Wed, 07 Feb 2018 00:44:17 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753535AbeBGInO (ORCPT + 99 others); Wed, 7 Feb 2018 03:43:14 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:37758 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753066AbeBGInM (ORCPT ); Wed, 7 Feb 2018 03:43:12 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D32F98182D1E; Wed, 7 Feb 2018 08:43:11 +0000 (UTC) Received: from localhost.localdomain (unknown [10.32.181.99]) by smtp.corp.redhat.com (Postfix) with ESMTP id 911192156A31; Wed, 7 Feb 2018 08:43:07 +0000 (UTC) Message-ID: <1517992986.2526.13.camel@redhat.com> Subject: Re: WARNING: proc registration bug in clusterip_tg_check From: Paolo Abeni To: Cong Wang , syzbot Cc: coreteam@netfilter.org, David Miller , Florian Westphal , Jozsef Kadlecsik , Alexey Kuznetsov , LKML , Linux Kernel Network Developers , netfilter-devel@vger.kernel.org, Pablo Neira Ayuso , syzkaller-bugs@googlegroups.com, Hideaki YOSHIFUJI Date: Wed, 07 Feb 2018 09:43:06 +0100 In-Reply-To: References: <089e082d13a0cf25ed05648bf8b3@google.com> Content-Type: text/plain; charset="UTF-8" Mime-Version: 1.0 Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Wed, 07 Feb 2018 08:43:12 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Wed, 07 Feb 2018 08:43:12 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'pabeni@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 2018-02-06 at 22:42 -0800, Cong Wang wrote: > On Tue, Feb 6, 2018 at 6:27 AM, syzbot > wrote: > > Hello, > > > > syzbot hit the following crash on net-next commit > > 617aebe6a97efa539cc4b8a52adccd89596e6be0 (Sun Feb 4 00:25:42 2018 +0000) > > Merge tag 'usercopy-v4.16-rc1' of > > git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux > > > > So far this crash happened 5 times on net-next, upstream. > > C reproducer is attached. > > syzkaller reproducer is attached. > > Raw console output is attached. > > compiler: gcc (GCC) 7.1.1 20170620 > > .config is attached. > > > > IMPORTANT: if you fix the bug, please add the following tag to the commit: > > Reported-by: syzbot+03218bcdba6aa76441a3@syzkaller.appspotmail.com > > It will help syzbot understand when the bug is fixed. See footer for > > details. > > If you forward the report, please keep this part and the footer. > > > > x_tables: ip_tables: osf match: only valid for protocol 6 > > x_tables: ip_tables: osf match: only valid for protocol 6 > > x_tables: ip_tables: osf match: only valid for protocol 6 > > ------------[ cut here ]------------ > > proc_dir_entry 'ipt_CLUSTERIP/172.20.0.170' already registered > > WARNING: CPU: 1 PID: 4152 at fs/proc/generic.c:330 proc_register+0x2a4/0x370 > > fs/proc/generic.c:329 > > Kernel panic - not syncing: panic_on_warn set ... > > > > CPU: 1 PID: 4152 Comm: syzkaller851476 Not tainted 4.15.0+ #221 > > Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS > > Google 01/01/2011 > > Call Trace: > > __dump_stack lib/dump_stack.c:17 [inline] > > dump_stack+0x194/0x257 lib/dump_stack.c:53 > > panic+0x1e4/0x41c kernel/panic.c:183 > > __warn+0x1dc/0x200 kernel/panic.c:547 > > report_bug+0x211/0x2d0 lib/bug.c:184 > > fixup_bug.part.11+0x37/0x80 arch/x86/kernel/traps.c:178 > > fixup_bug arch/x86/kernel/traps.c:247 [inline] > > do_error_trap+0x2d7/0x3e0 arch/x86/kernel/traps.c:296 > > do_invalid_op+0x1b/0x20 arch/x86/kernel/traps.c:315 > > invalid_op+0x22/0x40 arch/x86/entry/entry_64.S:1097 > > RIP: 0010:proc_register+0x2a4/0x370 fs/proc/generic.c:329 > > RSP: 0018:ffff8801cbd6ee20 EFLAGS: 00010286 > > RAX: dffffc0000000008 RBX: ffff8801d2181038 RCX: ffffffff815a57ae > > RDX: 0000000000000000 RSI: 1ffff100397add74 RDI: 1ffff100397add49 > > RBP: ffff8801cbd6ee70 R08: 1ffff100397add0b R09: 0000000000000000 > > R10: ffff8801cbd6ecd8 R11: 0000000000000000 R12: ffff8801b2bb1cc0 > > R13: dffffc0000000000 R14: ffff8801b0d8dbc8 R15: ffff8801b2bb1d81 > > proc_create_data+0xf8/0x180 fs/proc/generic.c:494 > > clusterip_config_init net/ipv4/netfilter/ipt_CLUSTERIP.c:250 [inline] > > I think there is probably a race condition between clusterip_config_entry_put() > and clusterip_config_init(), after we release the spinlock, a new proc > with the same IP could be created therefore triggers this warning.... > > I am not sure if it is enough to just move the proc_remove() under > spinlock... I *think* we should change the order on proc fs entry creation, because clusterip_config_init() can race with itself, clusterip_config_init() returns NULL if the clusterip_config_init has no pte, and currently such entry is inserted into the list with NULL pte and the list lock itself is released before creating the PTE. I'll try to test something the following: --- diff --git a/net/ipv4/netfilter/ipt_CLUSTERIP.c b/net/ipv4/netfilter/ipt_CLUSTERIP.c index 3a84a60f6b39..d8807c44cc61 100644 --- a/net/ipv4/netfilter/ipt_CLUSTERIP.c +++ b/net/ipv4/netfilter/ipt_CLUSTERIP.c @@ -230,17 +230,6 @@ clusterip_config_init(struct net *net, const struct ipt_clusterip_tgt_info *i, refcount_set(&c->refcount, 1); refcount_set(&c->entries, 1); - spin_lock_bh(&cn->lock); - if (__clusterip_config_find(net, ip)) { - spin_unlock_bh(&cn->lock); - kfree(c); - - return ERR_PTR(-EBUSY); - } - - list_add_rcu(&c->list, &cn->configs); - spin_unlock_bh(&cn->lock); - #ifdef CONFIG_PROC_FS { char buffer[16]; @@ -257,6 +246,18 @@ clusterip_config_init(struct net *net, const struct ipt_clusterip_tgt_info *i, } #endif + spin_lock_bh(&cn->lock); + if (__clusterip_config_find(net, ip)) { + spin_unlock_bh(&cn->lock); + kfree(c); + + proc_remove(c->pde); + return ERR_PTR(-EBUSY); + } + + list_add_rcu(&c->list, &cn->configs); + spin_unlock_bh(&cn->lock); + c->notifier.notifier_call = clusterip_netdev_event; err = register_netdevice_notifier(&c->notifier); if (!err) --- Cheers, Paolo