← Back to Pull requests

Simplify pointer masking spec #1259

Merged
tariqkurd-repo merged 1 files (80 lines) on Sep 29, 2026 10:19 UTC
View on GitHub
tariqkurd-repo tariqkurd-repo commented on Sep 17, 2026 15:23 UTC
Author

Fix #805

It seems to me that the pointer masking spec should be simple.
Apply the ignore transformation to representable range checking and bounds decoding as currently specified by the pointer masking extensions.

Diff: 80 lines (+54 / -26) across 1 files Reviewer: jrtc27 Review duration: 16975m
All Vouch review confidence checks passed
Residual risk 0.09 = Change Risk (0.29) × (1 − Review Confidence (0.68)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.29 · 80 lines diff across 1 files
0.29
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.56 · 3 substantive comment(s)
0.56
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
68%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.263
Real PR Conversation Timeline
4 items
tariqkurd-repo tariqkurd-repo commented on code on Sep 22, 2026 09:18 UTC
Code Review
src/cheri/ptrmask-integration.adoc:1
@@ -6,37 +6,65 @@ endif::[]
 
 IMPORTANT: {not_v1_ratification_package_experimental}
 
-Whenever pointer masking is enabled, all bounds decoding, <<section_cap_representable_check,representable range checks>> and bounds checks are affected.
+Pointer masking is enabled when PMM{ne}0 and applies to data memory access but not instruction memory access.
 
-NOTE: The suggestion in this section is based on the pointer masking approach from Morello but with changes
-to sign extension and to address the dynamic nature of bit masking.
+NOTE:  The "ignore" transformation has a dependency on the current virtual memory translation scheme, i.e. `satp.MODE`.
 
-When bounds are <<section_cap_bounds,encoded or decoded>>, a masked but _not_ sign-extended address is used.
-Changing how many bits are masked can therefore change the interpretation of the bounds of a capability,
-both for the purpose of implicit accesses via bounds checks and any instructions that report the bounds of a capability.
-Apart from treating the PMLEN high address bits as zero, there are no other changes to bounds decoding,
-which is still based on XLEN, not the new effectively addressable space.
-That is, the maximum length of a capability does not change, and
-it is not invalid to have a capability that covers a longer range than could actually be addressed with pointer masking enabled (such as one covering the entire XLEN address space).
-For the <<section_cap_representable_check,representable range check>>, both the original and new addresses
-are masked.
-Bounds setting instructions also mask the address in the same way.
+=== <<pcc>> checks
 
-NOTE: Because dynamically changing the number of masked bits changes the interpretation of a capability,
-software must take the same care when sharing capabilities between address spaces with differing pointer masking
-as it generally must when sharing capabilities between address spaces with different page mappings.
+<<pcc>> bounds checks are unaffected, as pointer masking does not affect the PC.
 
-Any address that is checked against a capability
-is also first subject to the same masking as bounds decode (masking without extension).
-After any CHERI operations, the final access address is still subject to as much sign extension as the pointer masking extensions mandate.
+Therefore no ignore transformation is applied before the checks on writing to __xtvec__.
 
-In summary, for data accesses only:
+=== Capability Address Increment or Replacement Instructions
 
-* When setting bounds ({SCBNDS}/{SCBNDSI}/{SCBNDSR}), bits [XLEN-1:XLEN-PMLEN] of the address are set to zero and therefore the resulting capability will have a base with the PMLEN high address bits set to zero.
-* When decoding bounds, the address used for decoding has bits [XLEN-1:XLEN-PMLEN] set to zero.
-* When checking the <<section_cap_representable_check,representable range>> for {CADDI}/{CADD}/{SCADDR}, the old address and new addresses both have bits [XLEN-1:XLEN-PMLEN] set to zero *before* the check.
+Instructions which derive a new capability by incrementing or replacing the capability address all determine the output address without taking pointer masking into account.
 
-Also note that:
+The associated representability check, however, does use the ignore transformation.
 
-* <<pcc>> bounds decoding isn't affected by pointer masking.
-* Any <<section_cap_representable_check,representable range check>> triggered by a write to a CSR (e.g., <<mtvec_y>>) is not affected by pointer masking.
+The rule from xref:section_rep_check_concept[xrefstyle=short] states that:
+
+_All instructions that derive a capability with a new address (such as <<SCADDR>>, <<CADD>>, and <<CADDI>>) must check that the new address does not change the decoding of the bounds._
+
+This rule is extended to support pointer masking by applying the ignore transformation to both the original and new addresses, and checking that the transformed new address does not change the decoding of the bounds.
+If the bounds decoding does change then the output capability is invalidated.
+
+=== Interaction With Bounds Setting Instructions
+
+Bounds setting instructions only calculate new values for the capability metadata and {ctag}, the address field is copied directly from input to output.
+
+The ignore transformation is applied to the address before calculating the new bounds.
+
+This affects <<SCBNDS>>, <<SCBNDSI>>, and <<SCBNDSR>>.
+
+If {rvy_bndsrdw_insn_ext_name} is implemented, <<SCBNDSRD>> follows the same rule.
+
+=== Interaction With Memory Access Instructions
+
+The ignore transformation is applied before capability bounds calculations, so that the bounds for memory accesses are calculated relative to the transformed address.
+
+This affects all loads, stores and AMOs.
+
+=== Interaction With Bounds Reading Instructions
+
+The ignore transformation is applied before capability bounds reading instructions, so that all returned values are based upon the transformed address.
+
+This affects <<GCBASE>>, <<GCLEN>>, and <<GCTOP>>.
+
+=== Interaction With Capability Subsets
+
+The definition of <<cap_subset>> is extended to apply the transformation to both `cap1` and `cap2` before the bounds calculation.
+
+This affects <<CBLD>>, <<SCSS>> and <<YSUNSEAL>>.
+
+WARNING: Because dynamically changing the number of masked bits changes the interpretation of a capability,
+software must take the same care when sharing capabilities between address spaces with differing pointer masking settings as it generally must when sharing capabilities between address spaces with different page mappings.

WARNING: Because dynamically changing the number of masked bits changes the interpretation of a capability, software must take the same care when sharing capabilities between address spaces with differing pointer masking settings as it generally must when sharing capabilities between address spaces with different page mappings.

tariqkurd-repo tariqkurd-repo commented on code on Sep 22, 2026 09:18 UTC
Code Review
src/cheri/ptrmask-integration.adoc:1
@@ -6,37 +6,65 @@ endif::[]
 
 IMPORTANT: {not_v1_ratification_package_experimental}
 
-Whenever pointer masking is enabled, all bounds decoding, <<section_cap_representable_check,representable range checks>> and bounds checks are affected.
+Pointer masking is enabled when PMM{ne}0 and applies to data memory access but not instruction memory access.
 
-NOTE: The suggestion in this section is based on the pointer masking approach from Morello but with changes
-to sign extension and to address the dynamic nature of bit masking.
+NOTE:  The "ignore" transformation has a dependency on the current virtual memory translation scheme, i.e. `satp.MODE`.
 
-When bounds are <<section_cap_bounds,encoded or decoded>>, a masked but _not_ sign-extended address is used.
-Changing how many bits are masked can therefore change the interpretation of the bounds of a capability,
-both for the purpose of implicit accesses via bounds checks and any instructions that report the bounds of a capability.
-Apart from treating the PMLEN high address bits as zero, there are no other changes to bounds decoding,
-which is still based on XLEN, not the new effectively addressable space.
-That is, the maximum length of a capability does not change, and
-it is not invalid to have a capability that covers a longer range than could actually be addressed with pointer masking enabled (such as one covering the entire XLEN address space).
-For the <<section_cap_representable_check,representable range check>>, both the original and new addresses
-are masked.
-Bounds setting instructions also mask the address in the same way.
+=== <<pcc>> checks
 
-NOTE: Because dynamically changing the number of masked bits changes the interpretation of a capability,
-software must take the same care when sharing capabilities between address spaces with differing pointer masking
-as it generally must when sharing capabilities between address spaces with different page mappings.
+<<pcc>> bounds checks are unaffected, as pointer masking does not affect the PC.
 
-Any address that is checked against a capability
-is also first subject to the same masking as bounds decode (masking without extension).
-After any CHERI operations, the final access address is still subject to as much sign extension as the pointer masking extensions mandate.
+Therefore no ignore transformation is applied before the checks on writing to __xtvec__.
 
-In summary, for data accesses only:
+=== Capability Address Increment or Replacement Instructions
 
-* When setting bounds ({SCBNDS}/{SCBNDSI}/{SCBNDSR}), bits [XLEN-1:XLEN-PMLEN] of the address are set to zero and therefore the resulting capability will have a base with the PMLEN high address bits set to zero.
-* When decoding bounds, the address used for decoding has bits [XLEN-1:XLEN-PMLEN] set to zero.
-* When checking the <<section_cap_representable_check,representable range>> for {CADDI}/{CADD}/{SCADDR}, the old address and new addresses both have bits [XLEN-1:XLEN-PMLEN] set to zero *before* the check.
+Instructions which derive a new capability by incrementing or replacing the capability address all determine the output address without taking pointer masking into account.
 
-Also note that:
+The associated representability check, however, does use the ignore transformation.
 
-* <<pcc>> bounds decoding isn't affected by pointer masking.
-* Any <<section_cap_representable_check,representable range check>> triggered by a write to a CSR (e.g., <<mtvec_y>>) is not affected by pointer masking.
+The rule from xref:section_rep_check_concept[xrefstyle=short] states that:
+
+_All instructions that derive a capability with a new address (such as <<SCADDR>>, <<CADD>>, and <<CADDI>>) must check that the new address does not change the decoding of the bounds._
+
+This rule is extended to support pointer masking by applying the ignore transformation to both the original and new addresses, and checking that the transformed new address does not change the decoding of the bounds.
+If the bounds decoding does change then the output capability is invalidated.
+
+=== Interaction With Bounds Setting Instructions
+
+Bounds setting instructions only calculate new values for the capability metadata and {ctag}, the address field is copied directly from input to output.
+
+The ignore transformation is applied to the address before calculating the new bounds.
+
+This affects <<SCBNDS>>, <<SCBNDSI>>, and <<SCBNDSR>>.
+
+If {rvy_bndsrdw_insn_ext_name} is implemented, <<SCBNDSRD>> follows the same rule.
+
+=== Interaction With Memory Access Instructions
+
+The ignore transformation is applied before capability bounds calculations, so that the bounds for memory accesses are calculated relative to the transformed address.
+
+This affects all loads, stores and AMOs.
+
+=== Interaction With Bounds Reading Instructions
+
+The ignore transformation is applied before capability bounds reading instructions, so that all returned values are based upon the transformed address.
+
+This affects <<GCBASE>>, <<GCLEN>>, and <<GCTOP>>.
+
+=== Interaction With Capability Subsets
+
+The definition of <<cap_subset>> is extended to apply the transformation to both `cap1` and `cap2` before the bounds calculation.
+
+This affects <<CBLD>>, <<SCSS>> and <<YSUNSEAL>>.
+
+WARNING: Because dynamically changing the number of masked bits changes the interpretation of a capability,
+software must take the same care when sharing capabilities between address spaces with differing pointer masking settings as it generally must when sharing capabilities between address spaces with different page mappings.
+
+WARNING: Because <<pcc>> bounds aren't masked but data memory access bounds are, if the PMLEN upper bits of a capability address are modified by the ignore transformation then the capability will only be usable for data memory access, as the address will be invalid for instruction fetch.
+
+WARNING: A capability with its address in the illegal VA space while PMM=0 will have its address and bounds move into the valid VA space if PMM is subsequently set to a nonzero value.

WARNING: A capability with its address in the illegal VA space while PMM=0 may have its address and bounds move into the valid VA space if PMM is subsequently set to a nonzero value.

tariqkurd-repo tariqkurd-repo commented on code on Sep 22, 2026 09:24 UTC
Code Review
src/cheri/ptrmask-integration.adoc:1
@@ -6,37 +6,65 @@ endif::[]
 
 IMPORTANT: {not_v1_ratification_package_experimental}
 
-Whenever pointer masking is enabled, all bounds decoding, <<section_cap_representable_check,representable range checks>> and bounds checks are affected.
+Pointer masking is enabled when PMM{ne}0 and applies to data memory access but not instruction memory access.
 
-NOTE: The suggestion in this section is based on the pointer masking approach from Morello but with changes
-to sign extension and to address the dynamic nature of bit masking.
+NOTE:  The "ignore" transformation has a dependency on the current virtual memory translation scheme, i.e. `satp.MODE`.
 
-When bounds are <<section_cap_bounds,encoded or decoded>>, a masked but _not_ sign-extended address is used.
-Changing how many bits are masked can therefore change the interpretation of the bounds of a capability,
-both for the purpose of implicit accesses via bounds checks and any instructions that report the bounds of a capability.
-Apart from treating the PMLEN high address bits as zero, there are no other changes to bounds decoding,
-which is still based on XLEN, not the new effectively addressable space.
-That is, the maximum length of a capability does not change, and
-it is not invalid to have a capability that covers a longer range than could actually be addressed with pointer masking enabled (such as one covering the entire XLEN address space).
-For the <<section_cap_representable_check,representable range check>>, both the original and new addresses
-are masked.
-Bounds setting instructions also mask the address in the same way.
+=== <<pcc>> checks
 
-NOTE: Because dynamically changing the number of masked bits changes the interpretation of a capability,
-software must take the same care when sharing capabilities between address spaces with differing pointer masking
-as it generally must when sharing capabilities between address spaces with different page mappings.
+<<pcc>> bounds checks are unaffected, as pointer masking does not affect the PC.
 
-Any address that is checked against a capability
-is also first subject to the same masking as bounds decode (masking without extension).
-After any CHERI operations, the final access address is still subject to as much sign extension as the pointer masking extensions mandate.
+Therefore no ignore transformation is applied before the checks on writing to __xtvec__.
 
-In summary, for data accesses only:
+=== Capability Address Increment or Replacement Instructions
 
-* When setting bounds ({SCBNDS}/{SCBNDSI}/{SCBNDSR}), bits [XLEN-1:XLEN-PMLEN] of the address are set to zero and therefore the resulting capability will have a base with the PMLEN high address bits set to zero.
-* When decoding bounds, the address used for decoding has bits [XLEN-1:XLEN-PMLEN] set to zero.
-* When checking the <<section_cap_representable_check,representable range>> for {CADDI}/{CADD}/{SCADDR}, the old address and new addresses both have bits [XLEN-1:XLEN-PMLEN] set to zero *before* the check.
+Instructions which derive a new capability by incrementing or replacing the capability address all determine the output address without taking pointer masking into account.
 
-Also note that:
+The associated representability check, however, does use the ignore transformation.
 
-* <<pcc>> bounds decoding isn't affected by pointer masking.
-* Any <<section_cap_representable_check,representable range check>> triggered by a write to a CSR (e.g., <<mtvec_y>>) is not affected by pointer masking.
+The rule from xref:section_rep_check_concept[xrefstyle=short] states that:
+
+_All instructions that derive a capability with a new address (such as <<SCADDR>>, <<CADD>>, and <<CADDI>>) must check that the new address does not change the decoding of the bounds._
+
+This rule is extended to support pointer masking by applying the ignore transformation to both the original and new addresses, and checking that the transformed new address does not change the decoding of the bounds.
+If the bounds decoding does change then the output capability is invalidated.
+
+=== Interaction With Bounds Setting Instructions
+
+Bounds setting instructions only calculate new values for the capability metadata and {ctag}, the address field is copied directly from input to output.
+
+The ignore transformation is applied to the address before calculating the new bounds.
+
+This affects <<SCBNDS>>, <<SCBNDSI>>, and <<SCBNDSR>>.
+
+If {rvy_bndsrdw_insn_ext_name} is implemented, <<SCBNDSRD>> follows the same rule.
+
+=== Interaction With Memory Access Instructions
+
+The ignore transformation is applied before capability bounds calculations, so that the bounds for memory accesses are calculated relative to the transformed address.
+
+This affects all loads, stores and AMOs.
+
+=== Interaction With Bounds Reading Instructions
+
+The ignore transformation is applied before capability bounds reading instructions, so that all returned values are based upon the transformed address.
+
+This affects <<GCBASE>>, <<GCLEN>>, and <<GCTOP>>.
+
+=== Interaction With Capability Subsets
+
+The definition of <<cap_subset>> is extended to apply the transformation to both `cap1` and `cap2` before the bounds calculation.
+
+This affects <<CBLD>>, <<SCSS>> and <<YSUNSEAL>>.
+
+WARNING: Because dynamically changing the number of masked bits changes the interpretation of a capability,
+software must take the same care when sharing capabilities between address spaces with differing pointer masking settings as it generally must when sharing capabilities between address spaces with different page mappings.
+
+WARNING: Because <<pcc>> bounds aren't masked but data memory access bounds are, if the PMLEN upper bits of a capability address are modified by the ignore transformation then the capability will only be usable for data memory access, as the address will be invalid for instruction fetch.
+
+WARNING: A capability with its address in the illegal VA space while PMM=0 will have its address and bounds move into the valid VA space if PMM is subsequently set to a nonzero value.
+Such a capability is only possible if capabilities are available which have at least some of the gap between valid VA spaces in their representable ranges.
+It is recommended that software should not create such capabilities.
+

It is recommended that software should not create such capabilities.
If PMLEN is less than the number upper address bits which represent the VA gap then enabling pointer masking can either cause bounds to move between invalid address ranges within the VA gap or from the VA gap into the valid space.

Reviewers
Assignees
tariqkurd-repo tariqkurd-repo
Labels
risk: low confidence: 68.3% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 29.3% (LOW) · Higher = larger blast radius
29.3%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 68.3% · Lower = rushed or shallow review
68.3%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 9.3% · Safe to merge
9.3%