Bug 1197464 (CVE-2022-27815) - AUDIT-FIND: CVE-2022-27815: swhkd: Use of Fixed Temporary File in /tmp/swhkd.pid
Summary: AUDIT-FIND: CVE-2022-27815: swhkd: Use of Fixed Temporary File in /tmp/swhkd.pid
Status: RESOLVED FIXED
Alias: CVE-2022-27815
Product: openSUSE Tumbleweed
Classification: openSUSE
Component: Security (show other bugs)
Version: Current
Hardware: Other Other
: P5 - None : Normal (vote)
Target Milestone: ---
Assignee: Aakash Sen Sharma
QA Contact: E-mail List
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 1196890
  Show dependency treegraph
 
Reported: 2022-03-24 09:29 UTC by Matthias Gerstner
Modified: 2022-04-14 08:55 UTC (History)
4 users (show)

See Also:
Found By: ---
Services Priority:
Business Priority:
Blocker: ---
Marketing QA Status: ---
IT Deployment: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Matthias Gerstner 2022-03-24 09:29:41 UTC
+++ This bug was initially created as a clone of Bug #1196890

This is to track issue 2.a) of the parent bug:

  ## 2.a) Use of Fixed Temporary File in /tmp/swhkd.pid

  The daemon running as root uses this path to records its own PID for instance
  monitoring. This fixed path has the following issues:

  - local application DoS: if an attacker places the PID of an existing process
    there (e.g. PID 1), other users cannot start the daemon any more.
  - local information leak if kernel symlink protection is turned off. The
    daemon logs the *full* content of the PID file to stdout:

      [2022-03-21T15:44:28Z DEBUG swhkd] Previous PID: secret
  - local system DoS if kernel symlink protection is off. The daemon will
    overwrite the target file with its own PID. This could also create a
    world-readable file in interesting locations that allow for further attack
    vectors in other programs.
  - functional issue: such a setup is not suitable for multiple users using the
    software in parallel.

Suggested Fix:

  ## 3.a) All PID and socket files should be placed in non-public locations:

  - The daemon PID file belongs in /run/swhkd/. This directory needs to be
    root-owned and read-only for others. The PID filename needs to be suffixed
    with the UID of the user that invoked pkexec. This information is available
    via the `PKEXEC_UID` environment variable. This way multiple swhkd instances
    don't interfere with each other.
Comment 1 Aakash Sen Sharma 2022-03-25 05:12:41 UTC
I have fixed CVE-2022-27815 in the following commit: https://github.com/waycrate/swhkd/commit/3864bb7cd9cec1ffdb303a7bbbf9c9d5ffe0ed1a

A review from the security team would help.
Comment 2 Aakash Sen Sharma 2022-03-25 07:26:38 UTC
I was wondering if this root-readonly directory could reside in /etc/swhkd? I really want to keep my tool init system independent and relying on /run adds the crutch of maintaining service files for runit, openrc, sysvinit, dinit, s6, and suite66 ( only the popular alternate inits to systemd ) along with systemd.
Comment 3 Aakash Sen Sharma 2022-03-25 07:46:30 UTC
I have decided to go with /etc/swhkd/runtime as the root owned read only directory, please do let me know if this entails any security risks.
Updated link: https://github.com/waycrate/swhkd/pull/93/commits/ee3534b401cba71fddf378f7e1cb18ada0e6fa75
Comment 4 Matthias Gerstner 2022-03-25 11:33:46 UTC
The patch looks good so far.

Putting state data into /etc is not a security problem but highly irregular,
plainly wrong for any UNIX system. /run hasn't much to do with init systems,
it is according to the FHS standard.
Comment 5 Aakash Sen Sharma 2022-03-25 15:21:26 UTC
> /run hasn't much to do with init systems,it is according to the FHS standard.

I understand, the only problem is that /run is cleared on reboot and I would need to write a service file to recreate it every single time..hence the /etc choice.

I might address this in the future.
Comment 6 Aakash Sen Sharma 2022-03-25 15:22:06 UTC
By recreate "it" I mean the root owned swhkd directory.
Comment 7 Matthias Gerstner 2022-03-28 08:44:41 UTC
(In reply to aakashsensharma@gmail.com from comment #6)
> By recreate "it" I mean the root owned swhkd directory.

I don't really see the problem, the swhkd has root privileges and can create
the directory on the fly, if necessary. Otherwise you could place the files
flat (i.e. directly into /run), which would clutter the directory, however.
Comment 8 Aakash Sen Sharma 2022-03-28 23:53:32 UTC
Hm yes I don't know why I didn't think of that initially. I will do that in the upcoming release just to not push too many breaking changes at once since some users are already on the /etc/runtime patch.
Comment 9 Matthias Gerstner 2022-04-14 08:55:30 UTC
I'm considering this finding fixed and will close the bug accordingly. You
should still take care of using a proper directory location for the PID file.