Class · High

CWE-1419: Incorrect Initialization of Resource

The product attempts to initialize a resource but does not correctly do so, which might leave the resource in an unexpected, incorrect, or insecure state when it is accessed.

CWE-1419 · Class Level ·5 CVEs ·4 Mitigations

Description

The product attempts to initialize a resource but does not correctly do so, which might leave the resource in an unexpected, incorrect, or insecure state when it is accessed.

This can have security implications when the associated resource is expected to have certain properties or values. Examples include a variable that determines whether a user has been authenticated or not, or a register or fuse value that determines the security state of the product. For software, this weakness can frequently occur when implicit initialization is used, meaning the resource is not explicitly set to a specific value. For example, in C, memory is not necessarily cleared when it is allocated on the stack, and many scripting languages use a default empty, null value, or zero value when a variable is not explicitly initialized. For hardware, this weakness frequently appears with reset values and fuses. After a product reset, hardware may initialize registers incorrectly. During different phases of a product lifecycle, fuses may be set to incorrect values. Even if fuses are set to correct values, the lines to the fuse could be broken or there might be hardware on the fuse line that alters the fuse value to be incorrect.

Potential Impact

Confidentiality

Read Memory, Read Application Data, Unexpected State

Authorization, Integrity

Gain Privileges or Assume Identity

Other

Varies by Context

Demonstrative Examples

Consider example design module system verilog code shown below. The register_example module is an example parameterized module that defines two parameters, REGISTER_WIDTH and REGISTER_DEFAULT. Register_example module defines a Secure_mode setting, which when set makes the register content read-only and not modifiable by software writes. register_top module instantiates two registers, Insecure_Device_ID_1 and Insecure_Device_ID_2. Generally, registers containing device identifier values are required to be read only to prevent any possibility of software modifying these values.
Bad
// Parameterized Register module example 
				  // Secure_mode : REGISTER_DEFAULT[0] : When set to 1 register is read only and not writable// 
				  module register_example 
				  #( 
				  parameter REGISTER_WIDTH = 8, // Parameter defines width of register, default 8 bits 
				  parameter [REGISTER_WIDTH-1:0] REGISTER_DEFAULT = 2**REGISTER_WIDTH -2 // Default value of register computed from Width. Sets all bits to 1s except bit 0 (Secure _mode) 
				  ) 
				  ( 
				  input [REGISTER_WIDTH-1:0] Data_in, 
				  input Clk, 
				  input resetn, 
				  input write, 
				  output reg [REGISTER_WIDTH-1:0] Data_out 
				  ); 
				  
				  reg Secure_mode; 
				  
				  always @(posedge Clk or negedge resetn) 
				  
					if (~resetn) 
					begin 
					
					  Data_out <= REGISTER_DEFAULT; // Register content set to Default at reset 
					  Secure_mode <= REGISTER_DEFAULT[0]; // Register Secure_mode set at reset 
					
					end 
					else if (write & ~Secure_mode) 
					begin 
					
					  Data_out <= Data_in; 
					
					end 
				  
				  endmodule 
                  
                  
				  module register_top 
				  ( 
				  input Clk, 
				  input resetn, 
				  input write, 
				  input [31:0] Data_in, 
				  output reg [31:0] Secure_reg, 
				  output reg [31:0] Insecure_reg 
				  ); 
				  
				  register_example #( 
				  
					.REGISTER_WIDTH (32), 
					.REGISTER_DEFAULT (1224) // Incorrect Default value used bit 0 is 0. 
				  
				  ) Insecure_Device_ID_1 ( 
				  
					.Data_in (Data_in), 
					.Data_out (Secure_reg), 
					.Clk (Clk), 
					.resetn (resetn), 
					.write (write) 
				  
				  ); 
                  
				  register_example #(
				  
					.REGISTER_WIDTH (32) // Default not defined 2^32-2 value will be used as default. 
				  
				  ) Insecure_Device_ID_2 ( 
				  
					.Data_in (Data_in), 
					.Data_out (Insecure_reg), 
					.Clk (Clk), 
					.resetn (resetn), 
					.write (write) 
				  
				  ); 
                  
				  endmodule
These example instantiations show how, in a hardware design, it would be possible to instantiate the register module with insecure defaults and parameters.
In the example design, both registers will be software writable since Secure_mode is defined as zero.
Good
register_example #( 
				  
					.REGISTER_WIDTH (32), 
					.REGISTER_DEFAULT (1225) // Correct default value set, to enable Secure_mode 
				  
				  ) Secure_Device_ID_example ( 
				  
					.Data_in (Data_in), 
					.Data_out (Secure_reg), 
					.Clk (Clk), 
					.resetn (resetn), 
					.write (write) 
				  
				  );
This code attempts to login a user using credentials from a POST request:
Bad
// $user and $pass automatically set from POST request
                    if (login_user($user,$pass)) {$authorized = true;}
                    ...
                    
                  if ($authorized) {generatePage();}
Because the $authorized variable is never initialized, PHP will automatically set $authorized to any value included in the POST request if register_globals is enabled. An attacker can send a POST request with an unexpected third value 'authorized' set to 'true' and gain authorized status without supplying valid credentials.
Here is a fixed version:
Good
$user = $_POST['user'];$pass = $_POST['pass'];$authorized = false;if (login_user($user,$pass)) {$authorized = true;}
                  ...
This code avoids the issue by initializing the $authorized variable to false and explicitly retrieving the login credentials from the $_POST variable. Regardless, register_globals should never be enabled and is disabled by default in current versions of PHP.
The following example code is excerpted from the Access Control module, acct_wrapper, in the Hack@DAC'21 buggy OpenPiton System-on-Chip (SoC). Within this module, a set of memory-mapped I/O registers, referred to as acct_mem, each 32-bit wide, is utilized to store access control permissions for peripherals [REF-1437]. Access control registers are typically used to define and enforce permissions and access rights for various system resources.
However, in the buggy SoC, these registers are all enabled at reset, i.e., essentially granting unrestricted access to all system resources [REF-1438]. This will introduce security vulnerabilities and risks to the system, such as privilege escalation or exposing sensitive information to unauthorized users or processes.
Bad
module acct_wrapper #(
						...
						
							always @(posedge clk_i)
							
								begin
								
									if(~(rst_ni && ~rst_6))
									
										begin
										
											for (j=0; j < AcCt_MEM_SIZE; j=j+1)
												
													begin
													
														acct_mem[j] <= 32'hffffffff;
													
													end
												
										
										end
									
								
								...
To fix this issue, the access control registers must be properly initialized during the reset phase of the SoC. Correct initialization values should be established to maintain the system's integrity, security, predictable behavior, and allow proper control of peripherals. The specifics of what values should be set depend on the SoC's design and the requirements of the system. To address the problem depicted in the bad code example [REF-1438], the default value for "acct_mem" should be set to 32'h00000000 (see good code example [REF-1439]). This ensures that during startup or after any reset, access to protected data is restricted until the system setup is complete and security procedures properly configure the access control settings.
Good
module acct_wrapper #(
						...
						
							always @(posedge clk_i)
							
								begin
								
									if(~(rst_ni && ~rst_6))
									
										begin
										
											for (j=0; j < AcCt_MEM_SIZE; j=j+1)
											
												begin
												
													acct_mem[j] <= 32'h00000000;
												
												end
											
										
										end
									
								
								...

Mitigations & Prevention

Implementation

Choose the safest-possible initialization for security-related resources.

Implementation

Ensure that each resource (whether variable, memory buffer, register, etc.) is fully initialized.

Implementation

Pay close attention to complex conditionals or reset sources that affect initialization, since some paths might not perform the initialization.

Architecture and Design

Ensure that the design and architecture clearly identify what the initialization should be, and that the initialization does not have security implications.

Detection Methods

  • Automated Static Analysis — Automated static analysis, commonly referred to as Static Application Security Testing (SAST), can find some instances of this weakness by analyzing source code (or binary/compiled code) without having to execute it. Typically, this is done by building a model of data flow and control flow, then sea

Real-World CVE Examples

CVE IDDescription
CVE-2020-27211Chain: microcontroller system-on-chip uses a register value stored in flash to set product protection state on the memory bus and does not contain protection against fault injection (CWE-1319) which l
CVE-2023-25815chain: a change in an underlying package causes the gettext function to use implicit initialization with a hard-coded path (CWE-1419) under the user-writable C:\ drive, introducing an untrusted search
CVE-2022-43468WordPress module sets internal variables based on external inputs, allowing false reporting of the number of views
CVE-2022-36349insecure default variable initialization in BIOS firmware for a hardware board allows DoS
CVE-2015-7763distributed filesystem only initializes part of the variable-length padding for a packet, allowing attackers to read sensitive information from previously-sent packets in the same memory location

Frequently Asked Questions

What is CWE-1419?

CWE-1419 (Incorrect Initialization of Resource) is a software weakness identified by MITRE's Common Weakness Enumeration. It is classified as a Class-level weakness. The product attempts to initialize a resource but does not correctly do so, which might leave the resource in an unexpected, incorrect, or insecure state when it is accessed.

How can CWE-1419 be exploited?

Attackers can exploit CWE-1419 (Incorrect Initialization of Resource) to read memory, read application data, unexpected state. This weakness is typically introduced during the Implementation, Manufacturing, Installation, System Configuration, Operation phase of software development.

How do I prevent CWE-1419?

Key mitigations include: Choose the safest-possible initialization for security-related resources.

What is the severity of CWE-1419?

CWE-1419 is classified as a Class-level weakness (High abstraction). It has been observed in 5 real-world CVEs.