-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Open
Description
During GC heap compaction a copy of data is made. In cases where there was no practical way to pin data (e.g. a returned byte[]) it isn't possible to ensure that the data has been adequately cleared because of the extra copy created compaction.
Having the GC clear the memory on compaction improve the security of applications for which heap dumps and in-memory probes are within their scope of threat, given some guidelines:
- A secret allocated to a caller is the caller's responsibility to clear (e.g. RSA.Decrypt).
- Current: Returned objects can't be pinned in a practical manner, API would have to also emit a GCHandle.
- A secret held by an IDisposable object should be cleared on Dispose, and it is the owner's responsibility to call Dispose (e.g. KeyedHashAlgorithm)
- Current: existing classes which have
byte[]fields would need to use GCHandle and add a finalizer to ensure that the handle got cleared.
- Current: existing classes which have
- A temporary copy of a secret must be cleared by the creator/owner (e.g. addition/removal of symmetric encryption padding)
If the GC can guarantee that pinning is no longer required to ensure that Span.Clear() removes the data from the heap then a good amount of defensive pinning can be eliminated from current BCL security code (theoretically reducing heap fragmentation?).
Gnbrkm41, benaadams, GrabYourPitchforks, Tornhoof, GSPP and 16 more
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
No status