-
Notifications
You must be signed in to change notification settings - Fork 754
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
[SYCL] Limit the directories that are searched when loading dependencies of the plugins #12336
Conversation
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.
8be7cc3
to
3f1c180
Compare
// 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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please merge comments into a single one.
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)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While we don't seem to need LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR
here, I think it would make sense to use it still for consistency and to unify code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, makes sense, fixed.
Included @intel/llvm-reviewers-cuda to get opinion on this change regarding cuda plugin and probably hip plugin. |
Co-authored-by: aelovikov-intel <andrei.elovikov@intel.com>
✅ With the latest revision this PR passed the C/C++ code formatter. |
Currently the default search order is used when loading dependencies of the plugins (these dependencies include the Level Zero loader and the ICD loader for opencl and level zero plugins respectively) 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.