]> nv-tegra.nvidia Code Review - linux-2.6.git/blobdiff - fs/namei.c
Simplify exec_permission_lite() logic
[linux-2.6.git] / fs / namei.c
index f3c5b278895a0d3e0f23fe6fd474e2728a1c6cb6..8c3580610eec721d34bccd391d0cdf0f10d28626 100644 (file)
@@ -435,7 +435,7 @@ static int exec_permission_lite(struct inode *inode)
        umode_t mode = inode->i_mode;
 
        if (inode->i_op->permission)
-               return -EAGAIN;
+               return inode_permission(inode, MAY_EXEC);
 
        if (current_fsuid() == inode->i_uid)
                mode >>= 6;
@@ -853,12 +853,6 @@ static int __link_path_walk(const char *name, struct nameidata *nd)
 
                nd->flags |= LOOKUP_CONTINUE;
                err = exec_permission_lite(inode);
-               if (err == -EAGAIN)
-                       err = inode_permission(nd->path.dentry->d_inode,
-                                              MAY_EXEC);
-               if (!err)
-                       err = ima_path_check(&nd->path, MAY_EXEC,
-                                            IMA_COUNT_UPDATE);
                if (err)
                        break;
 
@@ -1542,28 +1536,31 @@ int may_open(struct path *path, int acc_mode, int flag)
         * An append-only file must be opened in append mode for writing.
         */
        if (IS_APPEND(inode)) {
+               error = -EPERM;
                if  ((flag & FMODE_WRITE) && !(flag & O_APPEND))
-                       return -EPERM;
+                       goto err_out;
                if (flag & O_TRUNC)
-                       return -EPERM;
+                       goto err_out;
        }
 
        /* O_NOATIME can only be set by the owner or superuser */
        if (flag & O_NOATIME)
-               if (!is_owner_or_cap(inode))
-                       return -EPERM;
+               if (!is_owner_or_cap(inode)) {
+                       error = -EPERM;
+                       goto err_out;
+               }
 
        /*
         * Ensure there are no outstanding leases on the file.
         */
        error = break_lease(inode, flag);
        if (error)
-               return error;
+               goto err_out;
 
        if (flag & O_TRUNC) {
                error = get_write_access(inode);
                if (error)
-                       return error;
+                       goto err_out;
 
                /*
                 * Refuse to truncate files with mandatory locks held on them.
@@ -1581,12 +1578,17 @@ int may_open(struct path *path, int acc_mode, int flag)
                }
                put_write_access(inode);
                if (error)
-                       return error;
+                       goto err_out;
        } else
                if (flag & FMODE_WRITE)
                        vfs_dq_init(inode);
 
        return 0;
+err_out:
+       ima_counts_put(path, acc_mode ?
+                      acc_mode & (MAY_READ | MAY_WRITE | MAY_EXEC) :
+                      ACC_MODE(flag) & (MAY_READ | MAY_WRITE));
+       return error;
 }
 
 /*