libsemanage/genhomedircon: reject users with a relative home directory
PATCH 1/1 libsemanage/genhomedircon: reject users with a relative home directory
If a user's home directory in the password database is empty or otherwise does not start with "/" (e.g. because of a broken NSS lookup or a malformed passwd entry), the HOME_DIR template ends up being turned into a regular expression such as "/.+", which matches any path on the filesystem. This causes genhomedircon to generate a file context that relabels far more of the filesystem than intended. Skip such users instead of using their home directory to build the regex.
--- libsemanage/src/genhomedircon.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
libsemanage/src/genhomedircon.c +11 -0
@@ -1110,6 +1110,17 @@ retry: pwent->pw_dir[len] ='\0' ; } +if (pwent->pw_dir[0 ] !='/' ) { +/* an empty (or otherwise relative) home directory would +* turn the HOME_DIR template into a regex that matches +* everything, e.g. "/.+", so refuse to use it */ +WARN (s->h_semanage, +"user %s has an invalid home directory \"%s\", ignoring" , + name, pwent->pw_dir); + retval =STATUS_SUCCESS ; + goto cleanup; + } +if (strcmp (pwent->pw_dir,"/" ) ==0 ) {/* don't relabel / genhomdircon checked to see if root * was the user and if so, set his home directory to
Signature · 1 line
2.53.0
Quoted 10 lines · Vit Mojzis
If a user's home directory in the password database is empty or otherwise does not start with "/" (e.g. because of a broken NSS lookup or a malformed passwd entry), the
HOME_DIRtemplate ends up being turned into a regular expression such as "/.+", which matches any path on the filesystem. This causes genhomedircon to generate a file context that relabels far more of the filesystem than intended. Skip such users instead of using their home directory to build the regex.Signed-off-by Vit Mojzis <[email protected]>
Do we care if there are other questionable things in the user's home directory field, e.g. regex metacharacters?
Stephen Smalley
maintainerQuoted 11 lines · Stephen Smalley
Quoted 9 lines · Vit Mojzis
If a user's home directory in the password database is empty or otherwise does not start with "/" (e.g. because of a broken NSS lookup or a malformed passwd entry), the
HOME_DIRtemplate ends up being turned into a regular expression such as "/.+", which matches any path on the filesystem. This causes genhomedircon to generate a file context that relabels far more of the filesystem than intended. Skip such users instead of using their home directory to build the regex.
Quoted 6 lines
Quoted 1 line
Signed-off-by Vit Mojzis <[email protected]>Acked-by Stephen Smalley <[email protected]>Do we care if there are other questionable things in the user's home directory field, e.g. regex metacharacters?
Thanks, merged.