Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp861141pxb; Tue, 1 Feb 2022 11:58:51 -0800 (PST) X-Google-Smtp-Source: ABdhPJzzdx8yFUGvCqFqufecdbdHJ+0hCwRN3d48EZtCk4yvE55SNg4FWeVkXIWarZgCxn4cN3Lg X-Received: by 2002:a63:87c3:: with SMTP id i186mr13340407pge.122.1643745531326; Tue, 01 Feb 2022 11:58:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643745531; cv=none; d=google.com; s=arc-20160816; b=OiVj6wHMVfQ2UCNnt3AZBuAe1REX1BRsycO3zioYFTyU+rtgcJl7+B1oYZp4CRDsCU AT1YvyPlqnHbvaSbD1CblaUJuOBuYn6ZwutN2CxTVEM6gPa7AOfW5nKmc2foHtpn9vXT Celld382dtNLI+HbgcwtQAMuQ8uogl7lDVoLJhJPbotRSUwEqE3hQEOh8dAkF67m9NXH KI1zqqtxaKpaEcBWd5RDZCkxAhj+Y/xA8bqwiBpVHmF4MLPga3KjMFDsjjrKRZ0k3RIp QYLvMEUY3kyoy5RsKiVLE7VFuAPdws/s7vXQrGfs5dMXwh4KrSpdXkCniaiYlkUX+0Lq I33Q== 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=WJkgUQGJDFcRySZNykRpJ2PPCQB96B/FFbziQ0oNcO0=; b=KIlz60HeWiBQcBkkgS3RcBL2HvpMWc7dGdh8N2ik8UrpPLMcNvwoel0SfJhTGu/Hm5 zs2p0oztjT8rQyaIWa1NtvU1W4hryV1KAQrBwDFOFDcJxT0w5pRoKLg/zk4qvYh9XZE4 VuJ5ETtAzNIPAgqnYCWCpBnSkfMv/qFa4t6RexEOJXYi5ElIkbSy3X/zU7z+2Pgls5Lc EntfcoTsgZXefs6w0lZDDH7h4eM8Ti/Bc8oD12xjo61sWdjzaJISTuzD7+GLPWVI1Y/u jxHYPdBRauUINrdPUorJhFLRPjKc30sbpCyUiQ5UDKhaqCXbYatJbt2/hdbwo5vDRqET 0O4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="rRZ/n3MB"; 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 y36si20598828pga.623.2022.02.01.11.58.40; Tue, 01 Feb 2022 11:58:51 -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="rRZ/n3MB"; 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 S1344451AbiAaLHi (ORCPT + 99 others); Mon, 31 Jan 2022 06:07:38 -0500 Received: from ams.source.kernel.org ([145.40.68.75]:52194 "EHLO ams.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1359032AbiAaLEQ (ORCPT ); Mon, 31 Jan 2022 06:04:16 -0500 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 ams.source.kernel.org (Postfix) with ESMTPS id AE016B82A68; Mon, 31 Jan 2022 11:04:15 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BB029C340E8; Mon, 31 Jan 2022 11:04:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643627054; bh=q2Z8elQyrGNjcKvyqzotXwhcSaZaD3Bj681ehZS/2Yg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rRZ/n3MBs/UzYYdiL56XlpJwKcbI04JdwApU1regGcDWWe8sybwpgzXYx+jYjFakv FnGhMVXrGg+HgDx34guoa852hJigodxVVy/fGpnkLj3KrUR+Kp0+VxcnULfpLfOfG7 /c6662DkYgFPdwBGwYiQmnhLOPQJOtbRhO24mb7s= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Trond Myklebust , Anna Schumaker Subject: [PATCH 5.10 060/100] NFSv4: nfs_atomic_open() can race when looking up a non-regular file Date: Mon, 31 Jan 2022 11:56:21 +0100 Message-Id: <20220131105222.450508252@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220131105220.424085452@linuxfoundation.org> References: <20220131105220.424085452@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 @@ -1782,12 +1782,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) {