Received: by 10.213.65.68 with SMTP id h4csp456383imn; Tue, 13 Mar 2018 09:37:27 -0700 (PDT) X-Google-Smtp-Source: AG47ELvRP1VI84DzBQZttP6xbAbABVSLglcTG9sM3OIsBxfXw1DbVcGQiPpiPpWLPO1bMnSXzxCV X-Received: by 10.99.163.1 with SMTP id s1mr1011240pge.47.1520959047873; Tue, 13 Mar 2018 09:37:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1520959047; cv=none; d=google.com; s=arc-20160816; b=pcoN17UFbleuG0YWPuYZY9oAS33ryj4cZo3BpXsaYiNVDAP+haK2Ll44hkC+CCo+yf 3Mk7Fhi6yVMT5RRbFSZ0yN6VXXxFfmaBn8qhPyb4nFgaGJ/ez+9u2IbthgX/Rwprkpy8 zhDxalqYsaBaR7gcKiSyc5gFTX0Jn4mMwGvdjhC4w31IE2LVoPHgOsvsvAp5l+U6wrYb 91hiEVoJsGjX1iGefi+UqvAOrFlrq4AwoshjzBSpTYQhCZ48wlG7uQ+oU6u5KAEKJBXM NMTdWdxBiLyL7pzpPvwfYg+b1DWbW+cKiZHu3xEbLlKUP2CHZTpzxpoqBA/9hVfv9zNQ RnsQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=muiWVM/8avRqGZge6boG4JGqnWzA9gUb08dTn90cNxw=; b=jglmV8Ol5L6RsMyci26ULp+VG5AiSUYg5etXCkkP27dHQxqeYu3vjilsxjbKJR8jf4 u9E/NpfwVepXv4qD1bjpZkopabota3M006Av9WUJAiEY2b8gYg5A29735wMgPxCf8v/u 8GwOIp3FZwuz8gvn2uWfj4kLTWi5yGUW7BlEQBCXYpbRohMvPM5bxwvgd3VW3Y98UfNl Enmj+fjfU7QPDBFbsjndEe8jI2yH6WBgYgoBOoJP5z+eSkEq4ID61AN7LE8CkMhN9qwi zfIswLY6u+BjcEkXyKr1gC4sNhNGYi7nWgvveEzM4XzVAlN/e38BZxfbqsCst8VvDP6O GQPA== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l4-v6si321657plb.68.2018.03.13.09.37.13; Tue, 13 Mar 2018 09:37:27 -0700 (PDT) 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933539AbeCMQeh (ORCPT + 99 others); Tue, 13 Mar 2018 12:34:37 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:59872 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753026AbeCMPck (ORCPT ); Tue, 13 Mar 2018 11:32:40 -0400 Received: from localhost (LFbn-1-12258-90.w90-92.abo.wanadoo.fr [90.92.71.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 48F7B1220; Tue, 13 Mar 2018 15:32:38 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+03218bcdba6aa76441a3@syzkaller.appspotmail.com, Paolo Abeni , Xin Long , Pablo Neira Ayuso , Cong Wang Subject: [PATCH 4.15 109/146] netfilter: ipt_CLUSTERIP: fix a race condition of proc file creation Date: Tue, 13 Mar 2018 16:24:36 +0100 Message-Id: <20180313152328.815536418@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180313152320.439085687@linuxfoundation.org> References: <20180313152320.439085687@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Cong Wang commit b3e456fce9f51d6276e576d00271e2813c1b8b67 upstream. There is a race condition between clusterip_config_entry_put() and clusterip_config_init(), after we release the spinlock in clusterip_config_entry_put(), a new proc file with a same IP could be created immediately since it is already removed from the configs list, therefore it triggers this warning: ------------[ 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 ... As a quick fix, just move the proc_remove() inside the spinlock. Reported-by: Fixes: 6c5d5cfbe3c5 ("netfilter: ipt_CLUSTERIP: check duplicate config when initializing") Tested-by: Paolo Abeni Cc: Xin Long Cc: Pablo Neira Ayuso Signed-off-by: Cong Wang Reviewed-by: Xin Long Signed-off-by: Pablo Neira Ayuso Signed-off-by: Greg Kroah-Hartman --- net/ipv4/netfilter/ipt_CLUSTERIP.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) --- a/net/ipv4/netfilter/ipt_CLUSTERIP.c +++ b/net/ipv4/netfilter/ipt_CLUSTERIP.c @@ -107,12 +107,6 @@ clusterip_config_entry_put(struct net *n local_bh_disable(); if (refcount_dec_and_lock(&c->entries, &cn->lock)) { - list_del_rcu(&c->list); - spin_unlock(&cn->lock); - local_bh_enable(); - - unregister_netdevice_notifier(&c->notifier); - /* In case anyone still accesses the file, the open/close * functions are also incrementing the refcount on their own, * so it's safe to remove the entry even if it's in use. */ @@ -120,6 +114,12 @@ clusterip_config_entry_put(struct net *n if (cn->procdir) proc_remove(c->pde); #endif + list_del_rcu(&c->list); + spin_unlock(&cn->lock); + local_bh_enable(); + + unregister_netdevice_notifier(&c->notifier); + return; } local_bh_enable();