-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Implement kernel sanitizers #2527
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
Changes from all commits
88e6bd1
d617a13
23b5176
204b35f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -45,6 +45,7 @@ endif() | |||||
|
|
||||||
| target_link_libraries(ntoskrnl cportlib csq ${PSEH_LIB} arbiter cmlib ntlsalib rtl ${ROSSYM_LIB} libcntpr wdmguid ioevent) | ||||||
|
|
||||||
| # dynamic analysis switches | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| if(STACK_PROTECTOR) | ||||||
| target_sources(ntoskrnl PRIVATE $<TARGET_OBJECTS:gcc_ssp_nt>) | ||||||
| endif() | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -103,6 +103,12 @@ | |
|
|
||
| #endif | ||
|
|
||
| #ifdef __SANITIZE_UB__ | ||
| #define NO_SANITIZE __attribute__ ((no_sanitize("undefined"))) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd prefer to have it in crtdefs.h as This makes it clearer that you want to disable this or that sanitizer, and allows disabling more than one for them with e.g
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ahemmm... until we see whether there are other functions in our code base that may need the sanitizer to not be applied on them, it might be better to keep that only where it's needed (so far just the kernel), and not pollute our CRT with unrelated stuff. And even if you would want to move that into some global header, a specific separate one might be better.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Dunno... I see sanitizer stuff as something separate from compiler 🤷
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, it is the compiler instrumenting generated binaries in order to make the relevant checks. It can't be closer to compiler than that 😉
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @HBelusca check this article for example - explains how Address Sanitizer works https://lwn.net/Articles/612153/ |
||
| #else | ||
| #define NO_SANITIZE | ||
| #endif | ||
|
|
||
| #ifndef _WIN64 | ||
| C_ASSERT(FIELD_OFFSET(KUSER_SHARED_DATA, SystemCall) == 0x300); | ||
|
|
||
|
|
||
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -34,10 +34,15 @@ if(USE_DUMMY_PSEH) | |||||
| add_definitions(-D_USE_DUMMY_PSEH=1) | ||||||
| endif() | ||||||
|
|
||||||
| # Dynamic analysis | ||||||
| if(STACK_PROTECTOR) | ||||||
| add_compile_options(-fstack-protector-strong) | ||||||
| endif() | ||||||
|
|
||||||
| if(SANITIZE_UB) | ||||||
| add_compile_definitions(__SANITIZE_UB__) | ||||||
| endif() | ||||||
|
|
||||||
| # Compiler Core | ||||||
| add_compile_options(-pipe -fms-extensions -fno-strict-aliasing) | ||||||
|
|
||||||
|
|
@@ -138,6 +143,11 @@ else() | |||||
| endif() | ||||||
| endif() | ||||||
|
|
||||||
| # GCC optimizer bug. See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85175 | ||||||
| if((OPTIMIZE STREQUAL "3") AND (GCC_VERSION VERSION_GREATER 8)) | ||||||
| add_compile_options(-Wno-format-overflow) | ||||||
| endif() | ||||||
|
|
||||||
| # Link-time code generation | ||||||
| if(LTCG) | ||||||
| add_compile_options(-flto -fno-fat-lto-objects) | ||||||
|
|
@@ -314,6 +324,16 @@ function(set_module_type_toolchain MODULE TYPE) | |||||
|
|
||||||
| # Believe it or not, cmake doesn't do that | ||||||
| set_property(TARGET ${MODULE} APPEND PROPERTY LINK_DEPENDS $<TARGET_PROPERTY:native-pefixup,IMPORTED_LOCATION>) | ||||||
|
|
||||||
| if(SANITIZE_UB) | ||||||
| # we have too many alignment warnings at the moment | ||||||
| target_compile_options(${MODULE} PRIVATE "-fsanitize=undefined;-fno-sanitize=alignment") | ||||||
|
|
||||||
| # win32k&dependencies require a special version of ksanitize | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| if(NOT ${TYPE} STREQUAL "kerneldll") | ||||||
| target_link_libraries(${MODULE} ksanitize) | ||||||
| endif() | ||||||
| endif() | ||||||
| endif() | ||||||
| endfunction() | ||||||
|
|
||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
|
|
||
| list(APPEND SOURCE | ||
| ubsan.c) | ||
|
|
||
| add_library(ksanitize ${SOURCE}) | ||
| target_compile_definitions(ksanitize PUBLIC LIBSAN_KMODE) | ||
| add_importlibs(ksanitize ntoskrnl) | ||
|
|
||
| add_library(ksanitize_w32k ${SOURCE}) | ||
| target_compile_definitions(ksanitize_w32k PUBLIC LIBSAN_W32K) | ||
| add_importlibs(ksanitize_w32k win32k) |
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.
Why for this PR ? Maybe we should fix them.
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.
Oh, that's the UDF driver, I don't really want to look into it :D
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.
But that's a general problem - when various optimization levels are enabled, different errors pop up here and there