Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp849354ybi; Fri, 12 Jul 2019 05:40:34 -0700 (PDT) X-Google-Smtp-Source: APXvYqwX2gGeAw3jv46NLqmA3KGMT83P6Dz6fepUjZfiJiJzxOaPNBG4fo6d3SDkierEgyj+Kv6v X-Received: by 2002:a65:4507:: with SMTP id n7mr10258204pgq.86.1562935234297; Fri, 12 Jul 2019 05:40:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562935234; cv=none; d=google.com; s=arc-20160816; b=s5aqbTdW45ZyWN/6EicHQ5q0QoXqn+Kf1m1+lD2xmKzOt1S9b/qBDG0OaGv77f3hZw xP+D8Gtf6/jC3WggT0mprArGw9KEA3iJyV4wb8n8nSDYDpn4xM4MFHERki6EQ0s/eu7P pkxo8EARuZkQTvYohyBP8ZXwSh2Z0YVhMbW2lfa6Ew9uJnHA1PrTrxck1sHL9LEUAqHv zqvdvBZyQtmCUMkYayyQlylPMWJoObAA/Ki6tPL57kjYwlqMZnlQBsFAVsJm+18zBYeH jv+UaWq0mLL/+CYlvfVLDyuAJaK5iBvttSl+z7Vnfue/9qFsojnHWyVHab0D7pCdlRoy dgrA== 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=5dwoJIgHovstUEJi6lBCNk6tKT09sk1LDNffm5w+L2s=; b=kGZ4/1Sf0ddSBVKzKJT14AoopfRXQmEwVIYPCGtqtrJEY/wbCLvRptlJ4ifHavIMRw 6l9gaK33lijGrqnxZTP4DZSuZt8Nr8zUF5CdAqbIhhfrBm6kMp5LAzGxnlD63UO1Ah/4 weRgbqW8pXM1xSL6qvMWZyly/NAXb6AqTLnX+YcKu6nrWamnkfLYYBlnpSF048lQxVul D8am+0sqP0m6gQmv4u56zxa5+Pm5UYyzqYgXfKsm4mI1/7NbcDgJKNUWsHfaV9K0qr4r wfGNMN0xXoHnSpw8KP2TJFfQAB9tZHNo9/HxWkB0ONY1aZUOMty1WoAQOFGzxpuGp1iE 8ciQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=QDiwCvCC; 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 c7si8016856pjo.88.2019.07.12.05.40.18; Fri, 12 Jul 2019 05:40:34 -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=QDiwCvCC; 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 S1728468AbfGLMih (ORCPT + 99 others); Fri, 12 Jul 2019 08:38:37 -0400 Received: from mail.kernel.org ([198.145.29.99]:43270 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728886AbfGLM2w (ORCPT ); Fri, 12 Jul 2019 08:28:52 -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 C653A21019; Fri, 12 Jul 2019 12:28:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1562934531; bh=H6I2/ksPnVbn5p9q6Yu9BDSMuPFeLGvZrFTXPm23iHU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QDiwCvCCSvqjPhpAMYTHeXueHCp7rur69PL6OLZmwzmWp8LfTfrwZArLQ0+ZzU+LB 1aEHyJw990XA+CQ1KXMT0n3QFI9QkuamOeopEwOpZrenF4tZCCEPzXI9N/0E/TCYo9 rp1Cn+9GzaVispXgViki3Lz1TUb2sO2Qc5Ps/OM4= 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 5.1 087/138] NFS4: Only set creation opendata if O_CREAT Date: Fri, 12 Jul 2019 14:19:11 +0200 Message-Id: <20190712121632.082259484@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190712121628.731888964@linuxfoundation.org> References: <20190712121628.731888964@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 eeee100785a5..fd2c19eea647 100644 --- a/fs/nfs/nfs4proc.c +++ b/fs/nfs/nfs4proc.c @@ -1234,10 +1234,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)) { @@ -1261,7 +1271,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: @@ -1274,13 +1283,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