================
@@ -375,6 +375,78 @@ bool AtomicInfo::emitMemSetZeroIfNecessary() const {
   return true;
 }
 
+/// Compare-exchange on `__ptrauth`-qualified storage. The caller's expected
+/// value is never signed: that would mint a signature for a caller-chosen
+/// value, a signing oracle wherever the compiler spills it. The comparand is
+/// the object's own signed representation, authenticated and compared as a
+/// plain value. Leaves the builder in \p StoreExpectedBB and returns the plain
+/// value to write back there, with the block that reaches \p ContinueBB on
+/// success.
----------------
rjmccall wrote:

There's a lot that seems wrong here.

- We need to understand what type restrictions Sema places on the expected and 
desired operands. In particular, are they allowed to be `__ptrauth`-qualified? 
Because we probably *do* want to allow that, at least when the atomic operand 
is `__ptrauth`-qualified. (Maybe we can disallow it for an unqualified atomic 
just so we don't have to deal with a bunch of weird cases.)
- In order to deal with `__ptrauth`-qualified expected and desired operands, we 
really need to split authenticated cmpxchg out of the standard code path much 
earlier so that the loads and stores to those operands can be managed by the 
authenticated path. We also need to know their qualifiers.
- It doesn't look like you're actually signing the desired value correctly at 
any point. The raw value loaded from `Val2` seems to get directly passed as the 
desired operand of the cmpxchg instruction.
- Because the desired value is loaded from memory, there's an inherent signing 
oracle problem if it's not stored as a signed value there. So I think we really 
just need a semantic restriction that the desired operand is a signed type. It 
doesn't have to be a `__ptrauth`-qualified type; an inherently signed type, 
like a function pointer, should be good enough. I don't know if we already have 
a predicate for this on `QualType`, but it's logical to have.
- If the expected value is signed, there's no signing oracle problem from 
resigning it and doing a normal cmpxchg. Your extra load is only needed in 
order to deal with a raw expected value. Since we need a semantic restriction 
on the desired operand anyway, I think it would be fine if we just imposed the 
same restriction on the expected operand. In the most important case (a 
function pointer), the programmer won't need to do anything special for either 
operand.
- In particular, if the expected, desired, and atomic types are all using the 
same non-address-discriminated signing schema, there's zero reason for the 
generated code to be any different from a normal cmpxchg just because a 
`__ptrauth` qualifier is involved. Nothing needs to be resigned at any point.

https://github.com/llvm/llvm-project/pull/240090
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to