Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 11 Jan 2009 14:48:36 GMT
From:      Damien Bobillot <damien.bobillot_freebsd@m4x.org>
To:        freebsd-gnats-submit@FreeBSD.org
Subject:   ports/130379: screen : can't use it after a jail_attach() call
Message-ID:  <200901111448.n0BEmanf066012@www.freebsd.org>
Resent-Message-ID: <200901111450.n0BEo4vq024641@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         130379
>Category:       ports
>Synopsis:       screen : can't use it after a jail_attach() call
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-ports-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sun Jan 11 14:50:04 UTC 2009
>Closed-Date:
>Last-Modified:
>Originator:     Damien Bobillot
>Release:        7.0-RELEASE
>Organization:
>Environment:
FreeBSD asterix.local 7.0-RELEASE-p2 FreeBSD 7.0-RELEASE-p2 #0: Wed Jun 18 06:48:16 UTC 2008     root@amd64-builder.daemonology.net:/usr/obj/usr/src/sys/GENERIC  amd64


>Description:
When entering a jail with the jail_attach call (with jexec command for instance), it is not possible to run the screen command.

The reason is that the courant tty was open in the host (dom0) environment, and that screen try to reopen it from a jail with something like :
open(ttyname(0), O_RDWR)
=> EBUSY error. Maybe due to security checks in the kernel ?



>How-To-Repeat:
If there is a jail with JID=1 :

% jexec 1 screen
Cannot open your terminal '/dev/ttyp1' - please check.


>Fix:
See attached patch.

Patch attached with submission follows:

diff -Naur screen-orig/files/patch-screen.c screen/files/patch-screen.c
--- screen-orig/files/patch-screen.c    1970-01-01 00:00:00.000000000 +0000
+++ screen/files/patch-screen.c 2009-01-11 14:16:43.000000000 +0000
@@ -0,0 +1,24 @@
+--- screen.c.orig      2009-01-11 14:11:45.000000000 +0000
++++ screen.c   2009-01-11 14:14:08.000000000 +0000
+@@ -899,9 +899,9 @@
+ #ifdef MULTIUSER
+       tty_mode = (int)st.st_mode & 0777;
+ #endif
+-      if ((n = secopen(attach_tty, O_RDWR | O_NONBLOCK, 0)) < 0)
+-      Panic(0, "Cannot open your terminal '%s' - please check.", attach_tty);
+-      close(n);
++      //if ((n = secopen(attach_tty, O_RDWR | O_NONBLOCK, 0)) < 0)
++      //  Panic(0, "Cannot open your terminal '%s' - please check.", attach_tty);
++      //close(n);
+       debug1("attach_tty is %s\n", attach_tty);
+       if ((attach_term = getenv("TERM")) == 0 || *attach_term == 0)
+       Panic(0, "Please set a terminal type.");
+@@ -1197,7 +1197,7 @@
+   if (!detached)
+     {
+       /* reopen tty. must do this, because fd 0 may be RDONLY */
+-      if ((n = secopen(attach_tty, O_RDWR, 0)) < 0)
++      if ((n = dup(0)) < 0) // cannot reopen tty with open(attach_tty) after jail_attach(), so, just duplicate stdin
+       Panic(0, "Cannot reopen '%s' - please check.", attach_tty);
+     }
+   else


>Release-Note:
>Audit-Trail:
>Unformatted:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200901111448.n0BEmanf066012>