Received: by 10.223.176.5 with SMTP id f5csp972450wra; Fri, 2 Feb 2018 09:04:47 -0800 (PST) X-Google-Smtp-Source: AH8x224F67meP2XbScIebSe1ddbNCrCu6lqqc1jYKgJqp5+T1ZT8tfVB3xqvRTLw47GxDenucBNL X-Received: by 10.101.101.68 with SMTP id a4mr31759599pgw.368.1517591087307; Fri, 02 Feb 2018 09:04:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517591087; cv=none; d=google.com; s=arc-20160816; b=FIhi2uPOD+XAeATTOEO5zyq6uBL5NQQv0exSnwni07+kFiwUbrFCzkZDbLoDL0OfP9 C2LL+pKb3IAKg02hCVZeuYEaR9zkj3nMW3jHeBolEXIU2VUbJZr+QYST4fLHHrATQXxv AJCpsNRUHA2/64nIrLo7zBrCN7c8T9QPEUwO8tKpnTjsraUyEwP9DHxno86iuSwMXZTj ibBN4SlZWxY5JZkuQO19XtzSFUHZxLGrL2qNzjdL2+E3mVIUvmngrkpPBS2RGZ9T4lop ekv1IU50yMEY9bgY+v5SqdmVhpUnHUENgXgajEKAu+TXWiBB9UGLLoK5xmRwN8J1Kqp2 67zg== 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=cuXjsfoKMvVvY5RZjsrEBV0xFWM6HiopWgpPsSmUzYA=; b=NchAwAjHzj+FUx4j6JITZyFpoh9CFB5Z9R3mx+UPbWUVcD8Ba4u7amwskBJBqNOKWA 1lESBMp1/Srn0fV9qJSEjNwckikkkVhMiSbek7UDZk8C6O5wIG0sYW5GNARes+1VzIiB aP1mxfvs1uiF5jzb8tevCkuSqUY1MHe7QVwSmR2RMHw4vn5ihFESJxrZ31RX9N5CUw43 9OMDBmMB3QetE8qU0fbFn58pvu7RstJ4GLK1wCLl58D7QaKoqfcxMTo70bF0sCWGWO9p h4RCxZc2LGnfl1zgc29DzYDv+zB2vOPWdlkmCXXppxiZhDxCrbP9Zlzy+yg8JuFkR5v+ woYg== 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 b6-v6si605713plx.805.2018.02.02.09.04.31; Fri, 02 Feb 2018 09:04:47 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752811AbeBBRDY (ORCPT + 99 others); Fri, 2 Feb 2018 12:03:24 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:35012 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752678AbeBBRBJ (ORCPT ); Fri, 2 Feb 2018 12:01:09 -0500 Received: from localhost (LFbn-1-12258-90.w90-92.abo.wanadoo.fr [90.92.71.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 31839DF6; Fri, 2 Feb 2018 17:01:08 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jeff Layton , Vasily Averin , "J. Bruce Fields" , Sasha Levin Subject: [PATCH 4.4 42/67] lockd: fix "list_add double add" caused by legacy signal interface Date: Fri, 2 Feb 2018 17:58:11 +0100 Message-Id: <20180202140820.125721591@linuxfoundation.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180202140815.091718203@linuxfoundation.org> References: <20180202140815.091718203@linuxfoundation.org> User-Agent: quilt/0.65 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.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Vasily Averin [ Upstream commit 81833de1a46edce9ca20cfe079872ac1c20ef359 ] restart_grace() uses hardcoded init_net. It can cause to "list_add double add" in following scenario: 1) nfsd and lockd was started in several net namespaces 2) nfsd in init_net was stopped (lockd was not stopped because it have users from another net namespaces) 3) lockd got signal, called restart_grace() -> set_grace_period() and enabled lock_manager in hardcoded init_net. 4) nfsd in init_net is started again, its lockd_up() calls set_grace_period() and tries to add lock_manager into init_net 2nd time. Jeff Layton suggest: "Make it safe to call locks_start_grace multiple times on the same lock_manager. If it's already on the global grace_list, then don't try to add it again. (But we don't intentionally add twice, so for now we WARN about that case.) With this change, we also need to ensure that the nfsd4 lock manager initializes the list before we call locks_start_grace. While we're at it, move the rest of the nfsd_net initialization into nfs4_state_create_net. I see no reason to have it spread over two functions like it is today." Suggested patch was updated to generate warning in described situation. Suggested-by: Jeff Layton Signed-off-by: Vasily Averin Signed-off-by: J. Bruce Fields Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- fs/nfs_common/grace.c | 6 +++++- fs/nfsd/nfs4state.c | 7 ++++--- 2 files changed, 9 insertions(+), 4 deletions(-) --- a/fs/nfs_common/grace.c +++ b/fs/nfs_common/grace.c @@ -30,7 +30,11 @@ locks_start_grace(struct net *net, struc struct list_head *grace_list = net_generic(net, grace_net_id); spin_lock(&grace_lock); - list_add(&lm->list, grace_list); + if (list_empty(&lm->list)) + list_add(&lm->list, grace_list); + else + WARN(1, "double list_add attempt detected in net %x %s\n", + net->ns.inum, (net == &init_net) ? "(init_net)" : ""); spin_unlock(&grace_lock); } EXPORT_SYMBOL_GPL(locks_start_grace); --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -6792,6 +6792,10 @@ static int nfs4_state_create_net(struct INIT_LIST_HEAD(&nn->sessionid_hashtbl[i]); nn->conf_name_tree = RB_ROOT; nn->unconf_name_tree = RB_ROOT; + nn->boot_time = get_seconds(); + nn->grace_ended = false; + nn->nfsd4_manager.block_opens = true; + INIT_LIST_HEAD(&nn->nfsd4_manager.list); INIT_LIST_HEAD(&nn->client_lru); INIT_LIST_HEAD(&nn->close_lru); INIT_LIST_HEAD(&nn->del_recall_lru); @@ -6846,9 +6850,6 @@ nfs4_state_start_net(struct net *net) ret = nfs4_state_create_net(net); if (ret) return ret; - nn->boot_time = get_seconds(); - nn->grace_ended = false; - nn->nfsd4_manager.block_opens = true; locks_start_grace(net, &nn->nfsd4_manager); nfsd4_client_tracking_init(net); printk(KERN_INFO "NFSD: starting %ld-second grace period (net %p)\n",