Skip to content

Introduce Overflow Behavior Types

Kees Cook linux-doc linux-hardening linux-kbuild linux-kselftest lkml llvm 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest5 patches 45 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/5refcount: Remove unused __signed_wrap function annotationsinclude/linux/compiler_types.h include/linux/refcount.h+6 -130 replies
2/5hardening: Introduce Overflow Behavior Types supportMAINTAINERS Makefile include/linux/compiler-version.h +12 more+125 -450 replies
3/5compiler_attributes: Add overflow_behavior macros __ob_trap and __ob_wrapDocumentation/dev-tools/ubsan.rst Documentation/process/arithmetic-overflow.rst Documentation/process/deprecated.rst +3 more+389 -019 replies
4/5lkdtm/bugs: Add basic Overflow Behavior Types testdrivers/misc/lkdtm/bugs.c tools/testing/selftests/lkdtm/tests.txt+263 -01 reply
5/5types: Add standard __ob_trap and __ob_wrap scalar typesinclude/linux/types.h+24 -025 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [PATCH 0/5] Introduce Overflow Behavior Types

Hi,

This is the spiritual successor to the "Mitigating unexpected arithmetic overflow" thread from 2024[1]. After a long discussion there, and subsequent discussions with Peter at Linux Plumbers, Justin went off to build a type-based solution. After more than a year of RFCs and feedback from compiler folks and with an eye toward potentially making this part of the C Standard in the future, what has evolved is Overflow Behavior Types[2], which are first-class native types that mirror the existing native scalar types in C. They are created using a type qualifier ("__ob_trap" and "__ob_wrap"), but they are their own distinct types. e.g. "int" and "int __ob_trap" are different types, though they are mostly interchangable (e.g. format strings, implicit casts, etc), with some specific instrumentation in cases where wrap-around or truncation is possible.

This series provides support for building with them enabled, adds documentation, adds tests, and proposes the new typedefs (see the last patch in the series) for the corresponding kernel scalar types. With this, we can start converting variables (and types) that are never supposed to overflow/underflow to these new types[3]. (Or types that are always supposed to overflow/underflow.)

Enjoy! :)

-Kees

Justin Stitt (2):
hardening: Introduce Overflow Behavior Types support
compiler_attributes: Add overflow_behavior macros __ob_trap and

    __ob_wrap

Kees Cook (3):
refcount: Remove unused __signed_wrap function annotations lkdtm/bugs: Add basic Overflow Behavior Types test
types: Add standard __ob_trap and __ob_wrap scalar types

 lib/Kconfig.ubsan                             |  18 -
 security/Kconfig.hardening                    |  50 ++-
 Makefile                                      |   1 +
 scripts/basic/Makefile                        |   2 +-
 scripts/Makefile.lib                          |   7 +-
 scripts/Makefile.obt                          |  28 ++
 scripts/Makefile.ubsan                        |  10 -
 scripts/Makefile.warn                         |   7 +
 scripts/integer-wrap-ignore.scl               |   3 +-
 Documentation/dev-tools/ubsan.rst             |  13 +
 Documentation/process/arithmetic-overflow.rst | 323 ++++++++++++++++++
 Documentation/process/deprecated.rst          |  39 +++
 Documentation/process/index.rst               |   1 +
 include/linux/compiler-version.h              |   2 +-
 include/linux/compiler_attributes.h           |  12 +
 include/linux/compiler_types.h                |   9 +-
 include/linux/refcount.h                      |  10 +-
 include/linux/sched.h                         |   3 +-
 include/linux/types.h                         |  24 ++
 include/linux/ubsan.h                         |  12 +-
 drivers/misc/lkdtm/bugs.c                     | 253 ++++++++++++++
 lib/ubsan.c                                   |  17 +-
 MAINTAINERS                                   |  10 +
 kernel/configs/hardening.config               |   1 -
 tools/testing/selftests/lkdtm/tests.txt       |  10 +
 25 files changed, 807 insertions(+), 58 deletions(-)
 create mode 100644 scripts/Makefile.obt
 create mode 100644 Documentation/process/arithmetic-overflow.rst
Signature · 1 line
2.34.1