Skip to content
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

Merged
merged 7 commits into from
Jan 11, 2024

Conversation

againull
Copy link
Contributor

@againull againull commented Jan 9, 2024

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.

@againull againull requested a review from a team as a code owner January 9, 2024 17:28
@againull againull changed the title [SYCL] Limit the directories that are searched when loading plugins [SYCL] Limit the directories that are searched when loading dependencies of the plugins Jan 9, 2024
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.
Comment on lines 137 to 150
// 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;
Copy link
Contributor

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));
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, makes sense, fixed.

@againull againull requested review from a team and ldrumm and removed request for a team January 9, 2024 22:34
@againull
Copy link
Contributor Author

againull commented Jan 9, 2024

Included @intel/llvm-reviewers-cuda to get opinion on this change regarding cuda plugin and probably hip plugin.

againull and others added 2 commits January 10, 2024 15:11
Co-authored-by: aelovikov-intel <andrei.elovikov@intel.com>
Copy link
Contributor

github-actions bot commented Jan 10, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

@againull againull merged commit 218d9fe into intel:sycl Jan 11, 2024
11 checks passed
@againull againull deleted the limit_search_dir branch April 9, 2024 19:57
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.

2 participants