提交 44a41d57 编写于 作者: K Krzysztof Struczynski 提交者: Zheng Zengkai

user namespace: Add function that checks if the UID map is defined

hulk inclusion
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/I49KW1
CVE: NA

--------------------------------

Add function that checks if the UID map is defined. It will be used by
ima to check if ID remapping in subject-based rules is necessary.
Signed-off-by: NKrzysztof Struczynski <krzysztof.struczynski@huawei.com>
Reviewed-by: NZhang Tianxing <zhangtianxing3@huawei.com>
Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
上级 3ead0c63
...@@ -141,6 +141,7 @@ extern bool in_userns(const struct user_namespace *ancestor, ...@@ -141,6 +141,7 @@ extern bool in_userns(const struct user_namespace *ancestor,
const struct user_namespace *child); const struct user_namespace *child);
extern bool current_in_userns(const struct user_namespace *target_ns); extern bool current_in_userns(const struct user_namespace *target_ns);
struct ns_common *ns_get_owner(struct ns_common *ns); struct ns_common *ns_get_owner(struct ns_common *ns);
extern bool userns_set_uidmap(const struct user_namespace *ns);
#else #else
static inline struct user_namespace *get_user_ns(struct user_namespace *ns) static inline struct user_namespace *get_user_ns(struct user_namespace *ns)
...@@ -185,6 +186,11 @@ static inline struct ns_common *ns_get_owner(struct ns_common *ns) ...@@ -185,6 +186,11 @@ static inline struct ns_common *ns_get_owner(struct ns_common *ns)
{ {
return ERR_PTR(-EPERM); return ERR_PTR(-EPERM);
} }
static inline bool userns_set_uidmap(const struct user_namespace *ns)
{
return true;
}
#endif #endif
#endif /* _LINUX_USER_H */ #endif /* _LINUX_USER_H */
...@@ -1291,6 +1291,17 @@ bool current_in_userns(const struct user_namespace *target_ns) ...@@ -1291,6 +1291,17 @@ bool current_in_userns(const struct user_namespace *target_ns)
} }
EXPORT_SYMBOL(current_in_userns); EXPORT_SYMBOL(current_in_userns);
bool userns_set_uidmap(const struct user_namespace *ns)
{
bool mapping_defined;
mutex_lock(&userns_state_mutex);
mapping_defined = ns->uid_map.nr_extents != 0;
mutex_unlock(&userns_state_mutex);
return mapping_defined;
}
static inline struct user_namespace *to_user_ns(struct ns_common *ns) static inline struct user_namespace *to_user_ns(struct ns_common *ns)
{ {
return container_of(ns, struct user_namespace, ns); return container_of(ns, struct user_namespace, ns);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册