All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] tty: Allow stealing of controlling ttys within user namespaces
@ 2014-01-22 14:53 Seth Forshee
  2014-01-24 23:31 ` Eric W. Biederman
  0 siblings, 1 reply; 3+ messages in thread
From: Seth Forshee @ 2014-01-22 14:53 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Jiri Slaby
  Cc: Seth Forshee, Serge Hallyn, Eric W. Biederman, linux-kernel

root is allowed to steal ttys from other sessions, but it
requires system-wide CAP_SYS_ADMIN and therefore is not possible
for root within a user namespace. This should be allowed so long
as the process doing the stealing is privileged towards the
session which currently owns the tty.

Update this code to only require CAP_SYS_ADMIN in the user
namespaces of the target session's tasks, allowing the tty to be
stolen from sessions whose tasks are in the same or lesser
privileged user namespaces.

Cc: Serge Hallyn <serge.hallyn@canonical.com>
Cc: "Eric W. Biederman" <ebiederm@xmission.com>
Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
---
 drivers/tty/tty_io.c | 31 +++++++++++++++++++++++--------
 1 file changed, 23 insertions(+), 8 deletions(-)

diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
index c74a00a..558e6dc 100644
--- a/drivers/tty/tty_io.c
+++ b/drivers/tty/tty_io.c
@@ -2410,17 +2410,32 @@ static int tiocsctty(struct tty_struct *tty, int arg)
 		 * This tty is already the controlling
 		 * tty for another session group!
 		 */
-		if (arg == 1 && capable(CAP_SYS_ADMIN)) {
-			/*
-			 * Steal it away
-			 */
-			read_lock(&tasklist_lock);
-			session_clear_tty(tty->session);
-			read_unlock(&tasklist_lock);
-		} else {
+		struct user_namespace *user_ns;
+		struct task_struct *p;
+
+		if (arg != 1) {
 			ret = -EPERM;
 			goto unlock;
 		}
+
+		read_lock(&tasklist_lock);
+		do_each_pid_task(tty->session, PIDTYPE_SID, p) {
+			rcu_read_lock();
+			user_ns = task_cred_xxx(p, user_ns);
+			if (!ns_capable(user_ns, CAP_SYS_ADMIN)) {
+				rcu_read_unlock();
+				read_unlock(&tasklist_lock);
+				ret = -EPERM;
+				goto unlock;
+			}
+			rcu_read_unlock();
+		} while_each_pid_task(tty->session, PIDTYPE_SID, p);
+
+		/*
+		 * Steal it away
+		 */
+		session_clear_tty(tty->session);
+		read_unlock(&tasklist_lock);
 	}
 	proc_set_tty(current, tty);
 unlock:
-- 
1.8.3.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-02-07 16:39 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-01-22 14:53 [PATCH v2] tty: Allow stealing of controlling ttys within user namespaces Seth Forshee
2014-01-24 23:31 ` Eric W. Biederman
2014-02-07 16:40   ` Greg Kroah-Hartman

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.