Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp1741110pxb; Wed, 9 Feb 2022 03:35:29 -0800 (PST) X-Google-Smtp-Source: ABdhPJxHQu8GVXnOA6oOImjGa8rY597IPgd0IPDOPkiKZpz/B/UkgBf3qFu1h0FGS7qnVUehlZBD X-Received: by 2002:a17:90b:4ac6:: with SMTP id mh6mr2081286pjb.138.1644406528998; Wed, 09 Feb 2022 03:35:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644406528; cv=none; d=google.com; s=arc-20160816; b=HY0paJl1694BA1kAoCc8Jt/POGcYaOHy/FwLlEuC6DQFbpNrqA3S8HyH26hRV104rh z/N8YNHol5+IcMqmX1AmtxaeHhGxhxONnUFai12QeSqbU+C5EXJRAr0mQAAq1uMFORS7 3MBzcN4NfdaIF44lufxsVwEH3jEdtC4d/VMihKkUNweu4yiSKenXaBRwu1ad/R4U2JM0 lqEl6CGVORMuXB55J7JhZfLCxaiPJkJPEMp03bN0QRkuvKurx87NRqRPGfgCg5oPEUBA 1OXCxoHCr/ZNH4IP6lWIKw+MeLiFq/lf6VTXP5KMKtfSq7tLWYLIAhklkpljkdNSbS2Y XYDg== 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=/XifzP5qv6/XDK+mtAooB6eRs/PorlhGxZFffz5X+Mw=; b=Rg6/5xjiIyXWocMNyK14uI5UCWs/qwm8joMgjFTHEGoiGQ07gmQZaj8kLlqEMxaMja o6CnHqm6DFj8lzzu5fr4ZuApYCcoiZ80/W51DGnbMGNCaCAUR1zX9ZK4oIAcKrPluRUQ LlVuQ7DeIa9GhQk3TLXx68uMFFyWtJ2IgS4S1buPjw74PodI+qPGnJQ2wPx0hwO9p/9D PywxTo9qSvXFeYrdi5+kpX14tzDPvzz0uvQavdyneAJkfH+Wz4gA3WzXRySD5lro/peR 6sTrlwNBG8ljnN6xATQ8/RIJ8OIXhQIYzV8yXt8OWHUiJS1c19WDjQVf2JlY44XhZ3Vz kvrA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Q0a17t8K; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id r19si2356503plr.17.2022.02.09.03.35.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Feb 2022 03:35:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Q0a17t8K; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id BBB41E07820F; Wed, 9 Feb 2022 01:54:02 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1357454AbiBGLUW (ORCPT + 99 others); Mon, 7 Feb 2022 06:20:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53584 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377482AbiBGLPa (ORCPT ); Mon, 7 Feb 2022 06:15:30 -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 A9325C03FEC4; Mon, 7 Feb 2022 03:15:07 -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 E6AEA6142D; Mon, 7 Feb 2022 11:15:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C4DB5C340F6; Mon, 7 Feb 2022 11:15:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1644232506; bh=G2GXwaG7VfYaeJ0AwilszI2RAd+XAFkHHjVYCZ5A+JA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Q0a17t8Kfe379omtsiuXEtBc7YejPFr3uIEG9vlQGiESfHeAY+mMp7vWAJFajl2bv ByJRjL7ABqUOmyyI10fanmjIewP9PWVEbHhyYk0c0aCfsL+p/HOb+Q2U83qs0hUWJf rLit0v8QSZG3GMG6sbdcCQLB+CPYYbCTiAVyg13Y= 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 4.19 32/86] NFSv4: Handle case where the lookup of a directory fails Date: Mon, 7 Feb 2022 12:05:55 +0100 Message-Id: <20220207103758.589658540@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=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 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 @@ -1626,6 +1626,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)