Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp858919pxb; Tue, 1 Feb 2022 11:55:11 -0800 (PST) X-Google-Smtp-Source: ABdhPJwTW3Zept7MJo90Kt5YJqz45LUIT+MmhiXar1OVp9Xwq/69hTQHjfiVluQE3uwt4gIBaKU+ X-Received: by 2002:a05:6402:1910:: with SMTP id e16mr27055942edz.11.1643745311238; Tue, 01 Feb 2022 11:55:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643745311; cv=none; d=google.com; s=arc-20160816; b=lIcunutTTKMKtYwClikyhItSye9oTFZheiYc+7n7Y3HlvSuZlp7qxYU1FzayQtOL6t dqK0EXwGkF5ZnYp7GK5wYHynizVBTHhlD468xgVqYpkG1TMssf8419Z5OeFgAJ/qEPt0 ImJVHS2aU4ejgGLtKE8430sMH/Ccw+EmXQummEY+WB0XXKYl4F6ZXSvX5letTQxdqASu kHX4NqM63isN4er4Mki9h1+gmH0ur7yaXEAwG1uBk3LliD5fAIHcjd2hcIR73J94AlTw ILRFFS2iyotZ7vpv0f04ZNa8tlNWC7RrgodJL5qZjmfLZnlvbEUqYU+AcJAoWU8RGI6d /b/g== 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=+Coet0ru+r3zr9DCffxXE/XxWfFeDmYYjNOmOGzbxBQ=; b=S+earJdtN3ULD+GKhdbazeX8XAs7IRoH+zi7TmA9ZwA2hflA/i/kbiQmdUPZUNY0ch 4xv6UnbscW0/PfP4j4wjuWjI9jh0LF6ruBXfZ03okx94wn3IpO3HoFqsAUnpNm6JSDY8 PAnladOrghGCzXJGgILXTBJfuYFyC0Y2BYRb9jH9jw7MEASGprkd5ExuURl3MWAhMgvo fC/Mn7Ollp41UoYUfIvxbLB1EWtlNKpDlBWNNwCuRwUwG115QAvLbtcqY44r4ZCUT6eo lDRL9T8pxk5Cr5IlBGFigDzslnTNVMU+Qfv+v0419sMEdefO4QSSsJuv2K4QiqqV9CTn 1IDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="Kfqn8BU/"; 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 r4si9981993edy.369.2022.02.01.11.54.45; Tue, 01 Feb 2022 11:55:11 -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="Kfqn8BU/"; 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 S1359268AbiAaLEx (ORCPT + 99 others); Mon, 31 Jan 2022 06:04:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43302 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1359108AbiAaLC6 (ORCPT ); Mon, 31 Jan 2022 06:02:58 -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 3C6E8C061377; Mon, 31 Jan 2022 03:01:18 -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 D011260B2D; Mon, 31 Jan 2022 11:01:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AF0B7C340E8; Mon, 31 Jan 2022 11:01:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643626877; bh=AW09Hw0O0tjN//AzuiSh6wQwxIaj6bNbvICHTQHbuRw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Kfqn8BU/gXhBhL2qnZ43+Kloo9Dxp3Fqp8A+mycZIQwtXQ7wYM3tSNMItIgRNGhS5 IKzXzU4HhXTIrJK4zTIdCEbSjYF8o84ftJsLWr56J5hz7vtuZx9cjJp9BMht3ZxPQG BSBisKrvP7Hmh4AOYA/pJ9qQ8aBZMAphgAGdqTAs= 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.4 41/64] NFSv4: nfs_atomic_open() can race when looking up a non-regular file Date: Mon, 31 Jan 2022 11:56:26 +0100 Message-Id: <20220131105217.063133700@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220131105215.644174521@linuxfoundation.org> References: <20220131105215.644174521@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 @@ -1643,12 +1643,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) {