Skip to content

Commit

Permalink
[SYCL] Limit the directories that are searched when loading plugins
Browse files Browse the repository at this point in the history
Currently the default search order is used when loading dependencies of the
plugins (these depencies include the Level Zero loader and the ICD
loader) and that list includes current directory and some other
directories which are not considered safe. This patch limits the list of
directories when loading the dependencies of the plugins.
See: https://learn.microsoft.com/en-us/windows/win32/api/libloaderapi/nf-libloaderapi-loadlibraryexa
for reference.
  • Loading branch information
againull committed Jan 9, 2024
1 parent 90b6aee commit 3f1c180
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions sycl/pi_win_proxy_loader/pi_win_proxy_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,22 @@ void preloadLibraries() {
MapT &dllMap = getDllMap();

auto ocl_path = LibSYCLDir / __SYCL_OPENCL_PLUGIN_NAME;
dllMap.emplace(ocl_path,
LoadLibraryEx(ocl_path.wstring().c_str(), NULL, NULL));

// When searching for dependencies of the OpenCL plugin (which includes ICD
// loader) limit the list of directories to %windows%\system32 and the
// directory that contains the loaded DLL (OpenCL plugin). ICD loader is
// located in the same directory as OpenCL plugin. Standard library
// dependencies are in the system directory.
dllMap.emplace(ocl_path, LoadLibraryEx(ocl_path.wstring().c_str(), NULL,
LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR |
LOAD_LIBRARY_SEARCH_SYSTEM32));

// When searching for dependencies of the Level Zero plugin (which includes
// level zero loader) limit the list of directories to %windows%\system32.
// In this case we know that the Level Zero Loader is located in the system
// directory. Standard library dependencies are in the system directory.
auto l0_path = LibSYCLDir / __SYCL_LEVEL_ZERO_PLUGIN_NAME;
dllMap.emplace(l0_path, LoadLibraryEx(l0_path.wstring().c_str(), NULL, NULL));
dllMap.emplace(l0_path, LoadLibraryEx(l0_path.wstring().c_str(), NULL,
LOAD_LIBRARY_SEARCH_SYSTEM32));

auto cuda_path = LibSYCLDir / __SYCL_CUDA_PLUGIN_NAME;
dllMap.emplace(cuda_path,
Expand Down

0 comments on commit 3f1c180

Please sign in to comment.