Skip to content

[SYCL] Fix stack smashing due to different sizes of cl_bool and bool #9561

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 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 20 additions & 10 deletions sycl/plugins/opencl/pi_opencl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,9 @@ pi_result piDeviceGetInfo(pi_device device, pi_device_info paramName,
}
case PI_DEVICE_INFO_ATOMIC_64: {
cl_int ret_err = CL_SUCCESS;
cl_bool result = CL_FALSE;
bool result = false;
if (paramValueSize < sizeof(result))
return PI_ERROR_INVALID_VALUE;
bool supported = false;

ret_err = checkDeviceExtensions(
Expand All @@ -616,18 +618,22 @@ pi_result piDeviceGetInfo(pi_device device, pi_device_info paramName,
return static_cast<pi_result>(ret_err);

result = supported;
std::memcpy(paramValue, &result, sizeof(cl_bool));
std::memcpy(paramValue, &result, sizeof(result));
return PI_SUCCESS;
}
case PI_EXT_ONEAPI_DEVICE_INFO_BFLOAT16_MATH_FUNCTIONS: {
// bfloat16 math functions are not yet supported on Intel GPUs.
cl_bool result = false;
std::memcpy(paramValue, &result, sizeof(cl_bool));
bool result = false;
if (paramValueSize < sizeof(result))
return PI_ERROR_INVALID_VALUE;
std::memcpy(paramValue, &result, sizeof(result));
return PI_SUCCESS;
}
case PI_DEVICE_INFO_IMAGE_SRGB: {
cl_bool result = true;
std::memcpy(paramValue, &result, sizeof(cl_bool));
bool result = true;
if (paramValueSize < sizeof(result))
return PI_ERROR_INVALID_VALUE;
std::memcpy(paramValue, &result, sizeof(result));
return PI_SUCCESS;
}
case PI_DEVICE_INFO_BUILD_ON_SUBDEVICE: {
Expand All @@ -637,8 +643,10 @@ pi_result piDeviceGetInfo(pi_device device, pi_device_info paramName,

// FIXME: here we assume that program built for a root GPU device can be
// used on its sub-devices without re-building
cl_bool result = (res == CL_SUCCESS) && (devType == CL_DEVICE_TYPE_GPU);
std::memcpy(paramValue, &result, sizeof(cl_bool));
bool result = (res == CL_SUCCESS) && (devType == CL_DEVICE_TYPE_GPU);
if (paramValueSize < sizeof(result))
return PI_ERROR_INVALID_VALUE;
std::memcpy(paramValue, &result, sizeof(result));
return PI_SUCCESS;
}
case PI_EXT_ONEAPI_DEVICE_INFO_MAX_WORK_GROUPS_3D:
Expand Down Expand Up @@ -715,7 +723,9 @@ pi_result piDeviceGetInfo(pi_device device, pi_device_info paramName,
}
case PI_EXT_INTEL_DEVICE_INFO_MEM_CHANNEL_SUPPORT: {
cl_int ret_err = CL_SUCCESS;
cl_bool result = CL_FALSE;
bool result = false;
if (paramValueSize < sizeof(result))
return PI_ERROR_INVALID_VALUE;
bool supported = false;

ret_err =
Expand All @@ -725,7 +735,7 @@ pi_result piDeviceGetInfo(pi_device device, pi_device_info paramName,
return static_cast<pi_result>(ret_err);

result = supported;
std::memcpy(paramValue, &result, sizeof(cl_bool));
std::memcpy(paramValue, &result, sizeof(result));
return PI_SUCCESS;
}
default:
Expand Down