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 <[email protected]>
Signed-off-by: Kees Cook <[email protected]>
Acked-by: Serge Hallyn <[email protected]>
Reviewed-by: Andy Lutomirski <[email protected]>
Signed-off-by: Al Viro <[email protected]>
This commit is contained in:
Kees Cook 2017-06-21 09:53:06 -07:00 • committed by Al Viro
commit cc658db47d
2 changed files with 2 additions and 2 deletions

View 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);