libselinux: prevent path traversal via crafted username in getseuser()
Stephen Smalley
maintainerPATCH 1/1 libselinux: prevent path traversal via crafted username in getseuser()
getseuser() builds "<policy_root>/logins/<username>" and reads the per-user seuser mapping from that file. The username is whatever NSS resolved for the login and is passed straight through by pam_selinux; Linux imposes no character-set restriction on NSS names, and directory backends (LDAP/AD) can serve names containing "/".
A crafted username can make a root-running PAM stack read a file the user controls and take that user's SELinux user and MLS range from it, i.e. the confinement decision is delegated to whoever named the account. Fall through to the ordinary seusers lookup for such names instead.
--- libselinux/src/seusers.c | 8 ++++++++ 1 file changed, 8 insertions(+)
libselinux/src/seusers.c +8 -0
@@ -293,6 +293,14 @@ int getseuser(const char *username, const char *service, char **r_seuser,char *rec =NULL ;char *path =NULL ;FILE *fp =NULL ; + +/* +* Prevent path traversal via crafted username; no valid username +* should be NULL, start with ".", or contain a '/'. +*/ +if (!username || username[0 ] =='.' ||strchr (username,'/' )) + goto err; +if (asprintf (&path,"%s/logins/%s" ,selinux_policy_root (), username) <0 ) goto err;
Signature · 1 line
2.47.3
Quoted 6 lines · Stephen Smalley
getseuser()builds "<policy_root>/logins/<username>" and reads the per-user seuser mapping from that file. The username is whatever NSS resolved for the login and is passed straight through bypam_selinux; Linux imposes no character-set restriction on NSS names, and directory backends (LDAP/AD) can serve names containing "/".
Quoted 6 lines
A crafted username can make a root-running PAM stack read a file the user controls and take that user's SELinux user and MLS range from it, i.e. the confinement decision is delegated to whoever named the account. Fall through to the ordinary seusers lookup for such names instead.
Signed-off-by Stephen Smalley <[email protected]>
Quoted 25 lines
--- libselinux/src/seusers.c | 8 ++++++++ 1 file changed, 8 insertions(+)libselinux/src/seusers.c +8
-0@@ -293,6 +293,14 @@ int getseuser(const char *username, const char *service, char **r_seuser,char *rec =NULL ;char *path =NULL ;FILE *fp =NULL ; + +/* +* Prevent path traversal via crafted username; no valid username +* should be NULL, start with ".", or contain a '/'. +*/ +if (!username || username[0 ] =='.' ||strchr (username,'/' )) + goto err; +if (asprintf (&path,"%s/logins/%s" ,selinux_policy_root (), username) <0 ) goto err;Signature · 1 line
2.47.3
Quoted 8 lines · Petr Lautrbach
Quoted 6 lines · Stephen Smalley
getseuser()builds "<policy_root>/logins/<username>" and reads the per-user seuser mapping from that file. The username is whatever NSS resolved for the login and is passed straight through bypam_selinux; Linux imposes no character-set restriction on NSS names, and directory backends (LDAP/AD) can serve names containing "/".
Quoted 8 lines
Quoted 6 lines
A crafted username can make a root-running PAM stack read a file the user controls and take that user's SELinux user and MLS range from it, i.e. the confinement decision is delegated to whoever named the account. Fall through to the ordinary seusers lookup for such names instead.
Signed-off-by Stephen Smalley <[email protected]>Acked-by Petr Lautrbach <[email protected]>
Merged.
Quoted 25 lines
Quoted 25 lines
--- libselinux/src/seusers.c | 8 ++++++++ 1 file changed, 8 insertions(+)libselinux/src/seusers.c +8
-0@@ -293,6 +293,14 @@ int getseuser(const char *username, const char *service, char **r_seuser,char *rec =NULL ;char *path =NULL ;FILE *fp =NULL ; + +/* +* Prevent path traversal via crafted username; no valid username +* should be NULL, start with ".", or contain a '/'. +*/ +if (!username || username[0 ] =='.' ||strchr (username,'/' )) + goto err; +if (asprintf (&path,"%s/logins/%s" ,selinux_policy_root (), username) <0 ) goto err;Signature · 1 line
2.47.3