[RFC][PATCH 4/6][v3] Define siginfo_from_ancestor_ns()

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Sukadev Bhattiprolu
Date: Saturday, December 20, 2008 - 5:54 pm

From: Sukadev Bhattiprolu <sukadev@linux.vnet.ibm.com>
Date: Sat, 20 Dec 2008 12:19:29 -0800
Subject: [RFC][PATCH 4/6][v3] Define siginfo_from_ancestor_ns()

Determine if sender of a signal is from an ancestor namespace. This
function will be used in a follow-on patch.

This is an early/lightly tested RFC patch. Would it be safe to implement
siginfo_from_user() as below and then use it dereference the pid
namespace of sender ?

This is based on discussions on the patch from Oleg Nesterov and me
http://lkml.org/lkml/2008/11/25/462.

Signed-off-by: Sukadev Bhattiprolu <sukadev@linux.vnet.ibm.com>
---
 kernel/signal.c |   41 +++++++++++++++++++++++++++++++++++++++++
 1 files changed, 41 insertions(+), 0 deletions(-)

diff --git a/kernel/signal.c b/kernel/signal.c
index 55f41b6..058b4c0 100644
--- a/kernel/signal.c
+++ b/kernel/signal.c
@@ -820,6 +820,47 @@ static inline int legacy_queue(struct sigpending *signals, int sig)
 {
 	return (sig < SIGRTMIN) && sigismember(&signals->signal, sig);
 }
+/*
+ * Return 1 if this signal originated directly from a user process (i.e via
+ * kill(), tkill(), sigqueue()).  Return 0 otherwise.
+ *
+ * TODO:
+ * 	  Making SI_ASYNCIO a kernel signal could make this less hacky.
+ */
+#ifdef CONFIG_PID_NS
+static inline int siginfo_from_user(siginfo_t *info)
+{
+	if (!is_si_special(info) && SI_FROMUSER(info) &&
+				info->si_code != SI_ASYNCIO)
+		return 1;
+
+	return 0;
+}
+
+static inline int siginfo_from_ancestor_ns(struct task_struct *t,
+                       siginfo_t *info)
+{
+	/*
+	 * Ensure signal is from user-space before checking pid namespace
+	 */
+	if (siginfo_from_user(info)) {
+		/*
+		 * If we do not have a pid in the receiver's namespace,
+		 * we must be an ancestor of the receiver.
+		 */
+		if (task_pid_nr_ns(current, task_active_pid_ns(t)) <= 0)
+			return 1;
+	}
+
+	return 0;
+}
+#else
+static inline int siginfo_from_ancestor_ns(struct task_struct *t, siginfo_t *info)
+{
+       return 0;
+}
+#endif
+
 
 static int send_signal(int sig, struct siginfo *info, struct task_struct *t,
 			int group)
-- 
1.5.2.5

--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[RFC][PATCH 0/6][v3] Container-init signal semantics, Sukadev Bhattiprolu, (Sat Dec 20, 5:51 pm)
[RFC][PATCH 1/6][v3] Remove 'handler' parameter to traceho ..., Sukadev Bhattiprolu, (Sat Dec 20, 5:52 pm)
[RFC][PATCH 2/6][v3] Protect init from unwanted signals more, Sukadev Bhattiprolu, (Sat Dec 20, 5:53 pm)
[RFC][PATCH 3/6][v3] Define/set SIGNAL_UNKILLABLE_FROM_NS, Sukadev Bhattiprolu, (Sat Dec 20, 5:53 pm)
[RFC][PATCH 4/6][v3] Define siginfo_from_ancestor_ns(), Sukadev Bhattiprolu, (Sat Dec 20, 5:54 pm)
[RFC][PATCH 5/6][v3] Protect cinit from unblocked SIG_DFL ..., Sukadev Bhattiprolu, (Sat Dec 20, 5:54 pm)
[RFC][PATCH 6/6][v3] Protect cinit from blocked fatal signals, Sukadev Bhattiprolu, (Sat Dec 20, 5:55 pm)
Re: [RFC][PATCH 0/6][v3] Container-init signal semantics, Eric W. Biederman, (Mon Dec 22, 3:55 am)
Re: [RFC][PATCH 0/6][v3] Container-init signal semantics, Sukadev Bhattiprolu, (Mon Dec 22, 12:47 pm)
Re: [RFC][PATCH 6/6][v3] Protect cinit from blocked fatal ..., Sukadev Bhattiprolu, (Mon Dec 22, 4:38 pm)
Re: [RFC][PATCH 4/6][v3] Define siginfo_from_ancestor_ns(), Sukadev Bhattiprolu, (Mon Dec 22, 4:45 pm)
Re: [RFC][PATCH 4/6][v3] Define siginfo_from_ancestor_ns(), Sukadev Bhattiprolu, (Mon Dec 22, 4:58 pm)
Re: [RFC][PATCH 0/6][v3] Container-init signal semantics, Eric W. Biederman, (Mon Dec 22, 5:27 pm)
Re: [RFC][PATCH 4/6][v3] Define siginfo_from_ancestor_ns(), Eric W. Biederman, (Mon Dec 22, 5:32 pm)
Re: [RFC][PATCH 0/6][v3] Container-init signal semantics, Sukadev Bhattiprolu, (Mon Dec 22, 7:12 pm)
Re: [RFC][PATCH 4/6][v3] Define siginfo_from_ancestor_ns(), Sukadev Bhattiprolu, (Mon Dec 22, 9:47 pm)
Re: [RFC][PATCH 0/6][v3] Container-init signal semantics, Serge E. Hallyn, (Tue Dec 23, 9:51 am)