From: Michael Jeanson Date: Fri, 18 Nov 2022 20:59:56 +0000 (-0500) Subject: Drop 'linux/user_namespace.h' wrapper X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=6d0471df5846249bd61278ff6191676cb075b871;p=lttng-modules.git Drop 'linux/user_namespace.h' wrapper Change-Id: I38bb6ff741126e18a4a1deb59471adb68dacdcb0 Signed-off-by: Michael Jeanson Signed-off-by: Mathieu Desnoyers --- diff --git a/include/instrumentation/events/lttng-statedump.h b/include/instrumentation/events/lttng-statedump.h index e88fec57..7bf79a79 100644 --- a/include/instrumentation/events/lttng-statedump.h +++ b/include/instrumentation/events/lttng-statedump.h @@ -14,8 +14,10 @@ #include #include #include +#include + #include -#include + #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,6,0) || \ LTTNG_RHEL_KERNEL_RANGE(4,18,0,305,0,0, 4,19,0,0,0,0)) #include @@ -158,8 +160,8 @@ LTTNG_TRACEPOINT_EVENT(lttng_statedump_process_user_ns, TP_ARGS(session, p, user_ns), TP_FIELDS( ctf_integer(pid_t, tid, p->pid) - ctf_integer(uid_t, vuid, user_ns ? lttng_task_vuid(p, user_ns) : 0) - ctf_integer(gid_t, vgid, user_ns ? lttng_task_vgid(p, user_ns) : 0) + ctf_integer(uid_t, vuid, user_ns ? from_kuid_munged(user_ns, task_cred_xxx(p, uid)) : 0) + ctf_integer(gid_t, vgid, user_ns ? from_kgid_munged(user_ns, task_cred_xxx(p, gid)) : 0) #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(3,11,0)) ctf_integer(int, ns_level, user_ns ? user_ns->level : 0) #endif diff --git a/include/lttng/tracepoint-event-impl.h b/include/lttng/tracepoint-event-impl.h index 8e552556..88a2bccc 100644 --- a/include/lttng/tracepoint-event-impl.h +++ b/include/lttng/tracepoint-event-impl.h @@ -11,12 +11,12 @@ #include #include #include +#include #include /* for wrapper_vmalloc_sync_mappings() */ #include #include #include -#include #include #include #include @@ -1102,19 +1102,19 @@ static void __event_probe__##_name(_data_proto) \ return; \ __lf = lttng_rcu_dereference(__session->uid_tracker.p); \ if (__lf && likely(!lttng_id_tracker_lookup(__lf, \ - lttng_current_uid()))) \ + from_kuid_munged(&init_user_ns, current_uid())))) \ return; \ __lf = lttng_rcu_dereference(__session->vuid_tracker.p); \ if (__lf && likely(!lttng_id_tracker_lookup(__lf, \ - lttng_current_vuid()))) \ + from_kuid_munged(current_user_ns(), current_uid())))) \ return; \ __lf = lttng_rcu_dereference(__session->gid_tracker.p); \ if (__lf && likely(!lttng_id_tracker_lookup(__lf, \ - lttng_current_gid()))) \ + from_kgid_munged(&init_user_ns, current_gid())))) \ return; \ __lf = lttng_rcu_dereference(__session->vgid_tracker.p); \ if (__lf && likely(!lttng_id_tracker_lookup(__lf, \ - lttng_current_vgid()))) \ + from_kgid_munged(current_user_ns(), current_gid())))) \ return; \ break; \ } \ diff --git a/include/wrapper/user_namespace.h b/include/wrapper/user_namespace.h deleted file mode 100644 index 26d15c55..00000000 --- a/include/wrapper/user_namespace.h +++ /dev/null @@ -1,116 +0,0 @@ -/* SPDX-License-Identifier: (GPL-2.0-only or LGPL-2.1-only) - * - * wrapper/user_namespace.h - * - * Copyright (C) 2019 Michael Jeanson - * - */ - -#ifndef _LTTNG_WRAPPER_USER_NAMESPACE_H -#define _LTTNG_WRAPPER_USER_NAMESPACE_H - -#include -#include - - -#if LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(3, 5, 0) - -#define lttng_current_xxuid(xxx) \ - (from_kuid_munged(&init_user_ns, current_##xxx())) - -#define lttng_current_vxxuid(xxx) \ - (from_kuid_munged(current_user_ns(), current_##xxx())) - -#define lttng_current_xxgid(xxx) \ - (from_kgid_munged(&init_user_ns, current_##xxx())) - -#define lttng_current_vxxgid(xxx) \ - (from_kgid_munged(current_user_ns(), current_##xxx())) - -static inline -uid_t lttng_task_vuid(struct task_struct *p, struct user_namespace *ns) -{ - uid_t uid; - kuid_t kuid; - - kuid = task_cred_xxx(p, uid); - uid = from_kuid_munged(ns, kuid); - - return uid; -} - -static inline -gid_t lttng_task_vgid(struct task_struct *p, struct user_namespace *ns) -{ - gid_t gid; - kgid_t kgid; - - kgid = task_cred_xxx(p, gid); - gid = from_kgid_munged(ns, kgid); - - return gid; -} - -#else - -#define lttng_current_xxuid(xxx) (current_##xxx()) - -#define lttng_current_vxxuid(xxx) \ - (user_ns_map_uid(current_user_ns(), current_cred(), current_##xxx())) - -#define lttng_current_xxgid(xxx) (current_##xxx()) - -#define lttng_current_vxxgid(xxx) \ - (user_ns_map_gid(current_user_ns(), current_cred(), current_##xxx())) - -static inline -uid_t lttng_task_vuid(struct task_struct *p, struct user_namespace *ns) -{ - uid_t uid; - - /* - * __task_cred requires the RCU readlock be held - */ - rcu_read_lock(); - uid = user_ns_map_uid(ns, __task_cred(p), __task_cred(p)->uid); - rcu_read_unlock(); - - return uid; -} - -static inline -gid_t lttng_task_vgid(struct task_struct *p, struct user_namespace *ns) -{ - gid_t gid; - - /* - * __task_cred requires the RCU readlock be held - */ - rcu_read_lock(); - gid = user_ns_map_gid(ns, __task_cred(p), __task_cred(p)->gid); - rcu_read_unlock(); - - return gid; -} - -#endif - -#define lttng_current_uid() (lttng_current_xxuid(uid)) -#define lttng_current_euid() (lttng_current_xxuid(euid)) -#define lttng_current_suid() (lttng_current_xxuid(suid)) -#define lttng_current_fsuid() (lttng_current_xxuid(fsuid)) -#define lttng_current_gid() (lttng_current_xxgid(gid)) -#define lttng_current_egid() (lttng_current_xxgid(egid)) -#define lttng_current_sgid() (lttng_current_xxgid(sgid)) -#define lttng_current_fsgid() (lttng_current_xxgid(fsgid)) - -#define lttng_current_vuid() (lttng_current_vxxuid(uid)) -#define lttng_current_veuid() (lttng_current_vxxuid(euid)) -#define lttng_current_vsuid() (lttng_current_vxxuid(suid)) -#define lttng_current_vfsuid() (lttng_current_vxxuid(fsuid)) -#define lttng_current_vgid() (lttng_current_vxxgid(gid)) -#define lttng_current_vegid() (lttng_current_vxxgid(egid)) -#define lttng_current_vsgid() (lttng_current_vxxgid(sgid)) -#define lttng_current_vfsgid() (lttng_current_vxxgid(fsgid)) - -#endif /* _LTTNG_WRAPPER_USER_NAMESPACE_H */ diff --git a/src/lttng-context-egid.c b/src/lttng-context-egid.c index 2b6d3ef9..d38fb11e 100644 --- a/src/lttng-context-egid.c +++ b/src/lttng-context-egid.c @@ -11,12 +11,13 @@ #include #include +#include + #include #include #include #include #include -#include static size_t egid_get_size(void *priv, struct lttng_kernel_probe_ctx *probe_ctx, size_t offset) @@ -35,7 +36,7 @@ void egid_record(void *priv, struct lttng_kernel_probe_ctx *probe_ctx, { gid_t egid; - egid = lttng_current_egid(); + egid = from_kgid_munged(&init_user_ns, current_egid()); chan->ops->event_write(ctx, &egid, sizeof(egid), lttng_alignof(egid)); } @@ -44,7 +45,7 @@ void egid_get_value(void *priv, struct lttng_kernel_probe_ctx *lttng_probe_ctx, struct lttng_ctx_value *value) { - value->u.s64 = lttng_current_egid(); + value->u.s64 = from_kgid_munged(&init_user_ns, current_egid()); } static const struct lttng_kernel_ctx_field *ctx_field = lttng_kernel_static_ctx_field( diff --git a/src/lttng-context-euid.c b/src/lttng-context-euid.c index ace9f800..92c28681 100644 --- a/src/lttng-context-euid.c +++ b/src/lttng-context-euid.c @@ -11,12 +11,13 @@ #include #include +#include + #include #include #include #include #include -#include static size_t euid_get_size(void *priv, struct lttng_kernel_probe_ctx *probe_ctx, size_t offset) @@ -35,7 +36,7 @@ void euid_record(void *priv, struct lttng_kernel_probe_ctx *probe_ctx, { uid_t euid; - euid = lttng_current_euid(); + euid = from_kuid_munged(&init_user_ns, current_euid()); chan->ops->event_write(ctx, &euid, sizeof(euid), lttng_alignof(euid)); } @@ -44,7 +45,7 @@ void euid_get_value(void *priv, struct lttng_kernel_probe_ctx *lttng_probe_ctx, struct lttng_ctx_value *value) { - value->u.s64 = lttng_current_euid(); + value->u.s64 = from_kuid_munged(&init_user_ns, current_euid()); } static const struct lttng_kernel_ctx_field *ctx_field = lttng_kernel_static_ctx_field( diff --git a/src/lttng-context-gid.c b/src/lttng-context-gid.c index 142061c1..24692aac 100644 --- a/src/lttng-context-gid.c +++ b/src/lttng-context-gid.c @@ -11,12 +11,13 @@ #include #include +#include + #include #include #include #include #include -#include static size_t gid_get_size(void *priv, struct lttng_kernel_probe_ctx *probe_ctx, size_t offset) @@ -35,7 +36,7 @@ void gid_record(void *priv, struct lttng_kernel_probe_ctx *probe_ctx, { gid_t gid; - gid = lttng_current_gid(); + gid = from_kgid_munged(&init_user_ns, current_gid()); chan->ops->event_write(ctx, &gid, sizeof(gid), lttng_alignof(gid)); } @@ -44,7 +45,7 @@ void gid_get_value(void *priv, struct lttng_kernel_probe_ctx *lttng_probe_ctx, struct lttng_ctx_value *value) { - value->u.s64 = lttng_current_gid(); + value->u.s64 = from_kgid_munged(&init_user_ns, current_gid()); } static const struct lttng_kernel_ctx_field *ctx_field = lttng_kernel_static_ctx_field( diff --git a/src/lttng-context-sgid.c b/src/lttng-context-sgid.c index c9d4211a..82c90507 100644 --- a/src/lttng-context-sgid.c +++ b/src/lttng-context-sgid.c @@ -11,12 +11,13 @@ #include #include +#include + #include #include #include #include #include -#include static size_t sgid_get_size(void *priv, struct lttng_kernel_probe_ctx *probe_ctx, size_t offset) @@ -35,7 +36,7 @@ void sgid_record(void *priv, struct lttng_kernel_probe_ctx *probe_ctx, { gid_t sgid; - sgid = lttng_current_sgid(); + sgid = from_kgid_munged(&init_user_ns, current_sgid()); chan->ops->event_write(ctx, &sgid, sizeof(sgid), lttng_alignof(sgid)); } @@ -44,7 +45,7 @@ void sgid_get_value(void *priv, struct lttng_kernel_probe_ctx *lttng_probe_ctx, struct lttng_ctx_value *value) { - value->u.s64 = lttng_current_sgid(); + value->u.s64 = from_kgid_munged(&init_user_ns, current_sgid()); } static const struct lttng_kernel_ctx_field *ctx_field = lttng_kernel_static_ctx_field( diff --git a/src/lttng-context-suid.c b/src/lttng-context-suid.c index bd1f0246..a478b7bf 100644 --- a/src/lttng-context-suid.c +++ b/src/lttng-context-suid.c @@ -11,12 +11,13 @@ #include #include +#include + #include #include #include #include #include -#include static size_t suid_get_size(void *priv, struct lttng_kernel_probe_ctx *probe_ctx, size_t offset) @@ -35,7 +36,7 @@ void suid_record(void *priv, struct lttng_kernel_probe_ctx *probe_ctx, { uid_t suid; - suid = lttng_current_suid(); + suid = from_kuid_munged(&init_user_ns, current_suid()); chan->ops->event_write(ctx, &suid, sizeof(suid), lttng_alignof(suid)); } @@ -44,7 +45,7 @@ void suid_get_value(void *priv, struct lttng_kernel_probe_ctx *lttng_probe_ctx, struct lttng_ctx_value *value) { - value->u.s64 = lttng_current_suid(); + value->u.s64 = from_kuid_munged(&init_user_ns, current_suid()); } static const struct lttng_kernel_ctx_field *ctx_field = lttng_kernel_static_ctx_field( diff --git a/src/lttng-context-uid.c b/src/lttng-context-uid.c index 6121beef..da8fb301 100644 --- a/src/lttng-context-uid.c +++ b/src/lttng-context-uid.c @@ -11,12 +11,13 @@ #include #include +#include + #include #include #include #include #include -#include static size_t uid_get_size(void *priv, struct lttng_kernel_probe_ctx *probe_ctx, size_t offset) @@ -35,7 +36,7 @@ void uid_record(void *priv, struct lttng_kernel_probe_ctx *probe_ctx, { uid_t uid; - uid = lttng_current_uid(); + uid = from_kuid_munged(&init_user_ns, current_uid()); chan->ops->event_write(ctx, &uid, sizeof(uid), lttng_alignof(uid)); } @@ -44,7 +45,7 @@ void uid_get_value(void *priv, struct lttng_kernel_probe_ctx *lttng_probe_ctx, struct lttng_ctx_value *value) { - value->u.s64 = lttng_current_uid(); + value->u.s64 = from_kuid_munged(&init_user_ns, current_uid()); } static const struct lttng_kernel_ctx_field *ctx_field = lttng_kernel_static_ctx_field( diff --git a/src/lttng-context-vegid.c b/src/lttng-context-vegid.c index aa40c40f..c723411e 100644 --- a/src/lttng-context-vegid.c +++ b/src/lttng-context-vegid.c @@ -11,12 +11,13 @@ #include #include +#include + #include #include #include #include #include -#include static size_t vegid_get_size(void *priv, struct lttng_kernel_probe_ctx *probe_ctx, size_t offset) @@ -35,7 +36,7 @@ void vegid_record(void *priv, struct lttng_kernel_probe_ctx *probe_ctx, { gid_t vegid; - vegid = lttng_current_vegid(); + vegid = from_kgid_munged(current_user_ns(), current_egid()); chan->ops->event_write(ctx, &vegid, sizeof(vegid), lttng_alignof(vegid)); } @@ -44,7 +45,7 @@ void vegid_get_value(void *priv, struct lttng_kernel_probe_ctx *lttng_probe_ctx, struct lttng_ctx_value *value) { - value->u.s64 = lttng_current_vegid(); + value->u.s64 = from_kgid_munged(current_user_ns(), current_egid()); } static const struct lttng_kernel_ctx_field *ctx_field = lttng_kernel_static_ctx_field( diff --git a/src/lttng-context-veuid.c b/src/lttng-context-veuid.c index b941967b..8fc593e5 100644 --- a/src/lttng-context-veuid.c +++ b/src/lttng-context-veuid.c @@ -11,12 +11,13 @@ #include #include +#include + #include #include #include #include #include -#include static size_t veuid_get_size(void *priv, struct lttng_kernel_probe_ctx *probe_ctx, size_t offset) @@ -35,7 +36,7 @@ void veuid_record(void *priv, struct lttng_kernel_probe_ctx *probe_ctx, { uid_t veuid; - veuid = lttng_current_veuid(); + veuid = from_kuid_munged(current_user_ns(), current_euid()); chan->ops->event_write(ctx, &veuid, sizeof(veuid), lttng_alignof(veuid)); } @@ -44,7 +45,7 @@ void veuid_get_value(void *priv, struct lttng_kernel_probe_ctx *lttng_probe_ctx, struct lttng_ctx_value *value) { - value->u.s64 = lttng_current_veuid(); + value->u.s64 = from_kuid_munged(current_user_ns(), current_euid()); } static const struct lttng_kernel_ctx_field *ctx_field = lttng_kernel_static_ctx_field( diff --git a/src/lttng-context-vgid.c b/src/lttng-context-vgid.c index cd3091e8..a5a51bfb 100644 --- a/src/lttng-context-vgid.c +++ b/src/lttng-context-vgid.c @@ -11,12 +11,13 @@ #include #include +#include + #include #include #include #include #include -#include static size_t vgid_get_size(void *priv, struct lttng_kernel_probe_ctx *probe_ctx, size_t offset) @@ -35,7 +36,7 @@ void vgid_record(void *priv, struct lttng_kernel_probe_ctx *probe_ctx, { gid_t vgid; - vgid = lttng_current_vgid(); + vgid = from_kgid_munged(current_user_ns(), current_gid()); chan->ops->event_write(ctx, &vgid, sizeof(vgid), lttng_alignof(vgid)); } @@ -44,7 +45,7 @@ void vgid_get_value(void *priv, struct lttng_kernel_probe_ctx *lttng_probe_ctx, struct lttng_ctx_value *value) { - value->u.s64 = lttng_current_vgid(); + value->u.s64 = from_kgid_munged(current_user_ns(), current_gid()); } static const struct lttng_kernel_ctx_field *ctx_field = lttng_kernel_static_ctx_field( diff --git a/src/lttng-context-vsgid.c b/src/lttng-context-vsgid.c index e9b18b67..f5428865 100644 --- a/src/lttng-context-vsgid.c +++ b/src/lttng-context-vsgid.c @@ -11,12 +11,13 @@ #include #include +#include + #include #include #include #include #include -#include static size_t vsgid_get_size(void *priv, struct lttng_kernel_probe_ctx *probe_ctx, size_t offset) @@ -35,7 +36,7 @@ void vsgid_record(void *priv, struct lttng_kernel_probe_ctx *probe_ctx, { gid_t vsgid; - vsgid = lttng_current_vsgid(); + vsgid = from_kgid_munged(current_user_ns(), current_sgid()); chan->ops->event_write(ctx, &vsgid, sizeof(vsgid), lttng_alignof(vsgid)); } @@ -44,7 +45,7 @@ void vsgid_get_value(void *priv, struct lttng_kernel_probe_ctx *lttng_probe_ctx, struct lttng_ctx_value *value) { - value->u.s64 = lttng_current_vsgid(); + value->u.s64 = from_kgid_munged(current_user_ns(), current_sgid()); } static const struct lttng_kernel_ctx_field *ctx_field = lttng_kernel_static_ctx_field( diff --git a/src/lttng-context-vsuid.c b/src/lttng-context-vsuid.c index f7d5226b..e48654c8 100644 --- a/src/lttng-context-vsuid.c +++ b/src/lttng-context-vsuid.c @@ -11,12 +11,13 @@ #include #include +#include + #include #include #include #include #include -#include static size_t vsuid_get_size(void *priv, struct lttng_kernel_probe_ctx *probe_ctx, size_t offset) @@ -35,7 +36,7 @@ void vsuid_record(void *priv, struct lttng_kernel_probe_ctx *probe_ctx, { uid_t vsuid; - vsuid = lttng_current_vsuid(); + vsuid = from_kuid_munged(current_user_ns(), current_suid()); chan->ops->event_write(ctx, &vsuid, sizeof(vsuid), lttng_alignof(vsuid)); } @@ -44,7 +45,7 @@ void vsuid_get_value(void *priv, struct lttng_kernel_probe_ctx *lttng_probe_ctx, struct lttng_ctx_value *value) { - value->u.s64 = lttng_current_vsuid(); + value->u.s64 = from_kuid_munged(current_user_ns(), current_suid()); } static const struct lttng_kernel_ctx_field *ctx_field = lttng_kernel_static_ctx_field( diff --git a/src/lttng-context-vuid.c b/src/lttng-context-vuid.c index c76115f4..3fbee8aa 100644 --- a/src/lttng-context-vuid.c +++ b/src/lttng-context-vuid.c @@ -11,12 +11,13 @@ #include #include +#include + #include #include #include #include #include -#include static size_t vuid_get_size(void *priv, struct lttng_kernel_probe_ctx *probe_ctx, size_t offset) @@ -35,7 +36,7 @@ void vuid_record(void *priv, struct lttng_kernel_probe_ctx *probe_ctx, { uid_t vuid; - vuid = lttng_current_vuid(); + vuid = from_kuid_munged(current_user_ns(), current_uid()); chan->ops->event_write(ctx, &vuid, sizeof(vuid), lttng_alignof(vuid)); } @@ -44,7 +45,7 @@ void vuid_get_value(void *priv, struct lttng_kernel_probe_ctx *lttng_probe_ctx, struct lttng_ctx_value *value) { - value->u.s64 = lttng_current_vuid(); + value->u.s64 = from_kuid_munged(current_user_ns(), current_uid()); } static const struct lttng_kernel_ctx_field *ctx_field = lttng_kernel_static_ctx_field(