Skip to content

Issue 79: Detect use-after-free in sa_invoke#80

Closed
riwoh wants to merge 3 commits intordkcentral:mainfrom
riwoh:issue-79-use-after-free-sa-invoke
Closed

Issue 79: Detect use-after-free in sa_invoke#80
riwoh wants to merge 3 commits intordkcentral:mainfrom
riwoh:issue-79-use-after-free-sa-invoke

Conversation

@riwoh
Copy link
Copy Markdown
Contributor

@riwoh riwoh commented Apr 13, 2026

Validate that processorHandle is still in the global processorHandleList before accessing its fields. This prevents undefined behavior when sa_invoke is called with a dangling pointer to a freed handle.

Copilot AI review requested due to automatic review settings April 13, 2026 19:03
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses Issue 79 by preventing undefined behavior in sa_invoke when it is called with a dangling Sec_ProcessorHandle*, by validating that the handle is still registered before accessing/locking it.

Changes:

  • Register newly created Sec_ProcessorHandle in the global processorHandleList earlier during initialization.
  • Add a processorHandleList membership check in sa_invoke before locking/accessing handle fields.
  • Adjust locking order in sa_invoke to hold the global list mutex while acquiring the per-handle mutex.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/sec_adapter_processor.c
Comment thread src/sec_adapter_processor.c
Comment thread src/sec_adapter_processor.c
Validate that processorHandle is still in the global processorHandleList
before accessing its fields. This prevents undefined behavior when
sa_invoke is called with a dangling pointer to a freed handle.

Signed-off-by: jhewit200 <joseph_hewitt@cable.comcast.com>
Copilot AI review requested due to automatic review settings April 13, 2026 19:23
@riwoh riwoh force-pushed the issue-79-use-after-free-sa-invoke branch from e971871 to d789e69 Compare April 13, 2026 19:23
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread test/main/cpp/processor.cpp Outdated
@riwoh riwoh requested review from JRHewitt-CC and mhabrat April 13, 2026 21:07
Copy link
Copy Markdown

@mhabrat mhabrat left a comment

Choose a reason for hiding this comment

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

With the potential race condition addressed in a future PR.

mhabrat
mhabrat previously approved these changes Apr 14, 2026
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 14, 2026 02:35
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +151 to +156
// Attempt to use the freed handle - sa_invoke should detect this and return failure
Sec_Result result = SecKey_Generate(dangling, SEC_OBJECTID_USER_BASE, SEC_KEYTYPE_AES_128,
SEC_STORAGELOC_RAM);
if (result == SEC_RESULT_SUCCESS) {
SEC_LOG_ERROR("SecKey_Generate should have failed on a freed handle");
return SEC_RESULT_FAILURE;
Copy link

Copilot AI Apr 14, 2026

Choose a reason for hiding this comment

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

This unit test will pass even if SecKey_Generate fails for unrelated reasons (e.g., unsupported SA backend), because it only asserts that generation fails after release. To make the test actually validate the regression, consider first calling SecKey_Generate(proc, ...) (or another sa_invoke-based operation) and asserting it succeeds before releasing, then repeat the call with the dangling pointer and assert it fails.

Copilot uses AI. Check for mistakes.
@riwoh riwoh closed this Apr 14, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Apr 14, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants