Closed Bug 1663642 Opened 5 years ago Closed 5 years ago

nsStandardURL::SetSpec accepts schemeless `/` as a valid URL

Categories

(Core :: Networking, defect, P1)

defect

Tracking

()

RESOLVED FIXED
83 Branch
Tracking Status
firefox-esr78 82+ fixed
firefox80 --- wontfix
firefox81 --- wontfix
firefox82 + fixed
firefox83 + fixed

People

(Reporter: jkratzer, Assigned: valentin)

References

Details

(6 keywords, Whiteboard: [necko-triaged][post-critsmash-triage][adv-main82-][adv-esr78.4-])

Attachments

(4 files)

Attached file testcase.bin

Testcase found while fuzzing mozilla-central rev fb9c01b719fa.

Steps to reproduce:

  1. pip install fuzzfetch
  2. python -m fuzzfetch -a --fuzzing --gtest -n ff-asan
  3. FUZZER=URIParser ./ff-asan/firefox testcase.bin

Assertion failure: aSeg.mLen < 0 || (aSeg.mPos + aSeg.mLen <= aSpec.Length() && aSeg.mPos + aSeg.mLen >= aSeg.mPos), at /builds/worker/checkouts/gecko/netwerk/base/nsStandardURL.cpp:233

==16025==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000001 (pc 0x7f45f9a19bb8 bp 0x7ffeabf0a950 sp 0x7ffeabf0a950 T0)
==16025==The signal is caused by a WRITE memory access.
==16025==Hint: address points to the zero page.
    #0 0x7f45f9a19bb8 in mozilla::net::nsStandardURL::SanityCheck(mozilla::net::nsStandardURL::URLSegment const&, nsTString<char> const&) /builds/worker/checkouts/gecko/netwerk/base/nsStandardURL.cpp:231:3
    #1 0x7f45f9a19d1a in mozilla::net::nsStandardURL::~nsStandardURL() /builds/worker/checkouts/gecko/netwerk/base/nsStandardURL.cpp:249:3
    #2 0x7f45f9a19f1d in mozilla::net::nsStandardURL::~nsStandardURL() /builds/worker/checkouts/gecko/netwerk/base/nsStandardURL.cpp:236:33
    #3 0x7f45f9a24dcd in mozilla::net::nsStandardURL::Release() /builds/worker/checkouts/gecko/netwerk/base/nsStandardURL.cpp:1261:1
    #4 0x7f45f7fc96f8 in ~nsCOMPtr_base /builds/worker/workspace/obj-build/dist/include/nsCOMPtr.h:329:7
    #5 0x7f45f7fc96f8 in FuzzingRunURIParser(unsigned char const*, unsigned long) /builds/worker/checkouts/gecko/netwerk/test/fuzz/TestURIFuzzing.cpp:238:1
    #6 0x555c7b058ffe in fuzzer::Fuzzer::ExecuteCallback(unsigned char const*, unsigned long) /builds/worker/checkouts/gecko/tools/fuzzing/libfuzzer/FuzzerLoop.cpp:562:11
    #7 0x555c7b047a66 in fuzzer::RunOneTest(fuzzer::Fuzzer*, char const*, unsigned long) /builds/worker/checkouts/gecko/tools/fuzzing/libfuzzer/FuzzerDriver.cpp:301:6
    #8 0x555c7b04c2df in fuzzer::FuzzerDriver(int*, char***, int (*)(unsigned char const*, unsigned long)) /builds/worker/checkouts/gecko/tools/fuzzing/libfuzzer/FuzzerDriver.cpp:802:9
    #9 0x7f46051eac9f in mozilla::FuzzerRunner::Run(int*, char***) /builds/worker/checkouts/gecko/tools/fuzzing/interface/harness/FuzzerRunner.cpp:75:13
    #10 0x7f4605121053 in XREMain::XRE_mainStartup(bool*) /builds/worker/checkouts/gecko/toolkit/xre/nsAppRunner.cpp:3861:35
    #11 0x7f4605133597 in XREMain::XRE_main(int, char**, mozilla::BootstrapConfig const&) /builds/worker/checkouts/gecko/toolkit/xre/nsAppRunner.cpp:4933:12
    #12 0x7f4605134333 in XRE_main(int, char**, mozilla::BootstrapConfig const&) /builds/worker/checkouts/gecko/toolkit/xre/nsAppRunner.cpp:5003:21
    #13 0x555c7ae99375 in do_main /builds/worker/checkouts/gecko/browser/app/nsBrowserApp.cpp:217:22
    #14 0x555c7ae99375 in main /builds/worker/checkouts/gecko/browser/app/nsBrowserApp.cpp:331:16
    #15 0x7f461d52eb96 in __libc_start_main /build/glibc-2ORdQG/glibc-2.27/csu/../csu/libc-start.c:310
Flags: in-testsuite?

Given that this is a bug found in the fuzz harness and not in the browser, I suppose it will need some analysis to figure out if the browser is also affected.

Group: core-security → network-core-security
Keywords: csectype-bounds

This looks like the same assert as bug 1648493, but it was supposed to have been fixed on m-c by way of bug 1660975 a week prior to this being hit by the fuzzer.

Flags: needinfo?(valentin.gosu)
See Also: → 1648493

Same assert, different cause.

Assignee: nobody → valentin.gosu
Severity: normal → S3
Flags: needinfo?(valentin.gosu)
Priority: -- → P1
Whiteboard: [necko-triaged]

sec-high if a URL from web content can trigger this case.

Keywords: sec-high

(In reply to Daniel Veditz [:dveditz] from comment #4)

sec-high if a URL from web content can trigger this case.

From what I can tell this can't be triggered from web content - it may be possible but I've found no instances where we simply call SetSpec on a StandardURL without checking the scheme first.
The bug here was that nsStandardURL::SetSpec didn't treat / as an invalid URL. It just parsed an empty scheme. Most instances where we create a new URL go throught NS_NewURI which matches schemes with the proper implementation.

Summary: Assertion failure: aSeg.mLen < 0 || (aSeg.mPos + aSeg.mLen <= aSpec.Length() && aSeg.mPos + aSeg.mLen >= aSeg.mPos), at /builds/worker/checkouts/gecko/netwerk/base/nsStandardURL.cpp:233 → nsStandardURL::SetSpec accepts schemeless `/` as a valid URL

Comment on attachment 9175475 [details]
Bug 1663642 - fix r=#necko

Security Approval Request

  • How easily could an exploit be constructed based on the patch?: Not easily. It requires chaining with a different exploit to be able to call SetSpec on an existing or newly constructed standardURL.
  • Do comments in the patch, the check-in comment, or tests included in the patch paint a bulls-eye on the security problem?: Yes
  • Which older supported branches are affected by this flaw?: all
  • If not all supported branches, which bug introduced the flaw?: None
  • Do you have backports for the affected branches?: Yes
  • If not, how different, hard to create, and risky will they be?: Easy
  • How likely is this patch to cause regressions; how much testing does it need?: Unlikely to cause regressions. This state should not be allowed.
    No testing is necessary.
Attachment #9175475 - Flags: sec-approval?

Lowering to sec-moderate based on comment 7

Keywords: sec-highsec-moderate

Comment on attachment 9175475 [details]
Bug 1663642 - fix r=#necko

Clearing sec-approval because it was moved to moderate. I wondered if this could be used as a sandbox escape; but from the comment#7 I suspect not.

Attachment #9175475 - Flags: sec-approval?
Group: network-core-security → core-security-release
Status: NEW → RESOLVED
Closed: 5 years ago
Resolution: --- → FIXED
Target Milestone: --- → 83 Branch

Comment on attachment 9175475 [details]
Bug 1663642 - fix r=#necko

Beta/Release Uplift Approval Request

  • User impact if declined: Security in depth. This could be chained with other bugs to read arbitrary memory locations.
  • Is this code covered by automated tests?: Yes
  • Has the fix been verified in Nightly?: No
  • Needs manual test from QE?: No
  • If yes, steps to reproduce:
  • List of other uplifts needed: None
  • Risk to taking this patch: Low
  • Why is the change risky/not risky? (and alternatives if risky): Blocks a codepath that leads to invalid URL state.
    Assuming we don't have any code that expects that to work (it would be crazy if we did, considering this codepath is not normally exercised at all) we should not have any regressions.
  • String changes made/needed:
Attachment #9175475 - Flags: approval-mozilla-esr78?
Attachment #9175475 - Flags: approval-mozilla-beta?

Comment on attachment 9175475 [details]
Bug 1663642 - fix r=#necko

approved for 82.0b2

Attachment #9175475 - Flags: approval-mozilla-beta? → approval-mozilla-beta+
Flags: qe-verify-
Whiteboard: [necko-triaged] → [necko-triaged][post-critsmash-triage]

Comment on attachment 9175475 [details]
Bug 1663642 - fix r=#necko

Approved for 78.4esr.

Attachment #9175475 - Flags: approval-mozilla-esr78? → approval-mozilla-esr78+
Whiteboard: [necko-triaged][post-critsmash-triage] → [necko-triaged][post-critsmash-triage][adv-main82-]
Whiteboard: [necko-triaged][post-critsmash-triage][adv-main82-] → [necko-triaged][post-critsmash-triage][adv-main82-][adv-esr78.4-]
Group: core-security-release
Attachment #9218874 - Attachment description: WIP: Bug 1663642 - Fix eslint error in test_standardurl.js a=test-only → Bug 1663642 - Fix eslint error in test_standardurl.js a=test-only
Pushed by ncsoregi@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/bd4a2da695bd Fix eslint error in test_standardurl.js a=test-only CLOSED TREE

== Change summary for alert #29916 (as of Fri, 30 Apr 2021 07:56:44 GMT) ==

Improvements:

Ratio Suite Test Platform Options Absolute values (old vs new)
5% perf_reftest_singletons (docs) window-named-property-get.html linux1804-64-shippable e10s stylo 615.43 -> 582.90

For up to date results, see: https://treeherder.mozilla.org/perfherder/alerts?id=29916

No longer blocks: domino
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: