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

Fix random crash on app quit #11125

Merged
merged 1 commit into from
Nov 17, 2017

Conversation

tarruda
Copy link
Contributor

@tarruda tarruda commented Nov 15, 2017

Close #10051

@juturu can you confirm if this PR fixes the issue for you?

@tarruda tarruda requested review from a team, zcbenz and deepak1556 November 15, 2017 13:12
@tarruda tarruda force-pushed the fix-cert-verification-random-crash-on-exit branch from 704550f to 7ddf1ba Compare November 15, 2017 13:38
Copy link
Member

@ckerr ckerr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a few inline comments on the implementation, but for the main point -- keeping the delegate alive after the context is destroyed -- I'm not sure I understand the implications well enough and defer to @zcbenz & @deepak1556 there

In the first place, who is still trying to use the delegate after the context is destroyed? Is this a question of the context needing to clean up better in its dtor?

@@ -34,7 +34,7 @@ class AtomCertVerifier : public net::CertVerifier {
void SetVerifyProc(const VerifyProc& proc);

const VerifyProc verify_proc() const { return verify_proc_; }
AtomCTDelegate* ct_delegate() const { return ct_delegate_; }
AtomCTDelegate* ct_delegate() const { return ct_delegate_.get(); }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a side issue, returning a raw pointer to a managed resource like this worries me a little... but in this case we have a cheap workaround, the only customer of this method is CertVerifierRequest which is already a friend, so we could move ct_delegate() a few lines down here into the protected section of the class

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@@ -25,7 +25,7 @@ struct VerifyRequestParams {

class AtomCertVerifier : public net::CertVerifier {
public:
explicit AtomCertVerifier(AtomCTDelegate* ct_delegate);
explicit AtomCertVerifier(std::shared_ptr<AtomCTDelegate> ct_delegate);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be a const std::shared_ptr<AtomCTDelegate>& here and in the .cc to avoid unnecessary temporaries

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@tarruda
Copy link
Contributor Author

tarruda commented Nov 15, 2017

In the first place, who is still trying to use the delegate after the context is destroyed?

I can't answer that as I'm not very familiar with how chromium code works. In fact, I don't event know what the purpose of AtomBrowserContext is :)

What I can say is that our application was randomly crashing with a similar stack as the one posted in #10051, and that ensuring AtomCTDelegate alive after AtomBrowserContext is destroyed seemed to fix it.

It appears that whatever chromium object that calls AtomBrowserContext::CreateCertVerifier() has a possibility of using it after AtomBrowserContext is deleted, so wrapping AtomCTDelegate in a shared_ptr seemed like an appropriate fix.

@tarruda tarruda force-pushed the fix-cert-verification-random-crash-on-exit branch from 7ddf1ba to 832a950 Compare November 15, 2017 20:44
@deepak1556
Copy link
Member

In the first place, who is still trying to use the delegate after the context is destroyed? Is this a question of the context needing to clean up better in its dtor?

Its possible for URLRequestContextGetter to outlive a BrowserContext lifetime and the cert verifier and all other network stuff are owned by it. Hence, the crash. That said, I am not sure why I made AtomBrowserContext the owner of AtomCTDelegate :/ The better fix here is to make brightray::URLRequestContextGetter own the delegate.

@tarruda
Copy link
Contributor Author

tarruda commented Nov 16, 2017

The better fix here is to make brightray::URLRequestContextGetter own the delegate.

👍 I will adjust the PR

@tarruda tarruda force-pushed the fix-cert-verification-random-crash-on-exit branch 3 times, most recently from 46e736c to 28345e2 Compare November 16, 2017 19:03
@tarruda
Copy link
Contributor Author

tarruda commented Nov 16, 2017

@deepak1556 moved AtomCTDelegate to brightray (as RequireCTDelegate) and made it owned by brightray::URLRequestContextGetter.

@tarruda tarruda force-pushed the fix-cert-verification-random-crash-on-exit branch from 28345e2 to d2d8ae7 Compare November 17, 2017 00:35
Copy link
Member

@deepak1556 deepak1556 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just requires a few style changes 👍

@@ -138,6 +139,7 @@ URLRequestContextGetter::URLRequestContextGetter(
in_memory_(in_memory),
io_task_runner_(io_task_runner),
file_task_runner_(file_task_runner),
ct_delegate_(new RequireCTDelegate),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This creates the delegate on the UI thread, we should move the initialization into GetURLRequestContext method below.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@@ -280,8 +282,7 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() {

std::unique_ptr<net::TransportSecurityState> transport_security_state =
base::WrapUnique(new net::TransportSecurityState);
transport_security_state->SetRequireCTDelegate(
delegate_->GetRequireCTDelegate());
transport_security_state->SetRequireCTDelegate(ct_delegate_.get());
storage_->set_transport_security_state(std::move(transport_security_state));
storage_->set_cert_verifier(delegate_->CreateCertVerifier());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its better to pass the ct_delegate as a parameter of CreateCertVerifier, can avoid having a GetRequireCTDelegate getter.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Move AtomCTDelegate to brightray as RequireCTDelegate and transfer ownership to
brightray::URLRequestContextGetter. This fixes the wrong lifetime assumptions
that result in AtomCTDelegate being used after free in some scenarios.

Close #10051
@tarruda tarruda force-pushed the fix-cert-verification-random-crash-on-exit branch from d2d8ae7 to a9a9e58 Compare November 17, 2017 15:05
@tarruda
Copy link
Contributor Author

tarruda commented Nov 17, 2017

@deepak1556 done, addressed the requests.

Copy link
Member

@deepak1556 deepak1556 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@jkleinsc jkleinsc merged commit ccb6651 into master Nov 17, 2017
@jkleinsc jkleinsc deleted the fix-cert-verification-random-crash-on-exit branch November 17, 2017 15:54
juturu pushed a commit that referenced this pull request May 21, 2018
Backported from the upstream
#11125
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 on app quit at atom::AtomCTDelegate::ClearCTExcludedHostsList
4 participants