ModSecurity icon indicating copy to clipboard operation
ModSecurity copied to clipboard

segfault with assigned user id on OpenShift

Open arminabf opened this issue 6 years ago • 1 comments

When running httpd on OpenShift, by default the server instance will run with an assigned user ID not appearing in the UNIX password file.

There are several places in the code of mod_security where the user name is tried to retrieved by use of apr_uid_name_get(). As the function can not find a corresponding user name it returns with an error (and argument pointer being NULL). Due to missing error handling constant segmentation faults are faced on OpenShift.

As a fallback on OpenShift (and probably other container platforms), the user id should be used instead of the user name.

arminabf avatar Mar 13 '19 12:03 arminabf

Better to have a centralized function for this:

char* get_username(apr_pool_t* mp) {
 char* username;
 apr_uid_t uid;
 apr_gid_t gid;
 int rc = apr_uid_current(&uid, &gid, mp);
 if (rc != APR_SUCCESS) return "apache";
 rc = apr_uid_name_get(&username, uid, mp);
 if (rc != APR_SUCCESS) return "apache";
 return username;
}

marcstern avatar Apr 27 '21 08:04 marcstern

Why isn't this merged? Sometimes segmentation fault won't happens and it could lead to other major vulnerabilities.
In apache2/re_variables.c:2597 the rc is checked, why it isn't in these other 2 files?

FedericoHeichou avatar Sep 23 '22 06:09 FedericoHeichou

There are two slightly differing proposals for this issue if apr_uid_name_get() fails:

  • use the numeric value from apr_uid_current
  • use a fixed string such as "apache" (in the related issue)

There are some things I like about the first proposal, but I'm wondering if having an all-digit default could be confusing or obscure for some users.

martinhsv avatar Nov 22 '22 14:11 martinhsv

Using the numeric value from apr_uid_current is OK (and maybe even better). Both solutions are better than the current bogus behaviour anyway.

marcstern avatar Nov 22 '22 14:11 marcstern

Thanks all, for the contributions on this matter.

martinhsv avatar Nov 23 '22 22:11 martinhsv