From patchwork Tue Oct 27 13:53:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 307442 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A34E8C83014 for ; Tue, 27 Oct 2020 15:56:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6D3E9204EF for ; Tue, 27 Oct 2020 15:56:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603814199; bh=89eOMXG00ZpTuYUlULtwbjR6X+WEBo4UU7NKkhxzjE4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=L1KyTZe8FBjZNDlE6xmoj0ZzeDGuqhM+VrZSuD9x91jrkBNih9hjE+xc1P50TDLsI Glv5h37AHDLrHM8cLIlOdhQanqupWE2/q/HRjRWcSO6j+0WHUPDwINonPJEhY9n+xM F7EC0ywpM5D5d9jL2P3WTmiCqXvySckYIHmhPF0w= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1802666AbgJ0Pup (ORCPT ); Tue, 27 Oct 2020 11:50:45 -0400 Received: from mail.kernel.org ([198.145.29.99]:35568 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1801732AbgJ0PnQ (ORCPT ); Tue, 27 Oct 2020 11:43:16 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 8FAFE22202; Tue, 27 Oct 2020 15:43:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603813396; bh=89eOMXG00ZpTuYUlULtwbjR6X+WEBo4UU7NKkhxzjE4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=yr9OQbm4Xaj63v8gXHbPwDocs0X4qN3edWLi1X2AqRa+ALQgBhKBkd9RpTtPrEvb+ HpRDbQ7dOkej5jlnJK4vbX3URr1d/tgcG6lpT5xC3xQqVXxJCSPy+Jm6XXYW8OvH8X RaZ1SlOYRJSzPS854CPDLQN0Pw1Q9zoPXu4LoWmo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Chuck Lever , "J. Bruce Fields" , Sasha Levin Subject: [PATCH 5.9 536/757] nfsd: Cache R, RW, and W opens separately Date: Tue, 27 Oct 2020 14:53:06 +0100 Message-Id: <20201027135515.642163638@linuxfoundation.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201027135450.497324313@linuxfoundation.org> References: <20201027135450.497324313@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: J. Bruce Fields [ Upstream commit ae3c57b5ca47665dc3416447a5534a9796096d86 ] The nfsd open code has always kept separate read-only, read-write, and write-only opens as necessary to ensure that when a client closes or downgrades, we don't retain more access than necessary. Also, I didn't realize the cache behaved this way when I wrote 94415b06eb8a "nfsd4: a client's own opens needn't prevent delegations". There I assumed fi_fds[O_WRONLY] and fi_fds[O_RDWR] would always be distinct. The violation of that assumption is triggering a WARN_ON_ONCE() and could also cause the server to give out a delegation when it shouldn't. Fixes: 94415b06eb8a ("nfsd4: a client's own opens needn't prevent delegations") Tested-by: Chuck Lever Signed-off-by: J. Bruce Fields Signed-off-by: Sasha Levin --- fs/nfsd/filecache.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/nfsd/filecache.c b/fs/nfsd/filecache.c index c8b9d2667ee6f..3c6c2f7d1688b 100644 --- a/fs/nfsd/filecache.c +++ b/fs/nfsd/filecache.c @@ -889,7 +889,7 @@ nfsd_file_find_locked(struct inode *inode, unsigned int may_flags, hlist_for_each_entry_rcu(nf, &nfsd_file_hashtbl[hashval].nfb_head, nf_node, lockdep_is_held(&nfsd_file_hashtbl[hashval].nfb_lock)) { - if ((need & nf->nf_may) != need) + if (nf->nf_may != need) continue; if (nf->nf_inode != inode) continue;