nginx / unit

NGINX Unit - universal web app server - a lightweight and versatile open source server that simplifies the application stack by natively executing application code across eight different programming language runtimes.
https://unit.nginx.org
Apache License 2.0
5.36k stars 322 forks source link

'make install' can break system dirs #769

Open alejandro-colomar opened 1 year ago

alejandro-colomar commented 1 year ago

Currently, make install is implemented as:

install: ${NXT_DAEMON}-install manpage-install
${NXT_DAEMON}-install: $NXT_DAEMON install-check
    install -d \$(DESTDIR)$NXT_SBINDIR
    install -p $NXT_BUILD_DIR/$NXT_DAEMON \$(DESTDIR)$NXT_SBINDIR/
    install -d \$(DESTDIR)$NXT_STATE

If $NXT_SBINDIR or $NXT_STATE represent a system directory, it will be modified to have the same permissions as if it were just created by install(1), overwriting any permissions (or even SELinux security contexts, ...) that were previously present. This can put the system in an unsafe or unstable state.

The reason why install -d has this issue is described here: https://unix.stackexchange.com/questions/340169/whats-the-difference-between-mkdir-p-and-install-d.

Reported-by: Andrew Clayton <a.clayton@nginx.com>
Reported-by: Alejandro Colomar <alx@nginx.com>

@ac000

alejandro-colomar commented 1 year ago

The solution, IMO, would be to run mkdir -p instead, which will not modify existing directories, and will create new ones with reasonable defaults.

alejandro-colomar commented 1 year ago

Maybe a better solution would be to test for existence, and if it doesn't exist, run install -d, with which we can select the mode. This is especially important for NXT_TMP, which we should make sure it exists (will add a separate patch for it).