Received: by 10.223.176.46 with SMTP id f43csp273381wra; Tue, 23 Jan 2018 20:48:11 -0800 (PST) X-Google-Smtp-Source: AH8x224YvBuiim1KL6lH4ksV18ZihkEjFYLvA3vYNCQNJxw8n37LI9tIIfyDT3RdZewFpjG6WzTA X-Received: by 10.98.60.132 with SMTP id b4mr11941850pfk.120.1516769291239; Tue, 23 Jan 2018 20:48:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516769291; cv=none; d=google.com; s=arc-20160816; b=SFdH8y5IdcfT++c9sKTdwf1/d1r1+k++1uSCSsL6wKD6lZE6Bb4/QSmwM9kfZ60qjV tWQG80Nt3u6ltfWjDO3XaiuvYSHT/m3MlKw8mQPCNFkrEGiM0u058ka1i+MRcdEwrsOl fq2L/mFhmOcwtrnOPT0tqEvVxvpE9hFDK7uB9FrFC0pRrJI6rI0Hph7tllfhEL6GhLrl a+oaDTCOsSjk+JB8nLpgPfOoQ/6AFaCAmlhDZYsCd+runzvxDdBhxY4okDgFpjcyu6wo jfX5l++Pu5/983IQnuV/Ol38Z9mAK0237w8Ycu9CPYhbC2+evhuIX5QhdburuwIDlFMn dUUQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :spamdiagnosticmetadata:spamdiagnosticoutput:content-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=qtRYZJ2Q/k+gec+EBnLUdBvyScmlGrPdhhzMxyrFlL4=; b=W3X3A7/snfXkl2u/pvlnqAfm/EIC9+VE+yK4jgzZEVwbAV3l4ddeuCnvYvgvHntH+C Uq3kupb4OvjXkxOg+7wBjqSuFSqAst5WZs86Gkr4Vt7Vsq9+Rt5R10SBXaRlf33ru3+9 iNwSN+PPs4mldVQIoiyQLAwSHcakc5hLqtPWPWpe+nC3NZNjhPi5YTz1YYlDq5SOdujX 72dMNDGcDAWn8caz3I9iJEae8DK9DNWNMfJo4dPnz3tXxie1qGQLtW7ylgEYGAExsvRe MYFCKjL1MQkJxkV4a/HxmBNCjTZMCx5BRRIbPNw165r9sDtr6QtNfUHOx+MIRFX0vaxr CPCg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=YaCxcW0q; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k127si5309830pgk.733.2018.01.23.20.47.57; Tue, 23 Jan 2018 20:48:11 -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; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=YaCxcW0q; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932538AbeAXEQL (ORCPT + 99 others); Tue, 23 Jan 2018 23:16:11 -0500 Received: from mail-sn1nam01on0120.outbound.protection.outlook.com ([104.47.32.120]:45079 "EHLO NAM01-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932430AbeAXEP5 (ORCPT ); Tue, 23 Jan 2018 23:15:57 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=qtRYZJ2Q/k+gec+EBnLUdBvyScmlGrPdhhzMxyrFlL4=; b=YaCxcW0qf8YJNO7+/JIkppdOpHscf8llye7xvksakP+H9NweDFnL66tAK+8L2zYMN+PibPXAODtc/TI7Tij0l6p/zLZaGr9yWxbNtFacCZzMy448bhfuhpijJLQKoylyLdggm9bkbFnqrgPwDEqltraul7qcP8brjtJhWNHy5oE= Received: from DM5PR2101MB1032.namprd21.prod.outlook.com (52.132.128.13) by DM5PR2101MB1015.namprd21.prod.outlook.com (52.132.133.37) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.464.0; Wed, 24 Jan 2018 04:15:53 +0000 Received: from DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::6485:b98:d15e:9da7]) by DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::6485:b98:d15e:9da7%2]) with mapi id 15.20.0464.000; Wed, 24 Jan 2018 04:15:53 +0000 From: Sasha Levin To: "linux-kernel@vger.kernel.org" , "stable@vger.kernel.org" CC: Vasily Averin , "J . Bruce Fields" , Sasha Levin Subject: [PATCH AUTOSEL for 4.14 062/100] lockd: fix "list_add double add" caused by legacy signal interface Thread-Topic: [PATCH AUTOSEL for 4.14 062/100] lockd: fix "list_add double add" caused by legacy signal interface Thread-Index: AQHTlMnkFwf4ZkKG4kSloxf27LxB/Q== Date: Wed, 24 Jan 2018 04:14:56 +0000 Message-ID: <20180124041414.32065-62-alexander.levin@microsoft.com> References: <20180124041414.32065-1-alexander.levin@microsoft.com> In-Reply-To: <20180124041414.32065-1-alexander.levin@microsoft.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [52.168.54.252] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;DM5PR2101MB1015;7:Kg6TaXeuR5v4LkpebIvPpeasceSq/Rc5Hs7PqqT/Y3tKqwKKDBcbBkgF3goyl2AkJVhlAHp6mheiWZFERkV8gc5FT5AxqANHy7Q1waFgAqTCT9rFymzrWgBLHQwB++7h251ieKrU7x4WpgaZmZfEVaVlvZo2B3Jwj7JPoGy7LTKTHDuNqSox+fU4vm2b1m2UsBcpbP4zDN4LUqE8cxG0VVU9cmLBZCzYaTX4IqGavDxVbP6BEczFGDxxLzrY1XST x-ms-office365-filtering-correlation-id: 1169c14c-3996-4031-7b2d-08d562e128c9 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(5600026)(4604075)(3008032)(4534165)(4627221)(201703031133081)(201702281549075)(48565401081)(2017052603307)(7193020);SRVR:DM5PR2101MB1015; x-ms-traffictypediagnostic: DM5PR2101MB1015: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(28532068793085)(89211679590171); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(61425038)(6040501)(2401047)(5005006)(8121501046)(3002001)(10201501046)(3231046)(2400081)(944501161)(93006095)(93001095)(6055026)(61426038)(61427038)(6041288)(20161123558120)(20161123562045)(20161123564045)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011);SRVR:DM5PR2101MB1015;BCL:0;PCL:0;RULEID:;SRVR:DM5PR2101MB1015; x-forefront-prvs: 056297E276 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(396003)(39380400002)(376002)(366004)(39860400002)(346002)(199004)(189003)(478600001)(106356001)(6512007)(53936002)(2900100001)(36756003)(102836004)(2950100002)(2501003)(10290500003)(97736004)(14454004)(81166006)(72206003)(8936002)(6486002)(1076002)(10090500001)(6346003)(26005)(54906003)(4326008)(575784001)(76176011)(99286004)(86362001)(3660700001)(105586002)(6116002)(8676002)(68736007)(22452003)(66066001)(25786009)(6506007)(5660300001)(305945005)(59450400001)(7736002)(3280700002)(5250100002)(2906002)(107886003)(86612001)(6436002)(316002)(81156014)(3846002)(110136005)(22906009)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:DM5PR2101MB1015;H:DM5PR2101MB1032.namprd21.prod.outlook.com;FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:en; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alexander.Levin@microsoft.com; x-microsoft-antispam-message-info: y0Xx+03wpevYOq1g1dCkShBd/A5gAuLWf8leNvfWGgCCI1P7UFmbzq852mNVuQOwi3iSeyiLKPmsY9MPIUqI+A== spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1169c14c-3996-4031-7b2d-08d562e128c9 X-MS-Exchange-CrossTenant-originalarrivaltime: 24 Jan 2018 04:14:56.3865 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB1015 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- fs/nfs_common/grace.c | 6 +++++- fs/nfsd/nfs4state.c | 7 ++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/fs/nfs_common/grace.c b/fs/nfs_common/grace.c index 1bd659938646..3b13fb3b0553 100644 --- a/fs/nfs_common/grace.c +++ b/fs/nfs_common/grace.c @@ -30,7 +30,11 @@ locks_start_grace(struct net *net, struct lock_manager *= lm) struct list_head *grace_list =3D net_generic(net, grace_net_id); =20 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 =3D=3D &init_net) ? "(init_net)" : ""); spin_unlock(&grace_lock); } EXPORT_SYMBOL_GPL(locks_start_grace); diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index cc74fb0dc02d..58764786091e 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -7018,6 +7018,10 @@ static int nfs4_state_create_net(struct net *net) INIT_LIST_HEAD(&nn->sessionid_hashtbl[i]); nn->conf_name_tree =3D RB_ROOT; nn->unconf_name_tree =3D RB_ROOT; + nn->boot_time =3D get_seconds(); + nn->grace_ended =3D false; + nn->nfsd4_manager.block_opens =3D 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); @@ -7075,9 +7079,6 @@ nfs4_state_start_net(struct net *net) ret =3D nfs4_state_create_net(net); if (ret) return ret; - nn->boot_time =3D get_seconds(); - nn->grace_ended =3D false; - nn->nfsd4_manager.block_opens =3D 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", --=20 2.11.0