Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp1179353ybi; Fri, 2 Aug 2019 10:37:19 -0700 (PDT) X-Google-Smtp-Source: APXvYqwKZdrS8Di2UgffyRaeId8L1sf269OPwOJYH24JyzCS1mbxmAbcVzle1xY5rq72BuBJXbPX X-Received: by 2002:a17:90a:4803:: with SMTP id a3mr5542541pjh.58.1564767439081; Fri, 02 Aug 2019 10:37:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564767439; cv=none; d=google.com; s=arc-20160816; b=fzn3tNDsB6OPLm2N/wPPP7/0YmPOLRnr9L7tK6a3VZSZai4X5mGrzQ6xFkfjE6lX16 1kK8vm0YuTzbJLAHzcyZ23EXDtQbGMB77053qK2W1D0VbaUVLAtXXDLSLldxbZVLRIJF StD92cgzZHYoiF69Pe1mVWmTNKUv9/pWdc4bQqCk7tf3LpObK7W/0/tGvouJpKRttDwi g+YatpHuWwfLwfxCpE9eIi+Q5pxLJJMpIEZTrC6tcPIYgp8/pMh36KaDGQyx0uuNbO7G +QPkpQAAij9lJSNLkf6XDSj2qgaB1xtdGSMO4yVz++Zb3FqHV6t3W1WqsFFh2E2yVGzg 93QA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Z14O6g2AY4YTaD9CI8aDk+Sea0i9Bl7MHSihqG1UVEA=; b=lIGBfR5CADXF30rpxKFo1FqEujYpnKYiZzfSsN3fPO1FmI3N8BIXDEhdPH4R0N4u3i hR9IOyHOeNNDbmDE699L8+JD3Gime8xZUkpc4owHmvqk3b9h4ap5kLU4Rg6H58KhGXgP O80+jCJhjtx76FGI5OBQz9q3HsIEfXiwEJT5nzLl0EeG/GhelrVcJZGt3+lpe7WPUmQD 1WXh9Y4lUDxgSSkxPRVjn93o81gRT6Fc5Wkj/7yI070rakfQkS4BHEKgYq+6NPR6fKAw fFIT8tmP0wbmkaeEhB60+gg0dbHRviJI57gJaEzbow4UkJLP7d7nzFmAKz+kv0A2EC9T GUIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=aWDp0+8x; 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 k22si34625753pll.168.2019.08.02.10.37.04; Fri, 02 Aug 2019 10:37:19 -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; dkim=pass header.i=@kernel.org header.s=default header.b=aWDp0+8x; 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 S2405746AbfHBJrw (ORCPT + 99 others); Fri, 2 Aug 2019 05:47:52 -0400 Received: from mail.kernel.org ([198.145.29.99]:52816 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2405732AbfHBJru (ORCPT ); Fri, 2 Aug 2019 05:47:50 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E2B1E216C8; Fri, 2 Aug 2019 09:47:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1564739269; bh=/V/bS1x8kokfHbkBz4bKpmxwmkhk75JhZ17rhkivQTc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aWDp0+8x0NqzrCfvtsV/gAAAvlwK5PFVlFNzvnaUwQpT6K/9hxszB+mzRAKJHopAw 4S1uV0xyw5cy3tulMaej+QvHQ/0NUMf7NiPpbf8FRhWAJ5zB2EpXbQK8Yt5FBVUtm+ yQiubFDfiIkXMKuexXLIj3hNk7xHuBZu1xJ/vOms= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Tigran Mkrtchyan , Trond Myklebust , Anna Schumaker , Sasha Levin Subject: [PATCH 4.9 154/223] NFSv4: Fix open create exclusive when the server reboots Date: Fri, 2 Aug 2019 11:36:19 +0200 Message-Id: <20190802092248.362399703@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190802092238.692035242@linuxfoundation.org> References: <20190802092238.692035242@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ Upstream commit 8fd1ab747d2b1ec7ec663ad0b41a32eaa35117a8 ] If the server that does not implement NFSv4.1 persistent session semantics reboots while we are performing an exclusive create, then the return value of NFS4ERR_DELAY when we replay the open during the grace period causes us to lose the verifier. When the grace period expires, and we present a new verifier, the server will then correctly reply NFS4ERR_EXIST. This commit ensures that we always present the same verifier when replaying the OPEN. Reported-by: Tigran Mkrtchyan Signed-off-by: Trond Myklebust Signed-off-by: Anna Schumaker Signed-off-by: Sasha Levin --- fs/nfs/nfs4proc.c | 41 ++++++++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c index 6d0d94fc243d..ea29c608be89 100644 --- a/fs/nfs/nfs4proc.c +++ b/fs/nfs/nfs4proc.c @@ -1121,6 +1121,12 @@ struct nfs4_opendata { int cancelled; }; +struct nfs4_open_createattrs { + struct nfs4_label *label; + struct iattr *sattr; + const __u32 verf[2]; +}; + static bool nfs4_clear_cap_atomic_open_v1(struct nfs_server *server, int err, struct nfs4_exception *exception) { @@ -1190,8 +1196,7 @@ static void nfs4_init_opendata_res(struct nfs4_opendata *p) static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry, struct nfs4_state_owner *sp, fmode_t fmode, int flags, - const struct iattr *attrs, - struct nfs4_label *label, + const struct nfs4_open_createattrs *c, enum open_claim_type4 claim, gfp_t gfp_mask) { @@ -1199,6 +1204,7 @@ static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry, struct inode *dir = d_inode(parent); struct nfs_server *server = NFS_SERVER(dir); struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); + struct nfs4_label *label = (c != NULL) ? c->label : NULL; struct nfs4_opendata *p; p = kzalloc(sizeof(*p), gfp_mask); @@ -1255,15 +1261,11 @@ static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry, case NFS4_OPEN_CLAIM_DELEG_PREV_FH: p->o_arg.fh = NFS_FH(d_inode(dentry)); } - if (attrs != NULL && attrs->ia_valid != 0) { - __u32 verf[2]; - + if (c != NULL && c->sattr != NULL && c->sattr->ia_valid != 0) { p->o_arg.u.attrs = &p->attrs; - memcpy(&p->attrs, attrs, sizeof(p->attrs)); + memcpy(&p->attrs, c->sattr, sizeof(p->attrs)); - verf[0] = jiffies; - verf[1] = current->pid; - memcpy(p->o_arg.u.verifier.data, verf, + memcpy(p->o_arg.u.verifier.data, c->verf, sizeof(p->o_arg.u.verifier.data)); } p->c_arg.fh = &p->o_res.fh; @@ -1814,7 +1816,7 @@ static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context struct nfs4_opendata *opendata; opendata = nfs4_opendata_alloc(ctx->dentry, state->owner, 0, 0, - NULL, NULL, claim, GFP_NOFS); + NULL, claim, GFP_NOFS); if (opendata == NULL) return ERR_PTR(-ENOMEM); opendata->state = state; @@ -2759,8 +2761,7 @@ static int _nfs4_open_and_get_state(struct nfs4_opendata *opendata, static int _nfs4_do_open(struct inode *dir, struct nfs_open_context *ctx, int flags, - struct iattr *sattr, - struct nfs4_label *label, + const struct nfs4_open_createattrs *c, int *opened) { struct nfs4_state_owner *sp; @@ -2772,6 +2773,8 @@ static int _nfs4_do_open(struct inode *dir, struct nfs4_threshold **ctx_th = &ctx->mdsthreshold; fmode_t fmode = ctx->mode & (FMODE_READ|FMODE_WRITE|FMODE_EXEC); enum open_claim_type4 claim = NFS4_OPEN_CLAIM_NULL; + struct iattr *sattr = c->sattr; + struct nfs4_label *label = c->label; struct nfs4_label *olabel = NULL; int status; @@ -2790,8 +2793,8 @@ static int _nfs4_do_open(struct inode *dir, status = -ENOMEM; if (d_really_is_positive(dentry)) claim = NFS4_OPEN_CLAIM_FH; - opendata = nfs4_opendata_alloc(dentry, sp, fmode, flags, sattr, - label, claim, GFP_KERNEL); + opendata = nfs4_opendata_alloc(dentry, sp, fmode, flags, + c, claim, GFP_KERNEL); if (opendata == NULL) goto err_put_state_owner; @@ -2872,10 +2875,18 @@ static struct nfs4_state *nfs4_do_open(struct inode *dir, struct nfs_server *server = NFS_SERVER(dir); struct nfs4_exception exception = { }; struct nfs4_state *res; + struct nfs4_open_createattrs c = { + .label = label, + .sattr = sattr, + .verf = { + [0] = (__u32)jiffies, + [1] = (__u32)current->pid, + }, + }; int status; do { - status = _nfs4_do_open(dir, ctx, flags, sattr, label, opened); + status = _nfs4_do_open(dir, ctx, flags, &c, opened); res = ctx->state; trace_nfs4_open_file(ctx, flags, status); if (status == 0) -- 2.20.1