tree-wide: refuse user/group records lacking UID or GID

userdb allows user/group records without UID/GID (it only really
requires a name), in order to permit "unfixated" records. But that means
we cannot just rely on the field to be valid. And we mostly got that
right, but not everywhere. Fix that.
This commit is contained in:
Lennart Poettering
2025-03-17 22:37:14 +01:00
parent d43a440767
commit 91d11d53a1
3 changed files with 12 additions and 0 deletions

View File

@@ -195,6 +195,9 @@ int manager_add_user_by_name(
if (r < 0)
return r;
if (!uid_is_valid(ur->uid)) /* Refuse users without UID */
return -ESRCH;
return manager_add_user(m, ur, ret_user);
}

View File

@@ -241,6 +241,11 @@ static int acquire_user_record(
return PAM_USER_UNKNOWN;
}
if (!uid_is_valid(ur->uid)) {
pam_syslog_errno(handle, LOG_ERR, r, "User record of user '%s' has no UID, refusing: %m", username);
return PAM_USER_UNKNOWN;
}
r = sd_json_variant_format(ur->json, 0, &formatted);
if (r < 0)
return pam_syslog_errno(handle, LOG_ERR, r, "Failed to format user JSON: %m");

View File

@@ -244,9 +244,13 @@ int bind_user_prepare(
* UID is safer. */
if (user_record_is_root(u))
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Mapping 'root' user not supported, sorry.");
if (user_record_is_nobody(u))
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Mapping 'nobody' user not supported, sorry.");
if (!uid_is_valid(u->uid))
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Cannot bind user with no UID, refusing.");
if (u->uid >= uid_shift && u->uid < uid_shift + uid_range)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "UID of user '%s' to map is already in container UID range, refusing.", u->user_name);