vfs: deny fallocate() on directory
authorAmir Goldstein <amir73il@gmail.com>
Tue, 31 Jan 2017 08:34:55 +0000 (10:34 +0200)
committerMiklos Szeredi <mszeredi@redhat.com>
Tue, 7 Feb 2017 14:05:04 +0000 (15:05 +0100)
There was an obscure use case of fallocate of directory inode
in the vfs helper with the comment:
"Let individual file system decide if it supports preallocation
 for directories or not."

But there is no in-tree file system that implements fallocate
for directory operations.

Deny an attempt to fallocate a directory with EISDIR error.

This change is needed prior to converting sb_start_write()
to  file_start_write(), so freeze protection is correctly
handled for cases of fallocate file and blockdev.

Cc: linux-api@vger.kernel.org
Cc: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
fs/open.c

index 9921f70bc5ca07dab62d19ff9fded8d4a60ae9f0..f9118f4113e7e4573697f8371381e6ceb50f6ff7 100644 (file)
--- a/fs/open.c
+++ b/fs/open.c
@@ -301,12 +301,10 @@ int vfs_fallocate(struct file *file, int mode, loff_t offset, loff_t len)
        if (S_ISFIFO(inode->i_mode))
                return -ESPIPE;
 
-       /*
-        * Let individual file system decide if it supports preallocation
-        * for directories or not.
-        */
-       if (!S_ISREG(inode->i_mode) && !S_ISDIR(inode->i_mode) &&
-           !S_ISBLK(inode->i_mode))
+       if (S_ISDIR(inode->i_mode))
+               return -EISDIR;
+
+       if (!S_ISREG(inode->i_mode) && !S_ISBLK(inode->i_mode))
                return -ENODEV;
 
        /* Check for wrap through zero too */