Skip to content

[SYCL][Test] Fix out-of-bounds accesses in unit test device-image helpers - #23107

Open
uditagarwal97 wants to merge 1 commit into
intel:syclfrom
uditagarwal97:private/udit/test-device-image-helper-oob
Open

[SYCL][Test] Fix out-of-bounds accesses in unit test device-image helpers#23107
uditagarwal97 wants to merge 1 commit into
intel:syclfrom
uditagarwal97:private/udit/test-device-image-helper-oob

Conversation

@uditagarwal97

Copy link
Copy Markdown
Contributor

Problem

1. sycl/unittests/helpers/MockDeviceImage.hpp — 8 objects instead of 8 bytes

Four places wrote a size header like this:

std::uninitialized_copy(&PropByteArraySize, &PropByteArraySize + 8,
                        DescData.begin());

The intent is "copy 8 bytes", but the operands are size_t *, so the range spans 8 objects = 64 bytes: an out-of-bounds read of the scalar, and a 64-byte write into a 20-byte DescData.

UBSan diagnostic:

/usr/include/c++/13/bits/stl_algobase.h:388:20: runtime error: load of address ...
with insufficient space for an object of type 'const unsigned long'

Fixed by using std::memcpy with sizeof, and by making PropByteArraySize a uint64_t to match the on-disk property format.
The same file had a latent under-copy in makeAspectsProp():

std::uninitialized_copy(AspectsPtr, AspectsPtr + Aspects.size(), ...);

AspectsPtr is const unsigned char *, so this copies Aspects.size() bytes instead of Aspects.size() * sizeof(sycl::aspect). Not a sanitizer error (in bounds both ways) and currently harmless because both callers pass a single small-valued aspect, but a multi-aspect test would silently read zeros past the first aspect. The neighbouring makeReqdWGSizeProp() already multiplies by sizeof(int); this now matches it.

2. sycl/unittests/SYCL2020/KernelBundleStateFiltering.cpp — indexing the wrong pointer

for (unsigned i = 0; i < *params.pnumDevices; ++i)
  ... *params.pppBinaries[i] ...

*params.pppBinaries[i] parses as *(params.pppBinaries[i]): it indexes the pointer to the argument inside the params struct, not the binaries array, so for i > 0 it reads past the struct.

ERROR: AddressSanitizer: stack-buffer-overflow
    ... in redefinedUrProgramCreateWithBinary

ProgramManager::createURProgram fills every entry of that array with the same image pointer, so tracking one entry is both correct and what the code accidentally did before; the loop is dropped in favour of **params.pppBinaries. Indexing correctly instead would double-count images in the two-device case and break verifyImageUse.


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

makeSpecConstant() and friends wrote size headers with
std::uninitialized_copy(&Scalar, &Scalar + 8, ...), which copies 8 *objects*
(64 bytes) rather than 8 bytes, and KernelBundleStateFiltering indexed the
address of a parameter instead of the array it points to. The first one aborted
three test binaries during --gtest_list_tests, which lit reports as
"failed_to_discover_tests_from_gtest".

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.

🟡 Changes recommended

The multi-aspect serialization fix needs a regression test covering more than one aspect.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Fixes out-of-bounds and incomplete copies in SYCL unit-test device-image helpers.

Changes:

  • Replaces incorrect object-range copies with byte-accurate memcpy.
  • Correctly serializes multiple aspects.
  • Safely tracks the first shared binary in multi-device tests.
File summaries
File Description
sycl/unittests/SYCL2020/KernelBundleStateFiltering.cpp Fixes binary pointer indexing.
sycl/unittests/helpers/MockDeviceImage.hpp Fixes property serialization copies.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Balanced

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

Comment thread sycl/unittests/helpers/MockDeviceImage.hpp
@uditagarwal97
uditagarwal97 marked this pull request as ready for review September 4, 2026 23:47
@uditagarwal97
uditagarwal97 requested a review from a team as a code owner September 4, 2026 23:47

@KseniyaTikhomirova KseniyaTikhomirova 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.

LGTM

const size_t PropByteArraySize = sizeof...(T) * sizeof(uint32_t) * 3;
const uint64_t PropByteArraySize = sizeof...(T) * sizeof(uint32_t) * 3;
std::vector<char> DescData;
DescData.resize(8 + PropByteArraySize);

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.

I would then replace this "8" with sizeof(PropByteArraySize) since it seems to be related and makes intention more obvious.

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.

3 participants