Blame SOURCES/pam-1.1.8-cve-2014-2583.patch

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