drm/radeon: fix DP audio support for APU with DCE4.1 display engine
[firefly-linux-kernel-4.4.55.git] / fs / overlayfs / inode.c
index ec0c2a050043afbb3eff4c7451930dc6d86006ec..b29036aa8d7c073c2944350f5c6d105ffa4bc6df 100644 (file)
@@ -12,8 +12,7 @@
 #include <linux/xattr.h>
 #include "overlayfs.h"
 
-static int ovl_copy_up_last(struct dentry *dentry, struct iattr *attr,
-                           bool no_data)
+static int ovl_copy_up_truncate(struct dentry *dentry)
 {
        int err;
        struct dentry *parent;
@@ -30,10 +29,8 @@ static int ovl_copy_up_last(struct dentry *dentry, struct iattr *attr,
        if (err)
                goto out_dput_parent;
 
-       if (no_data)
-               stat.size = 0;
-
-       err = ovl_copy_up_one(parent, dentry, &lowerpath, &stat, attr);
+       stat.size = 0;
+       err = ovl_copy_up_one(parent, dentry, &lowerpath, &stat);
 
 out_dput_parent:
        dput(parent);
@@ -45,17 +42,30 @@ int ovl_setattr(struct dentry *dentry, struct iattr *attr)
        int err;
        struct dentry *upperdentry;
 
+       /*
+        * Check for permissions before trying to copy-up.  This is redundant
+        * since it will be rechecked later by ->setattr() on upper dentry.  But
+        * without this, copy-up can be triggered by just about anybody.
+        *
+        * We don't initialize inode->size, which just means that
+        * inode_newsize_ok() will always check against MAX_LFS_FILESIZE and not
+        * check for a swapfile (which this won't be anyway).
+        */
+       err = inode_change_ok(dentry->d_inode, attr);
+       if (err)
+               return err;
+
        err = ovl_want_write(dentry);
        if (err)
                goto out;
 
-       upperdentry = ovl_dentry_upper(dentry);
-       if (upperdentry) {
+       err = ovl_copy_up(dentry);
+       if (!err) {
+               upperdentry = ovl_dentry_upper(dentry);
+
                mutex_lock(&upperdentry->d_inode->i_mutex);
                err = notify_change(upperdentry, attr, NULL);
                mutex_unlock(&upperdentry->d_inode->i_mutex);
-       } else {
-               err = ovl_copy_up_last(dentry, attr, false);
        }
        ovl_drop_write(dentry);
 out:
@@ -353,7 +363,7 @@ struct inode *ovl_d_select_inode(struct dentry *dentry, unsigned file_flags)
                        return ERR_PTR(err);
 
                if (file_flags & O_TRUNC)
-                       err = ovl_copy_up_last(dentry, NULL, true);
+                       err = ovl_copy_up_truncate(dentry);
                else
                        err = ovl_copy_up(dentry);
                ovl_drop_write(dentry);