Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 683152 - net-misc/memcached: possible unsafe PID file ownership
Summary: net-misc/memcached: possible unsafe PID file ownership
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Robin Johnson
Depends on:
Reported: 2019-04-12 13:10 UTC by Tomáš Mózes
Modified: 2019-04-12 13:34 UTC (History)
2 users (show)

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


Note You need to log in before you can comment on or make changes to this bug.
Description Tomáš Mózes 2019-04-12 13:10:58 UTC
In default configuration, /run/memcached/ is owned by memcached user. If that users changes the content of the pidfile and then /etc/init.d/memcached stop is called, it can cause any arbitrary process to be killed.

Lots of examples of this (and fixes):

Why not dropping the possibility to configure the pidfile location and set it to /run/${RC_SVCNAME}.pid? This will then work even for multiple instances.
Comment 1 Michael Orlitzky gentoo-dev 2019-04-12 13:34:07 UTC
*thumbs up*

Lots of good info here, too:

Some daemons make it hard to get this right, by dropping permissions *before* they write the PID file. This usually happens when e.g. they want to dual-purpose the PID file as a lock file, or to prevent multiple instances of the same daemon from running, or something like that. But I have no idea if it applies here.

There's lots of other weird stuff in this service script that can probably go away, like

    local dir="$(dirname ${PIDFILE})"
    if [ ! -d "${dir}" ]; then
        einfo " Creating ${dir}"
        mkdir -p "${dir}"

    chown ${MEMCACHED_RUNAS} "${dir}"
    if [ -f "${PIDFILE}" ]; then
        einfo "  Removing stale pidfile ${PIDFILE}"
        rm -f "${PIDFILE}" 1>/dev/null

should be a single call to checkpath, but of course ideally should not be there at all (PID file should be where Tomas suggested, owned by root). And OpenRC cleans up the PID file for you.

These things,

      if [ -n "${SOCKET}" ]; then
        CONNECTION="-s ${SOCKET}"

can all be done at the top in a single line, declaratively, with ${parameter:+[word]} substitutions. And it's valid in any shell:

Afterwards, I'm pretty sure you can delete the start/stop functions and let the defaults do everything for you.