fs: Reorder inode_owner_or_capable() to avoid needless
authorKees Cook <keescook@chromium.org>
Wed, 21 Jun 2017 16:53:06 +0000 (09:53 -0700)
committerAl Viro <viro@zeniv.linux.org.uk>
Fri, 30 Jun 2017 00:08:32 +0000 (20:08 -0400)
Checking for capabilities should be the last operation when performing
access control tests so that PF_SUPERPRIV is set only when it was required
for success (implying that the capability was needed for the operation).

Reported-by: Solar Designer <solar@openwall.com>
Signed-off-by: Kees Cook <keescook@chromium.org>
Acked-by: Serge Hallyn <serge@hallyn.com>
Reviewed-by: Andy Lutomirski <luto@kernel.org>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
fs/inode.c
fs/namei.c

index db5914783a7130d77725502cb4182c05ff7775c2..7092debe90ccc602434274dadcfcc28115d59d8d 100644 (file)
@@ -2023,7 +2023,7 @@ bool inode_owner_or_capable(const struct inode *inode)
                return true;
 
        ns = current_user_ns();
-       if (ns_capable(ns, CAP_FOWNER) && kuid_has_mapping(ns, inode->i_uid))
+       if (kuid_has_mapping(ns, inode->i_uid) && ns_capable(ns, CAP_FOWNER))
                return true;
        return false;
 }
index 6571a5f5112ed82894fdbec1c9b6dfaf557d93b1..efe53a5d0737cce7199ef5ee7205cd4669c305f7 100644 (file)
@@ -1008,7 +1008,7 @@ static int may_linkat(struct path *link)
        /* Source inode owner (or CAP_FOWNER) can hardlink all they like,
         * otherwise, it must be a safe source.
         */
-       if (inode_owner_or_capable(inode) || safe_hardlink_source(inode))
+       if (safe_hardlink_source(inode) || inode_owner_or_capable(inode))
                return 0;
 
        audit_log_link_denied("linkat", link);