You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Gramine allows to map protected files, but unmapping the memory has no effect. As a result, closing the file can trigger saving garbage data to the file.
Found in #228 where copy_mmap_* tests trigger AddressSanitizer on file close.
Steps to reproduce
Map a protected file using mmap
Create another (anonymous) mapping over the same memory.
Modify the underlying memory.
Close the file.
On file close, Gramine read the underlying memory and save the data to the file, even though the file was not supposed to be mapped anymore.
Example code
The following example has been adapted from mmap_fixed.c LibOS regression test; you can overwrite that file to run it.
gramine-direct (and native Linux) print AAAA, gramine-sgx prints BBBB.
LibOS should notice when a user tries to remove a mapping, and explicitly ask PAL to unmap the file. This doesn't happen at all. There's a DkStreamUnmap PAL function that removes the protected-file mappings, but it's not used anywhere.
Note that a proper fix should also handle unmap/remap of overlapping area (which would remove only part of the protected file mapping). The current implementation of DkStreamUnmap / flush_pf_maps does not do that.
The text was updated successfully, but these errors were encountered:
I can quickly fix LibOS part, but from what you described we need to fix PAL part (especially PF part) first? If we unmmap part of the file, probably hell will break loose...
I think the PAL part should be reasonably simple to fix for Protected Files. IIRC, PF contents are already maintained at page granularity, so unmapping a part of the file is a matter of flushing only that page range and splitting the "PF mmap" metadata object into two.
This is now fixed after the protected files rewrite: when mapping and unmapping memory, we use LibOS VMA subsystem as the source of truth, so we no longer incorrectly flush the anonymous mapping to a file.
I ran the example code to confirm (replacing tmp/pf/ with tmp_enc/).
Description of the problem
Gramine allows to map protected files, but unmapping the memory has no effect. As a result, closing the file can trigger saving garbage data to the file.
Found in #228 where
copy_mmap_*
tests trigger AddressSanitizer on file close.Steps to reproduce
mmap
On file close, Gramine read the underlying memory and save the data to the file, even though the file was not supposed to be mapped anymore.
Example code
The following example has been adapted from
mmap_fixed.c
LibOS regression test; you can overwrite that file to run it.gramine-direct
(and native Linux) printAAAA
,gramine-sgx
printsBBBB
.Additional information
LibOS should notice when a user tries to remove a mapping, and explicitly ask PAL to unmap the file. This doesn't happen at all. There's a
DkStreamUnmap
PAL function that removes the protected-file mappings, but it's not used anywhere.Note that a proper fix should also handle unmap/remap of overlapping area (which would remove only part of the protected file mapping). The current implementation of
DkStreamUnmap
/flush_pf_maps
does not do that.The text was updated successfully, but these errors were encountered: