2017-06-20 21:40:28

by Kees Cook

[permalink] [raw]
Subject: [PATCH] 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]>
Cc: Serge E. Hallyn <[email protected]>
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(-)

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


2017-06-20 22:02:41

by Serge E. Hallyn

[permalink] [raw]
Subject: Re: [PATCH] fs: Reorder inode_owner_or_capable() to avoid needless

Quoting Kees Cook ([email protected]):
> 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]>
> Cc: Serge E. Hallyn <[email protected]>

Makes sense, thanks.

Acked-by: Serge Hallyn <[email protected]>

> 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(-)
>
> 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

2017-06-21 14:55:50

by Andy Lutomirski

[permalink] [raw]
Subject: Re: [PATCH] fs: Reorder inode_owner_or_capable() to avoid needless

On Tue, Jun 20, 2017 at 2:40 PM, Kees Cook <[email protected]> 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 <[email protected]>

2017-06-30 00:06:42

by Al Viro

[permalink] [raw]
Subject: Re: [PATCH] fs: Reorder inode_owner_or_capable() to avoid needless

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