Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 333821 - app-misc/screen should not keepdir /var/run/screen (because /var/run can be tmpfs and cleared on boot)
Summary: app-misc/screen should not keepdir /var/run/screen (because /var/run can be t...
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: High normal (vote)
Assignee: Sven Wegener
URL:
Whiteboard:
Keywords:
: 370453 390497 398769 424169 425382 (view as bug list)
Depends on: 396003
Blocks: keepdir-var-run_lock 423775
  Show dependency tree
 
Reported: 2010-08-21 15:58 UTC by Eray Aslan
Modified: 2012-08-27 22:17 UTC (History)
13 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
Use /var/lib/screen instead of /var/run/screen (screen-var-lib-instead-of-var-run.patch,4.90 KB, patch)
2012-01-16 20:55 UTC, Samuli Suominen (RETIRED)
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Eray Aslan gentoo-dev 2010-08-21 15:58:44 UTC
/var/run can be mounted tmpfs and cleared during a reboot.  Hence, programs (or their init scripts) should not rely on dirs under /var/run and should create them if necessary instead.

Screen creates the /var/run/screen dir when necessary.  After a complete /var/run wipe, different users can still use screen without a problem:
$ ls -ld /var/run/screen/ /var/run/screen/*
drwxr-xr-x 4 root  users 4096 Aug 21 15:03 /var/run/screen/
drwx------ 2 user1 users 4096 Aug 21 15:03 /var/run/screen/S-user1
drwx------ 2 user2 users 4096 Aug 21 15:03 /var/run/screen/S-user2

Note the lines below quoted from screen-4.0.3-r1.ebuild.  Almost all of it is necessary to enable different UIDs to connect to the same screen screen (including the suid screen binary, ugh).  This has security implications.  Also, it won't work with /var/run on tmpfs.  Please consider if we should drop the multiuser flag.

Please close if "Not a bug".  This is more of a security/reconsider check since screen works as it is with /var/run on tmpfs albeit without the multiuser flag.

src_install() {
    [...]
    keepdir /var/run/screen || die "keepdir failed"

    if use multiuser || use prefix
    then
        fperms 4755 /usr/bin/screen || die "fperms failed"
    else
        fowners root:utmp /{usr/bin,var/run}/screen \
            || die "fowners failed, use multiuser USE-flag instead"
        fperms 2755 /usr/bin/screen || die "fperms failed"
[...]
pkg_postinst() {
    if use multiuser || use prefix
    then
        use prefix || chown root:0 "${EROOT}"/var/run/screen
        if use prefix; then
            chmod 0777 "${EROOT}"/var/run/screen
        else
            chmod 0755 "${EROOT}"/var/run/screen
        fi
    else
        chown root:utmp "${EROOT}"/var/run/screen
        chmod 0775 "${EROOT}"/var/run/screen


Reproducible: Always
Comment 1 Sven Wegener gentoo-dev 2010-08-21 19:01:37 UTC
You argument of "Also, it won't work with /var/run on tmpfs." is wrong, the multiuser case is the only case when it works with /var/run on tmpfs, as screen can only create /var/run/screen by itself when it's setuid root. And I don't think it's good to force this on every user, which is what this bug is all about in the end. In general we need a way for a package to create these directories at boot time, without the overhead of creating an init script for very package as screen needs no init script by itself.
Comment 2 Eray Aslan gentoo-dev 2010-08-21 20:10:53 UTC
(In reply to comment #1)
> screen can only create /var/run/screen by itself when it's setuid root.

True.  So we can have
/usr/bin/screen 0755 and /var/run/screen 0777 or
/usr/bin/screen 2755 and /var/run/screen 0775 or
/usr/bin/screen 4755 and /var/run/screen 0755

> And I don't think it's good to force this on every user

Agreed.

> which is what this bug is all about in the end.

Well, partly.  Mostly we (that is you) have to make a decision.  We either have a init script for screen that adjusts permissions on /var/run/screen or screen may or may not work with /var/run on tmpfs depending on the permissions.

> In general we need a way for a package to create these
> directories at boot time, without the overhead of creating an init script for
> very package as screen needs no init script by itself.

In general yes.  In this particular case I am not sure.  But it is your decision and I am fine either way.
Comment 3 Eray Aslan gentoo-dev 2010-08-22 08:27:20 UTC
FWIW, Debian installs screen with sgid and checks the /var/run perms with an initscript.  Centos (and presumably RHEL) also installs the binary with sgid but with no init script and won't work with /var/run on tmpfs.  Slackware, perhaps not surprisingly, install the binary as a regular executable file  with socket file in $HOME/.screen.  And finally, FreeBSD seems to install the binary with suid bit set.
Comment 4 Jeroen Roovers (RETIRED) gentoo-dev 2011-11-15 15:22:51 UTC
*** Bug 390497 has been marked as a duplicate of this bug. ***
Comment 5 Maksim 'max_posedon' Melnikau 2011-12-20 07:53:44 UTC
I get hear from bug 390497.

systemd comes with solution for such keys (/var/run in tmpfs) - tmpfiles.d ( http://0pointer.de/public/systemd-man/tmpfiles.d.html )

It might be good idea too use this files/syntax in openrc (for compatibility) too. And start provide with all required packages files for tmpfiles.d

It gives us:
1. better systemd support
2. better openrc /var/run (tmpfs) support
Without introducing anything new.
Comment 6 Samuli Suominen (RETIRED) gentoo-dev 2012-01-16 19:37:26 UTC
*** Bug 370453 has been marked as a duplicate of this bug. ***
Comment 7 Samuli Suominen (RETIRED) gentoo-dev 2012-01-16 19:38:02 UTC
*** Bug 398769 has been marked as a duplicate of this bug. ***
Comment 8 Samuli Suominen (RETIRED) gentoo-dev 2012-01-16 20:55:05 UTC
Created attachment 299095 [details, diff]
Use /var/lib/screen instead of /var/run/screen

This will migrate everything in a way the current open screen(s) will continue to work.

But these socket files really belong to /var/run so I've not applied this to Portage.

OpenRC should have support for creating directories on boot, like systemd does.
Comment 9 Samuli Suominen (RETIRED) gentoo-dev 2012-01-16 20:55:57 UTC
@openrc maintainers: is there support for creating /var/run/screen, when screen doesn't have it's own init script?
Comment 10 Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2012-01-16 21:09:53 UTC
(In reply to comment #9)
> @openrc maintainers: is there support for creating /var/run/screen, when screen
> doesn't have it's own init script?

Bug 396003.
Comment 11 Михаил 2012-05-23 22:51:48 UTC
Changing socket directory is not required.

If USE=multiuser screen have suid and able to create direcrory at first run.

If USE=-multiuser we can configure --disable-socket-dir and screen store sockets in user's home. Also suid/sgid is not needed.
Comment 12 Jeremy Olexa (darkside) (RETIRED) archtester gentoo-dev Security 2012-05-24 04:14:00 UTC
(In reply to comment #11)
> Changing socket directory is not required.
> 
> If USE=multiuser screen have suid and able to create direcrory at first run.
> 
> If USE=-multiuser we can configure --disable-socket-dir and screen store
> sockets in user's home. Also suid/sgid is not needed.

I like that solution to be honest.

+*screen-4.0.3-r5 (24 May 2012)
+
+  24 May 2012; Jeremy Olexa <darkside@gentoo.org> +screen-4.0.3-r5.ebuild:
+  Revision bump to disable socket dir (and use ~/.screen/ instead) for cases
+  where /var/run is tmpfs, etc. This seems more portable and has been the best
+  solution proposed on bug 333821
Comment 13 Maksim 'max_posedon' Melnikau 2012-06-30 05:57:30 UTC
(In reply to comment #11)
> If USE=-multiuser we can configure --disable-socket-dir and screen store
> sockets in user's home. Also suid/sgid is not needed.
I think /run/user/ is better infrastructure for this, then /home, such sockets should be stored in /run/user/SOME_USER/screen.
Comment 14 Sergiy Borodych 2012-07-02 05:45:57 UTC
After last changes screen calls from my init.d scripts do not create any .sock files :( (none in /root/.screen)
Suddenly...
Only USE="multiuser" helps me. But what about compatibility?
Comment 15 Jeremy Olexa (darkside) (RETIRED) archtester gentoo-dev Security 2012-07-02 13:35:59 UTC
*** Bug 424169 has been marked as a duplicate of this bug. ***
Comment 16 Jeroen Roovers (RETIRED) gentoo-dev 2012-07-09 00:31:14 UTC
*** Bug 425382 has been marked as a duplicate of this bug. ***
Comment 17 Alex 2012-08-27 22:17:49 UTC
>After last changes screen calls from my init.d scripts do not create any .sock files :( (none in /root/.screen
They are in /.screen/ (yes, .screen directory under /), just in case. This is completely wrong. 

>Only USE="multiuser" helps me. But what about compatibility?
Same with me. screen is the one of apps prooving compatibility exits for me. And you broke it.