fs: Reorder inode_owner_or_capable() to avoid needless
PATCH 1/1 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).
--- fs/inode.c | 2 +- fs/namei.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
fs/inode.c +1 -1
@@ -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; }
fs/namei.c +1 -1
@@ -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);
Signature · 6 lines
2.7.4 -- Kees Cook Pixel Security
Quoted 6 lines · Kees Cook
Checking for capabilities should be the last operation when performing access control tests so that
PF_SUPERPRIVis set only when it was required for success (implying that the capability was needed for the operation).Reported-by Solar Designer <[email protected]>Cc Serge E. Hallyn <[email protected]>
Makes sense, thanks.
Quoted 40 lines
Cc Andy Lutomirski <[email protected]>Signed-off-by Kees Cook <[email protected]>--- fs/inode.c | 2 +- fs/namei.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)fs/inode.c +1
-1@@ -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; }fs/namei.c +1
-1@@ -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);Signature · 6 lines
2.7.4 -- Kees Cook Pixel Security
Quoted 4 lines · Kees Cook
Checking for capabilities should be the last operation when performing access control tests so that
PF_SUPERPRIVis set only when it was required for success (implying that the capability was needed for the operation).
Quoted 3 lines · Kees Cook
Checking for capabilities should be the last operation when performing access control tests so that
PF_SUPERPRIVis set only when it was required for success (implying that the capability was needed for the operation).
Applied