Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp6550471ybx; Mon, 11 Nov 2019 10:48:05 -0800 (PST) X-Google-Smtp-Source: APXvYqzzN2NAybQ2n4D6xYWKaBNDeOmW42zU/ukq3m3o214CWdAwb0yeTaLxgbDrX9S0+R5x+wwl X-Received: by 2002:a50:9fc1:: with SMTP id c59mr28658476edf.305.1573498085841; Mon, 11 Nov 2019 10:48:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573498085; cv=none; d=google.com; s=arc-20160816; b=DcKU+glqn9NHbyjGdJO+AGV1yZRj608ioVzgvzoRYRtkDYGmQGLcXge9R7Qu/mykeE o0oE42gaSBTtMX2XOuBAS4fY76iM6M1MUt6UUK85sKukuffRm4JzmUuCqUOb7yPqDdaj MrgRQKFEkQIgNMhh3vHjYv5+Wkd2wwGyKPCwflKrec/8Lk+eE+GvgG9K1QEHyILODCQ6 lZG/ffiNfIBu2BBOHNNemDFTCcRmVvChEH1Zp+YKDWFLHFW6vYeDiEjmbmqzWnmEAr45 iPTFoC9p5mhwIbcJOY0yYp84iWLZ7el+kio+kN6tj1FzeZYh24bIu2kwYwCAD3Em2XhP KFDQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=v4D+3tZu18p1rHLxteYjSTbDYE21esHAYNVniFSMmAU=; b=VSY3NN9dAu7w1qPn0QkJEmOSRMg2gwIAYkprcPeqF54i2Wp3PJk6buz+u6BtN9izR1 TUioei712TAHyCmaRw6H3EWSGgasNpWppJEsHVvhh6lLz8sYb54zOv8405WwWFwO0RC7 CQWfbqWk8Lq7rDbmWAfNhFAKCP3ZhL/xjm8JATmtDAFbgnc61T7DKiIzjFKyGspaF3xo BMdGSBFWbWDf6qiLZszAOo1vNwqs/NQuuYLl1lbZZsA57f2LV3p7URTbh0FdT6FCMAUx Oe7wA+cmQFMXkAUy2nUB5foUaS1sf2W1A8eA9HTOk/F0i89uUX2sV8C8lqMHVP0rjEo8 ZugQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=XJafm2i+; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z33si11537121edb.183.2019.11.11.10.47.41; Mon, 11 Nov 2019 10:48:05 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=XJafm2i+; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730000AbfKKSq2 (ORCPT + 99 others); Mon, 11 Nov 2019 13:46:28 -0500 Received: from mail.kernel.org ([198.145.29.99]:38896 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729996AbfKKSqZ (ORCPT ); Mon, 11 Nov 2019 13:46:25 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 170D021925; Mon, 11 Nov 2019 18:46:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1573497984; bh=qoJBrkv55Yvx3fUS2dlYaAZ2YK1eLNgX8mG9LyfTzr8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XJafm2i+4gq5Hvf3oxvQEM64ijF8+HI01m8aKxxMiS7HF7D3wqoYPbF4YfUL80cj9 MbW8QIOtM8crO0l0AWKOnpUzTOdqQwz/kZ9fWVgglpugWGvC/P0UwNHF3mbB+jjt0Q IaJbXIWIGTLm34jDrOou9lXZxspN9FFaq7eKzBtU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Trond Myklebust , Anna Schumaker , Sasha Levin Subject: [PATCH 4.19 114/125] NFSv4: Dont allow a cached open with a revoked delegation Date: Mon, 11 Nov 2019 19:29:13 +0100 Message-Id: <20191111181455.122357586@linuxfoundation.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191111181438.945353076@linuxfoundation.org> References: <20191111181438.945353076@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Trond Myklebust [ Upstream commit be3df3dd4c70ee020587a943a31b98a0fb4b6424 ] If the delegation is marked as being revoked, we must not use it for cached opens. Fixes: 869f9dfa4d6d ("NFSv4: Fix races between nfs_remove_bad_delegation() and delegation return") Signed-off-by: Trond Myklebust Signed-off-by: Anna Schumaker Signed-off-by: Sasha Levin --- fs/nfs/delegation.c | 10 ++++++++++ fs/nfs/delegation.h | 1 + fs/nfs/nfs4proc.c | 7 ++----- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/fs/nfs/delegation.c b/fs/nfs/delegation.c index 825a8c52165a2..c5c3394148f72 100644 --- a/fs/nfs/delegation.c +++ b/fs/nfs/delegation.c @@ -54,6 +54,16 @@ nfs4_is_valid_delegation(const struct nfs_delegation *delegation, return false; } +struct nfs_delegation *nfs4_get_valid_delegation(const struct inode *inode) +{ + struct nfs_delegation *delegation; + + delegation = rcu_dereference(NFS_I(inode)->delegation); + if (nfs4_is_valid_delegation(delegation, 0)) + return delegation; + return NULL; +} + static int nfs4_do_check_delegation(struct inode *inode, fmode_t flags, bool mark) { diff --git a/fs/nfs/delegation.h b/fs/nfs/delegation.h index c95477823fa6b..dd0f3eed3890d 100644 --- a/fs/nfs/delegation.h +++ b/fs/nfs/delegation.h @@ -66,6 +66,7 @@ int nfs4_lock_delegation_recall(struct file_lock *fl, struct nfs4_state *state, bool nfs4_copy_delegation_stateid(struct inode *inode, fmode_t flags, nfs4_stateid *dst, struct rpc_cred **cred); bool nfs4_refresh_delegation_stateid(nfs4_stateid *dst, struct inode *inode); +struct nfs_delegation *nfs4_get_valid_delegation(const struct inode *inode); void nfs_mark_delegation_referenced(struct nfs_delegation *delegation); int nfs4_have_delegation(struct inode *inode, fmode_t flags); int nfs4_check_delegation(struct inode *inode, fmode_t flags); diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c index 75faef7af22d3..792f8821b5d6b 100644 --- a/fs/nfs/nfs4proc.c +++ b/fs/nfs/nfs4proc.c @@ -1393,8 +1393,6 @@ static int can_open_delegated(struct nfs_delegation *delegation, fmode_t fmode, return 0; if ((delegation->type & fmode) != fmode) return 0; - if (test_bit(NFS_DELEGATION_RETURNING, &delegation->flags)) - return 0; switch (claim) { case NFS4_OPEN_CLAIM_NULL: case NFS4_OPEN_CLAIM_FH: @@ -1751,7 +1749,6 @@ static void nfs4_return_incompatible_delegation(struct inode *inode, fmode_t fmo static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata) { struct nfs4_state *state = opendata->state; - struct nfs_inode *nfsi = NFS_I(state->inode); struct nfs_delegation *delegation; int open_mode = opendata->o_arg.open_flags; fmode_t fmode = opendata->o_arg.fmode; @@ -1768,7 +1765,7 @@ static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata) } spin_unlock(&state->owner->so_lock); rcu_read_lock(); - delegation = rcu_dereference(nfsi->delegation); + delegation = nfs4_get_valid_delegation(state->inode); if (!can_open_delegated(delegation, fmode, claim)) { rcu_read_unlock(); break; @@ -2293,7 +2290,7 @@ static void nfs4_open_prepare(struct rpc_task *task, void *calldata) data->o_arg.open_flags, claim)) goto out_no_action; rcu_read_lock(); - delegation = rcu_dereference(NFS_I(data->state->inode)->delegation); + delegation = nfs4_get_valid_delegation(data->state->inode); if (can_open_delegated(delegation, data->o_arg.fmode, claim)) goto unlock_no_action; rcu_read_unlock(); -- 2.20.1