|
|
f2fdff |
From 9dcead87e6d7f66d34e7a56d11a30daca367dffb Mon Sep 17 00:00:00 2001
|
|
|
f2fdff |
From: "Dmitry V. Levin" <ldv@altlinux.org>
|
|
|
f2fdff |
Date: Wed, 26 Mar 2014 22:17:23 +0000
|
|
|
f2fdff |
Subject: [PATCH] pam_timestamp: fix potential directory traversal issue
|
|
|
f2fdff |
(ticket #27)
|
|
|
f2fdff |
|
|
|
f2fdff |
pam_timestamp uses values of PAM_RUSER and PAM_TTY as components of
|
|
|
f2fdff |
the timestamp pathname it creates, so extra care should be taken to
|
|
|
f2fdff |
avoid potential directory traversal issues.
|
|
|
f2fdff |
|
|
|
f2fdff |
* modules/pam_timestamp/pam_timestamp.c (check_tty): Treat
|
|
|
f2fdff |
"." and ".." tty values as invalid.
|
|
|
f2fdff |
(get_ruser): Treat "." and ".." ruser values, as well as any ruser
|
|
|
f2fdff |
value containing '/', as invalid.
|
|
|
f2fdff |
|
|
|
f2fdff |
Fixes CVE-2014-2583.
|
|
|
f2fdff |
|
|
|
f2fdff |
Reported-by: Sebastian Krahmer <krahmer@suse.de>
|
|
|
f2fdff |
---
|
|
|
f2fdff |
modules/pam_timestamp/pam_timestamp.c | 13 ++++++++++++-
|
|
|
f2fdff |
1 file changed, 12 insertions(+), 1 deletion(-)
|
|
|
f2fdff |
|
|
|
f2fdff |
diff --git a/modules/pam_timestamp/pam_timestamp.c b/modules/pam_timestamp/pam_timestamp.c
|
|
|
f2fdff |
index 5193733..b3f08b1 100644
|
|
|
f2fdff |
--- a/modules/pam_timestamp/pam_timestamp.c
|
|
|
f2fdff |
+++ b/modules/pam_timestamp/pam_timestamp.c
|
|
|
f2fdff |
@@ -158,7 +158,7 @@ check_tty(const char *tty)
|
|
|
f2fdff |
tty = strrchr(tty, '/') + 1;
|
|
|
f2fdff |
}
|
|
|
f2fdff |
/* Make sure the tty wasn't actually a directory (no basename). */
|
|
|
f2fdff |
- if (strlen(tty) == 0) {
|
|
|
f2fdff |
+ if (!strlen(tty) || !strcmp(tty, ".") || !strcmp(tty, "..")) {
|
|
|
f2fdff |
return NULL;
|
|
|
f2fdff |
}
|
|
|
f2fdff |
return tty;
|
|
|
f2fdff |
@@ -243,6 +243,17 @@ get_ruser(pam_handle_t *pamh, char *ruserbuf, size_t ruserbuflen)
|
|
|
f2fdff |
if (pwd != NULL) {
|
|
|
f2fdff |
ruser = pwd->pw_name;
|
|
|
f2fdff |
}
|
|
|
f2fdff |
+ } else {
|
|
|
f2fdff |
+ /*
|
|
|
f2fdff |
+ * This ruser is used by format_timestamp_name as a component
|
|
|
f2fdff |
+ * of constructed timestamp pathname, so ".", "..", and '/'
|
|
|
f2fdff |
+ * are disallowed to avoid potential path traversal issues.
|
|
|
f2fdff |
+ */
|
|
|
f2fdff |
+ if (!strcmp(ruser, ".") ||
|
|
|
f2fdff |
+ !strcmp(ruser, "..") ||
|
|
|
f2fdff |
+ strchr(ruser, '/')) {
|
|
|
f2fdff |
+ ruser = NULL;
|
|
|
f2fdff |
+ }
|
|
|
f2fdff |
}
|
|
|
f2fdff |
if (ruser == NULL || strlen(ruser) >= ruserbuflen) {
|
|
|
f2fdff |
*ruserbuf = '\0';
|
|
|
f2fdff |
--
|
|
|
f2fdff |
1.8.3.1
|
|
|
f2fdff |
|