Closed Bug 1347657 Opened 7 years ago Closed 7 years ago

nsUrlClassifierStreamUpdater::FetchNextRequest has potential use-after-free issue

Categories

(Toolkit :: Safe Browsing, enhancement)

enhancement
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla55
Tracking Status
firefox55 --- fixed

People

(Reporter: hchang, Assigned: hchang)

References

Details

(Keywords: csectype-uaf)

Attachments

(1 file)

http://searchfox.org/mozilla-central/rev/ca7015fa45b30b29176fbaa70ba0a36fe9263c38/toolkit/components/url-classifier/nsUrlClassifierStreamUpdater.cpp#

nsresult
nsUrlClassifierStreamUpdater::FetchNextRequest()
{
  //
  PendingRequest &request = mPendingRequests[0];
  DownloadUpdates(...) // (1)
  request.mSuccessCallback = nullptr;
}

At (1), mPendingRequests may be realloc'ed internally because of AppendElement [1][2]. If the realloc happens, |request| becomes a dangling reference.

[1] http://searchfox.org/mozilla-central/rev/ca7015fa45b30b29176fbaa70ba0a36fe9263c38/toolkit/components/url-classifier/nsUrlClassifierStreamUpdater.cpp#236
[2] http://searchfox.org/mozilla-central/rev/ca7015fa45b30b29176fbaa70ba0a36fe9263c38/toolkit/components/url-classifier/nsUrlClassifierStreamUpdater.cpp#276
Depends on: 1339050
Assignee: nobody → hchang
(In reply to Henry Chang [:henry][:hchang] from comment #0)
> http://searchfox.org/mozilla-central/rev/
> ca7015fa45b30b29176fbaa70ba0a36fe9263c38/toolkit/components/url-classifier/
> nsUrlClassifierStreamUpdater.cpp#
> 
> nsresult
> nsUrlClassifierStreamUpdater::FetchNextRequest()
> {
>   //
>   PendingRequest &request = mPendingRequests[0];
>   DownloadUpdates(...) // (1)
>   request.mSuccessCallback = nullptr;
> }
> 
> At (1), mPendingRequests may be realloc'ed internally because of
> AppendElement [1][2]. If the realloc happens, |request| becomes a dangling
> reference.
> 

What's actually caught by the address sanitizer is not 

"request.mSuccessCallback = nullptr"

but 

http://searchfox.org/mozilla-central/rev/571c1fd0ba0617f83175ccc06ed6f3eb0a1a8b92/toolkit/components/url-classifier/nsUrlClassifierStreamUpdater.cpp#237

because |aRequestTables| is the reference (const nsACString&) from a dangling reference.
Attachment #8847971 - Flags: review?(francois)
Comment on attachment 8847971 [details]
Bug 1347657 - Use array entry as value instead of reference to avoid being invalidated by realloc.

https://reviewboard.mozilla.org/r/120926/#review123216
Attachment #8847971 - Flags: review?(francois) → review+
Pushed by hchang@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/2d4a86ef46e9
Use array entry as value instead of reference to avoid being invalidated by realloc. r=francois
https://hg.mozilla.org/mozilla-central/rev/2d4a86ef46e9
Status: NEW → RESOLVED
Closed: 7 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla55
You need to log in before you can comment on or make changes to this bug.