Closed Bug 2035966 Opened 6 months ago Closed 6 months ago

gfx/thebes/SharedFontList.cpp:1281:11: runtime error: load of value 228, which is not a valid value for type 'value_type' (aka 'bool')

Categories

(Core :: Layout: Text and Fonts, defect)

Unspecified
Windows
defect

Tracking

()

VERIFIED FIXED
152 Branch
Tracking Status
firefox-esr115 --- unaffected
firefox-esr140 151+ fixed
firefox150 --- wontfix
firefox151 + fixed
firefox152 + fixed

People

(Reporter: tsmith, Assigned: dholbert)

References

(Blocks 1 open bug, Regression, )

Details

(4 keywords, Whiteboard: [adv-main151+r][adv-esr140.11+r])

Attachments

(3 external files)

This issue is hit by some of the top 100 websites when building with --enable-undefined-sanitizer on Windows.

gfx/thebes/SharedFontList.cpp:1281:11: runtime error: load of value 228, which is not a valid value for type 'value_type' (aka 'bool')
    #0 0x7ffb47b6d3df in mozilla::fontlist::FontList::FindFamily(class nsTString<char> const &, bool) src/objdir-ff-asan-win/gfx/thebes/./../../../gfx/thebes/SharedFontList.cpp:1281
    #1 0x7ffb47c70e5b in gfxPlatformFontList::FindAndAddFamiliesLocked(class FontVisibilityProvider *, enum mozilla::StyleGenericFontFamily, class nsTSubstring<char> const &, class nsTArray<struct FamilyAndGeneric> *, enum gfxPlatformFontList::FindFamiliesFlags, struct gfxFontStyle *, class nsAtom *, double) src/objdir-ff-asan-win/gfx/thebes/./../../../gfx/thebes/gfxPlatformFontList.cpp:1769
    #2 0x7ffb47b9edba in gfxDWriteFontList::FindAndAddFamiliesLocked(class FontVisibilityProvider *, enum mozilla::StyleGenericFontFamily, class nsTSubstring<char> const &, class nsTArray<struct FamilyAndGeneric> *, enum gfxPlatformFontList::FindFamiliesFlags, struct gfxFontStyle *, class nsAtom *, double) src/objdir-ff-asan-win/gfx/thebes/./../../../gfx/thebes/gfxDWriteFontList.cpp:2172
    #3 0x7ffb47c76266 in gfxPlatformFontList::GetFontFamiliesFromGenericFamilies(class FontVisibilityProvider *, enum mozilla::StyleGenericFontFamily, class nsTArray<class nsTString<char>> &, class nsAtom *, class nsTArray<struct FontFamily> *) src/objdir-ff-asan-win/gfx/thebes/./../../../gfx/thebes/gfxPlatformFontList.cpp:2347
    #4 0x7ffb47c75a78 in gfxPlatformFontList::ResolveGenericFontNames(class FontVisibilityProvider *, enum mozilla::StyleGenericFontFamily, enum eFontPrefLang, class nsTArray<struct FontFamily> *) src/objdir-ff-asan-win/gfx/thebes/./../../../gfx/thebes/gfxPlatformFontList.cpp:2307
    #5 0x7ffb47c768ff in gfxPlatformFontList::GetPrefFontsLangGroupLocked(class FontVisibilityProvider *, enum mozilla::StyleGenericFontFamily, enum eFontPrefLang) src/objdir-ff-asan-win/gfx/thebes/./../../../gfx/thebes/gfxPlatformFontList.cpp:2378
    #6 0x7ffb47c76a5a in gfxPlatformFontList::AddGenericFonts(class FontVisibilityProvider *, enum mozilla::StyleGenericFontFamily, class nsAtom *, class nsTArray<struct FamilyAndGeneric> &) src/objdir-ff-asan-win/gfx/thebes/./../../../gfx/thebes/gfxPlatformFontList.cpp:2407
    #7 0x7ffb47ca2a85 in gfxFontGroup::EnsureFontList(void) src/objdir-ff-asan-win/gfx/thebes/./../../../gfx/thebes/gfxTextRun.cpp:1932
    #8 0x7ffb47ca5da6 in gfxFontGroup::GetFirstValidFont(unsigned int, enum mozilla::StyleGenericFontFamily *, bool *) src/objdir-ff-asan-win/gfx/thebes/./../../../gfx/thebes/gfxTextRun.cpp:2246
    #9 0x7ffb47cce19d in gfxFontGroup::InitScriptRun<char16_t>(class mozilla::gfx::DrawTarget *, class gfxTextRun *, char16_t const *, unsigned int, unsigned int, enum mozilla::intl::Script, class gfxMissingFontRecorder *) src/objdir-ff-asan-win/gfx/thebes/./../../../gfx/thebes/gfxTextRun.cpp:2799
    #10 0x7ffb47cab256 in gfxFontGroup::InitTextRun<char16_t>(class mozilla::gfx::DrawTarget *, class gfxTextRun *, char16_t const *, unsigned int, class gfxMissingFontRecorder *) src/objdir-ff-asan-win/gfx/thebes/./../../../gfx/thebes/gfxTextRun.cpp:2694
    #11 0x7ffb47caaa64 in gfxFontGroup::MakeTextRun<char16_t>(char16_t const *, unsigned int, struct gfxTextRunFactory::Parameters const *, enum mozilla::gfx::ShapedTextFlags, enum nsTextFrameUtils::Flags, class gfxMissingFontRecorder *) src/objdir-ff-asan-win/gfx/thebes/./../../../gfx/thebes/gfxTextRun.cpp:2507
    #12 0x7ffb4f340c8d in BuildTextRunsScanner::BuildTextRunForFrames(void *) src/objdir-ff-asan-win/layout/generic/./../../../layout/generic/nsTextFrame.cpp:2720
    #13 0x7ffb4f33d8e1 in BuildTextRunsScanner::FlushFrames(bool, bool) src/objdir-ff-asan-win/layout/generic/./../../../layout/generic/nsTextFrame.cpp:1818
    #14 0x7ffb4f3494fc in BuildTextRuns src/objdir-ff-asan-win/layout/generic/./../../../layout/generic/nsTextFrame.cpp:1737
    #15 0x7ffb4f3494fc in nsTextFrame::EnsureTextRun(enum nsTextFrame::TextRunType, class mozilla::gfx::DrawTarget *, class nsIFrame *, class GenericLineListIterator<class nsLineLink, 0> const *, unsigned int *) src/objdir-ff-asan-win/layout/generic/./../../../layout/generic/nsTextFrame.cpp:3210
    #16 0x7ffb4f37f8eb in nsTextFrame::ReflowText(class nsLineLayout &, int, class mozilla::gfx::DrawTarget *, class mozilla::ReflowOutput &, class nsReflowStatus &) src/objdir-ff-asan-win/layout/generic/./../../../layout/generic/nsTextFrame.cpp:10878
    #17 0x7ffb4f2fc79b in nsLineLayout::ReflowFrame(class nsIFrame *, class nsReflowStatus &, class mozilla::ReflowOutput *, bool &) src/objdir-ff-asan-win/layout/generic/./../../../layout/generic/nsLineLayout.cpp:863
    #18 0x7ffb4f2a6c6d in nsInlineFrame::ReflowInlineFrame(class nsPresContext *, struct mozilla::ReflowInput const &, struct nsInlineFrame::InlineReflowInput &, class nsIFrame *, class nsReflowStatus &) src/objdir-ff-asan-win/layout/generic/./../../../layout/generic/nsInlineFrame.cpp:684
    #19 0x7ffb4f2a606d in nsInlineFrame::ReflowFrames(class nsPresContext *, struct mozilla::ReflowInput const &, struct nsInlineFrame::InlineReflowInput &, class mozilla::ReflowOutput &, class nsReflowStatus &) src/objdir-ff-asan-win/layout/generic/./../../../layout/generic/nsInlineFrame.cpp:558
    #20 0x7ffb4f2a5563 in nsInlineFrame::Reflow(class nsPresContext *, class mozilla::ReflowOutput &, struct mozilla::ReflowInput const &, class nsReflowStatus &) src/objdir-ff-asan-win/layout/generic/./../../../layout/generic/nsInlineFrame.cpp:375
    #21 0x7ffb4f2fc8f7 in nsLineLayout::ReflowFrame(class nsIFrame *, class nsReflowStatus &, class mozilla::ReflowOutput *, bool &) src/objdir-ff-asan-win/layout/generic/./../../../layout/generic/nsLineLayout.cpp:860

:lsalzman, can you look into the bug?

Flags: needinfo?(lsalzman)
Severity: -- → S2
Component: Graphics: Text → Layout: Text and Fonts
Flags: needinfo?(lsalzman) → needinfo?(jfkthame)

``

Group: gfx-core-security → layout-core-security

(In reply to Tyson Smith [:tsmith] from comment #0)

This issue is hit by some of the top 100 websites when building with --enable-undefined-sanitizer on Windows.

Can you provide one or more sample URLs that triggers this?

Quick analysis from code inspection... The error report seems to be pointing to the if (mFaceNamesRead[match]) check in this line of code:
https://searchfox.org/firefox-main/rev/de5d3d8eef25ed45afcb25f93f5aba573d4ccaf4/gfx/thebes/SharedFontList.cpp#1194,1281-1283

Family* FontList::FindFamily(const nsCString& aName, bool aPrimaryNameOnly) {
...
      if (mFaceNamesRead[match]) {
        return nullptr;
      }

...where mFaceNamesRead is a nsTArray of bool values:
https://searchfox.org/firefox-main/rev/de5d3d8eef25ed45afcb25f93f5aba573d4ccaf4/gfx/thebes/SharedFontList-impl.h#384-387

#ifdef XP_WIN
  // Bool array to track whether we have read face names from the name table.
  nsTArray<bool> mFaceNamesRead;
#endif

I guess the error is saying that mFaceNamesRead[match] somehow had the value 228 in this case, instead of the expected bit representation of true.

It looks like we only write into that array using the literal true value, here:
https://searchfox.org/firefox-main/rev/de5d3d8eef25ed45afcb25f93f5aba573d4ccaf4/gfx/thebes/SharedFontList.cpp#1294

mFaceNamesRead[match] = true;

...so either we're walking off the end of the array, or someone's stomping on the memory, or something else weird...

(ni=tyson for URLs that reproduce this)

Flags: needinfo?(twsmith)

ah sorry, I now see http://www.wikipedia.org/ is listed in the URL field. Maybe that answers that question...

I believe the is a case of reading uninitialized memory and UBSan is detecting it because the value it read from memory is not a 'bool'. We have seen this many times in the past.

Flags: needinfo?(twsmith)

Ah, the line/comment just before the bool-read might be relevant:
https://searchfox.org/firefox-main/rev/de5d3d8eef25ed45afcb25f93f5aba573d4ccaf4/gfx/thebes/SharedFontList.cpp#1278-1281

// Check to see if we have already read the face names for this base
// family. Note: EnsureLengthAtLeast will default new entries to false.
mFaceNamesRead.EnsureLengthAtLeast(familyCount);
if (mFaceNamesRead[match]) {

Maybe the comment is lying and EnsureLengthAtLeast does not default new entries to false? nsTArray documentation says "new elements will be constructed using value_type's default constructor" which for primitive types like bool I imagine means they just end up uninitialized.

Here value_type is bool, so probably we're effectively just declaring a bunch of new uninitialized bool values (and then reading one of them).

The mFaceNamesRead array gets allocated/extended here by calling EnsureLengthAtLeast(). The comment here claims that "EnsureLengthAtLeast will default new entries to false".

But if I'm reading things correctly, I think that's wrong.

nsTArray_impl::EnsureLengthAtLeast calls InsertElementsAtInternal, which iterates over any newly-allocated entries and calls elem_traits::Construct(iter) for each. But the default nsTArrayElementTraits::Construct behavior explicitly avoids default-constructing POD types such as bool:

  // Invoke the default constructor in place.
  static inline void Construct(E* aE) {
    // Do NOT call "E()"! That triggers C++ "default initialization"
    // which zeroes out POD ("plain old data") types such as regular
    // ints.  We don't want that because it can be a performance issue
    // and people don't expect it; nsTArray should work like a regular
    // C/C++ array in this respect.
    new (static_cast<void*>(aE)) E;
  }

So IIUC, this does not necessarily result in newly-allocated bool elements being initialized to false; they're left uninitialized.

[edit: mid-aired with comment 7, which I see is suspecting the same thing]

Attached file (secure) โ€”
Assignee: nobody → dholbert
Status: NEW → ASSIGNED
Flags: needinfo?(jfkthame)

This was regressed by bug 1891986 (which was fixed in Firefox 129), so the oldest affected version is ESR140.

I think we should uplift to esr140 and beta151. This probably isn't serious enough to uplift to the planned 150 dot-release (current release version) though.

--> Setting "affected/wontfix" flags accordingly.

Comment on attachment 9575716 [details]
(secure)

Security Approval Request

  • How easily could an exploit be constructed based on the patch?: Not easily. The bug here is that we're reading an uninitialized bool, which we expected to have been initialized to false, but since it's uninitialized, it might in fact be a garbage value that happens to be truthy. If that happens, things are still ~fine; I think it just means we won't consider some of the user's system fonts, so it's a correctness bug but nothing terrible.

The security-relevant issue here is that reading-the-uninitialized-bool is technically undefined behavior, so the compiler might do something weirder than just giving us a garbage possibly-truthy value back. I don't know if we or an attacker can usefully reason about what might happen though.

(Also, the garbage value could represent a data-leakage channel, though it's a bit of a stretch.)

  • Do comments in the patch, the check-in comment, or tests included in the patch paint a bulls-eye on the security problem?: Unknown
  • Which branches (beta, release, and/or ESR) are affected by this flaw, and do the release status flags reflect this affected/unaffected state correctly?: ESR140 and newer (yes, I've set the status flags)
  • If not all supported branches, which bug introduced the flaw?: bug 1891986
  • Do you have backports for the affected branches?: No
  • If not, how different, hard to create, and risky will they be?: Trivial
  • How likely is this patch to cause regressions; how much testing does it need?: Unlikely; it's just explicitly initializing some freshly allocated bool values to 'false'.
  • Is the patch ready to land after security approval is given?: Yes
  • Is Android affected?: No
Attachment #9575716 - Flags: sec-approval?

Comment on attachment 9575716 [details]
(secure)

Ah right, sec-approval isn't needed since this has been assessed as sec-low. I'll go ahead and land.

Attachment #9575716 - Flags: sec-approval?

firefox-beta Uplift Approval Request

  • User impact if declined/Reason for urgency: Avoiding C++ undefined-behavior (reading an uninitialized bool value which might be not a valid bool value).
  • Code covered by automated testing?: no
  • Fix verified in Nightly?: no
  • Needs manual QE testing?: yes
  • Steps to reproduce for manual QE testing: If QA has access to -enable-undefined-sanitizer builds on Windows:
  1. Launch such a build from the command line.
  2. Visit http://www.wikipedia.org/
  3. See if you hit the runtime error quoted in comment 0 (which probably would results in an abort)

"Bad" builds should trigger the runtime error. "Good" builds should not trigger the runtime error.

  • Risk associated with taking this patch: low
  • Explanation of risk level: This is just making some variable-initialization more explicit.
  • String changes made/needed?: None
  • Is Android affected?: no
Attachment #9576127 - Flags: approval-mozilla-beta?
Flags: qe-verify+
Attached file (secure) โ€”

firefox-esr140 Uplift Approval Request

  • User impact if declined/Reason for urgency: Avoiding C++ undefined-behavior (reading an uninitialized bool value which might be not a valid bool value).
  • Code covered by automated testing?: no
  • Fix verified in Nightly?: no
  • Needs manual QE testing?: yes
  • Steps to reproduce for manual QE testing: If QA has access to -enable-undefined-sanitizer builds on Windows:
  1. Launch such a build from the command line.
  2. Visit http://www.wikipedia.org/
  3. See if you hit the runtime error quoted in comment 0 (which probably would results in an abort)

"Bad" builds should trigger the runtime error. "Good" builds should not trigger the runtime error.

  • Risk associated with taking this patch: low
  • Explanation of risk level: This is just making some variable-initialization more explicit.
  • String changes made/needed?: None
  • Is Android affected?: no
Attachment #9576128 - Flags: approval-mozilla-esr140?
Attached file (secure) โ€”
Group: layout-core-security → core-security-release
Status: ASSIGNED → RESOLVED
Closed: 6 months ago
Resolution: --- → FIXED
Target Milestone: --- → 152 Branch
Attachment #9576127 - Flags: approval-mozilla-beta? → approval-mozilla-beta+
Attachment #9576128 - Flags: approval-mozilla-esr140? → approval-mozilla-esr140+
QA Whiteboard: [sec][uplift][qa-triage-done-c151/b151][qa-ver-needed-c152/b151]

Unfortunately QA doesn't have access to -enable-undefined-sanitizer builds on Windows. Is there any way to reproduce and verify this issue using a regular build (by launching Firefox from the command line with specific parameters)? Thanks!

Flags: needinfo?(dholbert)

(In reply to Ina Popescu, Desktop QA from comment #21)

Unfortunately QA doesn't have access to -enable-undefined-sanitizer builds on Windows.

OK, no worries; we can take this off of the "needs QA verification" list then (feel free to adjust flags to reflect that).

Is there any way to reproduce and verify this issue using a regular build (by launching Firefox from the command line with specific parameters)? Thanks!

Nope, there's no way to reproduce/verify in regular builds.

Tyson, do you know if we have Windows ubsan builds available for testing, and/or would you mind verifying the fix here?

Flags: needinfo?(dholbert) → needinfo?(twsmith)

I am working on Windows UBSan builds right now in bug 2035962. I'm happy to verify when I get back from the work week.

QA Whiteboard: [sec][uplift][qa-triage-done-c151/b151][qa-ver-needed-c152/b151] → [sec][uplift][qa-triage-done-c151/b151][qa-ver-blocked-c152/b151]
Flags: qe-verify+

I can confirm this issue is no longer reproducible, thank you!

Status: RESOLVED → VERIFIED
Flags: needinfo?(twsmith)
Whiteboard: [adv-main151+][adv-esr140.11+]
Whiteboard: [adv-main151+][adv-esr140.11+] → [adv-main151+r][adv-esr140.11+r]
Group: core-security-release
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: