Commit f134d3f4 authored by Yuxiao Mao's avatar Yuxiao Mao
Browse files

ROP: remove 1/2 step detection

parent abe8bc23
...@@ -34,28 +34,15 @@ class DetectPatternRopInternal(params: DetectPatternRopParams)(implicit mp: Mata ...@@ -34,28 +34,15 @@ class DetectPatternRopInternal(params: DetectPatternRopParams)(implicit mp: Mata
// 2) ROP gadget destination is likely not in cache, so jalr will take longer and will probably be visible in different clockDiv pack. But this property may increase false positive as legal chain will now seems to be shorter. // 2) ROP gadget destination is likely not in cache, so jalr will take longer and will probably be visible in different clockDiv pack. But this property may increase false positive as legal chain will now seems to be shorter.
val npackSizeMax = 2 val npackSizeMax = 2
val npack_jalr = RegInit(0.U(npackSizeMax.W)).suggestName("npack_jalr") val npack_jalr = RegInit(0.U(npackSizeMax.W)).suggestName("npack_jalr") // if last N valid cycles has jalr
when (in.pack_has_valid) { when (in.pack_has_valid) {
npack_jalr := Cat(npack_jalr(npackSizeMax - 2, 0), in.pack_has_jalr) npack_jalr := Cat(npack_jalr(npackSizeMax - 2, 0), in.pack_has_jalr)
} }
val nstepNum = 2 // step 1/2 of slow cycle
require(mp.clockDiv % nstepNum == 0)
require(nstepNum == 2) // Only support value 2 for now, else needs modify the use of dpack_jalr in when
val nstepSize: Int = mp.clockDiv / nstepNum
val dpack_jalr = Wire(Vec(nstepNum, Bool())).suggestName("dpack_jalr")
for (i <- 0 until nstepNum) {
dpack_jalr(i) := in.pack_jalr.zipWithIndex.filter{ case (data, index) =>
((index <= nstepSize*(i+1)-1) && (index >= nstepSize*i))
}.map(_._1).reduce(_||_)
}
val countjalr1 = RegInit(0.U(mp.counterWidth.W)).suggestName("dprop_countjalr1") val countjalr1 = RegInit(0.U(mp.counterWidth.W)).suggestName("dprop_countjalr1")
val countjalr2 = RegInit(0.U(mp.counterWidth.W)).suggestName("dprop_countjalr2")
when (in.resetCounters) { when (in.resetCounters) {
countjalr1 := 0.U countjalr1 := 0.U
countjalr2 := 0.U
}.otherwise { }.otherwise {
when (in.isMonitoring && in.pack_has_jalr) { // evaluate counter when jalr (include pack_has_valid) when (in.isMonitoring && in.pack_has_jalr) { // evaluate counter when jalr (include pack_has_valid)
when (npack_jalr(0)) { // has jalr adjacent when (npack_jalr(0)) { // has jalr adjacent
...@@ -63,14 +50,6 @@ class DetectPatternRopInternal(params: DetectPatternRopParams)(implicit mp: Mata ...@@ -63,14 +50,6 @@ class DetectPatternRopInternal(params: DetectPatternRopParams)(implicit mp: Mata
}.otherwise { // no jalr adjacent }.otherwise { // no jalr adjacent
countjalr1 := Mux(countjalr1 >= 2.U, countjalr1 - 2.U, 0.U) countjalr1 := Mux(countjalr1 >= 2.U, countjalr1 - 2.U, 0.U)
} }
when (npack_jalr(0) && dpack_jalr.reduce(_&&_)) { // has jalr in adjacent window and step
countjalr2 := countjalr2 + 2.U
}.elsewhen (npack_jalr(0) || dpack_jalr.reduce(_&&_)) { // has jalr in adjacent window or step
countjalr2 := countjalr2 + 1.U
}.otherwise { // no jalr adjacent
countjalr2 := Mux(countjalr2 >= 2.U, countjalr2 - 2.U, 0.U)
}
} }
} }
...@@ -88,7 +67,6 @@ class DetectPatternRopInternal(params: DetectPatternRopParams)(implicit mp: Mata ...@@ -88,7 +67,6 @@ class DetectPatternRopInternal(params: DetectPatternRopParams)(implicit mp: Mata
override def regmap(offset: Int) = override def regmap(offset: Int) =
RegmapUtil.readValueMax(countjalr1, in.resetCounters, mp.counterWidth, offset, "CountRopJalr1") ++ RegmapUtil.readValueMax(countjalr1, in.resetCounters, mp.counterWidth, offset, "CountRopJalr1") ++
RegmapUtil.readValueMax(countjalr2, in.resetCounters, mp.counterWidth, offset + 0x10, "CountRopJalr2") ++
Nil Nil
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment