From patchwork Thu Jul 10 14:25:43 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 4524291 Return-Path: X-Original-To: patchwork-linux-nfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 146D29F26C for ; Thu, 10 Jul 2014 14:25:51 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 182C5201EC for ; Thu, 10 Jul 2014 14:25:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C1CFF20179 for ; Thu, 10 Jul 2014 14:25:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751955AbaGJOZr (ORCPT ); Thu, 10 Jul 2014 10:25:47 -0400 Received: from mail-qa0-f43.google.com ([209.85.216.43]:64975 "EHLO mail-qa0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751813AbaGJOZr (ORCPT ); Thu, 10 Jul 2014 10:25:47 -0400 Received: by mail-qa0-f43.google.com with SMTP id w8so332664qac.30 for ; Thu, 10 Jul 2014 07:25:46 -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:cc:subject:date:message-id; bh=aStCQUYOXROOdf2MMrAdJC8bzYbBHk8G/ANTZSccTL4=; b=HDPyjCp3kTDf8UQiIaynT8Jo12LsXl93pO40ROlOFVqHM8D0Bvgn1HQs6EWD6RqI8Z Oy/026CMDq0xGvuLcEMs0i5/ov4CnKAqn9PZKFuiwrxbjFbxU0HG6guhzdMsFDEetD98 f+AQSvUbhSqjUO7p53Fs6BWCry3/IloLq3/ADAryNNO2yQ5wEvz2AqKw/x+k8S/h7Rx8 5EYQ286dtiuATGPAmTC+cztzGyE6TYFud3M8zxG3xE3JN/EhLmRAIxk6nFh4F1ZamjnV FBUIVF/JuauKHDWR6JEXAtGrmMGblhzaDhjM480SSID2jYJNafL6v6ETIwlDnKytNEIT BYCw== X-Gm-Message-State: ALoCoQmsnYfm9FOherlRANWBL06sYS+BpJ7QNQwmWhiuRQXFR/Bruu3tMpSbLkJsWcj7udWeFpun X-Received: by 10.224.55.202 with SMTP id v10mr82695703qag.10.1405002346273; Thu, 10 Jul 2014 07:25:46 -0700 (PDT) Received: from leira.trondhjem.org.localdomain (50-33-230-70.drr02.mskg.mi.frontiernet.net. [50.33.230.70]) by mx.google.com with ESMTPSA id k7sm49852463qas.24.2014.07.10.07.25.45 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 10 Jul 2014 07:25:45 -0700 (PDT) From: Trond Myklebust To: linux-nfs@vger.kernel.org Cc: "Frank S. Filz" Subject: [PATCH] NFSv4: Fix OPEN w/create access mode checking Date: Thu, 10 Jul 2014 10:25:43 -0400 Message-Id: <1405002343-15802-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=-7.6 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 POSIX states that open("foo", O_CREAT|O_RDONLY, 000) should succeed if the file "foo" does not already exist. With the current NFS client, it will fail with an EACCES error because of the permissions checks in nfs4_opendata_access(). Fix is to turn that test off if the server says that we created the file. Reported-by: "Frank S. Filz" Signed-off-by: Trond Myklebust --- fs/nfs/nfs4proc.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c index d0e0e54fb2b9..70e53a2ac75e 100644 --- a/fs/nfs/nfs4proc.c +++ b/fs/nfs/nfs4proc.c @@ -1954,6 +1954,14 @@ static int _nfs4_recover_proc_open(struct nfs4_opendata *data) return status; } +/* + * Additional permission checks in order to distinguish between an + * open for read, and an open for execute. This works around the + * fact that NFSv4 OPEN treats read and execute permissions as being + * the same. + * Note that in the non-execute case, we want to turn off permission + * checking if we just created a new file (POSIX open() semantics). + */ static int nfs4_opendata_access(struct rpc_cred *cred, struct nfs4_opendata *opendata, struct nfs4_state *state, fmode_t fmode, @@ -1968,14 +1976,14 @@ static int nfs4_opendata_access(struct rpc_cred *cred, return 0; mask = 0; - /* don't check MAY_WRITE - a newly created file may not have - * write mode bits, but POSIX allows the creating process to write. - * use openflags to check for exec, because fmode won't - * always have FMODE_EXEC set when file open for exec. */ + /* + * Use openflags to check for exec, because fmode won't + * always have FMODE_EXEC set when file open for exec. + */ if (openflags & __FMODE_EXEC) { /* ONLY check for exec rights */ mask = MAY_EXEC; - } else if (fmode & FMODE_READ) + } else if ((fmode & FMODE_READ) && !opendata->file_created) mask = MAY_READ; cache.cred = cred;