]> sourceware.org Git - systemtap.git/commitdiff
Handle CONFIG_USER_NS/CONFIG_UIDGID_STRICT_TYPE_CHECKS in the runtime.
authorAlexander Y. Fomichev <git.user@gmail.com>
Fri, 31 May 2013 19:46:56 +0000 (14:46 -0500)
committerDavid Smith <dsmith@redhat.com>
Fri, 31 May 2013 19:46:56 +0000 (14:46 -0500)
* runtime/linux/task_finder.c: Add CONFIG_UIDGID_STRICT_TYPE_CHECKS code.
* runtime/linux/task_finder2.c: Ditto.
* runtime/transport/control.c: Ditto.
* runtime/transport/transport.c: Ditto.
* runtime/linux/autoconf-uidgid.c: New autoconf test.
* buildrun.cxx (compile_pass): Add STAPCONF_LINUX_UIDGID_H autoconf test.
* runtime/procfs.c: Include uidgid_compatibility.h.
* runtime/proc_fs_compatibility.h: Move KUIDT_INIT()/KGIDT_INIT() macros
  to uidgid_compatibility.h.
* runtime/transport/debugfs.c: Use KUIDT_INIT/KGIDT_INIT macros.
* runtime/transport/relay_v2.c: Ditto
* runtime/uidgid_compatibility.h: New file.

buildrun.cxx
runtime/linux/autoconf-uidgid.c [new file with mode: 0644]
runtime/linux/task_finder.c
runtime/linux/task_finder2.c
runtime/proc_fs_compatibility.h
runtime/procfs.c
runtime/transport/control.c
runtime/transport/debugfs.c
runtime/transport/relay_v2.c
runtime/transport/transport.c
runtime/uidgid_compatibility.h [new file with mode: 0644]

index 2a9cd64ab6ca2c1da6fd6bc75c9555850cb7a798..14871504bab0766331ea8b2e230cba8ab8d2a11c 100644 (file)
@@ -395,6 +395,7 @@ compile_pass (systemtap_session& s)
 
   output_autoconf(s, o, "autoconf-pagefault_disable.c", "STAPCONF_PAGEFAULT_DISABLE", NULL);
   output_exportconf(s, o, "kallsyms_lookup_name", "STAPCONF_KALLSYMS");
+  output_autoconf(s, o, "autoconf-uidgid.c", "STAPCONF_LINUX_UIDGID_H", NULL);
 
   o << module_cflags << " += -include $(STAPCONF_HEADER)" << endl;
 
diff --git a/runtime/linux/autoconf-uidgid.c b/runtime/linux/autoconf-uidgid.c
new file mode 100644 (file)
index 0000000..3553545
--- /dev/null
@@ -0,0 +1,2 @@
+#include <linux/cred.h>
+#include <linux/uidgid.h>
index 74047c7dbfe9d67ec040f46aaedb79fa4968075a..8c198a746c37722c4c0cb815403d3836f6903813 100644 (file)
@@ -23,6 +23,7 @@
 #ifndef STAPCONF_TASK_UID
 #include <linux/cred.h>
 #endif
+#include "../uidgid_compatibility.h"
 #include "syscall.h"
 #include "utrace_compatibility.h"
 #include "task_finder_map.c"
@@ -850,8 +851,12 @@ __stp_utrace_attach_match_filename(struct task_struct *tsk,
 
 #ifdef STAPCONF_TASK_UID
        tsk_euid = tsk->euid;
+#else
+#ifdef CONFIG_UIDGID_STRICT_TYPE_CHECKS
+       tsk_euid = from_kuid_munged(current_user_ns(), task_euid(tsk));
 #else
        tsk_euid = task_euid(tsk);
+#endif
 #endif
        filelen = strlen(filename);
        list_for_each(tgt_node, &__stp_task_finder_list) {
@@ -1659,8 +1664,12 @@ stap_start_task_finder(void)
                /* Check the thread's exe's path/pid against our list. */
 #ifdef STAPCONF_TASK_UID
                tsk_euid = tsk->euid;
+#else
+#ifdef CONFIG_UIDGID_STRICT_TYPE_CHECKS
+               tsk_euid = from_kuid_munged(current_user_ns(), task_euid(tsk));
 #else
                tsk_euid = task_euid(tsk);
+#endif
 #endif
                mmpathlen = strlen(mmpath);
                list_for_each(tgt_node, &__stp_task_finder_list) {
index 15fa30963a0193cb9b3a7f80140f11a0f60b14af..2c34ab9b9e366995bc6bddf2e0992d2ce586132a 100644 (file)
@@ -9,6 +9,7 @@
 #ifndef STAPCONF_TASK_UID
 #include <linux/cred.h>
 #endif
+#include "../uidgid_compatibility.h"
 #include "syscall.h"
 #include "task_finder_map.c"
 #include "task_finder_vma.c"
@@ -812,8 +813,12 @@ __stp_utrace_attach_match_filename(struct task_struct *tsk,
 
 #ifdef STAPCONF_TASK_UID
        tsk_euid = tsk->euid;
+#else
+#ifdef CONFIG_UIDGID_STRICT_TYPE_CHECKS
+       tsk_euid = from_kuid_munged(current_user_ns(), task_euid(tsk));
 #else
        tsk_euid = task_euid(tsk);
+#endif
 #endif
        filelen = strlen(filename);
        list_for_each(tgt_node, &__stp_task_finder_list) {
@@ -1698,8 +1703,12 @@ stap_start_task_finder(void)
                /* Check the thread's exe's path/pid against our list. */
 #ifdef STAPCONF_TASK_UID
                tsk_euid = tsk->euid;
+#else
+#ifdef CONFIG_UIDGID_STRICT_TYPE_CHECKS
+               tsk_euid = from_kuid_munged(current_user_ns(), task_euid(tsk));
 #else
                tsk_euid = task_euid(tsk);
+#endif
 #endif
                mmpathlen = strlen(mmpath);
                list_for_each(tgt_node, &__stp_task_finder_list) {
index 09784359b6ad6382dc1b41758d5bece72b6d0cd8..c94da16d8ff091872f7ca004412745339d119b92 100644 (file)
  * some of the new interface's functions. */
 #ifndef STAPCONF_PDE_DATA
 
-#ifndef KUIDT_INIT
-#define KUIDT_INIT(value) ((uid_t) value)
-#define KGIDT_INIT(value) ((gid_t) value)
-
+#ifndef STAPCONF_LINUX_UIDGID_H
 static void proc_set_user(struct proc_dir_entry *de, uid_t uid, gid_t gid)
 {
        de->uid = uid;
index b2aa15814e5b26156df903c75941c3f7bb01d656..31cf36015cb52eb13fd0e23d03b8dcc3114898a2 100644 (file)
@@ -22,6 +22,7 @@
 #include <linux/pid_namespace.h>
 #endif
 #include "proc_fs_compatibility.h"
+#include "uidgid_compatibility.h"
 
 #if defined(STAPCONF_PATH_LOOKUP) && !defined(STAPCONF_KERN_PATH_PARENT)
 #define kern_path_parent(name, nameidata) \
index 6c5ce47604d42729a1a484fd579522e6024cb34f..cbc8e6d559ae9f7fe6b8a303e3988dec6e666830 100644 (file)
@@ -14,6 +14,7 @@
 #include "symbols.c"
 #include <linux/delay.h>
 #include <linux/poll.h>
+#include "../uidgid_compatibility.h"
 
 static _stp_mempool_t *_stp_pool_q;
 static struct list_head _stp_ctl_ready_q;
@@ -33,8 +34,12 @@ static ssize_t _stp_ctl_write_cmd(struct file *file, const char __user *buf, siz
 
 #ifdef STAPCONF_TASK_UID
        uid_t euid = current->euid;
+#else
+#ifdef CONFIG_UIDGID_STRICT_TYPE_CHECKS
+       uid_t euid = from_kuid_munged(current_user_ns(), current_euid());
 #else
        uid_t euid = current_euid();
+#endif
 #endif
 
        if (count < sizeof(u32))
index 96bd92bd96b29cdf4395e34dcb5f7d8d34eae525..a5ed276ef4e23960c633447986810592a40deb7f 100644 (file)
@@ -11,6 +11,7 @@
 
 #include <linux/debugfs.h>
 #include "transport.h"
+#include "../uidgid_compatibility.h"
 
 /* Defines the number of buffers allocated in control.c (which #includes
    this file) for the _stp_pool_q.  This is the number of .cmd messages
@@ -48,8 +49,8 @@ static int _stp_register_ctl_channel_fs(void)
                return -1;
        }
 
-       _stp_cmd_file->d_inode->i_uid = _stp_uid;
-       _stp_cmd_file->d_inode->i_gid = _stp_gid;
+       _stp_cmd_file->d_inode->i_uid = KUIDT_INIT(_stp_uid);
+       _stp_cmd_file->d_inode->i_gid = KGIDT_INIT(_stp_gid);
 
        return 0;
 }
index 50d3c117decc05f066a237b1e3f3f842a4f68843..6c9815d718a83b93a75e981e2fa99df18776d664 100644 (file)
@@ -31,6 +31,7 @@
 #include <linux/mm.h>
 #include <linux/relay.h>
 #include <linux/timer.h>
+#include "../uidgid_compatibility.h"
 
 #ifndef STP_RELAY_TIMER_INTERVAL
 /* Wakeup timer interval in jiffies (default 10 ms) */
@@ -234,8 +235,8 @@ __stp_relay_create_buf_file_callback(const char *filename,
                file = NULL;
        }
        else if (file) {
-               file->d_inode->i_uid = _stp_uid;
-               file->d_inode->i_gid = _stp_gid;
+               file->d_inode->i_uid = KUIDT_INIT(_stp_uid);
+               file->d_inode->i_gid = KGIDT_INIT(_stp_gid);
        }
        return file;
 }
@@ -303,8 +304,8 @@ static int _stp_transport_data_fs_init(void)
                goto err;
        }
 
-       _stp_relay_data.dropped_file->d_inode->i_uid = _stp_uid;
-       _stp_relay_data.dropped_file->d_inode->i_gid = _stp_gid;
+       _stp_relay_data.dropped_file->d_inode->i_uid = KUIDT_INIT(_stp_uid);
+       _stp_relay_data.dropped_file->d_inode->i_gid = KGIDT_INIT(_stp_gid);
 
        /* Create "trace" file. */
        npages = _stp_subbuf_size * _stp_nsubbufs;
index 46eb28f8437b880c81687db2698a58314637ff52..e81ac7dcb02b75978591d2ef2ac74a2dad43307f 100644 (file)
@@ -20,6 +20,7 @@
 #include <linux/namei.h>
 #include <linux/delay.h>
 #include <linux/mutex.h>
+#include "../uidgid_compatibility.h"
 
 static int _stp_exit_flag = 0;
 
@@ -335,10 +336,15 @@ static int _stp_transport_init(void)
 #ifdef STAPCONF_TASK_UID
        _stp_uid = current->uid;
        _stp_gid = current->gid;
+#else
+#ifdef CONFIG_UIDGID_STRICT_TYPE_CHECKS
+       _stp_uid = from_kuid_munged(current_user_ns(), current_uid());
+       _stp_gid = from_kgid_munged(current_user_ns(), current_gid());
 #else
        _stp_uid = current_uid();
        _stp_gid = current_gid();
 #endif
+#endif
 
 /* PR13489, missing inode-uprobes symbol-export workaround */
 #if !defined(STAPCONF_TASK_USER_REGSET_VIEW_EXPORTED) && !defined(STAPCONF_UTRACE_REGSET) /* RHEL5 era utrace */
diff --git a/runtime/uidgid_compatibility.h b/runtime/uidgid_compatibility.h
new file mode 100644 (file)
index 0000000..017142c
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * uidgid.h compatibility defines and inlines
+ * Copyright (C) 2013 Red Hat Inc.
+ *
+ * This file is part of systemtap, and is free software.  You can
+ * redistribute it and/or modify it under the terms of the GNU General
+ * Public License (GPL); either version 2, or (at your option) any
+ * later version.
+ */
+
+#ifndef _UIDGID_COMPATIBILITY_H_
+#define _UIDGID_COMPATIBILITY_H_
+
+#ifndef STAPCONF_LINUX_UIDGID_H
+
+#define KUIDT_INIT(value) ((uid_t) value)
+#define KGIDT_INIT(value) ((gid_t) value)
+
+#else
+
+#include <linux/cred.h>
+#include <linux/uidgid.h>
+
+#endif
+
+#endif /* _UIDGID_COMPATIBILITY_H_ */
This page took 0.043898 seconds and 5 git commands to generate.