ANDROID: sdcardfs: Hold i_mutex for i_size_write
authorDaniel Rosenberg <drosen@google.com>
Wed, 21 Feb 2018 04:25:45 +0000 (20:25 -0800)
committerStricted <info@stricted.net>
Thu, 11 Oct 2018 16:03:48 +0000 (18:03 +0200)
When we call i_size_write, we must be holding i_mutex to avoid
possible lockups on 32 bit/SMP architectures. This is not
necessary on 64 bit architectures.

Change-Id: Ic3b946507c54d81b5c9046f9b57d25d4b0f9feef
Signed-off-by: Daniel Rosenberg <drosen@google.com>
Bug: 73287721

fs/sdcardfs/file.c

index c560360f25c07dd0c09d0eb10778cb571f6a199d..72338cc3d322c672c9a1586a27700d06b1c3538f 100644 (file)
@@ -62,6 +62,7 @@ static ssize_t sdcardfs_write(struct file *file, const char __user *buf,
        int err = 0;
        struct file *lower_file;
        struct dentry *dentry = file->f_path.dentry;
+       struct inode *inode = dentry->d_inode;
 
        /* check disk space */
        if (!check_min_free_space(dentry, count, 0)) {
@@ -73,10 +74,12 @@ static ssize_t sdcardfs_write(struct file *file, const char __user *buf,
        err = vfs_write(lower_file, buf, count, ppos);
        /* update our inode times+sizes upon a successful lower write */
        if (err >= 0) {
-               fsstack_copy_inode_size(dentry->d_inode,
-                                       lower_file->f_path.dentry->d_inode);
-               fsstack_copy_attr_times(dentry->d_inode,
-                                       lower_file->f_path.dentry->d_inode);
+               if (sizeof(loff_t) > sizeof(long))
+                       mutex_lock(&inode->i_mutex);
+               fsstack_copy_inode_size(inode, file_inode(lower_file));
+               fsstack_copy_attr_times(inode, file_inode(lower_file));
+               if (sizeof(loff_t) > sizeof(long))
+                       mutex_unlock(&inode->i_mutex);
        }
 
        return err;