forked from torvalds/linux
-
Notifications
You must be signed in to change notification settings - Fork 5
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
Detect unsigned integer wrap-around (overflow and underflow) #27
Labels
Comments
This was referenced Sep 15, 2023
sirlucjan
pushed a commit
to CachyOS/linux
that referenced
this issue
Jan 23, 2024
In an effort to separate intentional arithmetic wrap-around from unexpected wrap-around, we need to refactor places that depend on this kind of math. One of the most common code patterns of this is: VAR + value < VAR Notably, this is considered "undefined behavior" for signed and pointer types, which the kernel works around by using the -fno-strict-overflow option in the build[1] (which used to just be -fwrapv). Regardless, we want to get the kernel source to the position where we can meaningfully instrument arithmetic wrap-around conditions and catch them when they are unexpected, regardless of whether they are signed[2], unsigned[3], or pointer[4] types. Switch to a more regular type for a 64-bit value and refactor the open-coded wrap-around addition test to use subtraction from the type max (since add_would_overflow() may not be defined in early boot code). This paves the way to enabling the wrap-around sanitizers in the future. Link: https://git.kernel.org/linus/68df3755e383e6fecf2354a67b08f92f18536594 [1] Link: KSPP#26 [2] Link: KSPP#27 [3] Link: KSPP#344 [4] Cc: Nick Terrell <terrelln@fb.com> Cc: Paul Jones <paul@pauljones.id.au> Cc: Sedat Dilek <sedat.dilek@gmail.com> Cc: Oleksandr Natalenko <oleksandr@natalenko.name> Cc: Xin Gao <gaoxin@cdjrlc.com> Signed-off-by: Kees Cook <keescook@chromium.org>
sirlucjan
pushed a commit
to CachyOS/linux
that referenced
this issue
Jan 23, 2024
In an effort to separate intentional arithmetic wrap-around from unexpected wrap-around, we need to refactor places that depend on this kind of math. One of the most common code patterns of this is: VAR + value < VAR Notably, this is considered "undefined behavior" for signed and pointer types, which the kernel works around by using the -fno-strict-overflow option in the build[1] (which used to just be -fwrapv). Regardless, we want to get the kernel source to the position where we can meaningfully instrument arithmetic wrap-around conditions and catch them when they are unexpected, regardless of whether they are signed[2], unsigned[3], or pointer[4] types. Switch to a more regular type for a 64-bit value and refactor the open-coded wrap-around addition test to use subtraction from the type max (since add_would_overflow() may not be defined in early boot code). This paves the way to enabling the wrap-around sanitizers in the future. Link: https://git.kernel.org/linus/68df3755e383e6fecf2354a67b08f92f18536594 [1] Link: KSPP#26 [2] Link: KSPP#27 [3] Link: KSPP#344 [4] Cc: Nick Terrell <terrelln@fb.com> Cc: Paul Jones <paul@pauljones.id.au> Cc: Sedat Dilek <sedat.dilek@gmail.com> Cc: Oleksandr Natalenko <oleksandr@natalenko.name> Cc: Xin Gao <gaoxin@cdjrlc.com> Signed-off-by: Kees Cook <keescook@chromium.org>
sirlucjan
pushed a commit
to CachyOS/linux
that referenced
this issue
Jan 23, 2024
In an effort to separate intentional arithmetic wrap-around from unexpected wrap-around, we need to refactor places that depend on this kind of math. One of the most common code patterns of this is: VAR + value < VAR Notably, this is considered "undefined behavior" for signed and pointer types, which the kernel works around by using the -fno-strict-overflow option in the build[1] (which used to just be -fwrapv). Regardless, we want to get the kernel source to the position where we can meaningfully instrument arithmetic wrap-around conditions and catch them when they are unexpected, regardless of whether they are signed[2], unsigned[3], or pointer[4] types. Switch to a more regular type for a 64-bit value and refactor the open-coded wrap-around addition test to use subtraction from the type max (since add_would_overflow() may not be defined in early boot code). This paves the way to enabling the wrap-around sanitizers in the future. Link: https://git.kernel.org/linus/68df3755e383e6fecf2354a67b08f92f18536594 [1] Link: KSPP#26 [2] Link: KSPP#27 [3] Link: KSPP#344 [4] Cc: Nick Terrell <terrelln@fb.com> Cc: Paul Jones <paul@pauljones.id.au> Cc: Sedat Dilek <sedat.dilek@gmail.com> Cc: Oleksandr Natalenko <oleksandr@natalenko.name> Cc: Xin Gao <gaoxin@cdjrlc.com> Signed-off-by: Kees Cook <keescook@chromium.org>
lseman
pushed a commit
to CachyOS/linux
that referenced
this issue
Feb 8, 2024
In an effort to separate intentional arithmetic wrap-around from unexpected wrap-around, we need to refactor places that depend on this kind of math. One of the most common code patterns of this is: VAR + value < VAR Notably, this is considered "undefined behavior" for signed and pointer types, which the kernel works around by using the -fno-strict-overflow option in the build[1] (which used to just be -fwrapv). Regardless, we want to get the kernel source to the position where we can meaningfully instrument arithmetic wrap-around conditions and catch them when they are unexpected, regardless of whether they are signed[2], unsigned[3], or pointer[4] types. Switch to a more regular type for a 64-bit value and refactor the open-coded wrap-around addition test to use subtraction from the type max (since add_would_overflow() may not be defined in early boot code). This paves the way to enabling the wrap-around sanitizers in the future. Link: https://git.kernel.org/linus/68df3755e383e6fecf2354a67b08f92f18536594 [1] Link: KSPP#26 [2] Link: KSPP#27 [3] Link: KSPP#344 [4] Cc: Nick Terrell <terrelln@fb.com> Cc: Paul Jones <paul@pauljones.id.au> Cc: Sedat Dilek <sedat.dilek@gmail.com> Cc: Oleksandr Natalenko <oleksandr@natalenko.name> Cc: Xin Gao <gaoxin@cdjrlc.com> Signed-off-by: Kees Cook <keescook@chromium.org>
ptr1337
pushed a commit
to CachyOS/linux
that referenced
this issue
Mar 25, 2024
In an effort to separate intentional arithmetic wrap-around from unexpected wrap-around, we need to refactor places that depend on this kind of math. One of the most common code patterns of this is: VAR + value < VAR Notably, this is considered "undefined behavior" for signed and pointer types, which the kernel works around by using the -fno-strict-overflow option in the build[1] (which used to just be -fwrapv). Regardless, we want to get the kernel source to the position where we can meaningfully instrument arithmetic wrap-around conditions and catch them when they are unexpected, regardless of whether they are signed[2], unsigned[3], or pointer[4] types. Switch to a more regular type for a 64-bit value and refactor the open-coded wrap-around addition test to use subtraction from the type max (since add_would_overflow() may not be defined in early boot code). This paves the way to enabling the wrap-around sanitizers in the future. Link: https://git.kernel.org/linus/68df3755e383e6fecf2354a67b08f92f18536594 [1] Link: KSPP#26 [2] Link: KSPP#27 [3] Link: KSPP#344 [4] Cc: Nick Terrell <terrelln@fb.com> Cc: Paul Jones <paul@pauljones.id.au> Cc: Sedat Dilek <sedat.dilek@gmail.com> Cc: Oleksandr Natalenko <oleksandr@natalenko.name> Cc: Xin Gao <gaoxin@cdjrlc.com> Signed-off-by: Kees Cook <keescook@chromium.org>
sirlucjan
pushed a commit
to CachyOS/linux
that referenced
this issue
Mar 27, 2024
In an effort to separate intentional arithmetic wrap-around from unexpected wrap-around, we need to refactor places that depend on this kind of math. One of the most common code patterns of this is: VAR + value < VAR Notably, this is considered "undefined behavior" for signed and pointer types, which the kernel works around by using the -fno-strict-overflow option in the build[1] (which used to just be -fwrapv). Regardless, we want to get the kernel source to the position where we can meaningfully instrument arithmetic wrap-around conditions and catch them when they are unexpected, regardless of whether they are signed[2], unsigned[3], or pointer[4] types. Switch to a more regular type for a 64-bit value and refactor the open-coded wrap-around addition test to use subtraction from the type max (since add_would_overflow() may not be defined in early boot code). This paves the way to enabling the wrap-around sanitizers in the future. Link: https://git.kernel.org/linus/68df3755e383e6fecf2354a67b08f92f18536594 [1] Link: KSPP#26 [2] Link: KSPP#27 [3] Link: KSPP#344 [4] Cc: Nick Terrell <terrelln@fb.com> Cc: Paul Jones <paul@pauljones.id.au> Cc: Sedat Dilek <sedat.dilek@gmail.com> Cc: Oleksandr Natalenko <oleksandr@natalenko.name> Cc: Xin Gao <gaoxin@cdjrlc.com> Signed-off-by: Kees Cook <keescook@chromium.org>
sirlucjan
pushed a commit
to CachyOS/linux
that referenced
this issue
Mar 27, 2024
In an effort to separate intentional arithmetic wrap-around from unexpected wrap-around, we need to refactor places that depend on this kind of math. One of the most common code patterns of this is: VAR + value < VAR Notably, this is considered "undefined behavior" for signed and pointer types, which the kernel works around by using the -fno-strict-overflow option in the build[1] (which used to just be -fwrapv). Regardless, we want to get the kernel source to the position where we can meaningfully instrument arithmetic wrap-around conditions and catch them when they are unexpected, regardless of whether they are signed[2], unsigned[3], or pointer[4] types. Switch to a more regular type for a 64-bit value and refactor the open-coded wrap-around addition test to use subtraction from the type max (since add_would_overflow() may not be defined in early boot code). This paves the way to enabling the wrap-around sanitizers in the future. Link: https://git.kernel.org/linus/68df3755e383e6fecf2354a67b08f92f18536594 [1] Link: KSPP#26 [2] Link: KSPP#27 [3] Link: KSPP#344 [4] Cc: Nick Terrell <terrelln@fb.com> Cc: Paul Jones <paul@pauljones.id.au> Cc: Sedat Dilek <sedat.dilek@gmail.com> Cc: Oleksandr Natalenko <oleksandr@natalenko.name> Cc: Xin Gao <gaoxin@cdjrlc.com> Signed-off-by: Kees Cook <keescook@chromium.org>
sirlucjan
pushed a commit
to CachyOS/linux
that referenced
this issue
Mar 27, 2024
In an effort to separate intentional arithmetic wrap-around from unexpected wrap-around, we need to refactor places that depend on this kind of math. One of the most common code patterns of this is: VAR + value < VAR Notably, this is considered "undefined behavior" for signed and pointer types, which the kernel works around by using the -fno-strict-overflow option in the build[1] (which used to just be -fwrapv). Regardless, we want to get the kernel source to the position where we can meaningfully instrument arithmetic wrap-around conditions and catch them when they are unexpected, regardless of whether they are signed[2], unsigned[3], or pointer[4] types. Switch to a more regular type for a 64-bit value and refactor the open-coded wrap-around addition test to use subtraction from the type max (since add_would_overflow() may not be defined in early boot code). This paves the way to enabling the wrap-around sanitizers in the future. Link: https://git.kernel.org/linus/68df3755e383e6fecf2354a67b08f92f18536594 [1] Link: KSPP#26 [2] Link: KSPP#27 [3] Link: KSPP#344 [4] Cc: Nick Terrell <terrelln@fb.com> Cc: Paul Jones <paul@pauljones.id.au> Cc: Sedat Dilek <sedat.dilek@gmail.com> Cc: Oleksandr Natalenko <oleksandr@natalenko.name> Cc: Xin Gao <gaoxin@cdjrlc.com> Signed-off-by: Kees Cook <keescook@chromium.org>
nilz3000
pushed a commit
to nilz3000/pf-linux
that referenced
this issue
Apr 10, 2024
In an effort to separate intentional arithmetic wrap-around from unexpected wrap-around, we need to refactor places that depend on this kind of math. One of the most common code patterns of this is: VAR + value < VAR Notably, this is considered "undefined behavior" for signed and pointer types, which the kernel works around by using the -fno-strict-overflow option in the build[1] (which used to just be -fwrapv). Regardless, we want to get the kernel source to the position where we can meaningfully instrument arithmetic wrap-around conditions and catch them when they are unexpected, regardless of whether they are signed[2], unsigned[3], or pointer[4] types. Switch to a more regular type for a 64-bit value and refactor the open-coded wrap-around addition test to use subtraction from the type max (since add_would_overflow() may not be defined in early boot code). This paves the way to enabling the wrap-around sanitizers in the future. Link: https://git.kernel.org/linus/68df3755e383e6fecf2354a67b08f92f18536594 [1] Link: KSPP/linux#26 [2] Link: KSPP/linux#27 [3] Link: KSPP/linux#344 [4] Cc: Nick Terrell <terrelln@fb.com> Cc: Paul Jones <paul@pauljones.id.au> Cc: Sedat Dilek <sedat.dilek@gmail.com> Cc: Oleksandr Natalenko <oleksandr@natalenko.name> Cc: Xin Gao <gaoxin@cdjrlc.com> Signed-off-by: Kees Cook <keescook@chromium.org>
nilz3000
pushed a commit
to nilz3000/pf-linux
that referenced
this issue
Apr 14, 2024
In an effort to separate intentional arithmetic wrap-around from unexpected wrap-around, we need to refactor places that depend on this kind of math. One of the most common code patterns of this is: VAR + value < VAR Notably, this is considered "undefined behavior" for signed and pointer types, which the kernel works around by using the -fno-strict-overflow option in the build[1] (which used to just be -fwrapv). Regardless, we want to get the kernel source to the position where we can meaningfully instrument arithmetic wrap-around conditions and catch them when they are unexpected, regardless of whether they are signed[2], unsigned[3], or pointer[4] types. Switch to a more regular type for a 64-bit value and refactor the open-coded wrap-around addition test to use subtraction from the type max (since add_would_overflow() may not be defined in early boot code). This paves the way to enabling the wrap-around sanitizers in the future. Link: https://git.kernel.org/linus/68df3755e383e6fecf2354a67b08f92f18536594 [1] Link: KSPP/linux#26 [2] Link: KSPP/linux#27 [3] Link: KSPP/linux#344 [4] Cc: Nick Terrell <terrelln@fb.com> Cc: Paul Jones <paul@pauljones.id.au> Cc: Sedat Dilek <sedat.dilek@gmail.com> Cc: Oleksandr Natalenko <oleksandr@natalenko.name> Cc: Xin Gao <gaoxin@cdjrlc.com> Signed-off-by: Kees Cook <keescook@chromium.org>
ptr1337
pushed a commit
to CachyOS/linux
that referenced
this issue
May 13, 2024
In an effort to separate intentional arithmetic wrap-around from unexpected wrap-around, we need to refactor places that depend on this kind of math. One of the most common code patterns of this is: VAR + value < VAR Notably, this is considered "undefined behavior" for signed and pointer types, which the kernel works around by using the -fno-strict-overflow option in the build[1] (which used to just be -fwrapv). Regardless, we want to get the kernel source to the position where we can meaningfully instrument arithmetic wrap-around conditions and catch them when they are unexpected, regardless of whether they are signed[2], unsigned[3], or pointer[4] types. Switch to a more regular type for a 64-bit value and refactor the open-coded wrap-around addition test to use subtraction from the type max (since add_would_overflow() may not be defined in early boot code). This paves the way to enabling the wrap-around sanitizers in the future. Link: https://git.kernel.org/linus/68df3755e383e6fecf2354a67b08f92f18536594 [1] Link: KSPP#26 [2] Link: KSPP#27 [3] Link: KSPP#344 [4] Cc: Nick Terrell <terrelln@fb.com> Cc: Paul Jones <paul@pauljones.id.au> Cc: Sedat Dilek <sedat.dilek@gmail.com> Cc: Oleksandr Natalenko <oleksandr@natalenko.name> Cc: Xin Gao <gaoxin@cdjrlc.com> Signed-off-by: Kees Cook <keescook@chromium.org>
ptr1337
pushed a commit
to CachyOS/linux
that referenced
this issue
May 26, 2024
In an effort to separate intentional arithmetic wrap-around from unexpected wrap-around, we need to refactor places that depend on this kind of math. One of the most common code patterns of this is: VAR + value < VAR Notably, this is considered "undefined behavior" for signed and pointer types, which the kernel works around by using the -fno-strict-overflow option in the build[1] (which used to just be -fwrapv). Regardless, we want to get the kernel source to the position where we can meaningfully instrument arithmetic wrap-around conditions and catch them when they are unexpected, regardless of whether they are signed[2], unsigned[3], or pointer[4] types. Switch to a more regular type for a 64-bit value and refactor the open-coded wrap-around addition test to use subtraction from the type max (since add_would_overflow() may not be defined in early boot code). This paves the way to enabling the wrap-around sanitizers in the future. Link: https://git.kernel.org/linus/68df3755e383e6fecf2354a67b08f92f18536594 [1] Link: KSPP#26 [2] Link: KSPP#27 [3] Link: KSPP#344 [4] Cc: Nick Terrell <terrelln@fb.com> Cc: Paul Jones <paul@pauljones.id.au> Cc: Sedat Dilek <sedat.dilek@gmail.com> Cc: Oleksandr Natalenko <oleksandr@natalenko.name> Cc: Xin Gao <gaoxin@cdjrlc.com> Signed-off-by: Kees Cook <keescook@chromium.org>
ptr1337
pushed a commit
to CachyOS/linux
that referenced
this issue
Jul 28, 2024
In an effort to separate intentional arithmetic wrap-around from unexpected wrap-around, we need to refactor places that depend on this kind of math. One of the most common code patterns of this is: VAR + value < VAR Notably, this is considered "undefined behavior" for signed and pointer types, which the kernel works around by using the -fno-strict-overflow option in the build[1] (which used to just be -fwrapv). Regardless, we want to get the kernel source to the position where we can meaningfully instrument arithmetic wrap-around conditions and catch them when they are unexpected, regardless of whether they are signed[2], unsigned[3], or pointer[4] types. Switch to a more regular type for a 64-bit value and refactor the open-coded wrap-around addition test to use subtraction from the type max (since add_would_overflow() may not be defined in early boot code). This paves the way to enabling the wrap-around sanitizers in the future. Link: https://git.kernel.org/linus/68df3755e383e6fecf2354a67b08f92f18536594 [1] Link: KSPP#26 [2] Link: KSPP#27 [3] Link: KSPP#344 [4] Cc: Nick Terrell <terrelln@fb.com> Cc: Paul Jones <paul@pauljones.id.au> Cc: Sedat Dilek <sedat.dilek@gmail.com> Cc: Oleksandr Natalenko <oleksandr@natalenko.name> Cc: Xin Gao <gaoxin@cdjrlc.com> Signed-off-by: Kees Cook <keescook@chromium.org>
ptr1337
pushed a commit
to CachyOS/linux
that referenced
this issue
Sep 27, 2024
In an effort to separate intentional arithmetic wrap-around from unexpected wrap-around, we need to refactor places that depend on this kind of math. One of the most common code patterns of this is: VAR + value < VAR Notably, this is considered "undefined behavior" for signed and pointer types, which the kernel works around by using the -fno-strict-overflow option in the build[1] (which used to just be -fwrapv). Regardless, we want to get the kernel source to the position where we can meaningfully instrument arithmetic wrap-around conditions and catch them when they are unexpected, regardless of whether they are signed[2], unsigned[3], or pointer[4] types. Switch to a more regular type for a 64-bit value and refactor the open-coded wrap-around addition test to use subtraction from the type max (since add_would_overflow() may not be defined in early boot code). This paves the way to enabling the wrap-around sanitizers in the future. Link: https://git.kernel.org/linus/68df3755e383e6fecf2354a67b08f92f18536594 [1] Link: KSPP#26 [2] Link: KSPP#27 [3] Link: KSPP#344 [4] Cc: Nick Terrell <terrelln@fb.com> Cc: Paul Jones <paul@pauljones.id.au> Cc: Sedat Dilek <sedat.dilek@gmail.com> Cc: Oleksandr Natalenko <oleksandr@natalenko.name> Cc: Xin Gao <gaoxin@cdjrlc.com> Signed-off-by: Kees Cook <keescook@chromium.org>
ptr1337
pushed a commit
to CachyOS/linux
that referenced
this issue
Sep 30, 2024
In an effort to separate intentional arithmetic wrap-around from unexpected wrap-around, we need to refactor places that depend on this kind of math. One of the most common code patterns of this is: VAR + value < VAR Notably, this is considered "undefined behavior" for signed and pointer types, which the kernel works around by using the -fno-strict-overflow option in the build[1] (which used to just be -fwrapv). Regardless, we want to get the kernel source to the position where we can meaningfully instrument arithmetic wrap-around conditions and catch them when they are unexpected, regardless of whether they are signed[2], unsigned[3], or pointer[4] types. Switch to a more regular type for a 64-bit value and refactor the open-coded wrap-around addition test to use subtraction from the type max (since add_would_overflow() may not be defined in early boot code). This paves the way to enabling the wrap-around sanitizers in the future. Link: https://git.kernel.org/linus/68df3755e383e6fecf2354a67b08f92f18536594 [1] Link: KSPP#26 [2] Link: KSPP#27 [3] Link: KSPP#344 [4] Cc: Nick Terrell <terrelln@fb.com> Cc: Paul Jones <paul@pauljones.id.au> Cc: Sedat Dilek <sedat.dilek@gmail.com> Cc: Oleksandr Natalenko <oleksandr@natalenko.name> Cc: Xin Gao <gaoxin@cdjrlc.com> Signed-off-by: Kees Cook <keescook@chromium.org>
hellsgod
pushed a commit
to hellsgod/linux
that referenced
this issue
Nov 26, 2024
In an effort to separate intentional arithmetic wrap-around from unexpected wrap-around, we need to refactor places that depend on this kind of math. One of the most common code patterns of this is: VAR + value < VAR Notably, this is considered "undefined behavior" for signed and pointer types, which the kernel works around by using the -fno-strict-overflow option in the build[1] (which used to just be -fwrapv). Regardless, we want to get the kernel source to the position where we can meaningfully instrument arithmetic wrap-around conditions and catch them when they are unexpected, regardless of whether they are signed[2], unsigned[3], or pointer[4] types. Switch to a more regular type for a 64-bit value and refactor the open-coded wrap-around addition test to use subtraction from the type max (since add_would_overflow() may not be defined in early boot code). This paves the way to enabling the wrap-around sanitizers in the future. Link: https://git.kernel.org/linus/68df3755e383e6fecf2354a67b08f92f18536594 [1] Link: KSPP#26 [2] Link: KSPP#27 [3] Link: KSPP#344 [4] Cc: Nick Terrell <terrelln@fb.com> Cc: Paul Jones <paul@pauljones.id.au> Cc: Sedat Dilek <sedat.dilek@gmail.com> Cc: Oleksandr Natalenko <oleksandr@natalenko.name> Cc: Xin Gao <gaoxin@cdjrlc.com> Signed-off-by: Kees Cook <keescook@chromium.org>
ptr1337
pushed a commit
to CachyOS/linux
that referenced
this issue
Nov 30, 2024
In an effort to separate intentional arithmetic wrap-around from unexpected wrap-around, we need to refactor places that depend on this kind of math. One of the most common code patterns of this is: VAR + value < VAR Notably, this is considered "undefined behavior" for signed and pointer types, which the kernel works around by using the -fno-strict-overflow option in the build[1] (which used to just be -fwrapv). Regardless, we want to get the kernel source to the position where we can meaningfully instrument arithmetic wrap-around conditions and catch them when they are unexpected, regardless of whether they are signed[2], unsigned[3], or pointer[4] types. Switch to a more regular type for a 64-bit value and refactor the open-coded wrap-around addition test to use subtraction from the type max (since add_would_overflow() may not be defined in early boot code). This paves the way to enabling the wrap-around sanitizers in the future. Link: https://git.kernel.org/linus/68df3755e383e6fecf2354a67b08f92f18536594 [1] Link: KSPP#26 [2] Link: KSPP#27 [3] Link: KSPP#344 [4] Cc: Nick Terrell <terrelln@fb.com> Cc: Paul Jones <paul@pauljones.id.au> Cc: Sedat Dilek <sedat.dilek@gmail.com> Cc: Oleksandr Natalenko <oleksandr@natalenko.name> Cc: Xin Gao <gaoxin@cdjrlc.com> Signed-off-by: Kees Cook <keescook@chromium.org>
intelfx
pushed a commit
to intelfx/linux
that referenced
this issue
Dec 4, 2024
In an effort to separate intentional arithmetic wrap-around from unexpected wrap-around, we need to refactor places that depend on this kind of math. One of the most common code patterns of this is: VAR + value < VAR Notably, this is considered "undefined behavior" for signed and pointer types, which the kernel works around by using the -fno-strict-overflow option in the build[1] (which used to just be -fwrapv). Regardless, we want to get the kernel source to the position where we can meaningfully instrument arithmetic wrap-around conditions and catch them when they are unexpected, regardless of whether they are signed[2], unsigned[3], or pointer[4] types. Switch to a more regular type for a 64-bit value and refactor the open-coded wrap-around addition test to use subtraction from the type max (since add_would_overflow() may not be defined in early boot code). This paves the way to enabling the wrap-around sanitizers in the future. Link: https://git.kernel.org/linus/68df3755e383e6fecf2354a67b08f92f18536594 [1] Link: KSPP#26 [2] Link: KSPP#27 [3] Link: KSPP#344 [4] Cc: Nick Terrell <terrelln@fb.com> Cc: Paul Jones <paul@pauljones.id.au> Cc: Sedat Dilek <sedat.dilek@gmail.com> Cc: Oleksandr Natalenko <oleksandr@natalenko.name> Cc: Xin Gao <gaoxin@cdjrlc.com> Signed-off-by: Kees Cook <keescook@chromium.org>
hellsgod
pushed a commit
to hellsgod/linux
that referenced
this issue
Dec 30, 2024
In an effort to separate intentional arithmetic wrap-around from unexpected wrap-around, we need to refactor places that depend on this kind of math. One of the most common code patterns of this is: VAR + value < VAR Notably, this is considered "undefined behavior" for signed and pointer types, which the kernel works around by using the -fno-strict-overflow option in the build[1] (which used to just be -fwrapv). Regardless, we want to get the kernel source to the position where we can meaningfully instrument arithmetic wrap-around conditions and catch them when they are unexpected, regardless of whether they are signed[2], unsigned[3], or pointer[4] types. Switch to a more regular type for a 64-bit value and refactor the open-coded wrap-around addition test to use subtraction from the type max (since add_would_overflow() may not be defined in early boot code). This paves the way to enabling the wrap-around sanitizers in the future. Link: https://git.kernel.org/linus/68df3755e383e6fecf2354a67b08f92f18536594 [1] Link: KSPP#26 [2] Link: KSPP#27 [3] Link: KSPP#344 [4] Cc: Nick Terrell <terrelln@fb.com> Cc: Paul Jones <paul@pauljones.id.au> Cc: Sedat Dilek <sedat.dilek@gmail.com> Cc: Oleksandr Natalenko <oleksandr@natalenko.name> Cc: Xin Gao <gaoxin@cdjrlc.com> Signed-off-by: Kees Cook <keescook@chromium.org>
1Naim
pushed a commit
to CachyOS/linux
that referenced
this issue
Feb 3, 2025
In an effort to separate intentional arithmetic wrap-around from unexpected wrap-around, we need to refactor places that depend on this kind of math. One of the most common code patterns of this is: VAR + value < VAR Notably, this is considered "undefined behavior" for signed and pointer types, which the kernel works around by using the -fno-strict-overflow option in the build[1] (which used to just be -fwrapv). Regardless, we want to get the kernel source to the position where we can meaningfully instrument arithmetic wrap-around conditions and catch them when they are unexpected, regardless of whether they are signed[2], unsigned[3], or pointer[4] types. Switch to a more regular type for a 64-bit value and refactor the open-coded wrap-around addition test to use subtraction from the type max (since add_would_overflow() may not be defined in early boot code). This paves the way to enabling the wrap-around sanitizers in the future. Link: https://git.kernel.org/linus/68df3755e383e6fecf2354a67b08f92f18536594 [1] Link: KSPP#26 [2] Link: KSPP#27 [3] Link: KSPP#344 [4] Cc: Nick Terrell <terrelln@fb.com> Cc: Paul Jones <paul@pauljones.id.au> Cc: Sedat Dilek <sedat.dilek@gmail.com> Cc: Oleksandr Natalenko <oleksandr@natalenko.name> Cc: Xin Gao <gaoxin@cdjrlc.com> Signed-off-by: Kees Cook <keescook@chromium.org>
hellsgod
pushed a commit
to hellsgod/linux
that referenced
this issue
Feb 5, 2025
In an effort to separate intentional arithmetic wrap-around from unexpected wrap-around, we need to refactor places that depend on this kind of math. One of the most common code patterns of this is: VAR + value < VAR Notably, this is considered "undefined behavior" for signed and pointer types, which the kernel works around by using the -fno-strict-overflow option in the build[1] (which used to just be -fwrapv). Regardless, we want to get the kernel source to the position where we can meaningfully instrument arithmetic wrap-around conditions and catch them when they are unexpected, regardless of whether they are signed[2], unsigned[3], or pointer[4] types. Switch to a more regular type for a 64-bit value and refactor the open-coded wrap-around addition test to use subtraction from the type max (since add_would_overflow() may not be defined in early boot code). This paves the way to enabling the wrap-around sanitizers in the future. Link: https://git.kernel.org/linus/68df3755e383e6fecf2354a67b08f92f18536594 [1] Link: KSPP#26 [2] Link: KSPP#27 [3] Link: KSPP#344 [4] Cc: Nick Terrell <terrelln@fb.com> Cc: Paul Jones <paul@pauljones.id.au> Cc: Sedat Dilek <sedat.dilek@gmail.com> Cc: Oleksandr Natalenko <oleksandr@natalenko.name> Cc: Xin Gao <gaoxin@cdjrlc.com> Signed-off-by: Kees Cook <keescook@chromium.org>
1Naim
pushed a commit
to CachyOS/linux
that referenced
this issue
Feb 20, 2025
In an effort to separate intentional arithmetic wrap-around from unexpected wrap-around, we need to refactor places that depend on this kind of math. One of the most common code patterns of this is: VAR + value < VAR Notably, this is considered "undefined behavior" for signed and pointer types, which the kernel works around by using the -fno-strict-overflow option in the build[1] (which used to just be -fwrapv). Regardless, we want to get the kernel source to the position where we can meaningfully instrument arithmetic wrap-around conditions and catch them when they are unexpected, regardless of whether they are signed[2], unsigned[3], or pointer[4] types. Switch to a more regular type for a 64-bit value and refactor the open-coded wrap-around addition test to use subtraction from the type max (since add_would_overflow() may not be defined in early boot code). This paves the way to enabling the wrap-around sanitizers in the future. Link: https://git.kernel.org/linus/68df3755e383e6fecf2354a67b08f92f18536594 [1] Link: KSPP#26 [2] Link: KSPP#27 [3] Link: KSPP#344 [4] Cc: Nick Terrell <terrelln@fb.com> Cc: Paul Jones <paul@pauljones.id.au> Cc: Sedat Dilek <sedat.dilek@gmail.com> Cc: Oleksandr Natalenko <oleksandr@natalenko.name> Cc: Xin Gao <gaoxin@cdjrlc.com> Signed-off-by: Kees Cook <keescook@chromium.org>
sirlucjan
pushed a commit
to CachyOS/linux
that referenced
this issue
Feb 20, 2025
In an effort to separate intentional arithmetic wrap-around from unexpected wrap-around, we need to refactor places that depend on this kind of math. One of the most common code patterns of this is: VAR + value < VAR Notably, this is considered "undefined behavior" for signed and pointer types, which the kernel works around by using the -fno-strict-overflow option in the build[1] (which used to just be -fwrapv). Regardless, we want to get the kernel source to the position where we can meaningfully instrument arithmetic wrap-around conditions and catch them when they are unexpected, regardless of whether they are signed[2], unsigned[3], or pointer[4] types. Switch to a more regular type for a 64-bit value and refactor the open-coded wrap-around addition test to use subtraction from the type max (since add_would_overflow() may not be defined in early boot code). This paves the way to enabling the wrap-around sanitizers in the future. Link: https://git.kernel.org/linus/68df3755e383e6fecf2354a67b08f92f18536594 [1] Link: KSPP#26 [2] Link: KSPP#27 [3] Link: KSPP#344 [4] Cc: Nick Terrell <terrelln@fb.com> Cc: Paul Jones <paul@pauljones.id.au> Cc: Sedat Dilek <sedat.dilek@gmail.com> Cc: Oleksandr Natalenko <oleksandr@natalenko.name> Cc: Xin Gao <gaoxin@cdjrlc.com> Signed-off-by: Kees Cook <keescook@chromium.org>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is nearly identical to issue #26, except that it is for unsigned wrap around (i.e. overflow and underflow). This is a distinct problem, though, because GCC's Undefined Behavior Sanitizer (UBSan) does not support the unsigned overflow checker (it is only present in Clang). Additionally, there are many more cases of intentional wrap (especially with pointer values), so it will be more work for find and mark each of these true positives.
To avoid Undefined Behavior, the kernel must keep
-fno-strict-overflow
.So, things to do:
-fno-strict-overflow
.__attribute__((no_sanitize("unsigned-integer-overflow")))
..The text was updated successfully, but these errors were encountered: