MDiv::collectRangeInfoPreTrunc might set canBeNegativeZero_ incorrectly
Categories
(Core :: JavaScript Engine: JIT, defect, P2)
Tracking
()
| Tracking | Status | |
|---|---|---|
| firefox134 | --- | fixed |
People
(Reporter: iain, Assigned: iain)
Details
Attachments
(1 external file)
Hovav Shacham (an external security researcher) asked on Slack whether this code in MDiv::collectRangeInfoPreTrunc is correct. "Specifically, what keeps this from saying -0 is impossible with inputs -0/3.1337?"
Tracing back the history of this code, it looks like this bug copied the logic from MDiv::analyzeEdgeCasesForward. But analyzeEdgeCasesForward only applies when the MDiv is Int32 (so the lhs can't be -0). I don't see the same restriction in collectRangeInfoPreTrunc.
Hovav couldn't think of any way that -0 bugs in RA could be exploited, and I can't immediately see any either, but RA is scary, so I'm marking this as sec-low.
nbp, do you have thoughts here? Would it be silly to add a type() == MIRType::Int32 check here? I don't have a good sense of how this is used.
Comment 1•1 year ago
|
||
In the general case, this analysis is indeed incorrect. However, it seems that we are saved by the fact that this flag is only used by LDivI specialization, thus implicitly adding the condition that operands are integer values might be enough to make this condition valid.
!lhs.canHaveFractionalPart_ && !lhs.canBeNegativeZero_ && rhs.lower_ >= 0 && !rhs.canBeInfiniteOrNaN() is a condition which sounds sufficient to exclude -0 as part of the output of a division. By excluding left-hand-side without a fractional part, we guarantee that the exponent of the lhs is at least 0. Thus any exponent from rhs can be negated and denormals saves us by being able to represent values smaller than the lowest exponent.
These flags are meant to save the conclusion of RangeAnalysis and to be used in code generator, and never for running analysis. The reason these flag exists is that this is the last time we can query the Range of the operands and have a valid consistent result. Further optimization, such as the truncation might happen which could disturb the range of the operands and induce errors.
Maybe naming these flags to reflect that these are integer division properties reserved for the code generator would help reading this code.
| Assignee | ||
Comment 2•1 year ago
|
||
If I understand correctly, we'll only look at canBeNegativeZero_ if we lower to LDivI, and that will only happen if type() == MIRType::Int32. So we could add that check without affecting current behaviour, and we'd be slightly more future-proof against misuse of the flag?
Assuming that's true, I think we should do that. I'll put up the one-line patch for you to review.
I think we can probably also open this up, since there's no actual bug here. I'll leave it closed for now and you can open it if/when you approve the patch.
| Assignee | ||
Comment 3•1 year ago
|
||
Updated•1 year ago
|
Comment 4•1 year ago
|
||
(In reply to Iain Ireland [:iain] from comment #2)
If I understand correctly, we'll only look at
canBeNegativeZero_if we lower to LDivI, and that will only happen iftype() == MIRType::Int32. So we could add that check without affecting current behaviour, and we'd be slightly more future-proof against misuse of the flag?Assuming that's true, I think we should do that. I'll put up the one-line patch for you to review.
Unfortunately no, the canBeNegativeZero_ field might be set while the type is still type() == MIRType::Double, but if we happen to truncate it after, we might convert it to a LDivI which makes use of this flag.
I think we can probably also open this up, since there's no actual bug here. I'll leave it closed for now and you can open it if/when you approve the patch.
Yes.
Updated•1 year ago
|
| Assignee | ||
Comment 5•1 year ago
|
||
As discussed above, there's no actual security bug here. Opening it up.
Description
•