Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 629950 - <mail-filter/rspamd-1.8.3: privilege escalation via PID file manipulation
Summary: <mail-filter/rspamd-1.8.3: privilege escalation via PID file manipulation
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Security
Classification: Unclassified
Component: Vulnerabilities (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Gentoo Security
URL:
Whiteboard: ~3 [noglsa]
Keywords:
Depends on:
Blocks:
 
Reported: 2017-09-05 11:51 UTC by Michael Orlitzky
Modified: 2019-04-13 02:39 UTC (History)
3 users (show)

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


Attachments
rspamd.init-r6 (rspamd,1.24 KB, text/plain)
2017-09-05 11:51 UTC, Michael Orlitzky
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Orlitzky gentoo-dev 2017-09-05 11:51:00 UTC
Created attachment 492422 [details]
rspamd.init-r6

The rspamd init script gives ownership of its PID file directory to the "rspamd" user:

  RUNDIR=/var/run/rspamd
  PIDFILE=$RUNDIR/rspamd.pid
  ...
  checkpath -d $RUNDIR -m 2750 -o rspamd:rspamd

This can be exploited by the "rspamd" user to kill root processes: when the rspamd service is stopped, root sends a SIGTERM to the contents of the PID file, which can be manipulated by the rspamd user.

I rewrote the init script to launch rspamd as root, letting it create the PID file as root before dropping privileges itself to rspamd:rspamd. It looks like it works, but I don't know what rspamd is supposed to do, so please test it.

Some random points:

  1. The "reload" action sometimes crashes the daemon, but it's not consistent.
     I don't think I broke this, at least -- it still just sends a HUP to the
     main rspamd PID.

  2. The "rspamd" binary now has its own "--config-test" flag. Would that be
     useful in the checkconfig() function? (Or does it do the same thing?)
Comment 1 Thomas Deutschmann (RETIRED) gentoo-dev 2019-01-16 12:56:09 UTC
Oh, I noticed the same this night (https://github.com/gentoo/gentoo/pull/10598#issuecomment-454635163).

I have rewritten the entire runscript.
Problem with PID should be solved now because rspamd.pid is now created in /run/rspamd.pid instead of /run/rspamd/rspamd.pid and is therefore only writeable for root.
And checkconfig now uses rspamd, too...

@ mjo: Can you please verify if you agree with my solution?
Comment 2 Michael Orlitzky gentoo-dev 2019-01-19 00:06:06 UTC
(In reply to Thomas Deutschmann from comment #1)
> 
> @ mjo: Can you please verify if you agree with my solution?

LGTM
Comment 3 Aaron Bauman (RETIRED) gentoo-dev 2019-03-10 05:00:06 UTC
(In reply to Thomas Deutschmann from comment #1)
> Oh, I noticed the same this night
> (https://github.com/gentoo/gentoo/pull/10598#issuecomment-454635163).
> 
> I have rewritten the entire runscript.
> Problem with PID should be solved now because rspamd.pid is now created in
> /run/rspamd.pid instead of /run/rspamd/rspamd.pid and is therefore only
> writeable for root.
> And checkconfig now uses rspamd, too...
> 
> @ mjo: Can you please verify if you agree with my solution?

Which version is fixed?
Comment 4 Aaron Bauman (RETIRED) gentoo-dev 2019-04-13 02:39:26 UTC
tree is clean