How does Spectre attack read the cache it tricked CPU to load?

前端 未结 3 1283
走了就别回头了
走了就别回头了 2021-02-14 00:40

I understand the part of the paper where they trick the CPU to speculatively load the part of the victim memory into the CPU cache. Part I do not understand is how they retrieve

3条回答
  •  孤独总比滥情好
    2021-02-14 01:06

    how they retrieve it from cache

    Basically, the secret retrieved speculatively is immediately used as an index to read from another array called side_effects. All we need is to "touch" an index in side_effects array, so the corresponding element get from memory to CPU cache:

    secret = base_array[huge_index_to_a_secret];
    tmp = side_effects[secret * PAGE_SIZE];
    

    Then the latency to access each element in side_effects array is measured and compared to a memory access time:

    for (i = 0; i < 256; i++) {
        start = time();
        tmp = side_effects[i * PAGE_SIZE];
        latency = time() - start;
        if (latency < MIN_MEMORY_ACCESS_TIME)
            return i; // so, thas was the secret!
    }
    

    If latency is lower that minimum memory access time, the element is in cache, so the secret was the current index. If the latency is high, the element is not in cache, so we continue our measurements.

    So, basically we do not retrieve any information directly, rather we touch some memory during the speculative execution and then observe the side effects.

    Here is the Specter-Based Meltdown proof of concept in 99 lines of code you might find easier to understand that the other PoCs: https://github.com/berestovskyy/spectre-meltdown

    In general, this technique is called Side-Channel Attack and more information could be found on Wikipedia: https://en.wikipedia.org/wiki/Side-channel_attack

提交回复
热议问题