Skip to content

Bug 1718838 - Don't call pthread_equal() on possibly-invalid thread IDs - #66

Merged
sylvestre merged 1 commit into
mozilla:mainfrom
larseggert:fix-pthread-equal
Oct 14, 2026
Merged

sylvestre merged 1 commit into
mozilla:mainfrom
larseggert:fix-pthread-equal

Conversation

@larseggert

@larseggert larseggert commented Sep 25, 2026 •

Copy link
Copy Markdown
Collaborator

lock/mon owner fields can be zero-initialized; pthread_equal() on that is UB. Add pt_pthread_equal(): fall back to == only for the invalid sentinel, else delegate to real pthread_equal(). Used wherever pthread_equal() compared a possibly-unset owner, in ptsynch.c and ptthread.c.

https://bugzilla.mozilla.org/show_bug.cgi?id=1718838

From NetBSD pkgsrc.

@codecov-commenter

codecov-commenter commented Sep 25, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 48.91%. Comparing base (6bac64c) to head (6d85421).
⚠️ Report is 23 commits behind head on main.

Files with missing lines Patch % Lines
pr/src/pthreads/ptsynch.c 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #66      +/-   ##
==========================================
+ Coverage   42.20%   48.91%   +6.70%     
==========================================
  Files          70       93      +23     
  Lines       12071    17828    +5757     
  Branches     2261     2261              
==========================================
+ Hits         5095     8720    +3625     
- Misses       6126     8687    +2561     
+ Partials      850      421     -429     
Flag Coverage Δ
freebsd 42.65% <0.00%> (+0.08%) ⬆️
macos-15-intel 42.70% <0.00%> (+0.01%) ⬆️
macos-latest 42.72% <0.00%> (+0.03%) ⬆️
netbsd 39.37% <0.00%> (+0.08%) ⬆️
openbsd 1.00% <0.00%> (ø)
solaris 39.77% <0.00%> (ø)
ubuntu-24.04-arm-clang 41.76% <0.00%> (-0.01%) ⬇️
ubuntu-latest-gcc 39.47% <0.00%> (-0.05%) ⬇️
ubuntu-latest-gcc-x86 39.49% <0.00%> (-0.01%) ⬇️
windows-arm64-cl 51.16% <ø> (?)
windows-x64-cl 51.46% <ø> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

Valid thread handles should retain POSIX comparison semantics, and the invalid-owner path needs regression coverage.

Get a fresh assessment by requesting another Copilot review.

Review effort: Balanced
Findings: 1 Medium severity · 1 Low severity

Open (2)
What changed in this PR

Prevents undefined behavior when comparing uninitialized pthread owner IDs.

Changes:

  • Adds a safe thread-ID comparison helper.
  • Updates lock, monitor, and thread comparisons.
File Description
pr/​src/​pthreads/​ptthread.c Uses the new comparison helper.
pr/​src/​pthreads/​ptsynch.c Adds the helper and updates owner comparisons.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread pr/src/pthreads/ptsynch.c Outdated
Comment thread pr/src/pthreads/ptsynch.c Outdated
@larseggert
larseggert force-pushed the fix-pthread-equal branch 3 times, most recently from a18c3b6 to d555b4c Compare September 25, 2026 10:08
@github-actions

github-actions Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

nspr4 backport check

Commit Alone In order Files ABI Subject
6d854212 yes yes source unchanged Bug 1718838 - Don't call pthread_equal() on possibly-invalid thread IDs

Alone: cherry-picks onto nspr4 by itself. In order: cherry-picks onto nspr4 after the earlier commits, skipping any that conflict.

Verdict: backportable

@larseggert
larseggert marked this pull request as ready for review October 13, 2026 09:30
Comment thread pr/src/pthreads/ptsynch.c Outdated
Comment thread pr/src/pthreads/ptsynch.c Outdated
Comment thread pr/src/pthreads/ptthread.c Outdated
Comment thread pr/src/pthreads/ptthread.c Outdated
PR_GetMonitorEntryCount() could pass an unset mon->owner to pthread_equal(), which is UB. Only compare when entryCount != 0.

https://bugzilla.mozilla.org/show_bug.cgi?id=1718838

From NetBSD pkgsrc.
@larseggert

Copy link
Copy Markdown
Collaborator Author

@sylvestre thanks, that really simplified the diff :-)

@sylvestre
sylvestre merged commit 51d47a1 into mozilla:main Oct 14, 2026
31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants