Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 890338 - net-irc/unrealircd-6.0.4.2 startup issues (with openrc)
Summary: net-irc/unrealircd-6.0.4.2 startup issues (with openrc)
Status: UNCONFIRMED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Sam James
URL:
Whiteboard:
Keywords: PATCH
Depends on:
Blocks:
 
Reported: 2023-01-10 12:48 UTC by dullfire
Modified: 2024-02-14 09:47 UTC (History)
2 users (show)

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


Attachments
new conf.d file for new pid location (unrealircd.confd-r5,1.41 KB, text/plain)
2023-04-12 04:08 UTC, Brian S. Stephan
Details
new init.d file for new pidfile location and working checkconfig (unrealircd.initd-r4,1.75 KB, text/plain)
2023-04-12 04:10 UTC, Brian S. Stephan
Details
modified unrealircd-6.0.4.2.ebuild to utilize new pidfile and openrc files (unrealircd-6.0.4.2.ebuild.patch,1.27 KB, patch)
2023-04-12 04:13 UTC, Brian S. Stephan
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description dullfire 2023-01-10 12:48:22 UTC
net-irc/unrealircd-6.0.4.2, and probably all unrealircd 6.x version, fail to start up when using alternate configuration files (e.g. symlink /etc/init.d/unrealircd.nappy-irc -> unrealircd).

The checkconfig openrc function always returns one is SVCNAME != unrealircd (thus aborting the startup).

Furthermore, the package is compiled with '--with-controlfile="${EPREFIX}"/run/${PN}/unrealircd.ctl', however  the openrc startup scripts ensure that "${EPREFIX}"/run/${PN}" is only writable by root (security measure since pidfile is also in that dir). Thus unrealircd dies when it fails to create it's socket.

Reproducible: Always

Steps to Reproduce:
1. install net-irc/unrealircd-6.0.4.2
2. create alternate config file & /etc/init.d/ symlink
3. start the service
Actual Results:  
unrealircd service fails to start

Expected Results:  
unrealircd service should have successfully started

Portage 3.0.41 (python 3.10.9-final-0, default/linux/ppc64/17.0, gcc-11, glibc-2.36-r5, 6.0.6-dormito ppc64)
=================================================================
                         System Settings
=================================================================
System uname: Linux-6.0.6-dormito-ppc64-POWER9,_altivec_supported-with-glibc2.36
KiB Mem:    33340736 total,   6963072 free
KiB Swap:          0 total,         0 free
Timestamp of repository gentoo: Fri, 30 Dec 2022 01:30:01 +0000
Head commit of repository gentoo: 123ef41078b189fd97322e1238ed9bab60a6f653
Head commit of repository fpga-dev: 9447eea26856eb98423b7c2aa9998b1ed62d6891

Head commit of repository vega: 82d2053f55527e55e59f54a99f082289007603c5

sh bash 5.1_p16-r2
ld GNU ld (Gentoo 2.38 p4) 2.38
distcc 3.4 powerpc64-unknown-linux-gnu [disabled]
app-misc/pax-utils:        1.3.5::gentoo
app-shells/bash:           5.1_p16-r2::gentoo
dev-java/java-config:      2.3.1::gentoo
dev-lang/perl:             5.36.0-r1::gentoo
dev-lang/python:           3.8.16::gentoo, 3.9.16::gentoo, 3.10.9::gentoo, 3.11.1::gentoo
dev-lang/rust:             1.65.0::gentoo
dev-util/cmake:            3.24.3::gentoo
dev-util/meson:            0.64.1::gentoo
sys-apps/baselayout:       2.9::gentoo
sys-apps/openrc:           0.45.2-r2::gentoo
sys-apps/sandbox:          2.29::gentoo
sys-devel/autoconf:        2.71-r5::gentoo
sys-devel/automake:        1.16.5::gentoo
sys-devel/binutils:        2.38-r2::gentoo
sys-devel/binutils-config: 5.4.1::gentoo
sys-devel/gcc:             10.4.0::gentoo, 11.3.1_p20221209::gentoo
sys-devel/gcc-config:      2.8::gentoo
sys-devel/libtool:         2.4.7::gentoo
sys-devel/llvm:            15.0.5::gentoo
sys-devel/make:            4.3::gentoo
sys-kernel/linux-headers:  5.15-r3::gentoo (virtual/os-headers)
sys-libs/glibc:            2.36-r5::gentoo
Repositories:

gentoo
    location: /usr/portage
    sync-type: rsync
    sync-uri: rsync://rsync.gentoo.org/gentoo-portage
    priority: -1000
    eclass-overrides: custom-override
    sync-rsync-verify-max-age: 24
    sync-rsync-verify-jobs: 1
    sync-rsync-verify-metamanifest: yes
    sync-rsync-extra-opts: 

crossdev
    location: /usr/local/portage-crossdev
    masters: gentoo
    priority: 10
    eclass-overrides: custom-override

custom-override
    location: /usr/local/portage-custom-override
    masters: gentoo
    priority: 10
    eclass-overrides: custom-override

fpga-dev
    location: /var/db/repos/fpga-dev
    sync-type: git
    sync-uri: https://git.firetree.us/portage-overlays/fpga-dev.git
    masters: gentoo
    priority: 10
    eclass-overrides: custom-override

vega
    location: /var/db/repos/vega
    sync-type: git
    sync-uri: https://git.firetree.us/portage-overlays/vega.git
    masters: gentoo
    priority: 10
    eclass-overrides: custom-override

Installed sets: @dullfire-core, @fpga-dev, @mini-fpga-dev, @vega-basic-gui, @vega-core
ACCEPT_KEYWORDS="ppc64"
ACCEPT_LICENSE="@FREE"
CBUILD="powerpc64-unknown-linux-gnu"
CFLAGS="-O2 -pipe -mcpu=power9 -fdiagnostics-color=always"
CHOST="powerpc64-unknown-linux-gnu"
CONFIG_PROTECT="/etc /usr/share/easy-rsa /usr/share/gnupg/qualified.txt"
CONFIG_PROTECT_MASK="/etc/ca-certificates.conf /etc/dconf /etc/env.d /etc/fonts/fonts.conf /etc/gconf /etc/gentoo-release /etc/revdep-rebuild /etc/sandbox.d /etc/terminfo"
CXXFLAGS="-O2 -pipe -mcpu=power9 -fdiagnostics-color=always"
DISTDIR="/usr/portage/distfiles"
ENV_UNSET="CARGO_HOME DBUS_SESSION_BUS_ADDRESS DISPLAY GOBIN GOPATH PERL5LIB PERL5OPT PERLPREFIX PERL_CORE PERL_MB_OPT PERL_MM_OPT XAUTHORITY XDG_CACHE_HOME XDG_CONFIG_HOME XDG_DATA_HOME XDG_RUNTIME_DIR XDG_STATE_HOME"
FCFLAGS="-O2 -pipe -mcpu=power9 -fdiagnostics-color=always"
FEATURES="assume-digests binpkg-docompress binpkg-dostrip binpkg-logs buildpkg-live config-protect-if-modified distlocks ebuild-locks fixlafiles ipc-sandbox merge-sync multilib-strict network-sandbox news parallel-fetch pid-sandbox preserve-libs protect-owned qa-unresolved-soname-deps sandbox sfperms strict unknown-features-warn unmerge-logs unmerge-orphans userfetch userpriv usersandbox usersync xattr"
FFLAGS="-O2 -pipe -mcpu=power9 -fdiagnostics-color=always"
GENTOO_MIRRORS="http://mirror.leaseweb.com/gentoo/ http://mirrors.aliyun.com/gentoo/ https://mirror.leaseweb.com/gentoo/"
LANG="en_US.utf8"
LDFLAGS="-Wl,-O1 -Wl,--as-needed"
LEX="flex"
MAKEOPTS="-j16"
PKGDIR="/usr/portage/packages"
PORTAGE_CONFIGROOT="/"
PORTAGE_RSYNC_OPTS="--recursive --links --safe-links --perms --times --omit-dir-times --compress --force --whole-file --delete --stats --human-readable --timeout=180 --exclude=/distfiles --exclude=/local --exclude=/packages --exclude=/.git"
PORTAGE_TMPDIR="/var/tmp"
SHELL="/bin/zsh"
USE="X acl altivec big-endian bzip2 cli crypt dbus dri egl ffmpeg fortran gbm gdbm ibm iconv ipv6 jpeg libglvnd lock ncurses nls nptl openmp pam pcre ppc64 readline seccomp session split-usr ssl startup-notification test-rust thunar unicode wayland xattr zlib" ADA_TARGET="gnat_2021" APACHE2_MODULES="authn_core authz_core socache_shmcb unixd actions alias auth_basic authn_alias authn_anon authn_dbm authn_default authn_file authz_dbm authz_default authz_groupfile authz_host authz_owner authz_user autoindex cache cgi cgid dav dav_fs dav_lock deflate dir disk_cache env expires ext_filter file_cache filter headers include info log_config logio mem_cache mime mime_magic negotiation rewrite setenvif speling status unique_id userdir usertrack vhost_alias" CALLIGRA_FEATURES="karbon sheets words" COLLECTD_PLUGINS="df interface irq load memory rrdtool swap syslog" CPU_FLAGS_PPC="altivec vsx vsx2 vsx3" ELIBC="glibc" GPSD_PROTOCOLS="ashtech aivdm earthmate evermore fv18 garmin garmintxt gpsclock greis isync itrax mtk3301 nmea ntrip navcom oceanserver oldstyle oncore rtcm104v2 rtcm104v3 sirf skytraq superstar2 timing tsip tripmate tnt ublox ubx" INPUT_DEVICES="synaptics evdev" KERNEL="linux" LCD_DEVICES="bayrad cfontz cfontz633 glk hd44780 lb216 lcdm001 mtxorb ncurses text" LIBREOFFICE_EXTENSIONS="presenter-console presenter-minimizer" LUA_SINGLE_TARGET="lua5-1" LUA_TARGETS="lua5-1" OFFICE_IMPLEMENTATION="libreoffice" PHP_TARGETS="php7-4 php8-0" POSTGRES_TARGETS="postgres12 postgres13" PYTHON_SINGLE_TARGET="python3_10" PYTHON_TARGETS="python3_10" RUBY_TARGETS="ruby27" USERLAND="GNU" VIDEO_CARDS="radeon" XTABLES_ADDONS="quota2 psd pknock lscan length2 ipv4options ipset ipp2p iface geoip fuzzy condition tee tarpit sysrq proto steal rawnat logmark ipmark dhcpmac delude chaos account"
Unset:  ADDR2LINE, AR, ARFLAGS, AS, ASFLAGS, CC, CCLD, CONFIG_SHELL, CPP, CPPFLAGS, CTARGET, CXX, CXXFILT, ELFEDIT, EMERGE_DEFAULT_OPTS, EXTRA_ECONF, F77FLAGS, FC, GCOV, GPROF, INSTALL_MASK, LC_ALL, LD, LFLAGS, LIBTOOL, LINGUAS, MAKE, MAKEFLAGS, NM, OBJCOPY, OBJDUMP, PORTAGE_BINHOST, PORTAGE_BUNZIP2_COMMAND, PORTAGE_COMPRESS, PORTAGE_COMPRESS_FLAGS, PORTAGE_RSYNC_EXTRA_OPTS, RANLIB, READELF, RUSTFLAGS, SIZE, STRINGS, STRIP, YACC, YFLAGS

=================================================================
                        Package Settings
=================================================================

net-irc/unrealircd-6.0.4.2::custom-override was built with the following:
USE="operoverride -class-nofakelag -curl -geoip -operoverride-verify -verify-sig"
Comment 1 Brian S. Stephan 2023-04-11 04:17:24 UTC
(In reply to dullfire from comment #0)
> Furthermore, the package is compiled with
> '--with-controlfile="${EPREFIX}"/run/${PN}/unrealircd.ctl', however  the
> openrc startup scripts ensure that "${EPREFIX}"/run/${PN}" is only writable
> by root (security measure since pidfile is also in that dir). Thus
> unrealircd dies when it fails to create it's socket.

I encountered this same problem. I found that removing start_pre() entirely fixed startup --- it seems that /run/unrealircd/ is created 755 unrealircd:unrealircd via unrealircd.tmpfiles (good) and openrc nevertheless creates /run/unrealircd/ircd.pid as root:root (also good). So it just works?

This also appeared necessary as `checkconfig` calls `unrealircd configtest` and that apparently starts the listeners, so running checkconfig in start_pre() would actually start the server, and then the actual startup would fail because it couldn't bind to the port(s). I think I saw this behavior in 5.x's init script too, I just never looked into it until now.

I'm working on a new ebuild to solve this; if it proves stable I'll share it here.
Comment 2 Brian S. Stephan 2023-04-11 04:21:34 UTC
I forgot to add that the configtest behavior is possibly an upstream bug, but I'm not confident of that just yet.
Comment 3 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2023-04-11 04:45:14 UTC
Thanks Brian. If you could, let me know either way. I'm preoccupied with some other bits at the moment so much appreciated even just with the comment you've left. Sorry for not getting to it yet.
Comment 4 dullfire 2023-04-11 11:53:36 UTC
(In reply to Brian S. Stephan from comment #1)
> (In reply to dullfire from comment #0)
> > Furthermore, the package is compiled with
> > '--with-controlfile="${EPREFIX}"/run/${PN}/unrealircd.ctl', however  the
> > openrc startup scripts ensure that "${EPREFIX}"/run/${PN}" is only writable
> > by root (security measure since pidfile is also in that dir). Thus
> > unrealircd dies when it fails to create it's socket.
> 
> I encountered this same problem. I found that removing start_pre() entirely
> fixed startup --- it seems that /run/unrealircd/ is created 755
> unrealircd:unrealircd via unrealircd.tmpfiles (good) and openrc nevertheless
> creates /run/unrealircd/ircd.pid as root:root (also good). So it just works?

Isn't that behavior a violating of the security design? In this case non-root (namely unrealircd) can rm /run/unrealircd/ircd.pid (since it has write access to /run/unrealircd) and replace it with it's own. IMHO: in order to preserve the security features, the socket needs to be in a different directory.

> 
> This also appeared necessary as `checkconfig` calls `unrealircd configtest`
> and that apparently starts the listeners, so running checkconfig in
> start_pre() would actually start the server, and then the actual startup
> would fail because it couldn't bind to the port(s). I think I saw this
> behavior in 5.x's init script too, I just never looked into it until now.
> 
> I'm working on a new ebuild to solve this; if it proves stable I'll share it
> here.

I have worked around these issues by having the socket live in a different directory (for reasons explained above), and the checkconfig  skip the test for SVCAME != unrealirc.

I will also note: the design of the control socket seems to preclude multiple unrealircd servers in the same mount namespace. This is due to fact that the path is configure-time selectable, and the actual file name is hard coded I believe. I haven't really tested this out though.
Comment 5 Brian S. Stephan 2023-04-11 16:30:11 UTC
(In reply to dullfire from comment #4)
> (In reply to Brian S. Stephan from comment #1)
> > I encountered this same problem. I found that removing start_pre() entirely
> > fixed startup --- it seems that /run/unrealircd/ is created 755
> > unrealircd:unrealircd via unrealircd.tmpfiles (good) and openrc nevertheless
> > creates /run/unrealircd/ircd.pid as root:root (also good). So it just works?
> 
> Isn't that behavior a violating of the security design? In this case
> non-root (namely unrealircd) can rm /run/unrealircd/ircd.pid (since it has
> write access to /run/unrealircd) and replace it with it's own. IMHO: in
> order to preserve the security features, the socket needs to be in a
> different directory.

I hadn't thought about that but you are right; I think a drwxrwxr-t root:unrealircd /run/unrealircd/ would also work, though maybe your way is clearer. What's an idiomatic alternative location for the named socket? That's what was holding me up when I was hacking at my ebuild last night.
Comment 6 Brian S. Stephan 2023-04-11 19:44:09 UTC
I've found the issue with checkconfig's config test --- it looks like they moved the configtest argument to a wrapper script which the ebuild doesn't install + the su invocation is dropping the argument (which is old anyway). Looking at the wrapper script, this is the new config check:

[ ${SVCNAME} = unrealircd ] && su -s /bin/sh ${command_user:=root} -c "${command} ${command_args%${UNREALIRCD_COMMAND_ARGS}} -c"

With that resolved I have something that starts clean, pidfile vs. socket location aside for now. I also bumped my ebuild to 6.0.7 (which removes the need for the clang patch) and added a IUSE + RDEPEND to get geoip_classic built since that's the default.

This is perhaps becoming something beyond this issue, but Sam, let me know how you'd like to see my changes (once we come up with something on pidfile vs. socket).
Comment 7 Brian S. Stephan 2023-04-12 04:08:43 UTC
Created attachment 859900 [details]
new conf.d file for new pid location
Comment 8 Brian S. Stephan 2023-04-12 04:10:23 UTC
Created attachment 859901 [details]
new init.d file for new pidfile location and working checkconfig
Comment 9 Brian S. Stephan 2023-04-12 04:13:09 UTC
Created attachment 859902 [details, diff]
modified unrealircd-6.0.4.2.ebuild to utilize new pidfile and openrc files
Comment 10 Brian S. Stephan 2023-04-12 04:15:13 UTC
I've attached what is working for me; I believe it satisfies the security concerns in a clean manner by putting the pidfile directly in /run, as is done by other services.