-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Package CMO: add deserialization checks to ensure correct memory layout #78258
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@swift-ci test |
2a5a1e6
to
9589546
Compare
@swift-ci test |
c24f01a
to
be6e16a
Compare
be6e16a
to
0633894
Compare
@swift-ci test |
@swift-ci test linux |
c50fd24
to
12c2e3d
Compare
@swift-ci smoke test |
…e memory layout of the decl being accessed is correct. When this assumption fails due to a deserialization error of its members, the use site accesses the layout with a wrong field offset, resulting in UB or a crash. The deserialization error is currently not caught at compile time due to LangOpts.EnableDeserializationRecovery being enabled by default to allow for recovery of some of the deserialization errors at a later time. In case of member deserialization, however, it's not necessarily recovered later on. This PR tracks whether member deserialization had an error by recursively loading members and checking for deserialization error, and fails and emits a diagnostic. It provides a way to prevent resilience bypassing when the deserialized decl's layout is incorrect. Resolves rdar://132411524
12c2e3d
to
c03abed
Compare
@swift-ci smoke test |
This PR is probably worth an eye from @xymus . |
@swift-ci smoke test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me in principle.
I'll leave it to AST/TypeChecker code base experts to comment on whether the implementation of IterableDeclContext::checkDeserializeMemberErrorInPackage
is the best way to do this.
Calling the |
Package optimization allows bypassing resilience, but that assumes the memory layout of the decl being accessed is correct. When this assumption fails due to a deserialization error of its members, the use site accesses the layout of the decl with a wrong field offset, resulting in UB or a crash. The deserialization error is currently not caught at compile time due to LangOpts.EnableDeserializationRecovery being enabled by default (to allow for recovery of some of the deserialization errors at a later time). In case of member deserialization, however, it's not necessarily recovered later on and is silently dropped.
This PR tracks errors in member deserialization by recursively loading members of a type and checking for deserialization errors. and fails and emits a diagnostic. It prevents resilience bypassing when the deserialized decl's layout is incorrect. It also provides an opt-out flag for deserialization checks for temporary migration purposes.
Resolves rdar://132411524