In spectre vulnerability describing paper, we can see that it talks about this specific vulnerability
if (x < array1_size)
y = array2[array1[x] * 256];
In spectre vulnerability, according to the paper, they first pass many legal values for x such that branch predictor gets trained and starts speculating the next statement i.e. start executing y = array2[array1[x] * 256];
. And after long enough iterations , when branch predictor has been trained , malicious value of x is passed and in this case processor starts speculatively executing y = array2[array1[x] * 256];
and this time it loads array1[x]
in cache which cannot be reverted as of now and can be used by attacker for a side channel attack.
So my question is why do we need to have this if
statement as well. If there would have been this statement only
y = array2[array1[x] * 256];
Shouldn't this above statement along ( without if
) would have been sufficient to load this array1[x]
into cache. Why do we need even this if
statement ?