Implement file posix capabilities
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / fs / attr.c
index 97de946708781df074388be1da5e4f811872766a..ae58bd3f875f9c92c9599bacebbab85ebdf2c800 100644 (file)
--- a/fs/attr.c
+++ b/fs/attr.c
@@ -9,7 +9,6 @@
 #include <linux/time.h>
 #include <linux/mm.h>
 #include <linux/string.h>
-#include <linux/smp_lock.h>
 #include <linux/capability.h>
 #include <linux/fsnotify.h>
 #include <linux/fcntl.h>
@@ -43,7 +42,7 @@ int inode_change_ok(struct inode *inode, struct iattr *attr)
 
        /* Make sure a caller can chmod. */
        if (ia_valid & ATTR_MODE) {
-               if ((current->fsuid != inode->i_uid) && !capable(CAP_FOWNER))
+               if (!is_owner_or_cap(inode))
                        goto error;
                /* Also check the setgid bit! */
                if (!in_group_p((ia_valid & ATTR_GID) ? attr->ia_gid :
@@ -53,7 +52,7 @@ int inode_change_ok(struct inode *inode, struct iattr *attr)
 
        /* Check for setting the inode time. */
        if (ia_valid & (ATTR_MTIME_SET | ATTR_ATIME_SET)) {
-               if (current->fsuid != inode->i_uid && !capable(CAP_FOWNER))
+               if (!is_owner_or_cap(inode))
                        goto error;
        }
 fine:
@@ -117,6 +116,15 @@ int notify_change(struct dentry * dentry, struct iattr * attr)
                attr->ia_atime = now;
        if (!(ia_valid & ATTR_MTIME_SET))
                attr->ia_mtime = now;
+       if (ia_valid & ATTR_KILL_PRIV) {
+               attr->ia_valid &= ~ATTR_KILL_PRIV;
+               ia_valid &= ~ATTR_KILL_PRIV;
+               error = security_inode_need_killpriv(dentry);
+               if (error > 0)
+                       error = security_inode_killpriv(dentry);
+               if (error)
+                       return error;
+       }
        if (ia_valid & ATTR_KILL_SUID) {
                attr->ia_valid &= ~ATTR_KILL_SUID;
                if (mode & S_ISUID) {