Skip to content

[SYCL][Unittests] Don't pass addresses of local variables as UR handles in unit tests - #23105

Open
uditagarwal97 wants to merge 1 commit into
intel:syclfrom
uditagarwal97:private/udit/test-stack-addresses-as-ur-handles
Open

[SYCL][Unittests] Don't pass addresses of local variables as UR handles in unit tests#23105
uditagarwal97 wants to merge 1 commit into
intel:syclfrom
uditagarwal97:private/udit/test-stack-addresses-as-ur-handles

Conversation

@uditagarwal97

Copy link
Copy Markdown
Contributor

Problem

The UR mock adapter reinterpret_casts every handle it receives to mock::dummy_handle_t_ and touches MRefCounter on retain/release. Three unit tests passed the address of a local variable where the runtime expects a handle, so those retain/release calls wrote into the tests' own stack frames.

1. sycl/unittests/Extensions/BindlessImages/Semaphores.cppBindlessImagesExtensionTests.ExternalSemaphoreSignal built fake device events with

int DummyInt1 = 0, DummyInt2 = 0;
DummyEventImpl1->setHandle(reinterpret_cast<ur_event_handle_t>(&DummyInt1));
DummyEventImpl2->setHandle(reinterpret_cast<ur_event_handle_t>(&DummyInt2));

~event_impl() calls urEventRelease on those handles:

ERROR: AddressSanitizer: stack-buffer-overflow on address ...
WRITE of size 8 at ... thread T0
    #0 ... in operator-- bits/atomic_base.h:410
    #1 ... in releaseDummyHandle<ur_event_handle_t_ *>
       unified-runtime/source/mock/ur_mock_helpers.hpp:74
    #2 ... in driver::urEventRelease(ur_event_handle_t_*)
    ...
    #6 ... in sycl::_V1::detail::event_impl::~event_impl()
    #10 ... in BindlessImagesExtensionTests_ExternalSemaphoreSignal_Test::TestBody()

The same pattern also produced a UBSan member access within misaligned address ... for type 'dummy_handle_t_' diagnostic, because a 4-byte-aligned int is not suitably aligned for the handle struct.

2. sycl/unittests/thread_safety/InteropKernelEnqueue.cpp (KernelEnqueue.InteropKernel) and 3. sycl/unittests/handler/SetArgForLocalAccessor.cpp (HandlerSetArg.LocalAccessor) — both created a native handle and then passed its address to make_kernel:

auto Handle = mock::createDummyHandle<ur_native_handle_t>();
... reinterpret_cast<cl_kernel>(&Handle) ...

so the runtime's retain/release of the interop kernel mutated the local Handle variable, and the handle it actually created was never released (a leak on top of the corruption).


Co-Authored-By: Claude Opus 5 (1M context) noreply@anthropic.com

…nit tests

Three unit tests handed the address of a stack variable to the runtime as a
ur_event_handle_t / native cl_kernel. The mock adapter treats every handle as a
mock::dummy_handle_t_ and increments or decrements its reference counter, so the
runtime's release calls were writing into the tests' stack frames. Use real
dummy handles instead.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

The changes correctly eliminate invalid stack-backed handles and balance mock handle ownership.

Pull request overview

Fixes unsafe mock-handle ownership in three SYCL unit tests.

Changes:

  • Replaces stack addresses with valid reference-counted dummy handles.
  • Ensures interop kernels are destroyed before releasing test-owned handles.
File summaries
File Description
sycl/unittests/thread_safety/InteropKernelEnqueue.cpp Corrects interop kernel handle lifetime.
sycl/unittests/handler/SetArgForLocalAccessor.cpp Corrects interop kernel handle lifetime.
sycl/unittests/Extensions/BindlessImages/Semaphores.cpp Uses releasable dummy event handles.
Review details
  • Files reviewed: 3/3 changed files
  • Comments generated: 0
  • Review effort level: Balanced

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

@uditagarwal97
uditagarwal97 marked this pull request as ready for review September 4, 2026 20:36
@uditagarwal97
uditagarwal97 requested review from a team as code owners September 4, 2026 20:36
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.

2 participants