[lttng-dev] [PATCH lttng-modules 2/3] RFC: Add uid/gid contexts

Michael Jeanson mjeanson at efficios.com
Thu Mar 1 17:39:09 EST 2018


Add a context for each available kernel user and group IDs

  * uid : real user ID
  * euid : effective user ID
  * suid : saved set-user ID
  * fsuid : filesystem ID

These are the IDs as seen in the initial user namespace, see
credentials(7) for details on each type.

Also add a "virtual" version of each type with the "v" prefix that
are the IDs as seen in the current user namespace.

Signed-off-by: Michael Jeanson <mjeanson at efficios.com>
---
 Makefile                 | 16 +++++++++
 lttng-abi.c              | 32 +++++++++++++++++
 lttng-abi.h              | 16 +++++++++
 lttng-context-egid.c     | 91 ++++++++++++++++++++++++++++++++++++++++++++++++
 lttng-context-euid.c     | 91 ++++++++++++++++++++++++++++++++++++++++++++++++
 lttng-context-fsgid.c    | 91 ++++++++++++++++++++++++++++++++++++++++++++++++
 lttng-context-fsuid.c    | 91 ++++++++++++++++++++++++++++++++++++++++++++++++
 lttng-context-gid.c      | 91 ++++++++++++++++++++++++++++++++++++++++++++++++
 lttng-context-sgid.c     | 91 ++++++++++++++++++++++++++++++++++++++++++++++++
 lttng-context-suid.c     | 91 ++++++++++++++++++++++++++++++++++++++++++++++++
 lttng-context-uid.c      | 91 ++++++++++++++++++++++++++++++++++++++++++++++++
 lttng-context-vegid.c    | 91 ++++++++++++++++++++++++++++++++++++++++++++++++
 lttng-context-veuid.c    | 91 ++++++++++++++++++++++++++++++++++++++++++++++++
 lttng-context-vfsgid.c   | 91 ++++++++++++++++++++++++++++++++++++++++++++++++
 lttng-context-vfsuid.c   | 91 ++++++++++++++++++++++++++++++++++++++++++++++++
 lttng-context-vgid.c     | 91 ++++++++++++++++++++++++++++++++++++++++++++++++
 lttng-context-vsgid.c    | 91 ++++++++++++++++++++++++++++++++++++++++++++++++
 lttng-context-vsuid.c    | 91 ++++++++++++++++++++++++++++++++++++++++++++++++
 lttng-context-vuid.c     | 91 ++++++++++++++++++++++++++++++++++++++++++++++++
 lttng-events.h           | 17 +++++++++
 wrapper/user_namespace.h | 73 ++++++++++++++++++++++++++++++++++++++
 21 files changed, 1610 insertions(+)
 create mode 100644 lttng-context-egid.c
 create mode 100644 lttng-context-euid.c
 create mode 100644 lttng-context-fsgid.c
 create mode 100644 lttng-context-fsuid.c
 create mode 100644 lttng-context-gid.c
 create mode 100644 lttng-context-sgid.c
 create mode 100644 lttng-context-suid.c
 create mode 100644 lttng-context-uid.c
 create mode 100644 lttng-context-vegid.c
 create mode 100644 lttng-context-veuid.c
 create mode 100644 lttng-context-vfsgid.c
 create mode 100644 lttng-context-vfsuid.c
 create mode 100644 lttng-context-vgid.c
 create mode 100644 lttng-context-vsgid.c
 create mode 100644 lttng-context-vsuid.c
 create mode 100644 lttng-context-vuid.c
 create mode 100644 wrapper/user_namespace.h

diff --git a/Makefile b/Makefile
index 15f18c4..c4c2216 100644
--- a/Makefile
+++ b/Makefile
@@ -50,6 +50,22 @@ ifneq ($(KERNELRELEASE),)
                        lttng-context-vpid.o lttng-context-tid.o \
                        lttng-context-vtid.o lttng-context-ppid.o \
                        lttng-context-vppid.o lttng-context-cpu-id.o \
+                       lttng-context-uid.o \
+                       lttng-context-euid.o \
+                       lttng-context-suid.o \
+                       lttng-context-fsuid.o \
+                       lttng-context-gid.o \
+                       lttng-context-egid.o \
+                       lttng-context-sgid.o \
+                       lttng-context-fsgid.o \
+                       lttng-context-vuid.o \
+                       lttng-context-veuid.o \
+                       lttng-context-vsuid.o \
+                       lttng-context-vfsuid.o \
+                       lttng-context-vgid.o \
+                       lttng-context-vegid.o \
+                       lttng-context-vsgid.o \
+                       lttng-context-vfsgid.o \
                        lttng-context-interruptible.o \
                        lttng-context-need-reschedule.o lttng-calibrate.o \
                        lttng-context-hostname.o wrapper/random.o \
diff --git a/lttng-abi.c b/lttng-abi.c
index 1345e93..5c547f3 100644
--- a/lttng-abi.c
+++ b/lttng-abi.c
@@ -261,6 +261,38 @@ long lttng_abi_add_context(struct file *file,
 		return lttng_add_user_ns_to_ctx(ctx);
 	case LTTNG_KERNEL_CONTEXT_UTS_NS:
 		return lttng_add_uts_ns_to_ctx(ctx);
+	case LTTNG_KERNEL_CONTEXT_UID:
+		return lttng_add_uid_to_ctx(ctx);
+	case LTTNG_KERNEL_CONTEXT_EUID:
+		return lttng_add_euid_to_ctx(ctx);
+	case LTTNG_KERNEL_CONTEXT_SUID:
+		return lttng_add_suid_to_ctx(ctx);
+	case LTTNG_KERNEL_CONTEXT_FSUID:
+		return lttng_add_fsuid_to_ctx(ctx);
+	case LTTNG_KERNEL_CONTEXT_GID:
+		return lttng_add_gid_to_ctx(ctx);
+	case LTTNG_KERNEL_CONTEXT_EGID:
+		return lttng_add_egid_to_ctx(ctx);
+	case LTTNG_KERNEL_CONTEXT_SGID:
+		return lttng_add_sgid_to_ctx(ctx);
+	case LTTNG_KERNEL_CONTEXT_FSGID:
+		return lttng_add_fsgid_to_ctx(ctx);
+	case LTTNG_KERNEL_CONTEXT_VUID:
+		return lttng_add_vuid_to_ctx(ctx);
+	case LTTNG_KERNEL_CONTEXT_VEUID:
+		return lttng_add_veuid_to_ctx(ctx);
+	case LTTNG_KERNEL_CONTEXT_VSUID:
+		return lttng_add_vsuid_to_ctx(ctx);
+	case LTTNG_KERNEL_CONTEXT_VFSUID:
+		return lttng_add_vfsuid_to_ctx(ctx);
+	case LTTNG_KERNEL_CONTEXT_VGID:
+		return lttng_add_vgid_to_ctx(ctx);
+	case LTTNG_KERNEL_CONTEXT_VEGID:
+		return lttng_add_vegid_to_ctx(ctx);
+	case LTTNG_KERNEL_CONTEXT_VSGID:
+		return lttng_add_vsgid_to_ctx(ctx);
+	case LTTNG_KERNEL_CONTEXT_VFSGID:
+		return lttng_add_vfsgid_to_ctx(ctx);
 	default:
 		return -EINVAL;
 	}
diff --git a/lttng-abi.h b/lttng-abi.h
index 47cacec..1f0877d 100644
--- a/lttng-abi.h
+++ b/lttng-abi.h
@@ -153,6 +153,22 @@ enum lttng_kernel_context_type {
 	LTTNG_KERNEL_CONTEXT_PID_NS		= 20,
 	LTTNG_KERNEL_CONTEXT_USER_NS		= 21,
 	LTTNG_KERNEL_CONTEXT_UTS_NS		= 22,
+	LTTNG_KERNEL_CONTEXT_UID		= 23,
+	LTTNG_KERNEL_CONTEXT_EUID		= 24,
+	LTTNG_KERNEL_CONTEXT_SUID		= 25,
+	LTTNG_KERNEL_CONTEXT_FSUID		= 26,
+	LTTNG_KERNEL_CONTEXT_GID		= 27,
+	LTTNG_KERNEL_CONTEXT_EGID		= 28,
+	LTTNG_KERNEL_CONTEXT_SGID		= 29,
+	LTTNG_KERNEL_CONTEXT_FSGID		= 30,
+	LTTNG_KERNEL_CONTEXT_VUID		= 31,
+	LTTNG_KERNEL_CONTEXT_VEUID		= 32,
+	LTTNG_KERNEL_CONTEXT_VSUID		= 33,
+	LTTNG_KERNEL_CONTEXT_VFSUID		= 34,
+	LTTNG_KERNEL_CONTEXT_VGID		= 35,
+	LTTNG_KERNEL_CONTEXT_VEGID		= 36,
+	LTTNG_KERNEL_CONTEXT_VSGID		= 37,
+	LTTNG_KERNEL_CONTEXT_VFSGID		= 38,
 };
 
 struct lttng_kernel_perf_counter_ctx {
diff --git a/lttng-context-egid.c b/lttng-context-egid.c
new file mode 100644
index 0000000..ace7475
--- /dev/null
+++ b/lttng-context-egid.c
@@ -0,0 +1,91 @@
+/*
+ * lttng-context-egid.c
+ *
+ * LTTng effective group ID context.
+ *
+ * Copyright (C) 2009-2012 Mathieu Desnoyers <mathieu.desnoyers at efficios.com>
+ *               2018 Michael Jeanson <mjeanson at efficios.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; only
+ * version 2.1 of the License.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <linux/module.h>
+#include <linux/sched.h>
+#include <lttng-events.h>
+#include <lttng-tracer.h>
+#include <wrapper/ringbuffer/frontend_types.h>
+#include <wrapper/vmalloc.h>
+#include <wrapper/user_namespace.h>
+
+static
+size_t egid_get_size(size_t offset)
+{
+	size_t size = 0;
+
+	size += lib_ring_buffer_align(offset, lttng_alignof(gid_t));
+	size += sizeof(gid_t);
+	return size;
+}
+
+static
+void egid_record(struct lttng_ctx_field *field,
+		 struct lib_ring_buffer_ctx *ctx,
+		 struct lttng_channel *chan)
+{
+	gid_t egid;
+
+	egid = lttng_current_egid();
+	lib_ring_buffer_align_ctx(ctx, lttng_alignof(egid));
+	chan->ops->event_write(ctx, &egid, sizeof(egid));
+}
+
+static
+void egid_get_value(struct lttng_ctx_field *field,
+		struct lttng_probe_ctx *lttng_probe_ctx,
+		union lttng_ctx_value *value)
+{
+	gid_t egid;
+
+	egid = lttng_current_egid();
+	value->s64 = egid;
+}
+
+int lttng_add_egid_to_ctx(struct lttng_ctx **ctx)
+{
+	struct lttng_ctx_field *field;
+
+	field = lttng_append_context(ctx);
+	if (!field)
+		return -ENOMEM;
+	if (lttng_find_context(*ctx, "egid")) {
+		lttng_remove_context_field(ctx, field);
+		return -EEXIST;
+	}
+	field->event_field.name = "egid";
+	field->event_field.type.atype = atype_integer;
+	field->event_field.type.u.basic.integer.size = sizeof(gid_t) * CHAR_BIT;
+	field->event_field.type.u.basic.integer.alignment = lttng_alignof(gid_t) * CHAR_BIT;
+	field->event_field.type.u.basic.integer.signedness = lttng_is_signed_type(gid_t);
+	field->event_field.type.u.basic.integer.reverse_byte_order = 0;
+	field->event_field.type.u.basic.integer.base = 10;
+	field->event_field.type.u.basic.integer.encoding = lttng_encode_none;
+	field->get_size = egid_get_size;
+	field->record = egid_record;
+	field->get_value = egid_get_value;
+	lttng_context_update(*ctx);
+	wrapper_vmalloc_sync_all();
+	return 0;
+}
+EXPORT_SYMBOL_GPL(lttng_add_egid_to_ctx);
diff --git a/lttng-context-euid.c b/lttng-context-euid.c
new file mode 100644
index 0000000..f12e96d
--- /dev/null
+++ b/lttng-context-euid.c
@@ -0,0 +1,91 @@
+/*
+ * lttng-context-euid.c
+ *
+ * LTTng effective user ID context.
+ *
+ * Copyright (C) 2009-2012 Mathieu Desnoyers <mathieu.desnoyers at efficios.com>
+ *               2018 Michael Jeanson <mjeanson at efficios.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; only
+ * version 2.1 of the License.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <linux/module.h>
+#include <linux/sched.h>
+#include <lttng-events.h>
+#include <lttng-tracer.h>
+#include <wrapper/ringbuffer/frontend_types.h>
+#include <wrapper/vmalloc.h>
+#include <wrapper/user_namespace.h>
+
+static
+size_t euid_get_size(size_t offset)
+{
+	size_t size = 0;
+
+	size += lib_ring_buffer_align(offset, lttng_alignof(uid_t));
+	size += sizeof(uid_t);
+	return size;
+}
+
+static
+void euid_record(struct lttng_ctx_field *field,
+		 struct lib_ring_buffer_ctx *ctx,
+		 struct lttng_channel *chan)
+{
+	uid_t euid;
+
+	euid = lttng_current_euid();
+	lib_ring_buffer_align_ctx(ctx, lttng_alignof(euid));
+	chan->ops->event_write(ctx, &euid, sizeof(euid));
+}
+
+static
+void euid_get_value(struct lttng_ctx_field *field,
+		struct lttng_probe_ctx *lttng_probe_ctx,
+		union lttng_ctx_value *value)
+{
+	uid_t euid;
+
+	euid = lttng_current_euid();
+	value->s64 = euid;
+}
+
+int lttng_add_euid_to_ctx(struct lttng_ctx **ctx)
+{
+	struct lttng_ctx_field *field;
+
+	field = lttng_append_context(ctx);
+	if (!field)
+		return -ENOMEM;
+	if (lttng_find_context(*ctx, "euid")) {
+		lttng_remove_context_field(ctx, field);
+		return -EEXIST;
+	}
+	field->event_field.name = "euid";
+	field->event_field.type.atype = atype_integer;
+	field->event_field.type.u.basic.integer.size = sizeof(uid_t) * CHAR_BIT;
+	field->event_field.type.u.basic.integer.alignment = lttng_alignof(uid_t) * CHAR_BIT;
+	field->event_field.type.u.basic.integer.signedness = lttng_is_signed_type(uid_t);
+	field->event_field.type.u.basic.integer.reverse_byte_order = 0;
+	field->event_field.type.u.basic.integer.base = 10;
+	field->event_field.type.u.basic.integer.encoding = lttng_encode_none;
+	field->get_size = euid_get_size;
+	field->record = euid_record;
+	field->get_value = euid_get_value;
+	lttng_context_update(*ctx);
+	wrapper_vmalloc_sync_all();
+	return 0;
+}
+EXPORT_SYMBOL_GPL(lttng_add_euid_to_ctx);
diff --git a/lttng-context-fsgid.c b/lttng-context-fsgid.c
new file mode 100644
index 0000000..2713cdb
--- /dev/null
+++ b/lttng-context-fsgid.c
@@ -0,0 +1,91 @@
+/*
+ * lttng-context-fsgid.c
+ *
+ * LTTng filesystem group ID context.
+ *
+ * Copyright (C) 2009-2012 Mathieu Desnoyers <mathieu.desnoyers at efficios.com>
+ *               2018 Michael Jeanson <mjeanson at efficios.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; only
+ * version 2.1 of the License.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <linux/module.h>
+#include <linux/sched.h>
+#include <lttng-events.h>
+#include <lttng-tracer.h>
+#include <wrapper/ringbuffer/frontend_types.h>
+#include <wrapper/vmalloc.h>
+#include <wrapper/user_namespace.h>
+
+static
+size_t fsgid_get_size(size_t offset)
+{
+	size_t size = 0;
+
+	size += lib_ring_buffer_align(offset, lttng_alignof(gid_t));
+	size += sizeof(gid_t);
+	return size;
+}
+
+static
+void fsgid_record(struct lttng_ctx_field *field,
+		 struct lib_ring_buffer_ctx *ctx,
+		 struct lttng_channel *chan)
+{
+	gid_t fsgid;
+
+	fsgid = lttng_current_fsgid();
+	lib_ring_buffer_align_ctx(ctx, lttng_alignof(fsgid));
+	chan->ops->event_write(ctx, &fsgid, sizeof(fsgid));
+}
+
+static
+void fsgid_get_value(struct lttng_ctx_field *field,
+		struct lttng_probe_ctx *lttng_probe_ctx,
+		union lttng_ctx_value *value)
+{
+	gid_t fsgid;
+
+	fsgid = lttng_current_fsgid();
+	value->s64 = fsgid;
+}
+
+int lttng_add_fsgid_to_ctx(struct lttng_ctx **ctx)
+{
+	struct lttng_ctx_field *field;
+
+	field = lttng_append_context(ctx);
+	if (!field)
+		return -ENOMEM;
+	if (lttng_find_context(*ctx, "fsgid")) {
+		lttng_remove_context_field(ctx, field);
+		return -EEXIST;
+	}
+	field->event_field.name = "fsgid";
+	field->event_field.type.atype = atype_integer;
+	field->event_field.type.u.basic.integer.size = sizeof(gid_t) * CHAR_BIT;
+	field->event_field.type.u.basic.integer.alignment = lttng_alignof(gid_t) * CHAR_BIT;
+	field->event_field.type.u.basic.integer.signedness = lttng_is_signed_type(gid_t);
+	field->event_field.type.u.basic.integer.reverse_byte_order = 0;
+	field->event_field.type.u.basic.integer.base = 10;
+	field->event_field.type.u.basic.integer.encoding = lttng_encode_none;
+	field->get_size = fsgid_get_size;
+	field->record = fsgid_record;
+	field->get_value = fsgid_get_value;
+	lttng_context_update(*ctx);
+	wrapper_vmalloc_sync_all();
+	return 0;
+}
+EXPORT_SYMBOL_GPL(lttng_add_fsgid_to_ctx);
diff --git a/lttng-context-fsuid.c b/lttng-context-fsuid.c
new file mode 100644
index 0000000..77bed3a
--- /dev/null
+++ b/lttng-context-fsuid.c
@@ -0,0 +1,91 @@
+/*
+ * lttng-context-fsuid.c
+ *
+ * LTTng filesystem user ID context.
+ *
+ * Copyright (C) 2009-2012 Mathieu Desnoyers <mathieu.desnoyers at efficios.com>
+ *               2018 Michael Jeanson <mjeanson at efficios.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; only
+ * version 2.1 of the License.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <linux/module.h>
+#include <linux/sched.h>
+#include <lttng-events.h>
+#include <lttng-tracer.h>
+#include <wrapper/ringbuffer/frontend_types.h>
+#include <wrapper/vmalloc.h>
+#include <wrapper/user_namespace.h>
+
+static
+size_t fsuid_get_size(size_t offset)
+{
+	size_t size = 0;
+
+	size += lib_ring_buffer_align(offset, lttng_alignof(uid_t));
+	size += sizeof(uid_t);
+	return size;
+}
+
+static
+void fsuid_record(struct lttng_ctx_field *field,
+		 struct lib_ring_buffer_ctx *ctx,
+		 struct lttng_channel *chan)
+{
+	uid_t fsuid;
+
+	fsuid = lttng_current_fsuid();
+	lib_ring_buffer_align_ctx(ctx, lttng_alignof(fsuid));
+	chan->ops->event_write(ctx, &fsuid, sizeof(fsuid));
+}
+
+static
+void fsuid_get_value(struct lttng_ctx_field *field,
+		struct lttng_probe_ctx *lttng_probe_ctx,
+		union lttng_ctx_value *value)
+{
+	uid_t fsuid;
+
+	fsuid = lttng_current_fsuid();
+	value->s64 = fsuid;
+}
+
+int lttng_add_fsuid_to_ctx(struct lttng_ctx **ctx)
+{
+	struct lttng_ctx_field *field;
+
+	field = lttng_append_context(ctx);
+	if (!field)
+		return -ENOMEM;
+	if (lttng_find_context(*ctx, "fsuid")) {
+		lttng_remove_context_field(ctx, field);
+		return -EEXIST;
+	}
+	field->event_field.name = "fsuid";
+	field->event_field.type.atype = atype_integer;
+	field->event_field.type.u.basic.integer.size = sizeof(uid_t) * CHAR_BIT;
+	field->event_field.type.u.basic.integer.alignment = lttng_alignof(uid_t) * CHAR_BIT;
+	field->event_field.type.u.basic.integer.signedness = lttng_is_signed_type(uid_t);
+	field->event_field.type.u.basic.integer.reverse_byte_order = 0;
+	field->event_field.type.u.basic.integer.base = 10;
+	field->event_field.type.u.basic.integer.encoding = lttng_encode_none;
+	field->get_size = fsuid_get_size;
+	field->record = fsuid_record;
+	field->get_value = fsuid_get_value;
+	lttng_context_update(*ctx);
+	wrapper_vmalloc_sync_all();
+	return 0;
+}
+EXPORT_SYMBOL_GPL(lttng_add_fsuid_to_ctx);
diff --git a/lttng-context-gid.c b/lttng-context-gid.c
new file mode 100644
index 0000000..c31c00f
--- /dev/null
+++ b/lttng-context-gid.c
@@ -0,0 +1,91 @@
+/*
+ * lttng-context-gid.c
+ *
+ * LTTng real group ID context.
+ *
+ * Copyright (C) 2009-2012 Mathieu Desnoyers <mathieu.desnoyers at efficios.com>
+ *               2018 Michael Jeanson <mjeanson at efficios.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; only
+ * version 2.1 of the License.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <linux/module.h>
+#include <linux/sched.h>
+#include <lttng-events.h>
+#include <lttng-tracer.h>
+#include <wrapper/ringbuffer/frontend_types.h>
+#include <wrapper/vmalloc.h>
+#include <wrapper/user_namespace.h>
+
+static
+size_t gid_get_size(size_t offset)
+{
+	size_t size = 0;
+
+	size += lib_ring_buffer_align(offset, lttng_alignof(gid_t));
+	size += sizeof(gid_t);
+	return size;
+}
+
+static
+void gid_record(struct lttng_ctx_field *field,
+		 struct lib_ring_buffer_ctx *ctx,
+		 struct lttng_channel *chan)
+{
+	gid_t gid;
+
+	gid = lttng_current_gid();
+	lib_ring_buffer_align_ctx(ctx, lttng_alignof(gid));
+	chan->ops->event_write(ctx, &gid, sizeof(gid));
+}
+
+static
+void gid_get_value(struct lttng_ctx_field *field,
+		struct lttng_probe_ctx *lttng_probe_ctx,
+		union lttng_ctx_value *value)
+{
+	gid_t gid;
+
+	gid = lttng_current_gid();
+	value->s64 = gid;
+}
+
+int lttng_add_gid_to_ctx(struct lttng_ctx **ctx)
+{
+	struct lttng_ctx_field *field;
+
+	field = lttng_append_context(ctx);
+	if (!field)
+		return -ENOMEM;
+	if (lttng_find_context(*ctx, "gid")) {
+		lttng_remove_context_field(ctx, field);
+		return -EEXIST;
+	}
+	field->event_field.name = "gid";
+	field->event_field.type.atype = atype_integer;
+	field->event_field.type.u.basic.integer.size = sizeof(gid_t) * CHAR_BIT;
+	field->event_field.type.u.basic.integer.alignment = lttng_alignof(gid_t) * CHAR_BIT;
+	field->event_field.type.u.basic.integer.signedness = lttng_is_signed_type(gid_t);
+	field->event_field.type.u.basic.integer.reverse_byte_order = 0;
+	field->event_field.type.u.basic.integer.base = 10;
+	field->event_field.type.u.basic.integer.encoding = lttng_encode_none;
+	field->get_size = gid_get_size;
+	field->record = gid_record;
+	field->get_value = gid_get_value;
+	lttng_context_update(*ctx);
+	wrapper_vmalloc_sync_all();
+	return 0;
+}
+EXPORT_SYMBOL_GPL(lttng_add_gid_to_ctx);
diff --git a/lttng-context-sgid.c b/lttng-context-sgid.c
new file mode 100644
index 0000000..7d3ce2f
--- /dev/null
+++ b/lttng-context-sgid.c
@@ -0,0 +1,91 @@
+/*
+ * lttng-context-sgid.c
+ *
+ * LTTng saved set-group-ID context.
+ *
+ * Copyright (C) 2009-2012 Mathieu Desnoyers <mathieu.desnoyers at efficios.com>
+ *               2018 Michael Jeanson <mjeanson at efficios.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; only
+ * version 2.1 of the License.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <linux/module.h>
+#include <linux/sched.h>
+#include <lttng-events.h>
+#include <lttng-tracer.h>
+#include <wrapper/ringbuffer/frontend_types.h>
+#include <wrapper/vmalloc.h>
+#include <wrapper/user_namespace.h>
+
+static
+size_t sgid_get_size(size_t offset)
+{
+	size_t size = 0;
+
+	size += lib_ring_buffer_align(offset, lttng_alignof(gid_t));
+	size += sizeof(gid_t);
+	return size;
+}
+
+static
+void sgid_record(struct lttng_ctx_field *field,
+		 struct lib_ring_buffer_ctx *ctx,
+		 struct lttng_channel *chan)
+{
+	gid_t sgid;
+
+	sgid = lttng_current_sgid();
+	lib_ring_buffer_align_ctx(ctx, lttng_alignof(sgid));
+	chan->ops->event_write(ctx, &sgid, sizeof(sgid));
+}
+
+static
+void sgid_get_value(struct lttng_ctx_field *field,
+		struct lttng_probe_ctx *lttng_probe_ctx,
+		union lttng_ctx_value *value)
+{
+	gid_t sgid;
+
+	sgid = lttng_current_sgid();
+	value->s64 = sgid;
+}
+
+int lttng_add_sgid_to_ctx(struct lttng_ctx **ctx)
+{
+	struct lttng_ctx_field *field;
+
+	field = lttng_append_context(ctx);
+	if (!field)
+		return -ENOMEM;
+	if (lttng_find_context(*ctx, "sgid")) {
+		lttng_remove_context_field(ctx, field);
+		return -EEXIST;
+	}
+	field->event_field.name = "sgid";
+	field->event_field.type.atype = atype_integer;
+	field->event_field.type.u.basic.integer.size = sizeof(gid_t) * CHAR_BIT;
+	field->event_field.type.u.basic.integer.alignment = lttng_alignof(gid_t) * CHAR_BIT;
+	field->event_field.type.u.basic.integer.signedness = lttng_is_signed_type(gid_t);
+	field->event_field.type.u.basic.integer.reverse_byte_order = 0;
+	field->event_field.type.u.basic.integer.base = 10;
+	field->event_field.type.u.basic.integer.encoding = lttng_encode_none;
+	field->get_size = sgid_get_size;
+	field->record = sgid_record;
+	field->get_value = sgid_get_value;
+	lttng_context_update(*ctx);
+	wrapper_vmalloc_sync_all();
+	return 0;
+}
+EXPORT_SYMBOL_GPL(lttng_add_sgid_to_ctx);
diff --git a/lttng-context-suid.c b/lttng-context-suid.c
new file mode 100644
index 0000000..2f13dd5
--- /dev/null
+++ b/lttng-context-suid.c
@@ -0,0 +1,91 @@
+/*
+ * lttng-context-suid.c
+ *
+ * LTTng saved set-user-ID context.
+ *
+ * Copyright (C) 2009-2012 Mathieu Desnoyers <mathieu.desnoyers at efficios.com>
+ *               2018 Michael Jeanson <mjeanson at efficios.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; only
+ * version 2.1 of the License.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <linux/module.h>
+#include <linux/sched.h>
+#include <lttng-events.h>
+#include <lttng-tracer.h>
+#include <wrapper/ringbuffer/frontend_types.h>
+#include <wrapper/vmalloc.h>
+#include <wrapper/user_namespace.h>
+
+static
+size_t suid_get_size(size_t offset)
+{
+	size_t size = 0;
+
+	size += lib_ring_buffer_align(offset, lttng_alignof(uid_t));
+	size += sizeof(uid_t);
+	return size;
+}
+
+static
+void suid_record(struct lttng_ctx_field *field,
+		 struct lib_ring_buffer_ctx *ctx,
+		 struct lttng_channel *chan)
+{
+	uid_t suid;
+
+	suid = lttng_current_suid();
+	lib_ring_buffer_align_ctx(ctx, lttng_alignof(suid));
+	chan->ops->event_write(ctx, &suid, sizeof(suid));
+}
+
+static
+void suid_get_value(struct lttng_ctx_field *field,
+		struct lttng_probe_ctx *lttng_probe_ctx,
+		union lttng_ctx_value *value)
+{
+	uid_t suid;
+
+	suid = lttng_current_suid();
+	value->s64 = suid;
+}
+
+int lttng_add_suid_to_ctx(struct lttng_ctx **ctx)
+{
+	struct lttng_ctx_field *field;
+
+	field = lttng_append_context(ctx);
+	if (!field)
+		return -ENOMEM;
+	if (lttng_find_context(*ctx, "suid")) {
+		lttng_remove_context_field(ctx, field);
+		return -EEXIST;
+	}
+	field->event_field.name = "suid";
+	field->event_field.type.atype = atype_integer;
+	field->event_field.type.u.basic.integer.size = sizeof(uid_t) * CHAR_BIT;
+	field->event_field.type.u.basic.integer.alignment = lttng_alignof(uid_t) * CHAR_BIT;
+	field->event_field.type.u.basic.integer.signedness = lttng_is_signed_type(uid_t);
+	field->event_field.type.u.basic.integer.reverse_byte_order = 0;
+	field->event_field.type.u.basic.integer.base = 10;
+	field->event_field.type.u.basic.integer.encoding = lttng_encode_none;
+	field->get_size = suid_get_size;
+	field->record = suid_record;
+	field->get_value = suid_get_value;
+	lttng_context_update(*ctx);
+	wrapper_vmalloc_sync_all();
+	return 0;
+}
+EXPORT_SYMBOL_GPL(lttng_add_suid_to_ctx);
diff --git a/lttng-context-uid.c b/lttng-context-uid.c
new file mode 100644
index 0000000..089bfd0
--- /dev/null
+++ b/lttng-context-uid.c
@@ -0,0 +1,91 @@
+/*
+ * lttng-context-uid.c
+ *
+ * LTTng real user ID context.
+ *
+ * Copyright (C) 2009-2012 Mathieu Desnoyers <mathieu.desnoyers at efficios.com>
+ *               2018 Michael Jeanson <mjeanson at efficios.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; only
+ * version 2.1 of the License.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <linux/module.h>
+#include <linux/sched.h>
+#include <lttng-events.h>
+#include <lttng-tracer.h>
+#include <wrapper/ringbuffer/frontend_types.h>
+#include <wrapper/vmalloc.h>
+#include <wrapper/user_namespace.h>
+
+static
+size_t uid_get_size(size_t offset)
+{
+	size_t size = 0;
+
+	size += lib_ring_buffer_align(offset, lttng_alignof(uid_t));
+	size += sizeof(uid_t);
+	return size;
+}
+
+static
+void uid_record(struct lttng_ctx_field *field,
+		 struct lib_ring_buffer_ctx *ctx,
+		 struct lttng_channel *chan)
+{
+	uid_t uid;
+
+	uid = lttng_current_uid();
+	lib_ring_buffer_align_ctx(ctx, lttng_alignof(uid));
+	chan->ops->event_write(ctx, &uid, sizeof(uid));
+}
+
+static
+void uid_get_value(struct lttng_ctx_field *field,
+		struct lttng_probe_ctx *lttng_probe_ctx,
+		union lttng_ctx_value *value)
+{
+	uid_t uid;
+
+	uid = lttng_current_uid();
+	value->s64 = uid;
+}
+
+int lttng_add_uid_to_ctx(struct lttng_ctx **ctx)
+{
+	struct lttng_ctx_field *field;
+
+	field = lttng_append_context(ctx);
+	if (!field)
+		return -ENOMEM;
+	if (lttng_find_context(*ctx, "uid")) {
+		lttng_remove_context_field(ctx, field);
+		return -EEXIST;
+	}
+	field->event_field.name = "uid";
+	field->event_field.type.atype = atype_integer;
+	field->event_field.type.u.basic.integer.size = sizeof(uid_t) * CHAR_BIT;
+	field->event_field.type.u.basic.integer.alignment = lttng_alignof(uid_t) * CHAR_BIT;
+	field->event_field.type.u.basic.integer.signedness = lttng_is_signed_type(uid_t);
+	field->event_field.type.u.basic.integer.reverse_byte_order = 0;
+	field->event_field.type.u.basic.integer.base = 10;
+	field->event_field.type.u.basic.integer.encoding = lttng_encode_none;
+	field->get_size = uid_get_size;
+	field->record = uid_record;
+	field->get_value = uid_get_value;
+	lttng_context_update(*ctx);
+	wrapper_vmalloc_sync_all();
+	return 0;
+}
+EXPORT_SYMBOL_GPL(lttng_add_uid_to_ctx);
diff --git a/lttng-context-vegid.c b/lttng-context-vegid.c
new file mode 100644
index 0000000..ec33bb0
--- /dev/null
+++ b/lttng-context-vegid.c
@@ -0,0 +1,91 @@
+/*
+ * lttng-context-vegid.c
+ *
+ * LTTng namespaced effective group ID context.
+ *
+ * Copyright (C) 2009-2012 Mathieu Desnoyers <mathieu.desnoyers at efficios.com>
+ *               2018 Michael Jeanson <mjeanson at efficios.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; only
+ * version 2.1 of the License.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <linux/module.h>
+#include <linux/sched.h>
+#include <lttng-events.h>
+#include <lttng-tracer.h>
+#include <wrapper/ringbuffer/frontend_types.h>
+#include <wrapper/vmalloc.h>
+#include <wrapper/user_namespace.h>
+
+static
+size_t vegid_get_size(size_t offset)
+{
+	size_t size = 0;
+
+	size += lib_ring_buffer_align(offset, lttng_alignof(gid_t));
+	size += sizeof(gid_t);
+	return size;
+}
+
+static
+void vegid_record(struct lttng_ctx_field *field,
+		 struct lib_ring_buffer_ctx *ctx,
+		 struct lttng_channel *chan)
+{
+	gid_t vegid;
+
+	vegid = lttng_current_vegid();
+	lib_ring_buffer_align_ctx(ctx, lttng_alignof(vegid));
+	chan->ops->event_write(ctx, &vegid, sizeof(vegid));
+}
+
+static
+void vegid_get_value(struct lttng_ctx_field *field,
+		struct lttng_probe_ctx *lttng_probe_ctx,
+		union lttng_ctx_value *value)
+{
+	gid_t vegid;
+
+	vegid = lttng_current_vegid();
+	value->s64 = vegid;
+}
+
+int lttng_add_vegid_to_ctx(struct lttng_ctx **ctx)
+{
+	struct lttng_ctx_field *field;
+
+	field = lttng_append_context(ctx);
+	if (!field)
+		return -ENOMEM;
+	if (lttng_find_context(*ctx, "vegid")) {
+		lttng_remove_context_field(ctx, field);
+		return -EEXIST;
+	}
+	field->event_field.name = "vegid";
+	field->event_field.type.atype = atype_integer;
+	field->event_field.type.u.basic.integer.size = sizeof(gid_t) * CHAR_BIT;
+	field->event_field.type.u.basic.integer.alignment = lttng_alignof(gid_t) * CHAR_BIT;
+	field->event_field.type.u.basic.integer.signedness = lttng_is_signed_type(gid_t);
+	field->event_field.type.u.basic.integer.reverse_byte_order = 0;
+	field->event_field.type.u.basic.integer.base = 10;
+	field->event_field.type.u.basic.integer.encoding = lttng_encode_none;
+	field->get_size = vegid_get_size;
+	field->record = vegid_record;
+	field->get_value = vegid_get_value;
+	lttng_context_update(*ctx);
+	wrapper_vmalloc_sync_all();
+	return 0;
+}
+EXPORT_SYMBOL_GPL(lttng_add_vegid_to_ctx);
diff --git a/lttng-context-veuid.c b/lttng-context-veuid.c
new file mode 100644
index 0000000..4a620c6
--- /dev/null
+++ b/lttng-context-veuid.c
@@ -0,0 +1,91 @@
+/*
+ * lttng-context-veuid.c
+ *
+ * LTTng namespaced effective user ID context.
+ *
+ * Copyright (C) 2009-2012 Mathieu Desnoyers <mathieu.desnoyers at efficios.com>
+ *               2018 Michael Jeanson <mjeanson at efficios.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; only
+ * version 2.1 of the License.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <linux/module.h>
+#include <linux/sched.h>
+#include <lttng-events.h>
+#include <lttng-tracer.h>
+#include <wrapper/ringbuffer/frontend_types.h>
+#include <wrapper/vmalloc.h>
+#include <wrapper/user_namespace.h>
+
+static
+size_t veuid_get_size(size_t offset)
+{
+	size_t size = 0;
+
+	size += lib_ring_buffer_align(offset, lttng_alignof(uid_t));
+	size += sizeof(uid_t);
+	return size;
+}
+
+static
+void veuid_record(struct lttng_ctx_field *field,
+		 struct lib_ring_buffer_ctx *ctx,
+		 struct lttng_channel *chan)
+{
+	uid_t veuid;
+
+	veuid = lttng_current_veuid();
+	lib_ring_buffer_align_ctx(ctx, lttng_alignof(veuid));
+	chan->ops->event_write(ctx, &veuid, sizeof(veuid));
+}
+
+static
+void veuid_get_value(struct lttng_ctx_field *field,
+		struct lttng_probe_ctx *lttng_probe_ctx,
+		union lttng_ctx_value *value)
+{
+	uid_t veuid;
+
+	veuid = lttng_current_veuid();
+	value->s64 = veuid;
+}
+
+int lttng_add_veuid_to_ctx(struct lttng_ctx **ctx)
+{
+	struct lttng_ctx_field *field;
+
+	field = lttng_append_context(ctx);
+	if (!field)
+		return -ENOMEM;
+	if (lttng_find_context(*ctx, "veuid")) {
+		lttng_remove_context_field(ctx, field);
+		return -EEXIST;
+	}
+	field->event_field.name = "veuid";
+	field->event_field.type.atype = atype_integer;
+	field->event_field.type.u.basic.integer.size = sizeof(uid_t) * CHAR_BIT;
+	field->event_field.type.u.basic.integer.alignment = lttng_alignof(uid_t) * CHAR_BIT;
+	field->event_field.type.u.basic.integer.signedness = lttng_is_signed_type(uid_t);
+	field->event_field.type.u.basic.integer.reverse_byte_order = 0;
+	field->event_field.type.u.basic.integer.base = 10;
+	field->event_field.type.u.basic.integer.encoding = lttng_encode_none;
+	field->get_size = veuid_get_size;
+	field->record = veuid_record;
+	field->get_value = veuid_get_value;
+	lttng_context_update(*ctx);
+	wrapper_vmalloc_sync_all();
+	return 0;
+}
+EXPORT_SYMBOL_GPL(lttng_add_veuid_to_ctx);
diff --git a/lttng-context-vfsgid.c b/lttng-context-vfsgid.c
new file mode 100644
index 0000000..56e54f7
--- /dev/null
+++ b/lttng-context-vfsgid.c
@@ -0,0 +1,91 @@
+/*
+ * lttng-context-vfsgid.c
+ *
+ * LTTng namespaced filesystem group ID context.
+ *
+ * Copyright (C) 2009-2012 Mathieu Desnoyers <mathieu.desnoyers at efficios.com>
+ *               2018 Michael Jeanson <mjeanson at efficios.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; only
+ * version 2.1 of the License.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <linux/module.h>
+#include <linux/sched.h>
+#include <lttng-events.h>
+#include <lttng-tracer.h>
+#include <wrapper/ringbuffer/frontend_types.h>
+#include <wrapper/vmalloc.h>
+#include <wrapper/user_namespace.h>
+
+static
+size_t vfsgid_get_size(size_t offset)
+{
+	size_t size = 0;
+
+	size += lib_ring_buffer_align(offset, lttng_alignof(gid_t));
+	size += sizeof(gid_t);
+	return size;
+}
+
+static
+void vfsgid_record(struct lttng_ctx_field *field,
+		 struct lib_ring_buffer_ctx *ctx,
+		 struct lttng_channel *chan)
+{
+	gid_t vfsgid;
+
+	vfsgid = lttng_current_vfsgid();
+	lib_ring_buffer_align_ctx(ctx, lttng_alignof(vfsgid));
+	chan->ops->event_write(ctx, &vfsgid, sizeof(vfsgid));
+}
+
+static
+void vfsgid_get_value(struct lttng_ctx_field *field,
+		struct lttng_probe_ctx *lttng_probe_ctx,
+		union lttng_ctx_value *value)
+{
+	gid_t vfsgid;
+
+	vfsgid = lttng_current_vfsgid();
+	value->s64 = vfsgid;
+}
+
+int lttng_add_vfsgid_to_ctx(struct lttng_ctx **ctx)
+{
+	struct lttng_ctx_field *field;
+
+	field = lttng_append_context(ctx);
+	if (!field)
+		return -ENOMEM;
+	if (lttng_find_context(*ctx, "vfsgid")) {
+		lttng_remove_context_field(ctx, field);
+		return -EEXIST;
+	}
+	field->event_field.name = "vfsgid";
+	field->event_field.type.atype = atype_integer;
+	field->event_field.type.u.basic.integer.size = sizeof(gid_t) * CHAR_BIT;
+	field->event_field.type.u.basic.integer.alignment = lttng_alignof(gid_t) * CHAR_BIT;
+	field->event_field.type.u.basic.integer.signedness = lttng_is_signed_type(gid_t);
+	field->event_field.type.u.basic.integer.reverse_byte_order = 0;
+	field->event_field.type.u.basic.integer.base = 10;
+	field->event_field.type.u.basic.integer.encoding = lttng_encode_none;
+	field->get_size = vfsgid_get_size;
+	field->record = vfsgid_record;
+	field->get_value = vfsgid_get_value;
+	lttng_context_update(*ctx);
+	wrapper_vmalloc_sync_all();
+	return 0;
+}
+EXPORT_SYMBOL_GPL(lttng_add_vfsgid_to_ctx);
diff --git a/lttng-context-vfsuid.c b/lttng-context-vfsuid.c
new file mode 100644
index 0000000..ce1a9fa
--- /dev/null
+++ b/lttng-context-vfsuid.c
@@ -0,0 +1,91 @@
+/*
+ * lttng-context-vfsuid.c
+ *
+ * LTTng namespaced filesystem user ID context.
+ *
+ * Copyright (C) 2009-2012 Mathieu Desnoyers <mathieu.desnoyers at efficios.com>
+ *               2018 Michael Jeanson <mjeanson at efficios.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; only
+ * version 2.1 of the License.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <linux/module.h>
+#include <linux/sched.h>
+#include <lttng-events.h>
+#include <lttng-tracer.h>
+#include <wrapper/ringbuffer/frontend_types.h>
+#include <wrapper/vmalloc.h>
+#include <wrapper/user_namespace.h>
+
+static
+size_t vfsuid_get_size(size_t offset)
+{
+	size_t size = 0;
+
+	size += lib_ring_buffer_align(offset, lttng_alignof(uid_t));
+	size += sizeof(uid_t);
+	return size;
+}
+
+static
+void vfsuid_record(struct lttng_ctx_field *field,
+		 struct lib_ring_buffer_ctx *ctx,
+		 struct lttng_channel *chan)
+{
+	uid_t vfsuid;
+
+	vfsuid = lttng_current_vfsuid();
+	lib_ring_buffer_align_ctx(ctx, lttng_alignof(vfsuid));
+	chan->ops->event_write(ctx, &vfsuid, sizeof(vfsuid));
+}
+
+static
+void vfsuid_get_value(struct lttng_ctx_field *field,
+		struct lttng_probe_ctx *lttng_probe_ctx,
+		union lttng_ctx_value *value)
+{
+	uid_t vfsuid;
+
+	vfsuid = lttng_current_vfsuid();
+	value->s64 = vfsuid;
+}
+
+int lttng_add_vfsuid_to_ctx(struct lttng_ctx **ctx)
+{
+	struct lttng_ctx_field *field;
+
+	field = lttng_append_context(ctx);
+	if (!field)
+		return -ENOMEM;
+	if (lttng_find_context(*ctx, "vfsuid")) {
+		lttng_remove_context_field(ctx, field);
+		return -EEXIST;
+	}
+	field->event_field.name = "vfsuid";
+	field->event_field.type.atype = atype_integer;
+	field->event_field.type.u.basic.integer.size = sizeof(uid_t) * CHAR_BIT;
+	field->event_field.type.u.basic.integer.alignment = lttng_alignof(uid_t) * CHAR_BIT;
+	field->event_field.type.u.basic.integer.signedness = lttng_is_signed_type(uid_t);
+	field->event_field.type.u.basic.integer.reverse_byte_order = 0;
+	field->event_field.type.u.basic.integer.base = 10;
+	field->event_field.type.u.basic.integer.encoding = lttng_encode_none;
+	field->get_size = vfsuid_get_size;
+	field->record = vfsuid_record;
+	field->get_value = vfsuid_get_value;
+	lttng_context_update(*ctx);
+	wrapper_vmalloc_sync_all();
+	return 0;
+}
+EXPORT_SYMBOL_GPL(lttng_add_vfsuid_to_ctx);
diff --git a/lttng-context-vgid.c b/lttng-context-vgid.c
new file mode 100644
index 0000000..b26eebb
--- /dev/null
+++ b/lttng-context-vgid.c
@@ -0,0 +1,91 @@
+/*
+ * lttng-context-vgid.c
+ *
+ * LTTng namespaced real group ID context.
+ *
+ * Copyright (C) 2009-2012 Mathieu Desnoyers <mathieu.desnoyers at efficios.com>
+ *               2018 Michael Jeanson <mjeanson at efficios.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; only
+ * version 2.1 of the License.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <linux/module.h>
+#include <linux/sched.h>
+#include <lttng-events.h>
+#include <lttng-tracer.h>
+#include <wrapper/ringbuffer/frontend_types.h>
+#include <wrapper/vmalloc.h>
+#include <wrapper/user_namespace.h>
+
+static
+size_t vgid_get_size(size_t offset)
+{
+	size_t size = 0;
+
+	size += lib_ring_buffer_align(offset, lttng_alignof(gid_t));
+	size += sizeof(gid_t);
+	return size;
+}
+
+static
+void vgid_record(struct lttng_ctx_field *field,
+		 struct lib_ring_buffer_ctx *ctx,
+		 struct lttng_channel *chan)
+{
+	gid_t vgid;
+
+	vgid = lttng_current_vgid();
+	lib_ring_buffer_align_ctx(ctx, lttng_alignof(vgid));
+	chan->ops->event_write(ctx, &vgid, sizeof(vgid));
+}
+
+static
+void vgid_get_value(struct lttng_ctx_field *field,
+		struct lttng_probe_ctx *lttng_probe_ctx,
+		union lttng_ctx_value *value)
+{
+	gid_t vgid;
+
+	vgid = lttng_current_vgid();
+	value->s64 = vgid;
+}
+
+int lttng_add_vgid_to_ctx(struct lttng_ctx **ctx)
+{
+	struct lttng_ctx_field *field;
+
+	field = lttng_append_context(ctx);
+	if (!field)
+		return -ENOMEM;
+	if (lttng_find_context(*ctx, "vgid")) {
+		lttng_remove_context_field(ctx, field);
+		return -EEXIST;
+	}
+	field->event_field.name = "vgid";
+	field->event_field.type.atype = atype_integer;
+	field->event_field.type.u.basic.integer.size = sizeof(gid_t) * CHAR_BIT;
+	field->event_field.type.u.basic.integer.alignment = lttng_alignof(gid_t) * CHAR_BIT;
+	field->event_field.type.u.basic.integer.signedness = lttng_is_signed_type(gid_t);
+	field->event_field.type.u.basic.integer.reverse_byte_order = 0;
+	field->event_field.type.u.basic.integer.base = 10;
+	field->event_field.type.u.basic.integer.encoding = lttng_encode_none;
+	field->get_size = vgid_get_size;
+	field->record = vgid_record;
+	field->get_value = vgid_get_value;
+	lttng_context_update(*ctx);
+	wrapper_vmalloc_sync_all();
+	return 0;
+}
+EXPORT_SYMBOL_GPL(lttng_add_vgid_to_ctx);
diff --git a/lttng-context-vsgid.c b/lttng-context-vsgid.c
new file mode 100644
index 0000000..1b65918
--- /dev/null
+++ b/lttng-context-vsgid.c
@@ -0,0 +1,91 @@
+/*
+ * lttng-context-vsgid.c
+ *
+ * LTTng namespaced saved set-group-ID context.
+ *
+ * Copyright (C) 2009-2012 Mathieu Desnoyers <mathieu.desnoyers at efficios.com>
+ *               2018 Michael Jeanson <mjeanson at efficios.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; only
+ * version 2.1 of the License.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <linux/module.h>
+#include <linux/sched.h>
+#include <lttng-events.h>
+#include <lttng-tracer.h>
+#include <wrapper/ringbuffer/frontend_types.h>
+#include <wrapper/vmalloc.h>
+#include <wrapper/user_namespace.h>
+
+static
+size_t vsgid_get_size(size_t offset)
+{
+	size_t size = 0;
+
+	size += lib_ring_buffer_align(offset, lttng_alignof(gid_t));
+	size += sizeof(gid_t);
+	return size;
+}
+
+static
+void vsgid_record(struct lttng_ctx_field *field,
+		 struct lib_ring_buffer_ctx *ctx,
+		 struct lttng_channel *chan)
+{
+	gid_t vsgid;
+
+	vsgid = lttng_current_vsgid();
+	lib_ring_buffer_align_ctx(ctx, lttng_alignof(vsgid));
+	chan->ops->event_write(ctx, &vsgid, sizeof(vsgid));
+}
+
+static
+void vsgid_get_value(struct lttng_ctx_field *field,
+		struct lttng_probe_ctx *lttng_probe_ctx,
+		union lttng_ctx_value *value)
+{
+	gid_t vsgid;
+
+	vsgid = lttng_current_vsgid();
+	value->s64 = vsgid;
+}
+
+int lttng_add_vsgid_to_ctx(struct lttng_ctx **ctx)
+{
+	struct lttng_ctx_field *field;
+
+	field = lttng_append_context(ctx);
+	if (!field)
+		return -ENOMEM;
+	if (lttng_find_context(*ctx, "vsgid")) {
+		lttng_remove_context_field(ctx, field);
+		return -EEXIST;
+	}
+	field->event_field.name = "vsgid";
+	field->event_field.type.atype = atype_integer;
+	field->event_field.type.u.basic.integer.size = sizeof(gid_t) * CHAR_BIT;
+	field->event_field.type.u.basic.integer.alignment = lttng_alignof(gid_t) * CHAR_BIT;
+	field->event_field.type.u.basic.integer.signedness = lttng_is_signed_type(gid_t);
+	field->event_field.type.u.basic.integer.reverse_byte_order = 0;
+	field->event_field.type.u.basic.integer.base = 10;
+	field->event_field.type.u.basic.integer.encoding = lttng_encode_none;
+	field->get_size = vsgid_get_size;
+	field->record = vsgid_record;
+	field->get_value = vsgid_get_value;
+	lttng_context_update(*ctx);
+	wrapper_vmalloc_sync_all();
+	return 0;
+}
+EXPORT_SYMBOL_GPL(lttng_add_vsgid_to_ctx);
diff --git a/lttng-context-vsuid.c b/lttng-context-vsuid.c
new file mode 100644
index 0000000..ac0721e
--- /dev/null
+++ b/lttng-context-vsuid.c
@@ -0,0 +1,91 @@
+/*
+ * lttng-context-vsuid.c
+ *
+ * LTTng namespaced saved set-user-ID context.
+ *
+ * Copyright (C) 2009-2012 Mathieu Desnoyers <mathieu.desnoyers at efficios.com>
+ *               2018 Michael Jeanson <mjeanson at efficios.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; only
+ * version 2.1 of the License.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <linux/module.h>
+#include <linux/sched.h>
+#include <lttng-events.h>
+#include <lttng-tracer.h>
+#include <wrapper/ringbuffer/frontend_types.h>
+#include <wrapper/vmalloc.h>
+#include <wrapper/user_namespace.h>
+
+static
+size_t vsuid_get_size(size_t offset)
+{
+	size_t size = 0;
+
+	size += lib_ring_buffer_align(offset, lttng_alignof(uid_t));
+	size += sizeof(uid_t);
+	return size;
+}
+
+static
+void vsuid_record(struct lttng_ctx_field *field,
+		 struct lib_ring_buffer_ctx *ctx,
+		 struct lttng_channel *chan)
+{
+	uid_t vsuid;
+
+	vsuid = lttng_current_vsuid();
+	lib_ring_buffer_align_ctx(ctx, lttng_alignof(vsuid));
+	chan->ops->event_write(ctx, &vsuid, sizeof(vsuid));
+}
+
+static
+void vsuid_get_value(struct lttng_ctx_field *field,
+		struct lttng_probe_ctx *lttng_probe_ctx,
+		union lttng_ctx_value *value)
+{
+	uid_t vsuid;
+
+	vsuid = lttng_current_vsuid();
+	value->s64 = vsuid;
+}
+
+int lttng_add_vsuid_to_ctx(struct lttng_ctx **ctx)
+{
+	struct lttng_ctx_field *field;
+
+	field = lttng_append_context(ctx);
+	if (!field)
+		return -ENOMEM;
+	if (lttng_find_context(*ctx, "vsuid")) {
+		lttng_remove_context_field(ctx, field);
+		return -EEXIST;
+	}
+	field->event_field.name = "vsuid";
+	field->event_field.type.atype = atype_integer;
+	field->event_field.type.u.basic.integer.size = sizeof(uid_t) * CHAR_BIT;
+	field->event_field.type.u.basic.integer.alignment = lttng_alignof(uid_t) * CHAR_BIT;
+	field->event_field.type.u.basic.integer.signedness = lttng_is_signed_type(uid_t);
+	field->event_field.type.u.basic.integer.reverse_byte_order = 0;
+	field->event_field.type.u.basic.integer.base = 10;
+	field->event_field.type.u.basic.integer.encoding = lttng_encode_none;
+	field->get_size = vsuid_get_size;
+	field->record = vsuid_record;
+	field->get_value = vsuid_get_value;
+	lttng_context_update(*ctx);
+	wrapper_vmalloc_sync_all();
+	return 0;
+}
+EXPORT_SYMBOL_GPL(lttng_add_vsuid_to_ctx);
diff --git a/lttng-context-vuid.c b/lttng-context-vuid.c
new file mode 100644
index 0000000..4852ea7
--- /dev/null
+++ b/lttng-context-vuid.c
@@ -0,0 +1,91 @@
+/*
+ * lttng-context-vuid.c
+ *
+ * LTTng namespaced real user ID context.
+ *
+ * Copyright (C) 2009-2012 Mathieu Desnoyers <mathieu.desnoyers at efficios.com>
+ *               2018 Michael Jeanson <mjeanson at efficios.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; only
+ * version 2.1 of the License.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <linux/module.h>
+#include <linux/sched.h>
+#include <lttng-events.h>
+#include <lttng-tracer.h>
+#include <wrapper/ringbuffer/frontend_types.h>
+#include <wrapper/vmalloc.h>
+#include <wrapper/user_namespace.h>
+
+static
+size_t vuid_get_size(size_t offset)
+{
+	size_t size = 0;
+
+	size += lib_ring_buffer_align(offset, lttng_alignof(uid_t));
+	size += sizeof(uid_t);
+	return size;
+}
+
+static
+void vuid_record(struct lttng_ctx_field *field,
+		 struct lib_ring_buffer_ctx *ctx,
+		 struct lttng_channel *chan)
+{
+	uid_t vuid;
+
+	vuid = lttng_current_vuid();
+	lib_ring_buffer_align_ctx(ctx, lttng_alignof(vuid));
+	chan->ops->event_write(ctx, &vuid, sizeof(vuid));
+}
+
+static
+void vuid_get_value(struct lttng_ctx_field *field,
+		struct lttng_probe_ctx *lttng_probe_ctx,
+		union lttng_ctx_value *value)
+{
+	uid_t vuid;
+
+	vuid = lttng_current_vuid();
+	value->s64 = vuid;
+}
+
+int lttng_add_vuid_to_ctx(struct lttng_ctx **ctx)
+{
+	struct lttng_ctx_field *field;
+
+	field = lttng_append_context(ctx);
+	if (!field)
+		return -ENOMEM;
+	if (lttng_find_context(*ctx, "vuid")) {
+		lttng_remove_context_field(ctx, field);
+		return -EEXIST;
+	}
+	field->event_field.name = "vuid";
+	field->event_field.type.atype = atype_integer;
+	field->event_field.type.u.basic.integer.size = sizeof(uid_t) * CHAR_BIT;
+	field->event_field.type.u.basic.integer.alignment = lttng_alignof(uid_t) * CHAR_BIT;
+	field->event_field.type.u.basic.integer.signedness = lttng_is_signed_type(uid_t);
+	field->event_field.type.u.basic.integer.reverse_byte_order = 0;
+	field->event_field.type.u.basic.integer.base = 10;
+	field->event_field.type.u.basic.integer.encoding = lttng_encode_none;
+	field->get_size = vuid_get_size;
+	field->record = vuid_record;
+	field->get_value = vuid_get_value;
+	lttng_context_update(*ctx);
+	wrapper_vmalloc_sync_all();
+	return 0;
+}
+EXPORT_SYMBOL_GPL(lttng_add_vuid_to_ctx);
diff --git a/lttng-events.h b/lttng-events.h
index f3b2b91..b7e357d 100644
--- a/lttng-events.h
+++ b/lttng-events.h
@@ -781,6 +781,23 @@ int lttng_add_uts_ns_to_ctx(struct lttng_ctx **ctx)
 }
 #endif
 
+int lttng_add_uid_to_ctx(struct lttng_ctx **ctx);
+int lttng_add_euid_to_ctx(struct lttng_ctx **ctx);
+int lttng_add_suid_to_ctx(struct lttng_ctx **ctx);
+int lttng_add_fsuid_to_ctx(struct lttng_ctx **ctx);
+int lttng_add_gid_to_ctx(struct lttng_ctx **ctx);
+int lttng_add_egid_to_ctx(struct lttng_ctx **ctx);
+int lttng_add_sgid_to_ctx(struct lttng_ctx **ctx);
+int lttng_add_fsgid_to_ctx(struct lttng_ctx **ctx);
+int lttng_add_vuid_to_ctx(struct lttng_ctx **ctx);
+int lttng_add_veuid_to_ctx(struct lttng_ctx **ctx);
+int lttng_add_vsuid_to_ctx(struct lttng_ctx **ctx);
+int lttng_add_vfsuid_to_ctx(struct lttng_ctx **ctx);
+int lttng_add_vgid_to_ctx(struct lttng_ctx **ctx);
+int lttng_add_vegid_to_ctx(struct lttng_ctx **ctx);
+int lttng_add_vsgid_to_ctx(struct lttng_ctx **ctx);
+int lttng_add_vfsgid_to_ctx(struct lttng_ctx **ctx);
+
 #if defined(CONFIG_PERF_EVENTS) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,33))
 int lttng_add_perf_counter_to_ctx(uint32_t type,
 				  uint64_t config,
diff --git a/wrapper/user_namespace.h b/wrapper/user_namespace.h
new file mode 100644
index 0000000..f1f4181
--- /dev/null
+++ b/wrapper/user_namespace.h
@@ -0,0 +1,73 @@
+#ifndef _LTTNG_WRAPPER_USER_NAMESPACE_H
+#define _LTTNG_WRAPPER_USER_NAMESPACE_H
+
+/*
+ * wrapper/user_namespace.h
+ *
+ * Copyright (C) 2018 Michael Jeanson <mjeanson at efficios.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; only
+ * version 2.1 of the License.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <linux/version.h>
+#include <linux/user_namespace.h>
+
+
+#if LINUX_VERSION_CODE >= 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()))
+
+#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()))
+#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 */
-- 
2.7.4



More information about the lttng-dev mailing list