Skip to content

Commit

Permalink
[bug-fix] prevent access to dasics registers in untrusted zone
Browse files Browse the repository at this point in the history
  • Loading branch information
DeltaZero7 committed Sep 12, 2024
1 parent 04cb360 commit 6004d19
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/main/scala/xiangshan/backend/fu/CSR.scala
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,11 @@ class CSR(implicit p: Parameters) extends FunctionUnit with HasCSRConst with PMP
(addr >= DasicsJmpBoundBase.U) && (addr <= DasicsJmpCfgBase.U) ||
addr === DasicsLibCfgBase.U

val addrInUExt = (addr >= Ustatus.U) && (addr <= Uip.U)
val addrIsMPK = (addr === Spkctl.U) || (addr === Spkrs.U) || (addr === Upkru.U)

val addrInProtection = addrInDasics || addrInUExt || addrIsMPK

// satp wen check
val satpLegalMode = (wdata.asTypeOf(new SatpStruct).mode===0.U) || (wdata.asTypeOf(new SatpStruct).mode===8.U)

Expand All @@ -789,7 +794,7 @@ class CSR(implicit p: Parameters) extends FunctionUnit with HasCSRConst with PMP
val triggerPermitted = triggerPermissionCheck(addr, true.B, debugMode) // todo dmode
val modePermitted = csrAccessPermissionCheck(addr, false.B, priviledgeMode) && dcsrPermitted && triggerPermitted
val perfcntPermitted = perfcntPermissionCheck(addr, priviledgeMode, mcounteren, scounteren)
val dasicsPermitted = !(CSROpType.needAccess(func) && addrInDasics && isUntrusted)
val dasicsPermitted = !(CSROpType.needAccess(func) && addrInProtection && isUntrusted)
val permitted = Mux(addrInPerfCnt, perfcntPermitted, modePermitted) && accessPermitted && dasicsPermitted

MaskedRegMap.generate(mapping, addr, rdata, wen && permitted, wdata)
Expand Down

0 comments on commit 6004d19

Please sign in to comment.