Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp860287pxb; Tue, 1 Feb 2022 11:57:28 -0800 (PST) X-Google-Smtp-Source: ABdhPJyhsw7225pVp1WMidNEiKRvIVrHMDVMu1h6rHxxNKXRETV2TpXF7If/tHne39M5ikq+pugT X-Received: by 2002:a17:906:c110:: with SMTP id do16mr21816936ejc.175.1643745448545; Tue, 01 Feb 2022 11:57:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643745448; cv=none; d=google.com; s=arc-20160816; b=rWBoK9pS3vvhqgJ/7SBB8vatBlpSxUWcD2jWe9fqSGcsX8kTpqo573tiZ8pKeTJIs/ zrtm0VSGPDfLp4W486zfggkWTdEPmwPFa+rVqimvNcwCgYont5iW9fXBbu8NIWSCNt5W Voz5AEqCVfs9M43cPkFQg9C97zzhox52t08XuDo9uMme/zLxO9Ov2gtkBG3vPrscscu4 phFNu8dbppInnUJr2NY4IJilFbuyPuj5AoWh7ZJ1kMirlMnyc8IC2aqSWbjSF7X53+sz oQ4Bxg/s5FEJBQaMBX6dtBXM9SiepV5tA7JXbwsSe4kfg+HFt2wMbepxx5xWOtY1eb4V q80A== 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=0ELGAseHmczLHmUtyulQ0jq/MacS6wfQyCWzyo3X+bY=; b=AEx8isa84PG8m3Wmjho2b09qvCe3T/Bp8zUpbAC5GH+Gc5OdIpqJbQV9rmp7GsfzRo IV0xJqtjDBbZdgh29zNICpgDXxNDO8ehJJ26tfMQoIPeCN/lNx6cKfib2X+ikuNDiPyp tFWm12hjEKylyRSkBtkJkxWgKL2uUOpdgbxQTV4WubSumC5eX7ajpSzaMijd62BZliYw imlIpxDcxB/OXOLxmAtpiCuZrzfk8APp+7Ff9W1zjobgL5315Xn5dhy927NRDlOXrrt9 nabhHWeFfqBk0h3bAbKM2yXi2dIaPP00MPNtTcso9Hvnoh2N4wGDwEm79QtPsYw8onUT pfJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=WdeOiLlU; 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 w6si12647628edu.367.2022.02.01.11.57.03; Tue, 01 Feb 2022 11:57:28 -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=WdeOiLlU; 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 S1358643AbiAaLE4 (ORCPT + 99 others); Mon, 31 Jan 2022 06:04:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42960 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1359103AbiAaLC6 (ORCPT ); Mon, 31 Jan 2022 06:02:58 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A8439C0613E3; Mon, 31 Jan 2022 03:01:15 -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 ams.source.kernel.org (Postfix) with ESMTPS id 4FCEEB82A57; Mon, 31 Jan 2022 11:01:15 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7C041C340EE; Mon, 31 Jan 2022 11:01:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643626874; bh=rpnftBRACWes5GtqEEFzPZ2+KGvGlU+bFKluK1c0RuM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WdeOiLlUbtcRGR1TJYkAyzlCZIghD5cdG1USbTygcxr+NLk8ptxP1WAG2yxvE4NEn CytheCYirY821//AelZgWFO23aBEKn/QYVj+wpD0ZLVCdog1/OfYyjbEEW0Uf/l45h sBbzpK4K8ilHaULhE8TvH81usAhtnlgNKfmeOc2w= 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.4 40/64] NFSv4: Handle case where the lookup of a directory fails Date: Mon, 31 Jan 2022 11:56:25 +0100 Message-Id: <20220131105217.032432494@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 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 @@ -1638,6 +1638,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)