Skip to content

Add a lock around the OBJ_NAME table#3525

Closed
sfackler wants to merge 2 commits intoopenssl:masterfrom
sfackler:obj-name-sync-fix
Closed

Add a lock around the OBJ_NAME table#3525
sfackler wants to merge 2 commits intoopenssl:masterfrom
sfackler:obj-name-sync-fix

Conversation

@sfackler
Copy link
Contributor

Various initialization functions modify this table, which can cause heap
corruption in the absence of external synchronization.

Fixes #3505

@openssl-machine openssl-machine added the hold: cla required The contributor needs to submit a license agreement label May 23, 2017
Various initialization functions modify this table, which can cause heap
corruption in the absence of external synchronization.

Fixes openssl#3505
@mattcaswell
Copy link
Member

CLA received - thank you!

@mattcaswell mattcaswell removed the hold: cla required The contributor needs to submit a license agreement label May 24, 2017
Copy link
Member

Choose a reason for hiding this comment

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

Too much indentation here! Indent the label one space and the other lines 4 spaces
Also the preferred style is now to not put () around a return expression (where we touch code that has that we remove it).

Copy link
Member

Choose a reason for hiding this comment

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

Remove the () for return expression.

Copy link
Member

Choose a reason for hiding this comment

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

I think a write lock is required here, lh_OBJ_NAME_retrieve() updates internal stats.

Copy link
Contributor

Choose a reason for hiding this comment

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

FWIW, there's other code which takes a read lock around lh_*_retrieve, like ssl_get_prev_session and int_err_get_item. But there's also performance reasons why you'd probably not want a write lock around those. I would have suggested taking those stats out, but sadly they're public API by way of OPENSSL_LH_stats_bio...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It looks like the tracked statistics are just a couple of counters, so we could swap over to atomic operations and avoid write locking.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, that is a great idea. We have CRYPTO_atomic_add() for that. Do you want to pick that up as part of this PR, or should we defer it to another one?

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah, agree with @sfackler's suggestion. hope he does it :)

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we can take this PR without the atomic add stuff.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, I'll update tonight.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated - it's kind of awful. Does anyone actually use OPENSSL_LH_stats_bio? It'd be great to remove the statistics tracking entirely and have that thing print a message about stats no longer being recorded.

Copy link
Contributor

Choose a reason for hiding this comment

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

Probably not. It was used by the since removed -stats flag for the errstr command. We removed it, and I've never seen anything notice.

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah, but ... we tend to be real picky about compatibility. i'd like to turn it off, then remove it. but sigh ...

Copy link
Member

Choose a reason for hiding this comment

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

Too much indentation

@mattcaswell mattcaswell added 1.1.0 branch: master Applies to master branch labels May 24, 2017
@sfackler sfackler force-pushed the obj-name-sync-fix branch from efd1f7b to aca3c7e Compare May 25, 2017 02:37
@sfackler
Copy link
Contributor Author

Updated!

Copy link
Member

@mattcaswell mattcaswell left a comment

Choose a reason for hiding this comment

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

Approved subject to one minor nit being fixed.

Copy link
Member

Choose a reason for hiding this comment

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

Wrong comment style. Multi-line comments should look like this:

/*
 * My multi-line
 * comment
 */

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

Copy link
Member

@mattcaswell mattcaswell left a comment

Choose a reason for hiding this comment

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

Damn...meant to select "approve" not "request changes"....still subject to the one minor nit fix.

@kroeckx
Copy link
Member

kroeckx commented May 26, 2017 via email

@sfackler sfackler force-pushed the obj-name-sync-fix branch from 0a02153 to 1b636a4 Compare May 27, 2017 01:37
@sfackler
Copy link
Contributor Author

I think this is ready to land.

@mattcaswell
Copy link
Member

Reconfirmed. Still looking for a second team approval.

Copy link
Contributor

@richsalz richsalz left a comment

Choose a reason for hiding this comment

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

minor change, then approved.

Copy link
Contributor

Choose a reason for hiding this comment

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

free of a NULL pointer is fine. As long as ret is init'd (via zalloc or explicitly), then you can collapse to one goto label.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed!

Some stats are modified from OPENSSL_LH_retrieve, where callers aren't
expecting to have to take out an exclusive lock. Switch to using atomic
operations for those stats.
@sfackler sfackler force-pushed the obj-name-sync-fix branch from 1b636a4 to 3b118a4 Compare May 31, 2017 03:23
@mattcaswell
Copy link
Member

@richsalz - can you confirm your approval?

@richsalz
Copy link
Contributor

+1 reconfirm

@sfackler
Copy link
Contributor Author

sfackler commented Jun 7, 2017

Is there anything left to do here on my end?

@richsalz richsalz self-assigned this Jun 7, 2017
@richsalz
Copy link
Contributor

richsalz commented Jun 7, 2017

no, just the occasional post as things fall through the cracks :)
i'll merge in a bit. thanks.

levitte pushed a commit that referenced this pull request Jun 7, 2017
Various initialization functions modify this table, which can cause heap
corruption in the absence of external synchronization.

Some stats are modified from OPENSSL_LH_retrieve, where callers aren't
expecting to have to take out an exclusive lock. Switch to using atomic
operations for those stats.

Reviewed-by: Matt Caswell <[email protected]>
Reviewed-by: Rich Salz <[email protected]>
(Merged from #3525)
levitte pushed a commit that referenced this pull request Jun 7, 2017
Various initialization functions modify this table, which can cause heap
corruption in the absence of external synchronization.

Some stats are modified from OPENSSL_LH_retrieve, where callers aren't
expecting to have to take out an exclusive lock. Switch to using atomic
operations for those stats.

Reviewed-by: Matt Caswell <[email protected]>
Reviewed-by: Rich Salz <[email protected]>
(Merged from #3525)
(cherry picked from commit be606c0)
@richsalz
Copy link
Contributor

richsalz commented Jun 7, 2017

merged at be606c0 in master and 1ec7eff in 1.1.0

Thank you for helping improve openssl!

@richsalz richsalz closed this Jun 7, 2017
@sfackler
Copy link
Contributor Author

sfackler commented Jun 8, 2017

Thanks!

@sfackler sfackler deleted the obj-name-sync-fix branch June 8, 2017 00:19
pracj3am pushed a commit to cdn77/openssl that referenced this pull request Aug 22, 2017
Various initialization functions modify this table, which can cause heap
corruption in the absence of external synchronization.

Some stats are modified from OPENSSL_LH_retrieve, where callers aren't
expecting to have to take out an exclusive lock. Switch to using atomic
operations for those stats.

Reviewed-by: Matt Caswell <[email protected]>
Reviewed-by: Rich Salz <[email protected]>
(Merged from openssl#3525)
(cherry picked from commit be606c0)
@dot-asm dot-asm mentioned this pull request Sep 26, 2017
bakaid pushed a commit to tresorit/openssl that referenced this pull request Oct 9, 2017
Various initialization functions modify this table, which can cause heap
corruption in the absence of external synchronization.

Some stats are modified from OPENSSL_LH_retrieve, where callers aren't
expecting to have to take out an exclusive lock. Switch to using atomic
operations for those stats.

Reviewed-by: Matt Caswell <[email protected]>
Reviewed-by: Rich Salz <[email protected]>
(Merged from openssl#3525)
(cherry picked from commit be606c0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

branch: master Applies to master branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants