libsemanage: genhomedircon: consider SEMANAGE_FCONTEXT_DIR in fcontext_matches()
PATCH 1/1 libsemanage: genhomedircon: consider SEMANAGE_FCONTEXT_DIR in fcontext_matches()
When generating file_contexts.homedirs, libsemanage enumerates the users on the system and tries to find misconfiguration issues by comparing their home directories with file contexts defined in the policy. The comparison is done by fcontext_matches().
Currently this function only operates on file contexts with type ALL, but it makes sense to also operate on the DIR ones, as a comment states in the function.
For example on a system with the following entry in /etc/passwd:
mytestservice:x:2000:100::/var/lib/mytestservice/dir:/bin/bash
and with the following file context definition:
/var/lib/mytestservice/.* -d gen_context(system_u:object_r:var_lib_t,s0)
"semodule -B" now shows the following warning:
libsemanage.get_home_dirs: mytestservice homedir /var/lib/mytestservice/dir or its parent directory conflicts with a file context already specified in the policy. This usually indicates an incorrectly defined system account. If it is a system account please make sure its uid is less than 1000 or greater than 60000 or its login shell is /sbin/nologin.
--- libsemanage/src/genhomedircon.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
libsemanage/src/genhomedircon.c +1 -1
@@ -246,7 +246,7 @@ static int fcontext_matches(const semanage_fcontext_t *fcontext, void *varg)/* Only match ALL or DIR */ type =semanage_fcontext_get_type (fcontext); -if (type !=SEMANAGE_FCONTEXT_ALL ) +if (type !=SEMANAGE_FCONTEXT_ALL && type !=SEMANAGE_FCONTEXT_DIR )return 0 ; len =strlen (oexpr);
Signature · 1 line
2.11.0
Stephen Smalley
AppliedQuoted 22 lines · Nicolas Iooss
When generating file_contexts.homedirs, libsemanage enumerates the users
on the system and tries to find misconfiguration issues by comparing their home directories with file contexts defined in the policy. The comparison is done byfcontext_matches().Currently this function only operates on file contexts with type ALL, but it makes sense to also operate on the DIR ones, as a comment states
in the function.For example on a system with the following entry in
/etc/passwd:mytestservice:x:2000:100::/var/lib/mytestservice/dir:/bin/bash
and with the following file context definition:
/var/lib/mytestservice/.* -d
gen_context(system_u:object_r:var_lib_t,s0)"semodule -B" now shows the following warning:
Quoted 9 lines
libsemanage.get_home_dirs: mytestservice homedir
/var/lib/mytestservice/diror its parent directory conflicts with a
file context already specified in the policy. This usually indicates an incorrectly defined system account. If it is a system
account please make sure its uid is less than 1000 or greater than
60000 or its login shell is/sbin/nologin.
Thanks, applied.
Quoted 22 lines
Signed-off-by Nicolas Iooss <[email protected]>---
libsemanage/src/genhomedircon.c | 2 +-1 file changed, 1 insertion(+), 1 deletion(-)libsemanage/src/genhomedircon.c +0
-0@@ -246,7 +246,7 @@ static int fcontext_matches(const semanage_fcontext_t *fcontext, void *varg)
/* Only match ALL or DIR */
type =semanage_fcontext_get_type(fcontext);libsemanage/src/genhomedircon.c +1
-1-if (type !=SEMANAGE_FCONTEXT_ALL ) + if (type != SEMANAGE_FCONTEXT_ALL && type !=
SEMANAGE_FCONTEXT_DIR)
return 0;
len = strlen(oexpr);