mirror of
https://github.com/Fishwaldo/linux-bl808.git
synced 2025-06-17 20:25:19 +00:00
userns: userns: check user namespace for task->file uid equivalence checks
Cheat for now and say all files belong to init_user_ns. Next step will be to let superblocks belong to a user_ns, and derive inode_userns(inode) from inode->i_sb->s_user_ns. Finally we'll introduce more flexible arrangements. Changelog: Feb 15: make is_owner_or_cap take const struct inode Feb 23: make is_owner_or_cap bool [akpm@linux-foundation.org: coding-style fixes] Signed-off-by: Serge E. Hallyn <serge.hallyn@canonical.com> Acked-by: "Eric W. Biederman" <ebiederm@xmission.com> Acked-by: Daniel Lezcano <daniel.lezcano@free.fr> Acked-by: David Howells <dhowells@redhat.com> Cc: James Morris <jmorris@namei.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
parent
b0e77598f8
commit
e795b71799
3 changed files with 40 additions and 7 deletions
17
fs/inode.c
17
fs/inode.c
|
@ -25,6 +25,7 @@
|
|||
#include <linux/async.h>
|
||||
#include <linux/posix_acl.h>
|
||||
#include <linux/ima.h>
|
||||
#include <linux/cred.h>
|
||||
|
||||
/*
|
||||
* This is needed for the following functions:
|
||||
|
@ -1733,3 +1734,19 @@ void inode_init_owner(struct inode *inode, const struct inode *dir,
|
|||
inode->i_mode = mode;
|
||||
}
|
||||
EXPORT_SYMBOL(inode_init_owner);
|
||||
|
||||
/*
|
||||
* return true if current either has CAP_FOWNER to the
|
||||
* file, or owns the file.
|
||||
*/
|
||||
bool is_owner_or_cap(const struct inode *inode)
|
||||
{
|
||||
struct user_namespace *ns = inode_userns(inode);
|
||||
|
||||
if (current_user_ns() == ns && current_fsuid() == inode->i_uid)
|
||||
return true;
|
||||
if (ns_capable(ns, CAP_FOWNER))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
EXPORT_SYMBOL(is_owner_or_cap);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue