CWE-1231: Improper Prevention of Lock Bit Modification

Description:
The product uses a trusted lock bit for restricting access to registers, address regions, or other resources, but the product does not prevent the value of the lock bit from being modified after it has been set.

Extended Description:
In integrated circuits and hardware
			  intellectual property (IP) cores, device configuration
			  controls are commonly programmed after a device power
			  reset by a trusted firmware or software module (e.g.,
			  BIOS/bootloader) and then locked from any further
			  modification. 

			   This behavior is commonly implemented using a trusted lock bit. 
			  When set, the lock bit disables writes to a protected set of
			  registers or address regions. Design or coding errors in
			  the implementation of the lock bit protection feature
			  may allow the lock bit to be modified or cleared by
			  software after it has been set. Attackers might be able to unlock the system and
			  features that the bit is intended to protect.

Affected languages: Not Language-Specific
Affected technologies: Not Technology-Specific
Parent weaknesses: CWE-284

Consequences:
  - Access Control: Modify Memory

Detection methods:
  - Manual Analysis: Set the lock bit. Power cycle the
	     device. Attempt to clear the lock bit.  If the
	     information is changed, implement a design
	     fix. Retest. Also, attempt to indirectly clear the lock
	 

Mitigations:
  - [Architecture and Design] Security lock bit protections must be reviewed for design inconsistency and common weaknesses. 
                             Security lock programming flow and lock properties must be tested in pre-silicon and post-silicon testing.

Demonstrative examples:
Consider the example design below for a digital thermal sensor that detects overheating of the silicon and triggers system shutdown. The system critical temperature limit (CRITICAL_TEMP_LIMIT) and thermal sensor calibration (TEMP_SENSOR_CALIB) data have to be programmed by firmware, and then the register needs to be locked (TEMP_SENSOR_LOCK).
In this example, note that if the system heats to critical temperature, the response of the system is controlled by the TEMP_HW_SHUTDOWN bit [1], which is not lockable. Thus, the intended security property of the critical temperature sensor cannot be fully protected, since software can misconfigure the TEMP_HW_SHUTDOWN register even after the lock bit is set to disable the shutdown response.
Register 
                                 Field description

The following example code is a snippet from the register locks inside the buggy OpenPiton SoC of HACK@DAC'21 [REF-1350]. Register locks help prevent SoC peripherals' registers from malicious use of resources. The registers that can potentially leak secret data are locked by register locks.
In the vulnerable code, the reglk_mem is used for locking information. If one of its bits toggle to 1, the corresponding peripheral's registers will be locked. In the context of the HACK@DAC System-on-Chip (SoC), it is pertinent to note the existence of two distinct categories of reset signals.
always @(posedge clk_i) 
                                 begin 
                                     if(~(rst_ni && ~jtag_unlock && ~rst_9)) 
										 begin
                                             for (j=

Real-world examples:
  - CVE-2017-6283: chip reset clears critical read/write lock permissions for RSA function