1From 2e94b6ec10f1d15e24867bab3063bb85f173406a Mon Sep 17 00:00:00 2001 2From: Jeremy Allison <jra@samba.org> 3Date: Thu, 9 Jul 2015 10:58:11 -0700 4Subject: [PATCH] CVE-2015-5252: s3: smbd: Fix symlink verification (file 5 access outside the share). 6 7Ensure matching component ends in '/' or '\0'. 8 9BUG: https://bugzilla.samba.org/show_bug.cgi?id=11395 10 11Signed-off-by: Jeremy Allison <jra@samba.org> 12Reviewed-by: Volker Lendecke <vl@samba.org> 13--- 14 source3/smbd/vfs.c | 7 +++++-- 15 1 file changed, 5 insertions(+), 2 deletions(-) 16 17--- a/source3/smbd/vfs.c 18+++ b/source3/smbd/vfs.c 19@@ -982,6 +982,7 @@ NTSTATUS check_reduced_name(connection_s 20 if (!allow_widelinks || !allow_symlinks) { 21 const char *conn_rootdir; 22 size_t rootdir_len; 23+ bool matched; 24 25 conn_rootdir = SMB_VFS_CONNECTPATH(conn, fname); 26 if (conn_rootdir == NULL) { 27@@ -992,8 +993,10 @@ NTSTATUS check_reduced_name(connection_s 28 } 29 30 rootdir_len = strlen(conn_rootdir); 31- if (strncmp(conn_rootdir, resolved_name, 32- rootdir_len) != 0) { 33+ matched = (strncmp(conn_rootdir, resolved_name, 34+ rootdir_len) == 0); 35+ if (!matched || (resolved_name[rootdir_len] != '/' && 36+ resolved_name[rootdir_len] != '\0')) { 37 DEBUG(2, ("check_reduced_name: Bad access " 38 "attempt: %s is a symlink outside the " 39 "share path\n", fname)); 40