Re: [PATCH -V1 08/22] vfs: Add permission flags for setting file attributes

From: Dave Chinner
Date: Mon Apr 28 2014 - 20:17:33 EST


On Sun, Apr 27, 2014 at 09:44:39PM +0530, Aneesh Kumar K.V wrote:
> From: Andreas Gruenbacher <agruen@xxxxxxxxxx>
>
> Some permission models can allow processes to take ownership of a file,
> change the file permissions, and set the file timestamps. Introduce new
> permission mask flags and check for those permissions in
> inode_change_ok().
>
> Signed-off-by: Andreas Gruenbacher <agruen@xxxxxxxxxx>
> Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@xxxxxxxxxxxxxxxxxx>
> ---
> fs/attr.c | 68 ++++++++++++++++++++++++++++++++++++++++++++----------
> fs/namei.c | 2 +-
> include/linux/fs.h | 4 ++++
> 3 files changed, 61 insertions(+), 13 deletions(-)
>
> diff --git a/fs/attr.c b/fs/attr.c
> index 1d158c972442..e468d4f2dca8 100644
> --- a/fs/attr.c
> +++ b/fs/attr.c
> @@ -16,6 +16,54 @@
> #include <linux/evm.h>
> #include <linux/ima.h>
>
> +static int richacl_change_ok(struct inode *inode, int mask)
> +{

acl_change_ok()

> + if (!IS_RICHACL(inode))
> + return -EPERM;
> +
> + if (inode->i_op->permission)
> + return inode->i_op->permission(inode, mask);
> +
> + return check_acl(inode, mask);
> +}
> +
> +static bool inode_uid_change_ok(struct inode *inode, kuid_t ia_uid)
> +{
> + if (uid_eq(current_fsuid(), inode->i_uid) &&
> + uid_eq(ia_uid, inode->i_uid))
> + return true;
> + if (uid_eq(current_fsuid(), ia_uid) &&
> + richacl_change_ok(inode, MAY_TAKE_OWNERSHIP) == 0)
> + return true;
> + if (capable(CAP_CHOWN))
> + return true;
> + return false;
> +}
> +
> +static bool inode_gid_change_ok(struct inode *inode, kgid_t ia_gid)
> +{
> + int in_group = in_group_p(ia_gid);
> + if (uid_eq(current_fsuid(), inode->i_uid) &&
> + (in_group || gid_eq(ia_gid, inode->i_gid)))
> + return true;
> + if (in_group && richacl_change_ok(inode, MAY_TAKE_OWNERSHIP) == 0)
> + return true;
> + if (capable(CAP_CHOWN))
> + return true;
> + return false;
> +}
> +
> +static bool inode_owner_permitted_or_capable(struct inode *inode, int mask)
> +{
> + if (uid_eq(current_fsuid(), inode->i_uid))
> + return true;
> + if (richacl_change_ok(inode, mask) == 0)
> + return true;
> + if (inode_capable(inode, CAP_FOWNER))
> + return true;
> + return false;
> +}

Some comments on when and why these need to be used instead of
inode_owner_or_capable() would be useful. I can see people getting
this wrong in future.

Cheers,

Dave.
--
Dave Chinner
david@xxxxxxxxxxxxx
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/