Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't pass async override_response_headers ptr #8619

Merged
merged 1 commit into from
Apr 23, 2021

Conversation

kkuehlz
Copy link
Contributor

@kkuehlz kkuehlz commented Apr 23, 2021

Don't pass async override_response_headers ptr

I have tried all day to consistently repproduce this locally to no avail. I got
it once with an asan build. It points to us using the raw pointer. So let's
pass the scoped_refpointer itself which should keep it alive.

We don't actually need the headers as a pointer after setting it in
OnHeadersReceived_AdBlockCspWork() anyway.

==2285653==ERROR: AddressSanitizer: heap-use-after-free on address
0x61d001294be8 at pc 0x5580b69e17e9 bp 0x7ffdf4686370 sp 0x7ffdf4686368 READ of
size 8 at 0x61d001294be8 thread T0 (brave) #0 0x5580b69e17e8 in operator->
base/memory/scoped_refptr.h:235:5 #1 0x5580b69e17e8 in
brave::OnReceiveCspDirectives(base::RepeatingCallback<void ()> const&,
std::__Cr::shared_ptrbrave::BraveRequestInfo,
scoped_refptrnet::HttpResponseHeaders,
base::Optional<std::__Cr::basic_string<char, std::__Cr::char_traits,
std::__Cr::allocator > >)
brave/browser/net/brave_ad_block_csp_network_delegate_helper.cc:52:5 #2
0x5580b69e3c72 in Invoke<void (
)(const base::RepeatingCallback<void ()> &,
std::shared_ptrbrave::BraveRequestInfo,
scoped_refptrnet::HttpResponseHeaders *, base::Optionalstd::string),
base::RepeatingCallback<void ()>, std::shared_ptrbrave::BraveRequestInfo,
scoped_refptrnet::HttpResponseHeaders , base::Optionalstd::string >
base/bind_internal.h:393:12 #3 0x5580b69e3c72 in MakeItSo<void (
)(const
base::RepeatingCallback<void ()> &, std::shared_ptrbrave::BraveRequestInfo,
scoped_refptrnet::HttpResponseHeaders *, base::Optionalstd::string),
base::RepeatingCallback<void ()>, std::shared_ptrbrave::BraveRequestInfo,
scoped_refptrnet::HttpResponseHeaders , base::Optionalstd::string >
base/bind_internal.h:637:12 #4 0x5580b69e3c72 in RunImpl<void (
)(const
base::RepeatingCallback<void ()> &, std::shared_ptrbrave::BraveRequestInfo,
scoped_refptrnet::HttpResponseHeaders *, base::Optionalstd::string),
std::tuple<base::RepeatingCallback<void ()>,
std::shared_ptrbrave::BraveRequestInfo,
scoped_refptrnet::HttpResponseHeaders *>, 0, 1, 2>
base/bind_internal.h:710:12

Maybe Resolves brave/brave-browser#15445

I have tried all day to consistently repproduce this locally to no avail. I got
it once with an asan build. It points to us using the raw pointer.  So let's
pass the scoped_refpointer itself which should keep it alive.

We don't actually need the headers as a pointer after setting it in
OnHeadersReceived_AdBlockCspWork() anyway.

==2285653==ERROR: AddressSanitizer: heap-use-after-free on address
0x61d001294be8 at pc 0x5580b69e17e9 bp 0x7ffdf4686370 sp 0x7ffdf4686368 READ of
size 8 at 0x61d001294be8 thread T0 (brave) #0 0x5580b69e17e8 in operator->
base/memory/scoped_refptr.h:235:5 #1 0x5580b69e17e8 in
brave::OnReceiveCspDirectives(base::RepeatingCallback<void ()> const&,
std::__Cr::shared_ptr<brave::BraveRequestInfo>,
scoped_refptr<net::HttpResponseHeaders>*,
base::Optional<std::__Cr::basic_string<char, std::__Cr::char_traits<char>,
std::__Cr::allocator<char> > >)
brave/browser/net/brave_ad_block_csp_network_delegate_helper.cc:52:5 #2
0x5580b69e3c72 in Invoke<void (*)(const base::RepeatingCallback<void ()> &,
std::shared_ptr<brave::BraveRequestInfo>,
scoped_refptr<net::HttpResponseHeaders> *, base::Optional<std::string>),
base::RepeatingCallback<void ()>, std::shared_ptr<brave::BraveRequestInfo>,
scoped_refptr<net::HttpResponseHeaders> *, base::Optional<std::string> >
base/bind_internal.h:393:12 #3 0x5580b69e3c72 in MakeItSo<void (*)(const
base::RepeatingCallback<void ()> &, std::shared_ptr<brave::BraveRequestInfo>,
scoped_refptr<net::HttpResponseHeaders> *, base::Optional<std::string>),
base::RepeatingCallback<void ()>, std::shared_ptr<brave::BraveRequestInfo>,
scoped_refptr<net::HttpResponseHeaders> *, base::Optional<std::string> >
base/bind_internal.h:637:12 #4 0x5580b69e3c72 in RunImpl<void (*)(const
base::RepeatingCallback<void ()> &, std::shared_ptr<brave::BraveRequestInfo>,
scoped_refptr<net::HttpResponseHeaders> *, base::Optional<std::string>),
std::tuple<base::RepeatingCallback<void ()>,
std::shared_ptr<brave::BraveRequestInfo>,
scoped_refptr<net::HttpResponseHeaders> *>, 0, 1, 2>
base/bind_internal.h:710:12

Maybe Resolves brave/brave-browser#15445
@kkuehlz kkuehlz force-pushed the adblock_csp_dont_pass_raw_ptr branch from f977dae to 71e6d16 Compare April 23, 2021 00:39
@iefremov
Copy link
Contributor

yeah, thanks a lot @keur . I was actually thinking about a larger fix (we basically shouldn't pass any raw pointers to callbacks, because owning URLLoader can die at any moment), but this bandaid should definitely fix the crash.

Please uplift once merged

@kkuehlz
Copy link
Contributor Author

kkuehlz commented Apr 23, 2021

The failing test on Linux is related to multiple uphold contributions. Seems unrelated.

@kkuehlz kkuehlz merged commit 26d0e0a into master Apr 23, 2021
@kkuehlz kkuehlz deleted the adblock_csp_dont_pass_raw_ptr branch April 23, 2021 16:03
@antonok-edm antonok-edm added this to the 1.25.x - Nightly milestone Apr 23, 2021
@antonok-edm
Copy link
Collaborator

Please uplift once merged

Uplifting shouldn't be required, the original PR that introduced this (#8281) is only in 1.25.x at the moment.

Thanks @keur!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Crash in CSP adblock filter
3 participants