Much like the array bounds checking (issue #25), the kernel should be detecting signed integer overflows using the Undefined Behavior Sanitizer (UBSan) compiler feature. There are some false positives that need to be fixed (e.g. commit a318f12), and there are some true positives that are expected (e.g. refcount_t overflow), and need to be marked.
There is, however, a complication with the kernel's use of -fno-strict-overflow which implies -fwrapv-pointer and -fwrapv (which is needed to keep the compiler from optimizing things away that are considered "undefined", when what is wanted is "expected" 2s-complement wrap-around on overflow). The former is for wrapped unsigned integer overflow (i.e. unsigned long pointer values), and the latter is needed for true positive signed overflow (i.e. refcount_t). However, this makes integer overflow no longer undefined behavior, making UBSan not catch overflows any more. :( To fix this, we need the "intentional overflow/wrap" helpers to DTRT in the face of -fno-wrapv so that UBSan will work correctly.
Language clarification:
- "overflow" has a specific meaning related to undefined behavior
- "wrap (around)" has a specific meaning related to the handling of signed overflow through wrap-around (i.e. defined behavior).
To avoid Undefined Behavior, the kernel must keep -fno-strict-overflow.
So, things to do:
Much like the array bounds checking (issue #25), the kernel should be detecting signed integer overflows using the Undefined Behavior Sanitizer (UBSan) compiler feature. There are some false positives that need to be fixed (e.g. commit a318f12), and there are some true positives that are expected (e.g.
refcount_toverflow), and need to be marked.There is, however, a complication with the kernel's use of
-fno-strict-overflowwhich implies-fwrapv-pointerand-fwrapv(which is needed to keep the compiler from optimizing things away that are considered "undefined", when what is wanted is "expected" 2s-complement wrap-around on overflow). The former is for wrapped unsigned integer overflow (i.e. unsigned long pointer values), and the latter is needed for true positive signed overflow (i.e.refcount_t). However, this makes integer overflow no longer undefined behavior, making UBSan not catch overflows any more. :( To fix this, we need the "intentional overflow/wrap" helpers to DTRT in the face of-fno-wrapvso that UBSan will work correctly.Language clarification:
To avoid Undefined Behavior, the kernel must keep
-fno-strict-overflow.So, things to do:
-fwrapv(and-fno-strict-overflow). done__attribute__((no_sanitize("signed-integer-overflow"))). done-fsanitize=signed-integer-truncationand create new issue if needed