[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Potential security weakness in Guix services

From: Leo Famulari
Subject: Potential security weakness in Guix services
Date: Thu, 28 Jan 2021 16:53:49 -0500

On January 19 2021, we received a message from Maxime Devos describing a
potential attack vector on Guix System.

If an attacker can exploit a remote code execution vulnerability (RCE)
in a program used by a Guix service, they could use it to take over the
system in some cases. We have not deployed any mitigations for this.

Below is a summary of their messages, including a mitigation proposal.
Your feedback is requested!

----- Forwarded message from Maxime Devos <> -----
For clarification: the scenario I currently have in mind, is that noone
has intentionally introduced a security hole in a service, but rather
there's an accidental security bug somewhere in service package, that
allows an attacker (I'm assuming the service is accessible from the
network) arbitrary code execution *within* the service's process.

As it is now, the attacker could overtake the service process, then chown
and chmod arbitrary directories from there. As a particular example, I'm
considering e.g. a hypothetical ipfs-service-type. A compromised IPFS process
shouldn't be able to change /etc/passwd entries. The security of the IPFS
service itself shouldn't be critical to the security of the system as a

A more specific exapmle:

----- Forwarded message from Maxime Devos <> -----
I seem to have stumbled upon a potential security issue, it has to
do with how some services use mkdir-p/perms. For example, in knot-activation:

   (define (knot-activation config)
         (use-modules (guix build utils))
         (mkdir-p/perms #$(knot-configuration-run-directory config)
                        (getpwnam "knot") #o755)
         (mkdir-p/perms "/var/lib/knot" (getpwnam "knot") #o755)
         (mkdir-p/perms "/var/lib/knot/keys" (getpwnam "knot") #o755)
         (mkdir-p/perms "/var/lib/knot/keys/keys" (getpwnam "knot") #o755)))

/var/lib/knot/keys/keys is chmodded and chowned, which seems innocent enough.
However, what if knot whas compromised at some point, and the compromised knot
process has replaced /var/lib/knot/keys with, say, a symlink to /gnu/store?
Then the next time the system the system is reconfigured, the knot-activation
gexp is ran agan, and the last ‘mkdir-p/perms’ will chown /gnu/store to "knot",
and now the (compromised) knot service can manipulate the store!

Ok, this would be a security issue in knot but ideally the security hole
wouldn't ‘propagate’ to the whole Guix system.

And in a followup:

----- Forwarded message from Maxime Devos <> -----
It's also possible to create a symlink to /etc/passwd, in which case a
compromised (non-containerised) service can change /etc/passwd after
system reconfiguration -- mkdir-p/perms doesn't verify whether its
target is a directory before chowning and chmodding.

And finally, a proposal:

----- Forwarded message from Maxime Devos <> -----
Also, I propose a procedure to guix-security:

(define (mkdir-p/own root sub/.../dir owner bits)
  "Create ROOT/SUB/.../DIR, and its parent directories.

This procedure bails out if ROOT/SUB/.../DIR isn't owned by
OWNER. No restrictions are placed on the ownership of ROOT.
If ROOT doesn't exist, it is created with the current
uid, gid and umask. If SUB/... don't exist, they are created
with uid and gid OWNER and the current umask. If
ROOT/SUB/.../DIR doesn't exist, it is created with uid, gid
and permission bits BITS.

Symbolic links under ROOT/ are not followed."
  ... implementation)

idk if symlinks components in /ROOT should be followed.
Probably no service definition requires this, so *never*
following symlinks may also be possible? Not strictly
required for security I think, but it eases reasoning
about security properties. (Less variables to consider)

Attachment: signature.asc
Description: PGP signature

reply via email to

[Prev in Thread] Current Thread [Next in Thread]