NFSv4: Handle the special Linux file open access mode [Linux 4.4.187]

This Linux kernel change "NFSv4: Handle the special Linux file open access mode" is included in the Linux 4.4.187 release. This change is authored by Trond Myklebust <trond.myklebust [at] hammerspace.com> on Thu Jun 27 06:41:45 2019 -0400. The commit for this change in Linux stable tree is 68c5c3f (patch) which is from upstream commit 44942b4. The same Linux upstream change may have been applied to various maintained Linux releases and you can find all Linux releases containing changes from upstream 44942b4.

NFSv4: Handle the special Linux file open access mode

commit 44942b4e457beda00981f616402a1a791e8c616e upstream.

According to the open() manpage, Linux reserves the access mode 3
to mean "check for read and write permission on the file and return
a file descriptor that can't be used for reading or writing."

Currently, the NFSv4 code will ask the server to open the file,
and will use an incorrect share access mode of 0. Since it has
an incorrect share access mode, the client later forgets to send
a corresponding close, meaning it can leak stateids on the server.

Fixes: ce4ef7c0a8a05 ("NFS: Split out NFS v4 file operations")
Cc: [email protected] # 3.6+
Signed-off-by: Trond Myklebust <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>

There are 3 lines of Linux source code added/deleted in this change. Code changes to Linux kernel are as follows.

 fs/nfs/inode.c    | 1 +
 fs/nfs/nfs4file.c | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
index 668ac19..d25b55c 100644
--- a/fs/nfs/inode.c
+++ b/fs/nfs/inode.c
@@ -935,6 +935,7 @@ int nfs_open(struct inode *inode, struct file *filp)
    nfs_fscache_open_file(inode, filp);
    return 0;
 }
+EXPORT_SYMBOL_GPL(nfs_open);

 /*
  * This function is called whenever some part of NFS notices that
diff --git a/fs/nfs/nfs4file.c b/fs/nfs/nfs4file.c
index 679e003..d3e3761 100644
--- a/fs/nfs/nfs4file.c
+++ b/fs/nfs/nfs4file.c
@@ -49,7 +49,7 @@
        return err;

    if ((openflags & O_ACCMODE) == 3)
-       openflags--;
+       return nfs_open(inode, filp);

    /* We can't create new files here */
    openflags &= ~(O_CREAT|O_EXCL);

Leave a Reply

Your email address will not be published. Required fields are marked *