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

Blake2b/s implementations have minor GIL issues #80700

Open
gwk mannequin opened this issue Apr 3, 2019 · 2 comments
Open

Blake2b/s implementations have minor GIL issues #80700

gwk mannequin opened this issue Apr 3, 2019 · 2 comments
Assignees
Labels
3.7 (EOL) end of life 3.8 only security fixes extension-modules C modules in the Modules dir type-bug An unexpected behavior, bug, or error

Comments

@gwk
Copy link
Mannequin

gwk mannequin commented Apr 3, 2019

BPO 36519
Nosy @tiran, @gwk

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = 'https://github.com/tiran'
closed_at = None
created_at = <Date 2019-04-03.15:04:35.230>
labels = ['extension-modules', '3.8', 'type-bug', '3.7']
title = 'Blake2b/s implementations have minor GIL issues'
updated_at = <Date 2019-04-03.15:20:57.965>
user = 'https://github.com/gwk'

bugs.python.org fields:

activity = <Date 2019-04-03.15:20:57.965>
actor = 'christian.heimes'
assignee = 'christian.heimes'
closed = False
closed_date = None
closer = None
components = ['Extension Modules']
creation = <Date 2019-04-03.15:04:35.230>
creator = 'gwk'
dependencies = []
files = []
hgrepos = []
issue_num = 36519
keywords = []
message_count = 2.0
messages = ['339394', '339396']
nosy_count = 2.0
nosy_names = ['christian.heimes', 'gwk']
pr_nums = []
priority = 'normal'
resolution = None
stage = None
status = 'open'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue36519'
versions = ['Python 3.6', 'Python 3.7', 'Python 3.8']

@gwk
Copy link
Mannequin Author

gwk mannequin commented Apr 3, 2019

I was browsing the Blake2b module implementation in master and noticed two subtle issues in blake2b_impl.c. There are two places where the GIL gets released; both of them appear flawed.

py_blake2b_new_impl, line 221. The ALLOW_THREADS block fails to acquire/release self->lock.

_blake2_blake2b_update, line 279. The lock is lazily allocated correctly on line 279. However the test on 282 that chooses to release the GIL or not fails to take into account the length test. This means that once a large block is fed to update, then every call to update will release the GIL, even if it is a single byte.

It should look something more like this:

bool should_allow_threads = (buf.len >= HASHLIB_GIL_MINSIZE);
if (should_allow_threads && self->lock == NULL)
  self->lock = PyThread_allocate_lock();
if (should_allow_threads && self->lock != NULL) { ... }
else { ... }

This respects the size criterion, and also protects against the case where the lock allocation fails.

@gwk gwk mannequin added 3.7 (EOL) end of life extension-modules C modules in the Modules dir labels Apr 3, 2019
@SilentGhost SilentGhost mannequin added the type-bug An unexpected behavior, bug, or error label Apr 3, 2019
@tiran
Copy link
Member

tiran commented Apr 3, 2019

Thanks, I'll have a look.

@tiran tiran added the 3.8 only security fixes label Apr 3, 2019
@tiran tiran self-assigned this Apr 3, 2019
@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.7 (EOL) end of life 3.8 only security fixes extension-modules C modules in the Modules dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

1 participant