CVE-2020-10174 (published 2020-03-05T16:15Z)

init_tmp in TeeJee.FileSystem.vala in Timeshift before 20.03 unsafely reuses a preexisting temporary directory in the predictable location /tmp/timeshift. It follows symlinks in this location or uses directories owned by unprivileged users. Because Timeshift also executes scripts under this location, an attacker can attempt to win a race condition to replace scripts created by Timeshift with attacker-controlled scripts. Upon success, an attacker-controlled script is executed with full root privileges. This logic is practically always triggered when Timeshift runs regardless of the command-line arguments used.

Severity: MEDIUM
CVSS v2 base score: 6.9 (AV:L/AC:M/Au:N/C:C/I:C/A:C)
CVSS v3 base score: 7.0, HIGH (CVSS:3.1/AV:L/AC:H/PR:L/UI:N/S:U/C:H/I:H/A:H)

Weakness information:
cwe_id: CWE-362
cwe_name: Concurrent Execution using Shared Resource with Improper Synchronization ('Race Condition')
description: The product contains a code sequence that can run concurrently with other code, and the code sequence requires temporary, exclusive access to a shared resource, but a timing window exists in which the shared resource can be modified by another code sequence that is operating concurrently.
extended_description: 
            This can have security implications when the expected synchronization is in security-critical code, such as recording whether a user is authenticated or modifying important state information that should not be influenced by an outsider.
            A race condition occurs within concurrent environments, and is effectively a property of a code sequence. Depending on the context, a code sequence may be in the form of a function call, a small number of instructions, a series of program invocations, etc.
            A race condition violates these properties, which are closely related:
               
                  Exclusivity - the code sequence is given exclusive access to the shared resource, i.e., no other code sequence can modify properties of the shared resource before the original sequence has completed execution.
                  Atomicity - the code sequence is behaviorally atomic, i.e., no other thread or process can concurrently execute the same sequence of instructions (or a subset) against the same resource.
               
            A race condition exists when an "interfering code sequence" can still access the shared resource, violating exclusivity. Programmers may assume that certain code sequences execute too quickly to be affected by an interfering code sequence; when they are not, this violates atomicity. For example, the single "x++" statement may appear atomic at the code layer, but it is actually non-atomic at the instruction layer, since it involves a read (the original value of x), followed by a computation (x+1), followed by a write (save the result to x).
            The interfering code sequence could be "trusted" or "untrusted." A trusted interfering code sequence occurs within the product; it cannot be modified by the attacker, and it can only be invoked indirectly. An untrusted interfering code sequence can be authored directly by the attacker, and typically it is external to the vulnerable product.
         
         
cwe_id: CWE-59
cwe_name: Improper Link Resolution Before File Access ('Link Following')
description: The product attempts to access a file based on the filename, but it does not properly prevent that filename from identifying a link or shortcut that resolves to an unintended resource.
extended_description: 
            
            
         
         

Fix information:
repo_url: https://github.com/teejee2008/timeshift
commit_details: repo_url: https://github.com/teejee2008/timeshift
author: Tony George
author_date: 2020-03-05 08:57:24+05:30
msg: Change TEMP_DIR permissions and path; Cleanup on exit;
repository: repo_url: https://github.com/teejee2008/timeshift
repo_name: teejee2008/timeshift
description: System restore tool for Linux. Creates filesystem snapshots using rsync+hardlinks, or BTRFS snapshots. Supports scheduled snapshots, multiple backup levels, and exclude filters. Snapshots can be restored while system is running or from Live CD/USB.
repo_language: Vala
owner: teejee2008
file_changes: filename: Main.vala
change_type: ModificationType.MODIFY
diff: @@ -4244,6 +4244,8 @@ public class Main : GLib.Object{
 		clean_logs();
 
 		app_lock.remove();
+		
+		dir_delete(TEMP_DIR);
 
 		exit(exit_code);
 

programming_language: Java
filename: TeeJee.FileSystem.vala
change_type: ModificationType.MODIFY
diff: @@ -344,8 +344,11 @@ namespace TeeJee.FileSystem{
 
 		try{
 			var dir = File.parse_name (dir_path);
+			
 			if (dir.query_exists () == false) {
+				
 				bool ok = dir.make_directory_with_parents (null);
+				
 				if (show_message){
 					if (ok){
 						log_msg(_("Created directory") + ": %s".printf(dir_path));
@@ -355,6 +358,7 @@ namespace TeeJee.FileSystem{
 					}
 				}
 			}
+			
 			return true;
 		}
 		catch (Error e) {
@@ -373,9 +377,12 @@ namespace TeeJee.FileSystem{
 		}
 		
 		string cmd = "rm -rf '%s'".printf(escape_single_quote(dir_path));
+		
 		log_debug(cmd);
+		
 		string std_out, std_err;
 		int status = exec_sync(cmd, out std_out, out std_err);
+		
 		if (show_message){
 			if (status == 0){
 				log_msg(_("Deleted directory") + ": %s".printf(dir_path));

programming_language: C
filename: TeeJee.Process.vala
change_type: ModificationType.MODIFY
diff: @@ -36,14 +36,17 @@ namespace TeeJee.ProcessHelper{
     public static void init_tmp(string subdir_name){
 		string std_out, std_err;
 
-		TEMP_DIR = Environment.get_tmp_dir() + "/" + subdir_name + "/" + random_string();
+		TEMP_DIR = Environment.get_tmp_dir() + "/" + random_string();
 		dir_create(TEMP_DIR);
-
+		chmod(TEMP_DIR, "0750");
+		
 		exec_script_sync("echo 'ok'",out std_out,out std_err, true);
-		if ((std_out == null)||(std_out.strip() != "ok")){
-			TEMP_DIR = Environment.get_home_dir() + "/.temp/" + subdir_name + "/" + random_string();
-			exec_sync("rm -rf '%s'".printf(TEMP_DIR), null, null);
+		
+		if ((std_out == null) || (std_out.strip() != "ok")){
+			
+			TEMP_DIR = Environment.get_home_dir() + "/.temp/" + random_string();
 			dir_create(TEMP_DIR);
+			chmod(TEMP_DIR, "0750");
 		}
 
 		//log_debug("TEMP_DIR=" + TEMP_DIR);

programming_language: C