Received: by 10.223.176.46 with SMTP id f43csp250197wra; Tue, 23 Jan 2018 20:16:54 -0800 (PST) X-Google-Smtp-Source: AH8x225Tp2+oZI5toPcDvG5nxiOPQZYYaQ+cEtAPnX57aJ3X8EUFYFwSWV/O+ZnMZ1FeEbanBUxD X-Received: by 10.98.156.143 with SMTP id u15mr11669881pfk.170.1516767414195; Tue, 23 Jan 2018 20:16:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516767414; cv=none; d=google.com; s=arc-20160816; b=fht62UmB91YOAfCaJIQxGinw0odyTPHmAcZAfnYj1X137IU9RzCUwBQJpp6JKlPci2 DQW7ULn58LhJ7OvD1p4LQ5K/MLneaRmRLGc/+06e1wqG0C4hBoYyeDFeTHtTcGrXSJtK Yqrq7iOS9CQTQ03zznUNyAJd005+WXNkt/wfWF+3Q4fDxtkQQATDgDuFFMGb6vMoKLUf LjhBWlciH6x75MNIAefR/PeDj9gybhaECAfophEfuPqZ0br5Qen/7IWCtDQ55T8E0YS3 AwlLGvxcIx2/8W59mlK0al1Sq2pr23olVY2xO8cLj0zqhKtrOPpVlGRIC2n4lX0gG36B BTcw== 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=PtzpmfJ/4tOb7VkzR0+d0qLHUGwAp9iGv9arcMNXXTY=; b=IrSbyPiQzl3FboHeLNEc/cY7WDlPbv10D/f92RsgXUZsjpmvv7ieLdYpM0t3CnHDJD Q13blAys5hs6/3d9vj/f6MwjOqC27IoqhxoWBde46hzpnSm8e7W2wOWw5cLRwiJ0GqWZ DFT3e2VILrFfLCFHcqyPjXpigqED9roLKJ71UoziufgwH24J3lHh/ISKSGvGjUJcr2gu 0FaADoHyhO60/Dlf+b/i+2O4lXX793Q8raQ1NnL4svW6d+CDS+sxEiNbSyHYHMEaa+ri VnpWYvnT5Re0mRPYvMham+h/HTmCfJ8COPGEMVOQP+CwEIK2FWqlGnSMp7xGENHHkkQz Vhsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=eO6eXEA8; 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 l5-v6si5570269pli.162.2018.01.23.20.16.40; Tue, 23 Jan 2018 20:16:54 -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=eO6eXEA8; 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 S932396AbeAXEPk (ORCPT + 99 others); Tue, 23 Jan 2018 23:15:40 -0500 Received: from mail-sn1nam01on0109.outbound.protection.outlook.com ([104.47.32.109]:45568 "EHLO NAM01-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932220AbeAXEP0 (ORCPT ); Tue, 23 Jan 2018 23:15:26 -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=PtzpmfJ/4tOb7VkzR0+d0qLHUGwAp9iGv9arcMNXXTY=; b=eO6eXEA8Ummvu3k6LBN/ZQev/dKPgekyV7i3uYGk9y69V8pGFkzI9IiDRTmgjOLYQLhhsIYN6DfNIVdvLl6BlP/n9xeEerlPQVv2gGksuQ01PAYgXkoCH8yr33yYQnxahJxdDQaf5coVwH59cc9kq1Xcu+yycxSHiRKdkCysy28= 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:20 +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:20 +0000 From: Sasha Levin To: "linux-kernel@vger.kernel.org" , "stable@vger.kernel.org" CC: Trond Myklebust , "J . Bruce Fields" , Sasha Levin Subject: [PATCH AUTOSEL for 4.14 057/100] nfsd: Ensure we don't recognise lock stateids after freeing them Thread-Topic: [PATCH AUTOSEL for 4.14 057/100] nfsd: Ensure we don't recognise lock stateids after freeing them Thread-Index: AQHTlMni0FqA8X0CD0ukthGE9IUuUw== Date: Wed, 24 Jan 2018 04:14:53 +0000 Message-ID: <20180124041414.32065-57-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:9YBVwcJ8AXTEqjSDyi4aihJKrOiucsszdDU+Fh1iLe64dmIN1McbA3eeR37H6lwIC/1bza5B8VirPg0Y5vQ1oE3RpPB/g9r35Owti5dc2a0Z7tzo3dPdY/FeQ2r6tkcEdHMmWgV/fa9DOLsGRsxgMVHuRfTQzxmKxv1c/v1OWgtjeWBh9dLvPJzoNwIm8759dXvh21drZFZPhMlJUIjLKMW7icueTiPqvhn+ZS7bJyYrTIMGkwqDD1alWNmYqBAg x-ms-office365-filtering-correlation-id: dde3e91a-b9f4-4b8c-1ba7-08d562e11545 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)(6666003)(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: AB67gAyeWzgyok2o/W9vlr1FzG4qJ2Te445EXVfYJgoiFqsDf+vDNiVB9Tu9xnOxVTIFUWCrRmUjUSAy08abHw== 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: dde3e91a-b9f4-4b8c-1ba7-08d562e11545 X-MS-Exchange-CrossTenant-originalarrivaltime: 24 Jan 2018 04:14:53.6395 (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: Trond Myklebust [ Upstream commit 659aefb68eca28ba9aa482a9fc64de107332e256 ] In order to deal with lookup races, nfsd4_free_lock_stateid() needs to be able to signal to other stateful functions that the lock stateid is no longer valid. Right now, nfsd_lock() will check whether or not an existing stateid is still hashed, but only in the "new lock" path. To ensure the stateid invalidation is also recognised by the "existing lock= " path, and also by a second call to nfsd4_free_lock_stateid() itself, we can change the type to NFS4_CLOSED_STID under the stp->st_mutex. Signed-off-by: Trond Myklebust Signed-off-by: J. Bruce Fields Signed-off-by: Sasha Levin --- fs/nfsd/nfs4state.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index 61f38346ce9d..5ec0ca5cbc1e 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -5099,7 +5099,9 @@ nfsd4_free_lock_stateid(stateid_t *stateid, struct nf= s4_stid *s) struct nfs4_ol_stateid *stp =3D openlockstateid(s); __be32 ret; =20 - mutex_lock(&stp->st_mutex); + ret =3D nfsd4_lock_ol_stateid(stp); + if (ret) + goto out_put_stid; =20 ret =3D check_stateid_generation(stateid, &s->sc_stateid, 1); if (ret) @@ -5110,11 +5112,13 @@ nfsd4_free_lock_stateid(stateid_t *stateid, struct = nfs4_stid *s) lockowner(stp->st_stateowner))) goto out; =20 + stp->st_stid.sc_type =3D NFS4_CLOSED_STID; release_lock_stateid(stp); ret =3D nfs_ok; =20 out: mutex_unlock(&stp->st_mutex); +out_put_stid: nfs4_put_stid(s); return ret; } @@ -5683,6 +5687,8 @@ find_lock_stateid(struct nfs4_lockowner *lo, struct n= fs4_file *fp) lockdep_assert_held(&clp->cl_lock); =20 list_for_each_entry(lst, &lo->lo_owner.so_stateids, st_perstateowner) { + if (lst->st_stid.sc_type !=3D NFS4_LOCK_STID) + continue; if (lst->st_stid.sc_file =3D=3D fp) { atomic_inc(&lst->st_stid.sc_count); return lst; @@ -5757,7 +5763,6 @@ lookup_or_create_lock_state(struct nfsd4_compound_sta= te *cstate, struct nfs4_lockowner *lo; struct nfs4_ol_stateid *lst; unsigned int strhashval; - bool hashed; =20 lo =3D find_lockowner_str(cl, &lock->lk_new_owner); if (!lo) { @@ -5780,15 +5785,7 @@ retry: goto out; } =20 - mutex_lock(&lst->st_mutex); - - /* See if it's still hashed to avoid race with FREE_STATEID */ - spin_lock(&cl->cl_lock); - hashed =3D !list_empty(&lst->st_perfile); - spin_unlock(&cl->cl_lock); - - if (!hashed) { - mutex_unlock(&lst->st_mutex); + if (nfsd4_lock_ol_stateid(lst) !=3D nfs_ok) { nfs4_put_stid(&lst->st_stid); goto retry; } --=20 2.11.0