Skip to content

Commit 37ff680

Browse files
committed
[CHERI CSA] Disable pointer alignment checker for sealed capabilities.
Sealed capabilities can't be dereferenced without unsealing, which effectively verifies that the type was dynamically correct.
1 parent 502aaee commit 37ff680

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

clang/lib/StaticAnalyzer/Checkers/PointerAlignmentChecker.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,11 @@ int getTrailingZerosCount(const SVal &V, ProgramStateRef State,
259259
if (V.isUnknownOrUndef())
260260
return -1;
261261

262+
// Sealed capabilities cannot be dereferenced, and any type-punning
263+
// will be dynamically checked during unsealing.
264+
if (V.getType(ASTCtx)->isCHERISealedCapabilityType(ASTCtx))
265+
return -1;
266+
262267
if (V.isConstant()) {
263268
if (auto LV = V.getAs<loc::ConcreteInt>())
264269
return LV->getValue()->countTrailingZeros();

clang/test/Analysis/pointer-alignment.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,3 +214,9 @@ void write_to_first_member(struct AlignedParentStruct *chunk) {
214214
*(long long*)(&chunk->a) = 0;
215215
}
216216

217+
// ----
218+
long long * __sealed_capability sealed_cast(int * __sealed_capability in) {
219+
// No warnings for sealed capabilities, since they will be effectively dynamically
220+
// verified when unsealed.
221+
return (long long * __sealed_capability)in;
222+
}

0 commit comments

Comments
 (0)