- 
                Notifications
    You must be signed in to change notification settings 
- Fork 128
[pointer] Improve soundness of invariant modeling #2397
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
          
     Merged
      
      
    
                
     Merged
            
            
          Conversation
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
    a60c4a8    to
    d603a4f      
    Compare
  
    | Codecov ReportAttention: Patch coverage is  
 
 Additional details and impacted files@@            Coverage Diff             @@
##             main    #2397      +/-   ##
==========================================
- Coverage   87.82%   87.48%   -0.35%     
==========================================
  Files          17       17              
  Lines        6200     6279      +79     
==========================================
+ Hits         5445     5493      +48     
- Misses        755      786      +31     ☔ View full report in Codecov by Sentry. | 
d6f0cd0    to
    6065dd6      
    Compare
  
    031279e    to
    c8eff72      
    Compare
  
    
              
                    joshlf
  
              
              commented
              
                  
                    Feb 26, 2025 
                  
              
              
            
            
              
                    joshlf
  
              
              commented
              
                  
                    Feb 27, 2025 
                  
              
              
            
            
c8eff72    to
    6640f2a      
    Compare
  
    This commit makes the following improvements: - Removes the `Inaccessible` aliasing mode. This mode was not unsound, but it was unnecessary in practice. - Replaces `Unknown` with `Unaligned` for alignment. - Replaces `Unknown` with `Uninit` for validity. Finally, with the exception of `transparent_wrapper_into_inner`, this commit ensures that all `Ptr` methods which modify the type or validity of a `Ptr` are sound. Previously, we modeled validity as "knowledge" about the `Ptr`'s referent (see #1866 for a more in-depth explanation). In particular, we assumed that it was always sound to "forget" information about a `Ptr`'s referent in the same way in which it is sound to "forget" that a `Ptr` is validly-aligned, converting a `Ptr<T, (_, Aligned, _)>` to a `Ptr<T, (_, Unaligned, _)>`. The problem with this approach is that validity doesn't just specify what bit patterns can be expected to be read from a `Ptr`'s referent, it also specifies what bit patterns are permitted to be *written* to the referent. Thus, "forgetting" about validity and expanding the set of expected bit patterns also expands the set of bit patterns which can be written. Consider, for example, "forgetting" that a `Ptr<bool, (_, _, Valid)>` is bit-valid, and downgrading it to a `Ptr<bool, (_, _, Initialized)>`. If the aliasing is `Exclusive`, then the resulting `Ptr` would permit writing arbitrary `u8`s to the referent, violating the bit validity of the `bool`. This commit moves us in the direction of a new model, in which changes to the referent type or the validity of a `Ptr` must abide by the following rules: - If the resulting `Ptr` permits mutation of its referent (either via interior mutation or `Exclusive` aliasing), then the set of allowed bit patterns in the referent may not expand - If the original `Ptr` permits mutation of its referent while the resulting `Ptr` is also live (i.e., via interior mutation on a `Shared` `Ptr`), then the set of allowed bit patterns in the referent may not shrink This commit does not fix `transparent_wrapper_into_inner`, which will require an overhaul or replacement of the `TransparentWrapper` trait. Makes progress on #2226, #1866 Co-authored-by: Jack Wrenn <[email protected]> gherrit-pr-id: I95d6c5cd23eb5ea6629cd6e4b99696913b1ded93
              
                    jswrenn
  
              
              approved these changes
              
                  
                    Feb 27, 2025 
                  
              
              
            
            
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.
Reviewed in-person.
6640f2a    to
    fb585cd      
    Compare
  
    
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
      
  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.
  
    
  
    
This commit makes the following improvements:
Inaccessiblealiasing mode. This mode was not unsound,but it was unnecessary in practice.
UnknownwithUnalignedfor alignment.UnknownwithUninitfor validity.Finally, with the exception of
transparent_wrapper_into_inner, thiscommit ensures that all
Ptrmethods which modify the type or validityof a
Ptrare sound.Previously, we modeled validity as "knowledge" about the
Ptr'sreferent (see #1866 for a more in-depth explanation). In particular, we
assumed that it was always sound to "forget" information about a
Ptr'sreferent in the same way in which it is sound to "forget" that a
Ptris validly-aligned, converting a
Ptr<T, (_, Aligned, _)>to aPtr<T, (_, Unaligned, _)>.The problem with this approach is that validity doesn't just specify
what bit patterns can be expected to be read from a
Ptr's referent, italso specifies what bit patterns are permitted to be written to the
referent. Thus, "forgetting" about validity and expanding the set of
expected bit patterns also expands the set of bit patterns which can be
written.
Consider, for example, "forgetting" that a
Ptr<bool, (_, _, Valid)>isbit-valid, and downgrading it to a
Ptr<bool, (_, _, Initialized)>. Ifthe aliasing is
Exclusive, then the resultingPtrwould permitwriting arbitrary
u8s to the referent, violating the bit validity ofthe
bool.This commit moves us in the direction of a new model, in which changes
to the referent type or the validity of a
Ptrmust abide by thefollowing rules:
Ptrpermits mutation of its referent (either viainterior mutation or
Exclusivealiasing), then the set of allowedbit patterns in the referent may not expand
Ptrpermits mutation of its referent while theresulting
Ptris also live (i.e., via interior mutation on aSharedPtr), then the set of allowed bit patterns in the referentmay not shrink
This commit does not fix
transparent_wrapper_into_inner, which willrequire an overhaul or replacement of the
TransparentWrappertrait.Makes progress on #2226, #1866
Co-authored-by: Jack Wrenn [email protected]
This PR is on branch v0.8.x-ptr-invariant-mapping.