User:Anotheridiot/Kernel Security

From OSDev Wiki
Jump to navigation Jump to search

This article is a stub! This page or section is a stub. You can help the wiki by accurately contributing to it.

This is my page dedicated to the development of security features within a kernel. Many features are quite needed for any basic security setup (for example, SSP). Personally I choose to pass the following flags in my makefile for security related things

# NOTE: Some of these flags may only exist on Clang.
# SSP exists on both GCC and Clang, the rest is unclear.
override CFLAGS += \
	-fstack-protector-all \
	-fsanitize=undefined \
	-fsanitize-minimal-runtime \
	-fsanitize=bounds \
	-fsanitize=object-size \
	-fsanitize=alignment \
	-fsanitize=bool \
	-fsanitize=enum \
	-fsanitize=shift \
	-fsanitize=shift-base \
	-fsanitize=shift-exponent \
	-fsanitize=integer-divide-by-zero \
	-fsanitize=unreachable \
	-fsanitize=return \
	-fsanitize=nonnull-attribute \
	-fsanitize=null \
	-fsanitize=implicit-integer-truncation \
	-fsanitize=implicit-integer-sign-change

The three most important lines are the first three in these flags, SSP (stack protector) which is used to stop stack overflow attacks taking over the kernel, the undefined behavior sanitizer which when undefined C behavior is found it will call a function which is traditionally made to call kpanic, and usually dumps the RIP that called it via __builtin_return_address(0);. And of course then there is the fact its told to use the minimal runtime, which makes implementation considerably easier.

The reason to scan for Undefined Behavior and patch it is because if Behavior is undefined it stops C from acting normally and introduces possible bugs and exploits like out of bounds memory writes and reads.

The rest are mostly enabling extra checks in -fsanitize. Though of course some may be redundent depending on the build of clang used.