Closed Bug 1931375 Opened 1 year ago Closed 1 year ago

MDiv::collectRangeInfoPreTrunc might set canBeNegativeZero_ incorrectly

Categories

(Core :: JavaScript Engine: JIT, defect, P2)

defect

Tracking

()

RESOLVED FIXED
134 Branch
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.

Flags: needinfo?(nicolas.b.pierron)

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.

Flags: needinfo?(nicolas.b.pierron)

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: nobody → iireland
Status: NEW → ASSIGNED

(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 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.

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.

Attachment #9438010 - Attachment description: Bug 1931375: Only set canBeNegativeZero_ for integer division r=nbp → Bug 1931375: Assert that MDiv::canBeNegativeZero is only used for integer division r=nbp

As discussed above, there's no actual security bug here. Opening it up.

Group: javascript-core-security
Keywords: sec-low
Pushed by iireland@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/98dc5f7fef1c Assert that MDiv::canBeNegativeZero is only used for integer division r=nbp
Status: ASSIGNED → RESOLVED
Closed: 1 year ago
Resolution: --- → FIXED
Target Milestone: --- → 134 Branch
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: