Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Zicfiss and Zicfilp extensions for Control-Flow Integrity #47

Draft
wants to merge 2 commits into
base: astral
Choose a base branch
from

Conversation

emanueleparisi
Copy link

Implement the Zicfiss and Zicfilp ISA extensions for Control-Flow Integrity.

Zicfiss

The Zicfiss extension introduces a shadow stack to enforce backward-edge control-flow integrity. A shadow stack is a second stack used to store a shadow copy of the return address in the link register if it needs to be spilled. The shadow stack is designed to provide integrity to control transfers performed using a return, where the return may be from a procedure invoked using an indirect call or a direct call, and this is referred to as backward-edge protection. The extension adds the following instructions:

  • SSPUSH x1, SSPUSH x5
  • C.SSPUSH x1
  • SSPOPCHK x1, SSPOPCHK x5
  • C.SSPOPCHK x5
  • SSRDP
  • SSAMOSWAP.W, SSAMOSWAP.D

Zicfilp

To enforce forward-edge control-flow integrity, the Zicfilp extension introduces a landing pad (LPAD) instruction. The LPAD instruction must be placed at the program locations that are valid targets of indirect jumps or calls. The LPAD instruction is encoded using the AUIPC major opcode with rd = x0.

Relevant links:

Comment on lines 47 to 53
always_comb begin : landingpad_port
elp_o = elp_i;
lpl_o = lpl_i;
commit_ack_o = commit_ack_i;
we_gpr_o = we_gpr_i;
lp_fault_o = 'b0;
end

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[verible-verilog-format] reported by reviewdog 🐶

Suggested change
always_comb begin : landingpad_port
elp_o = elp_i;
lpl_o = lpl_i;
commit_ack_o = commit_ack_i;
we_gpr_o = we_gpr_i;
lp_fault_o = 'b0;
end
always_comb begin : landingpad_port
elp_o = elp_i;
lpl_o = lpl_i;
commit_ack_o = commit_ack_i;
we_gpr_o = we_gpr_i;
lp_fault_o = 'b0;
end

@emanueleparisi emanueleparisi force-pushed the dev/zicfi branch 2 times, most recently from eda1b97 to d74f5af Compare April 17, 2024 23:41
Comment on lines +2655 to +2657
menvcfg_q <= menvcfg_d;
henvcfg_q <= henvcfg_d;
senvcfg_q <= senvcfg_d;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[verible-verilog-format] reported by reviewdog 🐶

Suggested change
menvcfg_q <= menvcfg_d;
henvcfg_q <= henvcfg_d;
senvcfg_q <= senvcfg_d;
menvcfg_q <= menvcfg_d;
henvcfg_q <= henvcfg_d;
senvcfg_q <= senvcfg_d;

Comment on lines +803 to +808
localparam logic [63:0] ENVCFG_FIOM = 64'h0000000000000001;
localparam logic [63:0] ENVCFG_LPE = 64'h0000000000000004;
localparam logic [63:0] ENVCFG_SSE = 64'h0000000000000008;
localparam logic [63:0] ENVCFG_CBIE = 64'h0000000000000030;
localparam logic [63:0] ENVCFG_CBFE = 64'h0000000000000040;
localparam logic [63:0] ENVCFG_CBZE = 64'h0000000000000080;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[verible-verilog-format] reported by reviewdog 🐶

Suggested change
localparam logic [63:0] ENVCFG_FIOM = 64'h0000000000000001;
localparam logic [63:0] ENVCFG_LPE = 64'h0000000000000004;
localparam logic [63:0] ENVCFG_SSE = 64'h0000000000000008;
localparam logic [63:0] ENVCFG_CBIE = 64'h0000000000000030;
localparam logic [63:0] ENVCFG_CBFE = 64'h0000000000000040;
localparam logic [63:0] ENVCFG_CBZE = 64'h0000000000000080;
localparam logic [63:0] ENVCFG_FIOM = 64'h0000000000000001;
localparam logic [63:0] ENVCFG_LPE = 64'h0000000000000004;
localparam logic [63:0] ENVCFG_SSE = 64'h0000000000000008;
localparam logic [63:0] ENVCFG_CBIE = 64'h0000000000000030;
localparam logic [63:0] ENVCFG_CBFE = 64'h0000000000000040;
localparam logic [63:0] ENVCFG_CBZE = 64'h0000000000000080;

localparam logic [63:0] ENVCFG_CBFE = 64'h0000000000000040;
localparam logic [63:0] ENVCFG_CBZE = 64'h0000000000000080;
localparam logic [63:0] ENVCFG_PBMTE = 64'h4000000000000000;
localparam logic [63:0] ENVCFG_STCE = 64'h8000000000000000;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[verible-verilog-format] reported by reviewdog 🐶

Suggested change
localparam logic [63:0] ENVCFG_STCE = 64'h8000000000000000;
localparam logic [63:0] ENVCFG_STCE = 64'h8000000000000000;

Comment on lines +813 to +815
localparam logic [63:0] SECCFG_MML = 64'h0000000000000001;
localparam logic [63:0] SECCFG_MMWP = 64'h0000000000000002;
localparam logic [63:0] SECCFG_RLP = 64'h0000000000000004;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[verible-verilog-format] reported by reviewdog 🐶

Suggested change
localparam logic [63:0] SECCFG_MML = 64'h0000000000000001;
localparam logic [63:0] SECCFG_MMWP = 64'h0000000000000002;
localparam logic [63:0] SECCFG_RLP = 64'h0000000000000004;
localparam logic [63:0] SECCFG_MML = 64'h0000000000000001;
localparam logic [63:0] SECCFG_MMWP = 64'h0000000000000002;
localparam logic [63:0] SECCFG_RLP = 64'h0000000000000004;

localparam logic [63:0] SECCFG_RLP = 64'h0000000000000004;
localparam logic [63:0] SECCFG_USEED = 64'h0000000000000100;
localparam logic [63:0] SECCFG_SSEED = 64'h0000000000000200;
localparam logic [63:0] SECCFG_MLPE = 64'h0000000000000400;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[verible-verilog-format] reported by reviewdog 🐶

Suggested change
localparam logic [63:0] SECCFG_MLPE = 64'h0000000000000400;
localparam logic [63:0] SECCFG_MLPE = 64'h0000000000000400;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant