From f269fdc2626228534c39292c288a63c19a4c779d Mon Sep 17 00:00:00 2001 From: tv Date: Fri, 4 Dec 2026 01:56:12 +0000 Subject: slock: password hash from enstate, else setuid The hash no longer goes into the store. With enstate, it can come from the slot secrets/slock.hashed-password: then slock runs as its user, with that hash. Without a hash, the credential falls back to "none" and slock runs setuid root, reading /etc/shadow. A validator for text/x-crypt-hash checks the hash the way slock uses it, with crypt. The slot is optional, so enstate leaves out a hash the validator objects to, and slock runs setuid instead of locking with a hash no password matches. --- modules/slock/preload.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 modules/slock/preload.c (limited to 'modules/slock/preload.c') diff --git a/modules/slock/preload.c b/modules/slock/preload.c new file mode 100644 index 00000000..0b7e81d4 --- /dev/null +++ b/modules/slock/preload.c @@ -0,0 +1,41 @@ +// Preloaded into slock, which then runs as its user instead of root: +// getspnam returns the password hash from the credential hashed-password, +// and dropping privileges does nothing. + +#include +#include +#include +#include +#include + +static char hash[4096]; + +static struct spwd entry = { + .sp_namp = "", + .sp_pwdp = hash, +}; + +struct spwd *getspnam(const char *name) { + (void) name; + const char *dir = getenv("CREDENTIALS_DIRECTORY"); + char path[4096]; + if (dir == NULL || + snprintf(path, sizeof path, "%s/hashed-password", dir) >= (int) sizeof path) { + return NULL; + } + FILE *f = fopen(path, "r"); + if (f == NULL) { + return NULL; + } + char *line = fgets(hash, sizeof hash, f); + fclose(f); + if (line == NULL) { + return NULL; + } + hash[strcspn(hash, "\n")] = '\0'; + return &entry; +} + +int setgroups(size_t size, const gid_t *list) { (void) size; (void) list; return 0; } +int setgid(gid_t gid) { (void) gid; return 0; } +int setuid(uid_t uid) { (void) uid; return 0; } -- cgit v1.3.1