aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobias Stoeckmann <tobias@stoeckmann.org>2024-01-02 18:34:45 +0100
committerDmitry V. Levin <ldv@strace.io>2024-01-03 17:16:02 +0000
commit353aa13b9c81beb4ba7f02ae57b0722de6a4d565 (patch)
treedb02a99cd7ac96741750457e7ff724b84428f6be
parentb6eda496fd5f7a9724887b208b5d4338c474bb7b (diff)
downloadpam-353aa13b9c81beb4ba7f02ae57b0722de6a4d565.tar.gz
pam-353aa13b9c81beb4ba7f02ae57b0722de6a4d565.tar.bz2
pam-353aa13b9c81beb4ba7f02ae57b0722de6a4d565.zip
pam_namespace: validate amount of uids in config
If more than INT_MAX uids are found in a configuration line, the variable `count` would trigger a signed integer overflow. If more than UINT_MAX uids are found in a configuration line, then the `num_uids` counter is invalid, which could eventually lead to out of boundary accesses. Also make sure that size multiplication for malloc does not overflow. Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
-rw-r--r--modules/pam_namespace/pam_namespace.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/modules/pam_namespace/pam_namespace.c b/modules/pam_namespace/pam_namespace.c
index 92372ab4..09d19ca0 100644
--- a/modules/pam_namespace/pam_namespace.c
+++ b/modules/pam_namespace/pam_namespace.c
@@ -637,7 +637,7 @@ static int process_line(char *line, const char *home, const char *rhome,
if (uids) {
uid_t *uidptr;
const char *ustr, *sstr;
- int count, i;
+ size_t count, i;
if (*uids == '~') {
poly->flags |= POLYDIR_EXCLUSIVE;
@@ -646,6 +646,11 @@ static int process_line(char *line, const char *home, const char *rhome,
for (count = 0, ustr = sstr = uids; sstr; ustr = sstr + 1, count++)
sstr = strchr(ustr, ',');
+ if (count > UINT_MAX || count > SIZE_MAX / sizeof(uid_t)) {
+ pam_syslog(idata->pamh, LOG_ERR, "Too many uids encountered in configuration");
+ goto skipping;
+ }
+
poly->num_uids = count;
poly->uid = malloc(count * sizeof (uid_t));
uidptr = poly->uid;