Skip to content

Commit cc658db

Browse files
keesAl Viro
authored andcommitted
fs: Reorder inode_owner_or_capable() to avoid needless
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>
1 parent 41124db commit cc658db

2 files changed

Lines changed: 2 additions & 2 deletions

File tree

‎fs/inode.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2023,7 +2023,7 @@ bool inode_owner_or_capable(const struct inode *inode)
20232023
return true;
20242024

20252025
ns = current_user_ns();
2026-
if (ns_capable(ns, CAP_FOWNER) && kuid_has_mapping(ns, inode->i_uid))
2026+
if (kuid_has_mapping(ns, inode->i_uid) && ns_capable(ns, CAP_FOWNER))
20272027
return true;
20282028
return false;
20292029
}

‎fs/namei.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1008,7 +1008,7 @@ static int may_linkat(struct path *link)
10081008
/* Source inode owner (or CAP_FOWNER) can hardlink all they like,
10091009
* otherwise, it must be a safe source.
10101010
*/
1011-
if (inode_owner_or_capable(inode) || safe_hardlink_source(inode))
1011+
if (safe_hardlink_source(inode) || inode_owner_or_capable(inode))
10121012
return 0;
10131013

10141014
audit_log_link_denied("linkat", link);

0 commit comments

Comments
 (0)