Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1671164 > unrolled thread

[PATCH] fs: Reorder inode_owner_or_capable() to avoid needless

Started byKees Cook <keescook@chromium.org>
First post2017-06-20 23:50 +0200
Last post2017-06-30 02:10 +0200
Articles 4 — 4 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH] fs: Reorder inode_owner_or_capable() to avoid needless Kees Cook <keescook@chromium.org> - 2017-06-20 23:50 +0200
    Re: [PATCH] fs: Reorder inode_owner_or_capable() to avoid needless "Serge E. Hallyn" <serge@hallyn.com> - 2017-06-21 00:10 +0200
    Re: [PATCH] fs: Reorder inode_owner_or_capable() to avoid needless Andy Lutomirski <luto@kernel.org> - 2017-06-21 17:00 +0200
    Re: [PATCH] fs: Reorder inode_owner_or_capable() to avoid needless Al Viro <viro@ZenIV.linux.org.uk> - 2017-06-30 02:10 +0200

#1671164 — [PATCH] fs: Reorder inode_owner_or_capable() to avoid needless

FromKees Cook <keescook@chromium.org>
Date2017-06-20 23:50 +0200
Subject[PATCH] fs: Reorder inode_owner_or_capable() to avoid needless
Message-ID<tUzc5-5At-9@gated-at.bofh.it>
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>
Cc: Serge E. Hallyn <serge@hallyn.com>
Cc: Andy Lutomirski <luto@kernel.org>
Signed-off-by: Kees Cook <keescook@chromium.org>
---
 fs/inode.c | 2 +-
 fs/namei.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/inode.c b/fs/inode.c
index db5914783a71..7092debe90cc 100644
--- a/fs/inode.c
+++ b/fs/inode.c
@@ -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;
 }
diff --git a/fs/namei.c b/fs/namei.c
index 6571a5f5112e..efe53a5d0737 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -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);
-- 
2.7.4


-- 
Kees Cook
Pixel Security

[toc] | [next] | [standalone]


#1671186

From"Serge E. Hallyn" <serge@hallyn.com>
Date2017-06-21 00:10 +0200
Message-ID<tUzvt-5W2-45@gated-at.bofh.it>
In reply to#1671164
Quoting Kees Cook (keescook@chromium.org):
> 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>
> Cc: Serge E. Hallyn <serge@hallyn.com>

Makes sense, thanks.

Acked-by: Serge Hallyn <serge@hallyn.com>

> Cc: Andy Lutomirski <luto@kernel.org>
> Signed-off-by: Kees Cook <keescook@chromium.org>
> ---
>  fs/inode.c | 2 +-
>  fs/namei.c | 2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/inode.c b/fs/inode.c
> index db5914783a71..7092debe90cc 100644
> --- a/fs/inode.c
> +++ b/fs/inode.c
> @@ -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;
>  }
> diff --git a/fs/namei.c b/fs/namei.c
> index 6571a5f5112e..efe53a5d0737 100644
> --- a/fs/namei.c
> +++ b/fs/namei.c
> @@ -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);
> -- 
> 2.7.4
> 
> 
> -- 
> Kees Cook
> Pixel Security

[toc] | [prev] | [next] | [standalone]


#1671741

FromAndy Lutomirski <luto@kernel.org>
Date2017-06-21 17:00 +0200
Message-ID<tUPgS-7q0-35@gated-at.bofh.it>
In reply to#1671164
On Tue, Jun 20, 2017 at 2:40 PM, Kees Cook <keescook@chromium.org> wrote:
> 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).
>

Reviewed-by: Andy Lutomirski <luto@kernel.org>

[toc] | [prev] | [next] | [standalone]


#1678321

FromAl Viro <viro@ZenIV.linux.org.uk>
Date2017-06-30 02:10 +0200
Message-ID<tXRFx-6oX-45@gated-at.bofh.it>
In reply to#1671164
On Tue, Jun 20, 2017 at 02:40:24PM -0700, Kees Cook wrote:
> 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).

Applied

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web