diff options
author | Christian Göttsche <cgzones@googlemail.com> | 2020-12-07 14:45:34 +0100 |
---|---|---|
committer | Tomáš Mráz <tmraz@redhat.com> | 2020-12-08 18:15:08 +0100 |
commit | deb5a9fb07ce3dad86ad66789c91b703ad12ca2f (patch) | |
tree | 8d2745046c40af3bc5e8905499ad16b149574048 | |
parent | 017c3ff13d1bb7804799deadd8f58b92eba7979e (diff) | |
download | pam-deb5a9fb07ce3dad86ad66789c91b703ad12ca2f.tar.gz pam-deb5a9fb07ce3dad86ad66789c91b703ad12ca2f.tar.bz2 pam-deb5a9fb07ce3dad86ad66789c91b703ad12ca2f.zip |
pam_selinux: check for string_to_security_class failure
Check for the unlikely case string_to_security_class() does not find the
associated SELinux security class.
This will only happen if the loaded SELinux policy does not define the
class "chr_file" (which no sane policy does) or querying the selinuxfs
fails.
Suggested by #309
-rw-r--r-- | modules/pam_selinux/pam_selinux.c | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/modules/pam_selinux/pam_selinux.c b/modules/pam_selinux/pam_selinux.c index 06c3ce65..d8e10d8e 100644 --- a/modules/pam_selinux/pam_selinux.c +++ b/modules/pam_selinux/pam_selinux.c @@ -519,6 +519,7 @@ static int compute_tty_context(const pam_handle_t *pamh, module_data_t *data) { const char *tty = get_item(pamh, PAM_TTY); + security_class_t tclass; if (!tty || !*tty || !strcmp(tty, "ssh") || pam_str_skip_prefix(tty, "NODEV") != NULL) { @@ -555,8 +556,18 @@ compute_tty_context(const pam_handle_t *pamh, module_data_t *data) return (security_getenforce() == 1) ? PAM_SESSION_ERR : PAM_SUCCESS; } + tclass = string_to_security_class("chr_file"); + if (tclass == 0) { + pam_syslog(pamh, LOG_ERR, "Failed to get chr_file security class"); + freecon(data->prev_tty_context); + data->prev_tty_context = NULL; + free(data->tty_path); + data->tty_path = NULL; + return (security_getenforce() == 1) ? PAM_SESSION_ERR : PAM_SUCCESS; + } + if (security_compute_relabel(data->exec_context, data->prev_tty_context, - string_to_security_class("chr_file"), &data->tty_context)) { + tclass, &data->tty_context)) { data->tty_context = NULL; pam_syslog(pamh, LOG_ERR, "Failed to compute new context for %s: %m", data->tty_path); |