Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp833664ybi; Fri, 12 Jul 2019 05:25:11 -0700 (PDT) X-Google-Smtp-Source: APXvYqxFOlHApMXy9RCIjh2Uuh4ezJlk3NqqkWyTcZpa8wfzT+AuHnG7kgVZU2miDa3ukrkDyxo1 X-Received: by 2002:a17:902:2a68:: with SMTP id i95mr11358042plb.167.1562934311514; Fri, 12 Jul 2019 05:25:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562934311; cv=none; d=google.com; s=arc-20160816; b=ZyWqhuDeFh3DRrRd/b3T2uS9Vc799eQQiv9gMfr0akMfA9vUKSVIndQRvzjP4V6aEq xqXUnKgmaUTpAMdARyYWFeDSvi0sqHVbHjR5OdPugXnYiyLU92HtFEAX349KJPsxaRSR slwApyLmV98JrDe8fLMtJPlaoV4aEhCrnW12vzdxHLclE+t0Q/BfnarotNWNfJe+cJDi hrSSOQdABD7oEXwy8Dr7gB623PY/ZbYIyC5RlmQnV1Lci8wzKm73c30u53+8mEWtp4Dz ZYjy72NPHd1gSC3cR35zsmrrJpITSbtbAibirk01XhwhmkND9M78a7nY6tSma0HrJ7KV XsWw== 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=802dZ9nPsy7gC219/hwzZWvajnK3w0lznvhJiPF4ffA=; b=eMI8g5VkmZtlYo25e6Qk/230kN1Ro7j/b2mdoMkxv95Vl133oM5IKXPU+DLt4cr/2x sM5Tm6gMkbVWjx6835cvrRoUewqlijbP7akYoaKrSlG2iqvdH2eOni+KbOTHl3QVq2ep Pu+vUw/OrAuOMjakVSOMU487/PE/coGumXGuxwuZqZz3C4Ezwg5Ku3r61uh6bWUKpuwz xUOQxLadski9AmmKb5hsVAWJuZ7jsPcqvozasac/U2L2SKri3qYZzJQ4yAQAP8J4kFKV UIVo5S2LDydM1V6fpCGeH18G8TGVn3upE9TiNnGwWmOnc2qjOXV/NZzBS9Aw/2tNM1Y5 x3Sw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=z8tJXjHP; 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 31si7736093pld.245.2019.07.12.05.24.56; Fri, 12 Jul 2019 05:25:11 -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=z8tJXjHP; 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 S1727477AbfGLMWh (ORCPT + 99 others); Fri, 12 Jul 2019 08:22:37 -0400 Received: from mail.kernel.org ([198.145.29.99]:57360 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727305AbfGLMWf (ORCPT ); Fri, 12 Jul 2019 08:22:35 -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 CD59E208E4; Fri, 12 Jul 2019 12:22:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1562934154; bh=YRtuN/2H0rgjM6ilhMgMIYYR1DuAJ8TUFcq6UJ9NsLs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=z8tJXjHPgCyJNnfHCeLG/veWiefpnIfRGen6i/vX5pT0ZNI71D3IPs8KirsBWzGWl 9Ajry+VENawxGsjK5taB9T0Kq+SdL3RChbV77DnzedzqzTgHwEAHtIRd0Jcdlkc5NZ BbSK3NrOMnQRYN7QP8ijmxd8McV/ZgwszdjgOxZo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Trond Myklebust , Benjamin Coddington , Anna Schumaker , Sasha Levin Subject: [PATCH 4.19 54/91] NFS4: Only set creation opendata if O_CREAT Date: Fri, 12 Jul 2019 14:18:57 +0200 Message-Id: <20190712121624.573994260@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190712121621.422224300@linuxfoundation.org> References: <20190712121621.422224300@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 909105199a682cb09c500acd443d34b182846c9c ] We can end up in nfs4_opendata_alloc during task exit, in which case current->fs has already been cleaned up. This leads to a crash in current_umask(). Fix this by only setting creation opendata if we are actually doing an open with O_CREAT. We can drop the check for NULL nfs4_open_createattrs, since O_CREAT will never be set for the recovery path. Suggested-by: Trond Myklebust Signed-off-by: Benjamin Coddington Signed-off-by: Anna Schumaker Signed-off-by: Sasha Levin --- fs/nfs/nfs4proc.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c index 53cf8599a46e..1de855e0ae61 100644 --- a/fs/nfs/nfs4proc.c +++ b/fs/nfs/nfs4proc.c @@ -1243,10 +1243,20 @@ static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry, atomic_inc(&sp->so_count); p->o_arg.open_flags = flags; p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE); - p->o_arg.umask = current_umask(); p->o_arg.claim = nfs4_map_atomic_open_claim(server, claim); p->o_arg.share_access = nfs4_map_atomic_open_share(server, fmode, flags); + if (flags & O_CREAT) { + p->o_arg.umask = current_umask(); + p->o_arg.label = nfs4_label_copy(p->a_label, label); + if (c->sattr != NULL && c->sattr->ia_valid != 0) { + p->o_arg.u.attrs = &p->attrs; + memcpy(&p->attrs, c->sattr, sizeof(p->attrs)); + + memcpy(p->o_arg.u.verifier.data, c->verf, + sizeof(p->o_arg.u.verifier.data)); + } + } /* don't put an ACCESS op in OPEN compound if O_EXCL, because ACCESS * will return permission denied for all bits until close */ if (!(flags & O_EXCL)) { @@ -1270,7 +1280,6 @@ static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry, p->o_arg.server = server; p->o_arg.bitmask = nfs4_bitmask(server, label); p->o_arg.open_bitmap = &nfs4_fattr_bitmap[0]; - p->o_arg.label = nfs4_label_copy(p->a_label, label); switch (p->o_arg.claim) { case NFS4_OPEN_CLAIM_NULL: case NFS4_OPEN_CLAIM_DELEGATE_CUR: @@ -1283,13 +1292,6 @@ 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 (c != NULL && c->sattr != NULL && c->sattr->ia_valid != 0) { - p->o_arg.u.attrs = &p->attrs; - memcpy(&p->attrs, c->sattr, sizeof(p->attrs)); - - memcpy(p->o_arg.u.verifier.data, c->verf, - sizeof(p->o_arg.u.verifier.data)); - } p->c_arg.fh = &p->o_res.fh; p->c_arg.stateid = &p->o_res.stateid; p->c_arg.seqid = p->o_arg.seqid; -- 2.20.1