]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
NFS: nfs_find_open_context() may only select open files
authorTrond Myklebust <trond.myklebust@hammerspace.com>
Wed, 12 May 2021 03:41:10 +0000 (23:41 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 20 Jul 2021 14:02:15 +0000 (16:02 +0200)
[ Upstream commit e97bc66377bca097e1f3349ca18ca17f202ff659 ]

If a file has already been closed, then it should not be selected to
support further I/O.

Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
[Trond: Fix an invalid pointer deref reported by Colin Ian King]
Signed-off-by: Sasha Levin <sashal@kernel.org>
fs/nfs/inode.c
include/linux/nfs_fs.h

index ae8bc84e39fb399c6a3174fb311c5328a2d7235a..6b1f2bf65bee9dc288d29fc5a80ba2c753fc2eb1 100644 (file)
@@ -1079,6 +1079,7 @@ EXPORT_SYMBOL_GPL(nfs_inode_attach_open_context);
 void nfs_file_set_open_context(struct file *filp, struct nfs_open_context *ctx)
 {
        filp->private_data = get_nfs_open_context(ctx);
+       set_bit(NFS_CONTEXT_FILE_OPEN, &ctx->flags);
        if (list_empty(&ctx->list))
                nfs_inode_attach_open_context(ctx);
 }
@@ -1098,6 +1099,8 @@ struct nfs_open_context *nfs_find_open_context(struct inode *inode, const struct
                        continue;
                if ((pos->mode & (FMODE_READ|FMODE_WRITE)) != mode)
                        continue;
+               if (!test_bit(NFS_CONTEXT_FILE_OPEN, &pos->flags))
+                       continue;
                ctx = get_nfs_open_context(pos);
                if (ctx)
                        break;
@@ -1113,6 +1116,7 @@ void nfs_file_clear_open_context(struct file *filp)
        if (ctx) {
                struct inode *inode = d_inode(ctx->dentry);
 
+               clear_bit(NFS_CONTEXT_FILE_OPEN, &ctx->flags);
                /*
                 * We fatal error on write before. Try to writeback
                 * every page again.
index eadaabd18dc7d557765fdc99feb5a9426706a3a2..be9eadd23659e6a09e2336e5bfa33637ee70f9f9 100644 (file)
@@ -84,6 +84,7 @@ struct nfs_open_context {
 #define NFS_CONTEXT_RESEND_WRITES      (1)
 #define NFS_CONTEXT_BAD                        (2)
 #define NFS_CONTEXT_UNLOCK     (3)
+#define NFS_CONTEXT_FILE_OPEN          (4)
        int error;
 
        struct list_head list;