-
Notifications
You must be signed in to change notification settings - Fork 124
[DeviceSanitizer] Support check invalid kernel argument #1843
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
omarahmed1111
merged 15 commits into
oneapi-src:main
from
AllanZyne:review/yang/invalid_arguments
Aug 7, 2024
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
ee2a5f1
chack invalid arg in kernel
AllanZyne 5ba3170
fix build
AllanZyne d2e4949
Merge branch 'main' into review/yang/invalid_arguments
AllanZyne 70dc457
fix build
AllanZyne 4949b1a
Merge branch 'main' into review/yang/invalid_arguments
AllanZyne cc40e85
fix lit
AllanZyne 0a916a1
Merge branch 'main' into review/yang/invalid_arguments
AllanZyne 88f2156
fix crash
AllanZyne 237a4af
Merge branch 'llvm' into review/yang/invalid_arguments
AllanZyne 1391baa
default disable
AllanZyne ef0e07f
Merge branch 'llvm' into review/yang/invalid_arguments
AllanZyne 5b12e29
change log message
AllanZyne 38d10ec
argument index start from 1
AllanZyne 7b04b92
default enable
AllanZyne 4e4b04c
Merge branch 'llvm' into review/yang/invalid_arguments
AllanZyne File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| /* | ||
| * | ||
| * Copyright (C) 2024 Intel Corporation | ||
| * | ||
| * Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| * See LICENSE.TXT | ||
| * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| * | ||
| * @file asan_validator.cpp | ||
| * | ||
| */ | ||
|
|
||
| #include "asan_validator.hpp" | ||
| #include "asan_interceptor.hpp" | ||
| #include "ur_sanitizer_utils.hpp" | ||
|
|
||
| namespace ur_sanitizer_layer { | ||
|
|
||
| namespace { | ||
|
|
||
| bool IsSameDevice(ur_device_handle_t Device1, ur_device_handle_t Device2) { | ||
| if (Device1 == Device2) { | ||
| return true; | ||
| } | ||
| auto RootDevice1 = GetParentDevice(Device1); | ||
| RootDevice1 = RootDevice1 ? RootDevice1 : Device1; | ||
| auto RootDevice2 = GetParentDevice(Device2); | ||
| RootDevice2 = RootDevice2 ? RootDevice2 : Device2; | ||
| if (RootDevice1 == RootDevice2) { | ||
| return true; | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| } // namespace | ||
|
|
||
| ValidateUSMResult ValidateUSMPointer(ur_context_handle_t Context, | ||
| ur_device_handle_t Device, uptr Ptr) { | ||
| assert(Ptr != 0 && "Don't validate nullptr here"); | ||
|
|
||
| auto AllocInfoItOp = getContext()->interceptor->findAllocInfoByAddress(Ptr); | ||
| if (!AllocInfoItOp) { | ||
| auto DI = getContext()->interceptor->getDeviceInfo(Device); | ||
| bool IsSupportSharedSystemUSM = DI->IsSupportSharedSystemUSM; | ||
| if (IsSupportSharedSystemUSM) { | ||
| // maybe it's host pointer | ||
| return ValidateUSMResult::success(); | ||
| } | ||
| return ValidateUSMResult::fail(ValidateUSMResult::MAYBE_HOST_POINTER); | ||
| } | ||
|
|
||
| auto AllocInfo = AllocInfoItOp.value()->second; | ||
|
|
||
| if (AllocInfo->Context != Context) { | ||
| return ValidateUSMResult::fail(ValidateUSMResult::BAD_CONTEXT, | ||
| AllocInfo); | ||
| } | ||
|
|
||
| if (AllocInfo->Device && !IsSameDevice(AllocInfo->Device, Device)) { | ||
| return ValidateUSMResult::fail(ValidateUSMResult::BAD_DEVICE, | ||
| AllocInfo); | ||
| } | ||
|
|
||
| if (AllocInfo->IsReleased) { | ||
| return ValidateUSMResult::fail(ValidateUSMResult::RELEASED_POINTER, | ||
| AllocInfo); | ||
| } | ||
|
|
||
| if (Ptr < AllocInfo->UserBegin || Ptr >= AllocInfo->UserEnd) { | ||
| return ValidateUSMResult::fail(ValidateUSMResult::OUT_OF_BOUNDS, | ||
| AllocInfo); | ||
| } | ||
|
|
||
| return ValidateUSMResult::success(); | ||
| } | ||
|
|
||
| } // namespace ur_sanitizer_layer |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| /* | ||
| * | ||
| * Copyright (C) 2024 Intel Corporation | ||
| * | ||
| * Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| * See LICENSE.TXT | ||
| * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| * | ||
| * @file asan_validator.hpp | ||
| * | ||
| */ | ||
| #pragma once | ||
|
|
||
| #include "asan_allocator.hpp" | ||
|
|
||
| namespace ur_sanitizer_layer { | ||
|
|
||
| struct ValidateUSMResult { | ||
| enum ErrorType { | ||
| SUCCESS, | ||
| NULL_POINTER, | ||
| MAYBE_HOST_POINTER, | ||
| RELEASED_POINTER, | ||
| BAD_CONTEXT, | ||
| BAD_DEVICE, | ||
| OUT_OF_BOUNDS | ||
| }; | ||
| ErrorType Type; | ||
| std::shared_ptr<AllocInfo> AI; | ||
|
|
||
| operator bool() { return Type != SUCCESS; } | ||
|
|
||
| static ValidateUSMResult success() { return {SUCCESS, nullptr}; } | ||
|
|
||
| static ValidateUSMResult fail(ErrorType Type, | ||
| const std::shared_ptr<AllocInfo> &AI) { | ||
| assert(Type != SUCCESS && "The error type shouldn't be SUCCESS"); | ||
| return {Type, AI}; | ||
| } | ||
|
|
||
| static ValidateUSMResult fail(ErrorType Type) { | ||
| assert(Type != SUCCESS && "The error type shouldn't be SUCCESS"); | ||
| return {Type, nullptr}; | ||
| } | ||
| }; | ||
|
|
||
| ValidateUSMResult ValidateUSMPointer(ur_context_handle_t Context, | ||
| ur_device_handle_t Device, uptr Ptr); | ||
|
|
||
| } // namespace ur_sanitizer_layer |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
nit: I just looked at https://github.com/intel/llvm/pull/14512/files#diff-4bf2f0aa3bc4ee23b6e8f0e9cc81b9c9be49d730701d0609fc928b07ec722af1R20, "0th" looks odd :) I'd do
Argument at index {ArgIndex} ....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.
Thanks for reminding me :)
I fall into programmer's mindset.