Skip to content

[SYCL] fix for std::locale::global interfering with allowlist check #18550

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

Merged
merged 3 commits into from
May 28, 2025

Conversation

cperkinsintel
Copy link
Contributor

std::locale::global() is a very common way for apps to initialize string localization for numeric and monetary values. Unfortunately, it is global.
In this very limited fix, we are preventing it from interfering with the allowlist check which uses std::stringstream. The insertion of commas into numbers for the locale support messes with the expected values.
We'll probably have to audit the other uses of std streams to see if they would be similarly vulnerable.

Signed-off-by: Chris Perkins <[email protected]>
@@ -428,6 +428,8 @@ void applyAllowList(std::vector<ur_device_handle_t> &UrDevices,
uint32_t DeviceVendorIdUInt =
DeviceImpl.get_info<info::device::vendor_id>();
std::stringstream DeviceVendorIdHexStringStream;
// To avoid commas or other locale-specific modifications, call imbue().
DeviceVendorIdHexStringStream.imbue(std::locale::classic());
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like we do this for a couple other stringstream objects. Could we make a derived class that automatically sets this in the ctor? Might also want to use it in getUint32PropAsOptStr in sycl/source/detail/program_manager/program_manager.cpp.

Copy link
Contributor Author

@cperkinsintel cperkinsintel May 27, 2025

Choose a reason for hiding this comment

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

I considered making a derived class, but decided against it. The other places ( #18578 ) are few and are in both sycl and syclcompat, and just creating a class doesn't mean people will actually use it.
We've already had a "use custom iostream alternate" phase and "remove custom iostream alternate" phase in the years I've been on this project.

Copy link
Contributor

@steffenlarsen steffenlarsen left a comment

Choose a reason for hiding this comment

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

Fair points made. I'm hoping people will see this and be aware of it, but it bothers me that locale has an effect on stringstream to begin with.

@againull againull merged commit da1c320 into intel:sycl May 28, 2025
24 checks passed
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