This repository has been archived by the owner on Jan 20, 2022. It is now read-only.
[Pal/Linux-SGX] Fix refcounting on open/close of Protected Files #2372
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description of the changes
Previously,
file_open()
andfile_close()
on a Protected File had weird semnatics: if the same PF was opened twice, there was only one PF context created, but there were several underlying host FDs. Even weirder, the PF context tied itself to the host FD (the very first opened one) using the pointer to this FD:&pal_handle->file.fd
.This resulted in bugs and cumbersome workarounds: the associated PAL handle could be closed and freed by our common PAL code, and the PF context would contain a dangling pointer. And for
file_attrquery()
, there was a workaround to destroy the PAL context if it seemed to be created only for this attrquery flow (this was based on this pointer-to-pal-handle-fd).This PR fixes these bugs: the PF context stores the underlying host FD directly, and doesn't open new FDs on subsequent
file_open()
. So, there is always only one host FD for one PF context. As a side effect, the logic offile_open()
andfile_close()
is refactored.A new LibOS regression test
protected_file
is added for GDB debugging because the dedicatedfs/
tests are harder to debug.Fixes #2360.
How to test this PR?
A new test is added. Also,
fs/pf-test
should succeed.This change is