Hard
Speculation past a trained bounds check with an out-of-bounds index
The branch predictor has been trained (via many prior in-bounds calls) to predict x < array1_size as taken. An attacker then calls this function with an out-of-bounds x. The core speculatively executes past the branch before it's resolved: it computes array1[x] (an out-of-bounds read) and uses that byte to index and load from array2, all before discovering the branch was mispredicted and squashing the instructions. After the misprediction is detected and architectural state is rolled back to what it would have been had the branch gone the other way, what remains observable?
gadget.cpp
if (x < array1_size) {
y = array2[array1[x] * 4096];
}7 of 47 in Computer Architecture