Dacobi
Dacobi

Reputation: 437

How does virtual/physical addresses work in regards to the Spectre example?

I haven't been programming in a couple of years but with all the fuss about Meltdown and Spectre I've install VS2017 and compiled the Spectre example from this pdf: https://spectreattack.com/spectre.pdf

However I have no idea how the addresses that the Spectre example takes on the command line works?

I modified the code to output the pointer address of the secret string and compiled with cl in the Native Tools Shell and it outputs something like:

00007FF6CF2210F0

Entering this address on the command line to the example it outputs the secret string correctly.

But if I make a simple program with a similar string and output that address and then feed it to the Spectre example, in another shell, I don't get the correct string.

I've been reading about virtual vs physical addresses and pages and offsets, but I'm quite lost.

So the question is:

How would you in C code calculate the physical address of a pointer?

Upvotes: 1

Views: 99

Answers (1)

John Bollinger
John Bollinger

Reputation: 180141

How would you in C code calculate the physical address of a pointer?

I take you to be asking about calculating the physical address represented by a pointer value, as opposed to the physical address at which the pointer value is stored. The latter just boils down to the former anyway.

But as far as the C language itself is concerned, you don't do this. C does not recognize the distinction between physical and virtual memory in the first place, nor does it have any need to do so. That distinction is an OS-level concern with hardware support. Thus, any technique that accomplishes what you describe relies on details of the C implementation and execution environment.

That Spectre manages to break the process isolation provided (in part) by virtual memory is probably the most frightening thing about it.

Upvotes: 1

Related Questions