Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp861051pxb; Tue, 1 Feb 2022 11:58:44 -0800 (PST) X-Google-Smtp-Source: ABdhPJwtnYsc9YhPbMPLjSf/pE+4tmCorWU/ojaG9xL5qQEgbO4S1hbnHGKxrY8QJvSA7cgU8rTE X-Received: by 2002:a17:90a:de98:: with SMTP id n24mr4184626pjv.87.1643745524183; Tue, 01 Feb 2022 11:58:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643745524; cv=none; d=google.com; s=arc-20160816; b=U9aqxMxpjJ5qSNj/fZ2SnH2J2eMKYgfLV0R4IncFtd74joH3+DGyrXyvrotwJsKoFV iEYJ8d1600KK1guZANqQa/hsEAktaLYOEByhVvHs556l653lmGNbDsJOvE3vhCu/7/3Q GJJawfm01bFXfKNT3akJuE5rE6DhwNjKNaq3QcF28LNxuaY78wrmCemQvIoGQUIkkftl LOEu5FTxaaZQTx9OFTyPsTBX8Cqz1hNoo38sANjvx7aN6b4O3sxurECTE1QYGm4naG5x P0dS+mi3WsLWd/crf25Ox67B7oys/i4tCoKhLNXgnX4dmuAGoJEZm0uPHwUGVueW6z6w vQ8g== 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=egP8tNlbQydgnfYan+ih8ejBSSgBZN0/Jhxg2V/9TNI=; b=SkFTZyha9BlSyrbzpBXSZQYAg1THinKdpphPii9CrP6f5uXuLhgcqpGMqBYtE0TPq+ zFTwIyc0inhQ2cm0TrtaVWW2PsxOR47CUMHFuXljLaAAaatH4Tga2TdAKHYnp4cY3GiM ZSlOFP+GRy2xvPPJNuLu1WrTG7jvgPjDq9h2kQi+GUMkxQGXzKGBemz+UIH+ISUdmvkp nSbI/x2KAW03CKje3yfUs0H6cN9gUhsq8BQDIBI6dVmTXbkce3OKK6psLIY4Hc/+bMWo Oj7Y8OO0GfLr7ezQ10m/vY/rv2UMQQTgAwNem2VkpDtgwy1UX7NC5RfM+tfA6AOBnA3e Cjuw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=CnVyRhCg; 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 u3si19036989plg.68.2022.02.01.11.58.32; Tue, 01 Feb 2022 11:58:44 -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=CnVyRhCg; 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 S1359371AbiAaLHc (ORCPT + 99 others); Mon, 31 Jan 2022 06:07:32 -0500 Received: from dfw.source.kernel.org ([139.178.84.217]:38682 "EHLO dfw.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1359001AbiAaLEM (ORCPT ); Mon, 31 Jan 2022 06:04:12 -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 dfw.source.kernel.org (Postfix) with ESMTPS id D7E5060B98; Mon, 31 Jan 2022 11:04:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A04F3C340E8; Mon, 31 Jan 2022 11:04:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643627051; bh=COVT00Ds8BHWKWCGWI3NHPctY/Se/QhM+ZCvt+pvWIY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CnVyRhCgmRJIZh1BWzQ25cF2x1JgyYTRPdx6MrL4t7Bn2EV6s5JcKgyeGFsFFpIqo Pxcl931IounFC9aVatsSmFVT/Bsxx1H4/WE2oxaNXu/Msbr64UvnzYc6ncudXxnQen 6xu0gKr+Sn+b/CK+55mqYFZHJhx6JO8TojJFL23o= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lyu Tao , Trond Myklebust , Anna Schumaker Subject: [PATCH 5.10 059/100] NFSv4: Handle case where the lookup of a directory fails Date: Mon, 31 Jan 2022 11:56:20 +0100 Message-Id: <20220131105222.419819274@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 ac795161c93699d600db16c1a8cc23a65a1eceaf upstream. If the application sets the O_DIRECTORY flag, and tries to open a regular file, nfs_atomic_open() will punt to doing a regular lookup. If the server then returns a regular file, we will happily return a file descriptor with uninitialised open state. The fix is to return the expected ENOTDIR error in these cases. Reported-by: Lyu Tao 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 | 13 +++++++++++++ 1 file changed, 13 insertions(+) --- a/fs/nfs/dir.c +++ b/fs/nfs/dir.c @@ -1777,6 +1777,19 @@ out: no_open: res = nfs_lookup(dir, dentry, lookup_flags); + if (!res) { + inode = d_inode(dentry); + if ((lookup_flags & LOOKUP_DIRECTORY) && inode && + !S_ISDIR(inode->i_mode)) + res = ERR_PTR(-ENOTDIR); + } 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); + } + } if (switched) { d_lookup_done(dentry); if (!res)