Skip to contentSkip to conversation

libsemanage/genhomedircon: reject users with a relative home directory

PATCH In review Vit Mojzis 2 participants 3 messages Sep 2 SELinux security module

lore
Share & tools
lore

Vit Mojzis

author
#0 lore raw

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
index f04fc127..2717712c 100644
@@ -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
maintainer Acked-by on v1 1/1
#1 lore raw
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_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.

Do we care if there are other questionable things in the user's home directory field, e.g. regex metacharacters?

maintainer
#2 lore raw
Quoted 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_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.

Quoted 6 lines
Quoted 1 line

Do we care if there are other questionable things in the user's home directory field, e.g. regex metacharacters?

Thanks, merged.