Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp1681358pxb; Wed, 9 Feb 2022 02:03:20 -0800 (PST) X-Google-Smtp-Source: ABdhPJzkRihBXK3VwSVLeeksDxfMprBr2FaaLoqjkaiXPCIjmF3doRjw+T4ZFtv7+rcbpJHpjzjG X-Received: by 2002:a62:80d3:: with SMTP id j202mr1427194pfd.20.1644400999834; Wed, 09 Feb 2022 02:03:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644400999; cv=none; d=google.com; s=arc-20160816; b=gvQA/EX6o6aMlmrQdXkwUka/HvsBC36UmZgXUwZ/hH/03QJE+P/jPjG8PKNDDUR+OC 4LyZ8cpmfJtsGeuk2e7OGyffiuJ3ebXVbOtSUS1mx0rq+Z2BgTPy0+dBmqJ0Uw/+s6wY a2fEcf4sthLMj7YWjZRjizZq2/+7acCnINL1XxQgS4CWmrVGmUKVWjyrj6D2Z6/0ZNlq H8Uxgf+3YBXYAZLGc6gabQnJ5BWz52bmggffKD4u/vVUzgNlNtQ2D6JsUZhR9KW1eB6r mJVHiSwfrKdYxi9SIromu1mOV3hvO6OsndHhe3n+7/1JjW+uN2dnZEbwMhYEcW0ROqej w14Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=B9g3R6qfAVJ/0I3LpBNOobO/SHDbxcEu73iwG7l+/mc=; b=sWd7T+c8B3aQGVWq0tQwb6U4ejcSYxdLIm5sj5HvwscTG9mtzqYaJcC9OUWQN7oKz+ SeMtyiHmAaaYPF4Lh0+ykeHgbTL/LFMlA+6/gndjmL3bcVMC+gDYeaObMuBZ4+GbJUeQ tY0RBa9Own+jdWABg8Fax9fvucBmdbn0L+KaWumXbTYxftpY4juuMHqpxuHeTqYXHbu2 XQmGXR241k1P+nstEwOFY0JERXhiQWHvgUxxKY/E94hiJW1MLDtX6QYhgfiHXTE8chPc N/Gw7XQLmSLFOOe3jZZdDHsUu/9HBi10iqwLFEEg4CPQsxPhl5n+CYZEN1YobnmvvbYm PJ4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ZteLBP58; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z17si15475769pfh.116.2022.02.09.02.03.06; Wed, 09 Feb 2022 02:03:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ZteLBP58; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1382627AbiBGLU0 (ORCPT + 99 others); Mon, 7 Feb 2022 06:20:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53568 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377570AbiBGLPc (ORCPT ); Mon, 7 Feb 2022 06:15:32 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AC455C03FEC0; Mon, 7 Feb 2022 03:15:10 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id F312561411; Mon, 7 Feb 2022 11:15:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C9738C004E1; Mon, 7 Feb 2022 11:15:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1644232509; bh=M0cMgKneMQEtkHPYz2TR3UDX4EWd6irIUp+5etFqrs8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZteLBP58wbhY+lnkemJLQbJhew0TAB9fjkadR5A2g4+GQC/752oWx/WcqnfYPysyE iedAmF54JmfC0beAMi41s0t95vCSfx8at6dvmI+yPwZSngrcjjuU4NLLUMpq5VxUA3 EkX2k3TjjYX+Ixct7DlJupdQpN9PvY3NDo+GahGc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Trond Myklebust , Anna Schumaker Subject: [PATCH 4.19 33/86] NFSv4: nfs_atomic_open() can race when looking up a non-regular file Date: Mon, 7 Feb 2022 12:05:56 +0100 Message-Id: <20220207103758.620906929@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220207103757.550973048@linuxfoundation.org> References: <20220207103757.550973048@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Trond Myklebust commit 1751fc1db36f6f411709e143d5393f92d12137a9 upstream. If the file type changes back to being a regular file on the server between the failed OPEN and our LOOKUP, then we need to re-run the OPEN. Fixes: 0dd2b474d0b6 ("nfs: implement i_op->atomic_open()") Signed-off-by: Trond Myklebust Signed-off-by: Anna Schumaker Signed-off-by: Greg Kroah-Hartman --- fs/nfs/dir.c | 5 +++++ 1 file changed, 5 insertions(+) --- a/fs/nfs/dir.c +++ b/fs/nfs/dir.c @@ -1631,12 +1631,17 @@ no_open: if ((lookup_flags & LOOKUP_DIRECTORY) && inode && !S_ISDIR(inode->i_mode)) res = ERR_PTR(-ENOTDIR); + else if (inode && S_ISREG(inode->i_mode)) + res = ERR_PTR(-EOPENSTALE); } else if (!IS_ERR(res)) { inode = d_inode(res); if ((lookup_flags & LOOKUP_DIRECTORY) && inode && !S_ISDIR(inode->i_mode)) { dput(res); res = ERR_PTR(-ENOTDIR); + } else if (inode && S_ISREG(inode->i_mode)) { + dput(res); + res = ERR_PTR(-EOPENSTALE); } } if (switched) {