Received: by 10.213.65.68 with SMTP id h4csp446357imn; Tue, 13 Mar 2018 09:18:09 -0700 (PDT) X-Google-Smtp-Source: AG47ELs4TwZnKueCfKnogk6u649j0zLHpVlUlAHm3p1VRDsezTEI5MebCt18bXZzp6pYiUkz9a1G X-Received: by 2002:a17:902:8d87:: with SMTP id v7-v6mr1084046plo.146.1520957888988; Tue, 13 Mar 2018 09:18:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1520957888; cv=none; d=google.com; s=arc-20160816; b=pFwODyZk7UJSbWESX5kNfD8/ZY83DkOb7Hc9ppbkz1VprzNpUw+cMcWDd9JZfy0/Ms 2Z7ptytoU8GwqPqEzerfym3Zsi8JVtd+e5a0LKpgmWuBO+GR08Pf7L0efueJaSEHYfaD 5zwAMFTV1ogP+CsTAaMFwYJHYVxilqJ9ijkRhx/KctrU9fnHqqd89zEhEmEyxAUyRjBJ ZI706TGIGcFsYFnPgUtgbVJtOm3JcTxG0+KmVujI+TgsQC6/zVdNPUMtfT9yD9TkiQb0 HoGIKznYxkLY5uQDV/0+NfV+nFlYD0iBMJKhyk+784FF/UkRdPvJe3p/AhNpGpGZapdy 1UDg== 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=BuKetAszhdWL0BFzucOfWdQQic/cU2B55877HErNGhE=; b=Z7usId3Fb4ysSCsLy+vK+DcS04l8EbXmu6LihzcwWEQ8KxPfZffguUPhbIZL06BxbA FoMGxdEbW62exTsej/iWCmpfBlnoZ5HifMO1nG/HwddCWxM1wZAfET4dgfOWWRScKGXz I1lqNQfSO3+8wzkzbCn2gg9aoGfv2KX8BCUAtg5uDMAmJxJKEldqE3RizEXUjYe5MtYb 2+bJlF42cOlq+IG03fNUxCMH6ekT58u0uFd1nozn9Ifk5DI8Qf+8G3Qqg3WVcWT0oGq0 q4h1PJ0/p5uJxW1JI9vxlv6uwQ2a4+QbpWeZdqHX6FkTs2NsT6fhuJkZpcF/AXrzn8IF zZAw== 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 q18si342192pfd.194.2018.03.13.09.17.54; Tue, 13 Mar 2018 09:18:08 -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 S933971AbeCMPfX (ORCPT + 99 others); Tue, 13 Mar 2018 11:35:23 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:33128 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933957AbeCMPfV (ORCPT ); Tue, 13 Mar 2018 11:35:21 -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 22DA61136; Tue, 13 Mar 2018 15:35:20 +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.14 010/140] netfilter: ipt_CLUSTERIP: fix a race condition of proc file creation Date: Tue, 13 Mar 2018 16:23:33 +0100 Message-Id: <20180313152458.810866282@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180313152458.201155692@linuxfoundation.org> References: <20180313152458.201155692@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.14-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();