2160
Example Language: Verilog (Good)
assign z <= and_out1 or and_out2 or (in0 and in1);
This line of code removes the glitch in signal z.
Example 2:
The example code is taken from the DMA (Direct Memory Access) module of the buggy OpenPiton
SoC of HACK@DAC'21. The DMA contains a finite-state machine (FSM) for accessing the
permissions using the physical memory protection (PMP) unit.
PMP provides secure regions of physical memory against unauthorized access. It allows an
operating system or a hypervisor to define a series of physical memory regions and then set
permissions for those regions, such as read, write, and execute permissions. When a user tries
to access a protected memory area (e.g., through DMA), PMP checks the access of a PMP
address (e.g., pmpaddr_i) against its configuration (pmpcfg_i). If the access violates the defined
permissions (e.g., CTRL_ABORT), the PMP can trigger a fault or an interrupt. This access check is
implemented in the pmp parametrized module in the below code snippet. The below code assumes
that the state of the pmpaddr_i and pmpcfg_i signals will not change during the different DMA
states (i.e., CTRL_IDLE to CTRL_DONE) while processing a DMA request (via dma_ctrl_reg). The
DMA state machine is implemented using a case statement (not shown in the code snippet).
Example Language: Verilog (Bad)
module dma # (...)(...);
...
input [7:0] [16-1:0] pmpcfg_i;
input logic [16-1:0][53:0] pmpaddr_i;
...
//// Save the input command
always @ (posedge clk_i or negedge rst_ni)
begin: save_inputs
if (!rst_ni)
begin
...
end
else
begin
if (dma_ctrl_reg == CTRL_IDLE || dma_ctrl_reg == CTRL_DONE)
begin
...
end
end
end // save_inputs
...
// Load/store PMP check
pmp #(
.XLEN ( 64 ),
.PMP_LEN ( 54 ),
.NR_ENTRIES ( 16 )
) i_pmp_data (
.addr_i ( pmp_addr_reg ),
.priv_lvl_i ( riscv::PRIV_LVL_U ),
.access_type_i ( pmp_access_type_reg ),
// Configuration
.conf_addr_i ( pmpaddr_i ),
.conf_i ( pmpcfg_i ),
.allow_o ( pmp_data_allow )
);
endmodule
CWE Version 4.14
CWE-1298: Hardware Logic Contains Race Conditions
CWE-1298: Hardware Logic Contains Race Conditions