From patchwork Tue Aug 26 02:46:31 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 4777521 Return-Path: X-Original-To: patchwork-linux-nfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 19122C0338 for ; Tue, 26 Aug 2014 02:46:35 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 14DD3201D3 for ; Tue, 26 Aug 2014 02:46:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 27FA72016C for ; Tue, 26 Aug 2014 02:46:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756991AbaHZCqc (ORCPT ); Mon, 25 Aug 2014 22:46:32 -0400 Received: from mail-ie0-f176.google.com ([209.85.223.176]:35463 "EHLO mail-ie0-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755379AbaHZCqb (ORCPT ); Mon, 25 Aug 2014 22:46:31 -0400 Received: by mail-ie0-f176.google.com with SMTP id tr6so10875588ieb.21 for ; Mon, 25 Aug 2014 19:46:30 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id; bh=uo/f5UJ180L1fiLkZlGeFhCfX66FpFCrgjPjBnkiPYg=; b=IUtmaQayzgn4OlqyKxUSGglQlyMsyrqsHo3MifZiYNmNhtQZr6ABttN1XxIToIowPg Q5fn3J/k+2/rkHojqTT6Q2yLSRLBnytXJeAnjbqTnSeNUYqLsF357vWTjXbpYkuYU/48 OyNbj7d6K+qKXZq7dgE4+o7N3TFGs/iGMqmiptttUd6hgYxQh7xRkQ7YMMDg2By+ncbI 0B/SW00SIAYLsgsyzFpG0bG3OsniwkLKDWSD/olnAqG6Hi8p+ibw+4aD2gcfqmQg/7JR 63gfW9DFLzgJObRT5K3V6dvy+C24lrpNC6yNLc2FuxQApFvbt5Qn1t6Fd16DCwUQfTtr Nudw== X-Gm-Message-State: ALoCoQke7Mb89K9oTmuQpk2bWTu5wzGpwven2JWXVwkQjHhwjtQ8raTsEY1Yh9oCMxvBPDvLiTXF X-Received: by 10.43.126.8 with SMTP id gu8mr131701icc.79.1409021190315; Mon, 25 Aug 2014 19:46:30 -0700 (PDT) Received: from leira.trondhjem.org.localdomain (50-108-91-78.adr01.mskg.mi.frontiernet.net. [50.108.91.78]) by mx.google.com with ESMTPSA id j4sm7533311igx.20.2014.08.25.19.46.29 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 25 Aug 2014 19:46:29 -0700 (PDT) From: Trond Myklebust To: linux-nfs@vger.kernel.org Subject: [PATCH 1/2] NFSv4: Fix problems with close in the presence of a delegation Date: Mon, 25 Aug 2014 22:46:31 -0400 Message-Id: <1409021192-12706-1-git-send-email-trond.myklebust@primarydata.com> X-Mailer: git-send-email 1.9.3 Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP In the presence of delegations, we can no longer assume that the state->n_rdwr, state->n_rdonly, state->n_wronly reflect the open stateid share mode, and so we need to need to calculate the initial value for calldata->arg.fmode using the state->flags. Fixes: 88069f77e1ac5 (NFSv41: Fix a potential state leakage when...) Cc: stable@vger.kernel.org # 2.6.33+ Signed-off-by: Trond Myklebust --- fs/nfs/nfs4proc.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c index 75ae8d22f067..caf838b4edbd 100644 --- a/fs/nfs/nfs4proc.c +++ b/fs/nfs/nfs4proc.c @@ -2601,6 +2601,7 @@ static void nfs4_close_prepare(struct rpc_task *task, void *data) struct nfs4_closedata *calldata = data; struct nfs4_state *state = calldata->state; struct inode *inode = calldata->inode; + bool is_rdonly, is_wronly, is_rdwr; int call_close = 0; dprintk("%s: begin!\n", __func__); @@ -2608,18 +2609,23 @@ static void nfs4_close_prepare(struct rpc_task *task, void *data) goto out_wait; task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE]; - calldata->arg.fmode = FMODE_READ|FMODE_WRITE; + calldata->arg.fmode = 0; spin_lock(&state->owner->so_lock); /* Calculate the change in open mode */ + is_rdwr = test_bit(NFS_O_RDWR_STATE, &state->flags); + is_rdonly = test_bit(NFS_O_RDONLY_STATE, &state->flags); + is_wronly = test_bit(NFS_O_WRONLY_STATE, &state->flags); + if (is_rdonly || is_rdwr) + calldata->arg.fmode |= FMODE_READ; + if (is_wronly || is_rdwr) + calldata->arg.fmode |= FMODE_WRITE; if (state->n_rdwr == 0) { if (state->n_rdonly == 0) { - call_close |= test_bit(NFS_O_RDONLY_STATE, &state->flags); - call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); + call_close |= is_rdonly || is_rdwr; calldata->arg.fmode &= ~FMODE_READ; } if (state->n_wronly == 0) { - call_close |= test_bit(NFS_O_WRONLY_STATE, &state->flags); - call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); + call_close |= is_wronly || is_rdwr; calldata->arg.fmode &= ~FMODE_WRITE; } }