Blame SOURCES/rhbz1035850.patch

f43afa
From 10632b637aa12614e36ef83c7762bd44bef80716 Mon Sep 17 00:00:00 2001
f43afa
From: David Smith <dsmith@redhat.com>
f43afa
Date: Tue, 3 Dec 2013 10:52:37 -0600
f43afa
Subject: [PATCH 2/2] Resolves: #1035850
f43afa
f43afa
Upstream commit f112949.
f43afa
---
f43afa
 testsuite/systemtap.examples/process/pfiles.stp | 54 +++++++++++++++++++++++++
f43afa
 1 file changed, 54 insertions(+)
f43afa
f43afa
diff --git a/testsuite/systemtap.examples/process/pfiles.stp b/testsuite/systemtap.examples/process/pfiles.stp
f43afa
index 6f5a834..b2bdbd8 100755
f43afa
--- a/testsuite/systemtap.examples/process/pfiles.stp
f43afa
+++ b/testsuite/systemtap.examples/process/pfiles.stp
f43afa
@@ -77,6 +77,10 @@
f43afa
 #include <net/sock.h>
f43afa
 #include <linux/un.h>
f43afa
 #include <linux/tcp.h>
f43afa
+#ifdef CONFIG_USER_NS
f43afa
+#include <linux/user_namespace.h>
f43afa
+#include <linux/uidgid.h>
f43afa
+#endif
f43afa
 %}
f43afa
 
f43afa
 function task_valid_file_handle:long (task:long, fd:long) %{ /* pure */
f43afa
@@ -199,6 +203,9 @@ function task_file_handle_uid:long (task:long, fd:long) %{ /* pure */
f43afa
 	struct task_struct *p = (struct task_struct *)((long)STAP_ARG_task);
f43afa
 	struct files_struct *files;
f43afa
 	struct file *filp;
f43afa
+#ifdef CONFIG_USER_NS
f43afa
+	struct user_namespace *ns = NULL;
f43afa
+#endif
f43afa
 
f43afa
 	rcu_read_lock();
f43afa
 	if ((files = kread(&p->files)) &&
f43afa
@@ -207,7 +214,25 @@ function task_file_handle_uid:long (task:long, fd:long) %{ /* pure */
f43afa
 		/* git commit d76b0d9b */
f43afa
 		const struct cred *cred;
f43afa
 		if ((cred = kread(&filp->f_cred))) {
f43afa
+#ifdef CONFIG_USER_NS
f43afa
+			ns = get_user_ns(task_cred_xxx(p, user_ns));
f43afa
+			if (ns) {
f43afa
+				// We call kderef_buffer() here to
f43afa
+				// ensure the memory at the kuid_t
f43afa
+				// location is valid to read. We can't
f43afa
+				// use kderef()/kread(), since they
f43afa
+				// only handle data with a size of 1,
f43afa
+				// 2, 4, or 8 bytes.
f43afa
+				kderef_buffer(NULL,  &cred->fsuid,
f43afa
+					      sizeof(kuid_t));
f43afa
+				STAP_RETVALUE = from_kuid(ns, cred->fsuid);
f43afa
+			}
f43afa
+			else
f43afa
+				STAP_RETVALUE = -1;
f43afa
+
f43afa
+#else	/* ! CONFIG_USER_NS */
f43afa
 			STAP_RETVALUE = kread(&cred->fsuid);
f43afa
+#endif	/* ! CONFIG_USER_NS */
f43afa
 		}
f43afa
 #else
f43afa
 		STAP_RETVALUE = kread(&filp->f_uid);
f43afa
@@ -215,6 +240,10 @@ function task_file_handle_uid:long (task:long, fd:long) %{ /* pure */
f43afa
 	}
f43afa
 
f43afa
 	CATCH_DEREF_FAULT();
f43afa
+#ifdef CONFIG_USER_NS
f43afa
+	if (ns)
f43afa
+		put_user_ns(ns);
f43afa
+#endif
f43afa
 	rcu_read_unlock();
f43afa
 %}
f43afa
 
f43afa
@@ -222,6 +251,9 @@ function task_file_handle_gid:long (task:long, fd:long) %{ /* pure */
f43afa
 	struct task_struct *p = (struct task_struct *)((long)STAP_ARG_task);
f43afa
 	struct files_struct *files;
f43afa
 	struct file *filp;
f43afa
+#ifdef CONFIG_USER_NS
f43afa
+	struct user_namespace *ns = NULL;
f43afa
+#endif
f43afa
 
f43afa
 	rcu_read_lock();
f43afa
 	if ((files = kread(&p->files)) &&
f43afa
@@ -230,7 +262,25 @@ function task_file_handle_gid:long (task:long, fd:long) %{ /* pure */
f43afa
 		/* git commit d76b0d9b */
f43afa
 		const struct cred *cred;
f43afa
 		if ((cred = kread(&filp->f_cred))) {
f43afa
+#ifdef CONFIG_USER_NS
f43afa
+			ns = get_user_ns(task_cred_xxx(p, user_ns));
f43afa
+			if (ns) {
f43afa
+				// We call kderef_buffer() here to
f43afa
+				// ensure the memory at the kgid_t
f43afa
+				// location is valid to read. We can't
f43afa
+				// use kderef()/kread(), since they
f43afa
+				// only handle data with a size of 1,
f43afa
+				// 2, 4, or 8 bytes.
f43afa
+				kderef_buffer(NULL,  &cred->fsgid,
f43afa
+					      sizeof(kgid_t));
f43afa
+				STAP_RETVALUE = from_kgid(ns, cred->fsgid);
f43afa
+			}
f43afa
+			else
f43afa
+				STAP_RETVALUE = -1;
f43afa
+
f43afa
+#else	/* ! CONFIG_USER_NS */
f43afa
 			STAP_RETVALUE = kread(&cred->fsgid);
f43afa
+#endif	/* ! CONFIG_USER_NS */
f43afa
 		}
f43afa
 #else
f43afa
 		STAP_RETVALUE = kread(&filp->f_gid);
f43afa
@@ -238,6 +288,10 @@ function task_file_handle_gid:long (task:long, fd:long) %{ /* pure */
f43afa
 	}
f43afa
 
f43afa
 	CATCH_DEREF_FAULT();
f43afa
+#ifdef CONFIG_USER_NS
f43afa
+	if (ns)
f43afa
+		put_user_ns(ns);
f43afa
+#endif
f43afa
 	rcu_read_unlock();
f43afa
 %}
f43afa
 
f43afa
-- 
f43afa
1.8.3.1
f43afa