]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/commitdiff
5.10-stable patches
authorGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 13 Sep 2025 11:45:29 +0000 (13:45 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 13 Sep 2025 11:45:29 +0000 (13:45 +0200)
added patches:
compiler.h-drop-fallback-overflow-checkers.patch
overflow-allow-mixed-type-arguments.patch
overflow-correct-check_shl_overflow-comment.patch

queue-5.10/compiler.h-drop-fallback-overflow-checkers.patch [new file with mode: 0644]
queue-5.10/overflow-allow-mixed-type-arguments.patch [new file with mode: 0644]
queue-5.10/overflow-correct-check_shl_overflow-comment.patch [new file with mode: 0644]
queue-5.10/series

diff --git a/queue-5.10/compiler.h-drop-fallback-overflow-checkers.patch b/queue-5.10/compiler.h-drop-fallback-overflow-checkers.patch
new file mode 100644 (file)
index 0000000..ee07f91
--- /dev/null
@@ -0,0 +1,403 @@
+From stable+bounces-179393-greg=kroah.com@vger.kernel.org Fri Sep 12 20:56:41 2025
+From: Eliav Farber <farbere@amazon.com>
+Date: Fri, 12 Sep 2025 18:55:14 +0000
+Subject: compiler.h: drop fallback overflow checkers
+To: <luc.vanoostenryck@gmail.com>, <rostedt@goodmis.org>, <mingo@redhat.com>, <natechancellor@gmail.com>, <ndesaulniers@google.com>, <keescook@chromium.org>, <sashal@kernel.org>, <akpm@linux-foundation.org>, <ojeda@kernel.org>, <elver@google.com>, <gregkh@linuxfoundation.org>, <kbusch@kernel.org>, <sj@kernel.org>, <bvanassche@acm.org>, <leon@kernel.org>, <jgg@ziepe.ca>, <linux-kernel@vger.kernel.org>, <linux-sparse@vger.kernel.org>, <clang-built-linux@googlegroups.com>, <stable@vger.kernel.org>
+Cc: <jonnyc@amazon.com>, <farbere@amazon.com>, Rasmus Villemoes <linux@rasmusvillemoes.dk>, Nathan Chancellor <nathan@kernel.org>
+Message-ID: <20250912185518.39980-3-farbere@amazon.com>
+
+From: Nick Desaulniers <ndesaulniers@google.com>
+
+[ Upstream commit 4eb6bd55cfb22ffc20652732340c4962f3ac9a91 ]
+
+Once upgrading the minimum supported version of GCC to 5.1, we can drop
+the fallback code for !COMPILER_HAS_GENERIC_BUILTIN_OVERFLOW.
+
+This is effectively a revert of commit f0907827a8a9 ("compiler.h: enable
+builtin overflow checkers and add fallback code")
+
+Link: https://github.com/ClangBuiltLinux/linux/issues/1438#issuecomment-916745801
+Suggested-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
+Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
+Acked-by: Kees Cook <keescook@chromium.org>
+Reviewed-by: Nathan Chancellor <nathan@kernel.org>
+Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
+Signed-off-by: Eliav Farber <farbere@amazon.com>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ include/linux/compiler-clang.h     |   13 ---
+ include/linux/compiler-gcc.h       |    4 -
+ include/linux/overflow.h           |  138 ------------------------------------
+ tools/include/linux/compiler-gcc.h |    4 -
+ tools/include/linux/overflow.h     |  140 -------------------------------------
+ 5 files changed, 6 insertions(+), 293 deletions(-)
+
+--- a/include/linux/compiler-clang.h
++++ b/include/linux/compiler-clang.h
+@@ -72,19 +72,6 @@
+ #define __no_sanitize_coverage
+ #endif
+-/*
+- * Not all versions of clang implement the type-generic versions
+- * of the builtin overflow checkers. Fortunately, clang implements
+- * __has_builtin allowing us to avoid awkward version
+- * checks. Unfortunately, we don't know which version of gcc clang
+- * pretends to be, so the macro may or may not be defined.
+- */
+-#if __has_builtin(__builtin_mul_overflow) && \
+-    __has_builtin(__builtin_add_overflow) && \
+-    __has_builtin(__builtin_sub_overflow)
+-#define COMPILER_HAS_GENERIC_BUILTIN_OVERFLOW 1
+-#endif
+-
+ #if __has_feature(shadow_call_stack)
+ # define __noscs      __attribute__((__no_sanitize__("shadow-call-stack")))
+ #endif
+--- a/include/linux/compiler-gcc.h
++++ b/include/linux/compiler-gcc.h
+@@ -140,10 +140,6 @@
+ #define __no_sanitize_coverage
+ #endif
+-#if GCC_VERSION >= 50100
+-#define COMPILER_HAS_GENERIC_BUILTIN_OVERFLOW 1
+-#endif
+-
+ /*
+  * Turn individual warnings and errors on and off locally, depending
+  * on version.
+--- a/include/linux/overflow.h
++++ b/include/linux/overflow.h
+@@ -6,12 +6,9 @@
+ #include <linux/limits.h>
+ /*
+- * In the fallback code below, we need to compute the minimum and
+- * maximum values representable in a given type. These macros may also
+- * be useful elsewhere, so we provide them outside the
+- * COMPILER_HAS_GENERIC_BUILTIN_OVERFLOW block.
+- *
+- * It would seem more obvious to do something like
++ * We need to compute the minimum and maximum values representable in a given
++ * type. These macros may also be useful elsewhere. It would seem more obvious
++ * to do something like:
+  *
+  * #define type_min(T) (T)(is_signed_type(T) ? (T)1 << (8*sizeof(T)-1) : 0)
+  * #define type_max(T) (T)(is_signed_type(T) ? ((T)1 << (8*sizeof(T)-1)) - 1 : ~(T)0)
+@@ -54,7 +51,6 @@ static inline bool __must_check __must_c
+       return unlikely(overflow);
+ }
+-#ifdef COMPILER_HAS_GENERIC_BUILTIN_OVERFLOW
+ /*
+  * For simplicity and code hygiene, the fallback code below insists on
+  * a, b and *d having the same type (similar to the min() and max()
+@@ -90,134 +86,6 @@ static inline bool __must_check __must_c
+       __builtin_mul_overflow(__a, __b, __d);  \
+ }))
+-#else
+-
+-
+-/* Checking for unsigned overflow is relatively easy without causing UB. */
+-#define __unsigned_add_overflow(a, b, d) ({   \
+-      typeof(a) __a = (a);                    \
+-      typeof(b) __b = (b);                    \
+-      typeof(d) __d = (d);                    \
+-      (void) (&__a == &__b);                  \
+-      (void) (&__a == __d);                   \
+-      *__d = __a + __b;                       \
+-      *__d < __a;                             \
+-})
+-#define __unsigned_sub_overflow(a, b, d) ({   \
+-      typeof(a) __a = (a);                    \
+-      typeof(b) __b = (b);                    \
+-      typeof(d) __d = (d);                    \
+-      (void) (&__a == &__b);                  \
+-      (void) (&__a == __d);                   \
+-      *__d = __a - __b;                       \
+-      __a < __b;                              \
+-})
+-/*
+- * If one of a or b is a compile-time constant, this avoids a division.
+- */
+-#define __unsigned_mul_overflow(a, b, d) ({           \
+-      typeof(a) __a = (a);                            \
+-      typeof(b) __b = (b);                            \
+-      typeof(d) __d = (d);                            \
+-      (void) (&__a == &__b);                          \
+-      (void) (&__a == __d);                           \
+-      *__d = __a * __b;                               \
+-      __builtin_constant_p(__b) ?                     \
+-        __b > 0 && __a > type_max(typeof(__a)) / __b : \
+-        __a > 0 && __b > type_max(typeof(__b)) / __a;  \
+-})
+-
+-/*
+- * For signed types, detecting overflow is much harder, especially if
+- * we want to avoid UB. But the interface of these macros is such that
+- * we must provide a result in *d, and in fact we must produce the
+- * result promised by gcc's builtins, which is simply the possibly
+- * wrapped-around value. Fortunately, we can just formally do the
+- * operations in the widest relevant unsigned type (u64) and then
+- * truncate the result - gcc is smart enough to generate the same code
+- * with and without the (u64) casts.
+- */
+-
+-/*
+- * Adding two signed integers can overflow only if they have the same
+- * sign, and overflow has happened iff the result has the opposite
+- * sign.
+- */
+-#define __signed_add_overflow(a, b, d) ({     \
+-      typeof(a) __a = (a);                    \
+-      typeof(b) __b = (b);                    \
+-      typeof(d) __d = (d);                    \
+-      (void) (&__a == &__b);                  \
+-      (void) (&__a == __d);                   \
+-      *__d = (u64)__a + (u64)__b;             \
+-      (((~(__a ^ __b)) & (*__d ^ __a))        \
+-              & type_min(typeof(__a))) != 0;  \
+-})
+-
+-/*
+- * Subtraction is similar, except that overflow can now happen only
+- * when the signs are opposite. In this case, overflow has happened if
+- * the result has the opposite sign of a.
+- */
+-#define __signed_sub_overflow(a, b, d) ({     \
+-      typeof(a) __a = (a);                    \
+-      typeof(b) __b = (b);                    \
+-      typeof(d) __d = (d);                    \
+-      (void) (&__a == &__b);                  \
+-      (void) (&__a == __d);                   \
+-      *__d = (u64)__a - (u64)__b;             \
+-      ((((__a ^ __b)) & (*__d ^ __a))         \
+-              & type_min(typeof(__a))) != 0;  \
+-})
+-
+-/*
+- * Signed multiplication is rather hard. gcc always follows C99, so
+- * division is truncated towards 0. This means that we can write the
+- * overflow check like this:
+- *
+- * (a > 0 && (b > MAX/a || b < MIN/a)) ||
+- * (a < -1 && (b > MIN/a || b < MAX/a) ||
+- * (a == -1 && b == MIN)
+- *
+- * The redundant casts of -1 are to silence an annoying -Wtype-limits
+- * (included in -Wextra) warning: When the type is u8 or u16, the
+- * __b_c_e in check_mul_overflow obviously selects
+- * __unsigned_mul_overflow, but unfortunately gcc still parses this
+- * code and warns about the limited range of __b.
+- */
+-
+-#define __signed_mul_overflow(a, b, d) ({                             \
+-      typeof(a) __a = (a);                                            \
+-      typeof(b) __b = (b);                                            \
+-      typeof(d) __d = (d);                                            \
+-      typeof(a) __tmax = type_max(typeof(a));                         \
+-      typeof(a) __tmin = type_min(typeof(a));                         \
+-      (void) (&__a == &__b);                                          \
+-      (void) (&__a == __d);                                           \
+-      *__d = (u64)__a * (u64)__b;                                     \
+-      (__b > 0   && (__a > __tmax/__b || __a < __tmin/__b)) ||        \
+-      (__b < (typeof(__b))-1  && (__a > __tmin/__b || __a < __tmax/__b)) || \
+-      (__b == (typeof(__b))-1 && __a == __tmin);                      \
+-})
+-
+-
+-#define check_add_overflow(a, b, d)   __must_check_overflow(          \
+-      __builtin_choose_expr(is_signed_type(typeof(a)),                \
+-                      __signed_add_overflow(a, b, d),                 \
+-                      __unsigned_add_overflow(a, b, d)))
+-
+-#define check_sub_overflow(a, b, d)   __must_check_overflow(          \
+-      __builtin_choose_expr(is_signed_type(typeof(a)),                \
+-                      __signed_sub_overflow(a, b, d),                 \
+-                      __unsigned_sub_overflow(a, b, d)))
+-
+-#define check_mul_overflow(a, b, d)   __must_check_overflow(          \
+-      __builtin_choose_expr(is_signed_type(typeof(a)),                \
+-                      __signed_mul_overflow(a, b, d),                 \
+-                      __unsigned_mul_overflow(a, b, d)))
+-
+-#endif /* COMPILER_HAS_GENERIC_BUILTIN_OVERFLOW */
+-
+ /** check_shl_overflow() - Calculate a left-shifted value and check overflow
+  *
+  * @a: Value to be shifted
+--- a/tools/include/linux/compiler-gcc.h
++++ b/tools/include/linux/compiler-gcc.h
+@@ -38,7 +38,3 @@
+ #endif
+ #define __printf(a, b)        __attribute__((format(printf, a, b)))
+ #define __scanf(a, b) __attribute__((format(scanf, a, b)))
+-
+-#if GCC_VERSION >= 50100
+-#define COMPILER_HAS_GENERIC_BUILTIN_OVERFLOW 1
+-#endif
+--- a/tools/include/linux/overflow.h
++++ b/tools/include/linux/overflow.h
+@@ -5,12 +5,9 @@
+ #include <linux/compiler.h>
+ /*
+- * In the fallback code below, we need to compute the minimum and
+- * maximum values representable in a given type. These macros may also
+- * be useful elsewhere, so we provide them outside the
+- * COMPILER_HAS_GENERIC_BUILTIN_OVERFLOW block.
+- *
+- * It would seem more obvious to do something like
++ * We need to compute the minimum and maximum values representable in a given
++ * type. These macros may also be useful elsewhere. It would seem more obvious
++ * to do something like:
+  *
+  * #define type_min(T) (T)(is_signed_type(T) ? (T)1 << (8*sizeof(T)-1) : 0)
+  * #define type_max(T) (T)(is_signed_type(T) ? ((T)1 << (8*sizeof(T)-1)) - 1 : ~(T)0)
+@@ -36,8 +33,6 @@
+ #define type_max(T) ((T)((__type_half_max(T) - 1) + __type_half_max(T)))
+ #define type_min(T) ((T)((T)-type_max(T)-(T)1))
+-
+-#ifdef COMPILER_HAS_GENERIC_BUILTIN_OVERFLOW
+ /*
+  * For simplicity and code hygiene, the fallback code below insists on
+  * a, b and *d having the same type (similar to the min() and max()
+@@ -73,135 +68,6 @@
+       __builtin_mul_overflow(__a, __b, __d);  \
+ })
+-#else
+-
+-
+-/* Checking for unsigned overflow is relatively easy without causing UB. */
+-#define __unsigned_add_overflow(a, b, d) ({   \
+-      typeof(a) __a = (a);                    \
+-      typeof(b) __b = (b);                    \
+-      typeof(d) __d = (d);                    \
+-      (void) (&__a == &__b);                  \
+-      (void) (&__a == __d);                   \
+-      *__d = __a + __b;                       \
+-      *__d < __a;                             \
+-})
+-#define __unsigned_sub_overflow(a, b, d) ({   \
+-      typeof(a) __a = (a);                    \
+-      typeof(b) __b = (b);                    \
+-      typeof(d) __d = (d);                    \
+-      (void) (&__a == &__b);                  \
+-      (void) (&__a == __d);                   \
+-      *__d = __a - __b;                       \
+-      __a < __b;                              \
+-})
+-/*
+- * If one of a or b is a compile-time constant, this avoids a division.
+- */
+-#define __unsigned_mul_overflow(a, b, d) ({           \
+-      typeof(a) __a = (a);                            \
+-      typeof(b) __b = (b);                            \
+-      typeof(d) __d = (d);                            \
+-      (void) (&__a == &__b);                          \
+-      (void) (&__a == __d);                           \
+-      *__d = __a * __b;                               \
+-      __builtin_constant_p(__b) ?                     \
+-        __b > 0 && __a > type_max(typeof(__a)) / __b : \
+-        __a > 0 && __b > type_max(typeof(__b)) / __a;  \
+-})
+-
+-/*
+- * For signed types, detecting overflow is much harder, especially if
+- * we want to avoid UB. But the interface of these macros is such that
+- * we must provide a result in *d, and in fact we must produce the
+- * result promised by gcc's builtins, which is simply the possibly
+- * wrapped-around value. Fortunately, we can just formally do the
+- * operations in the widest relevant unsigned type (u64) and then
+- * truncate the result - gcc is smart enough to generate the same code
+- * with and without the (u64) casts.
+- */
+-
+-/*
+- * Adding two signed integers can overflow only if they have the same
+- * sign, and overflow has happened iff the result has the opposite
+- * sign.
+- */
+-#define __signed_add_overflow(a, b, d) ({     \
+-      typeof(a) __a = (a);                    \
+-      typeof(b) __b = (b);                    \
+-      typeof(d) __d = (d);                    \
+-      (void) (&__a == &__b);                  \
+-      (void) (&__a == __d);                   \
+-      *__d = (u64)__a + (u64)__b;             \
+-      (((~(__a ^ __b)) & (*__d ^ __a))        \
+-              & type_min(typeof(__a))) != 0;  \
+-})
+-
+-/*
+- * Subtraction is similar, except that overflow can now happen only
+- * when the signs are opposite. In this case, overflow has happened if
+- * the result has the opposite sign of a.
+- */
+-#define __signed_sub_overflow(a, b, d) ({     \
+-      typeof(a) __a = (a);                    \
+-      typeof(b) __b = (b);                    \
+-      typeof(d) __d = (d);                    \
+-      (void) (&__a == &__b);                  \
+-      (void) (&__a == __d);                   \
+-      *__d = (u64)__a - (u64)__b;             \
+-      ((((__a ^ __b)) & (*__d ^ __a))         \
+-              & type_min(typeof(__a))) != 0;  \
+-})
+-
+-/*
+- * Signed multiplication is rather hard. gcc always follows C99, so
+- * division is truncated towards 0. This means that we can write the
+- * overflow check like this:
+- *
+- * (a > 0 && (b > MAX/a || b < MIN/a)) ||
+- * (a < -1 && (b > MIN/a || b < MAX/a) ||
+- * (a == -1 && b == MIN)
+- *
+- * The redundant casts of -1 are to silence an annoying -Wtype-limits
+- * (included in -Wextra) warning: When the type is u8 or u16, the
+- * __b_c_e in check_mul_overflow obviously selects
+- * __unsigned_mul_overflow, but unfortunately gcc still parses this
+- * code and warns about the limited range of __b.
+- */
+-
+-#define __signed_mul_overflow(a, b, d) ({                             \
+-      typeof(a) __a = (a);                                            \
+-      typeof(b) __b = (b);                                            \
+-      typeof(d) __d = (d);                                            \
+-      typeof(a) __tmax = type_max(typeof(a));                         \
+-      typeof(a) __tmin = type_min(typeof(a));                         \
+-      (void) (&__a == &__b);                                          \
+-      (void) (&__a == __d);                                           \
+-      *__d = (u64)__a * (u64)__b;                                     \
+-      (__b > 0   && (__a > __tmax/__b || __a < __tmin/__b)) ||        \
+-      (__b < (typeof(__b))-1  && (__a > __tmin/__b || __a < __tmax/__b)) || \
+-      (__b == (typeof(__b))-1 && __a == __tmin);                      \
+-})
+-
+-
+-#define check_add_overflow(a, b, d)                                   \
+-      __builtin_choose_expr(is_signed_type(typeof(a)),                \
+-                      __signed_add_overflow(a, b, d),                 \
+-                      __unsigned_add_overflow(a, b, d))
+-
+-#define check_sub_overflow(a, b, d)                                   \
+-      __builtin_choose_expr(is_signed_type(typeof(a)),                \
+-                      __signed_sub_overflow(a, b, d),                 \
+-                      __unsigned_sub_overflow(a, b, d))
+-
+-#define check_mul_overflow(a, b, d)                                   \
+-      __builtin_choose_expr(is_signed_type(typeof(a)),                \
+-                      __signed_mul_overflow(a, b, d),                 \
+-                      __unsigned_mul_overflow(a, b, d))
+-
+-
+-#endif /* COMPILER_HAS_GENERIC_BUILTIN_OVERFLOW */
+-
+ /**
+  * array_size() - Calculate size of 2-dimensional array.
+  *
diff --git a/queue-5.10/overflow-allow-mixed-type-arguments.patch b/queue-5.10/overflow-allow-mixed-type-arguments.patch
new file mode 100644 (file)
index 0000000..fa23f9d
--- /dev/null
@@ -0,0 +1,128 @@
+From stable+bounces-179394-greg=kroah.com@vger.kernel.org Fri Sep 12 20:56:48 2025
+From: Eliav Farber <farbere@amazon.com>
+Date: Fri, 12 Sep 2025 18:55:15 +0000
+Subject: overflow: Allow mixed type arguments
+To: <luc.vanoostenryck@gmail.com>, <rostedt@goodmis.org>, <mingo@redhat.com>, <natechancellor@gmail.com>, <ndesaulniers@google.com>, <keescook@chromium.org>, <sashal@kernel.org>, <akpm@linux-foundation.org>, <ojeda@kernel.org>, <elver@google.com>, <gregkh@linuxfoundation.org>, <kbusch@kernel.org>, <sj@kernel.org>, <bvanassche@acm.org>, <leon@kernel.org>, <jgg@ziepe.ca>, <linux-kernel@vger.kernel.org>, <linux-sparse@vger.kernel.org>, <clang-built-linux@googlegroups.com>, <stable@vger.kernel.org>
+Cc: <jonnyc@amazon.com>, <farbere@amazon.com>, Rasmus Villemoes <linux@rasmusvillemoes.dk>, Gwan-gyeong Mun <gwan-gyeong.mun@intel.com>, "Gustavo A. R. Silva" <gustavoars@kernel.org>, <linux-hardening@vger.kernel.org>, Andrzej Hajda <andrzej.hajda@intel.com>
+Message-ID: <20250912185518.39980-4-farbere@amazon.com>
+
+From: Kees Cook <keescook@chromium.org>
+
+commit d219d2a9a92e39aa92799efe8f2aa21259b6dd82 upstream.
+
+When the check_[op]_overflow() helpers were introduced, all arguments
+were required to be the same type to make the fallback macros simpler.
+However, now that the fallback macros have been removed[1], it is fine
+to allow mixed types, which makes using the helpers much more useful,
+as they can be used to test for type-based overflows (e.g. adding two
+large ints but storing into a u8), as would be handy in the drm core[2].
+
+Remove the restriction, and add additional self-tests that exercise
+some of the mixed-type overflow cases, and double-check for accidental
+macro side-effects.
+
+[1] https://git.kernel.org/linus/4eb6bd55cfb22ffc20652732340c4962f3ac9a91
+[2] https://lore.kernel.org/lkml/20220824084514.2261614-2-gwan-gyeong.mun@intel.com
+
+Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>
+Cc: Gwan-gyeong Mun <gwan-gyeong.mun@intel.com>
+Cc: "Gustavo A. R. Silva" <gustavoars@kernel.org>
+Cc: Nick Desaulniers <ndesaulniers@google.com>
+Cc: linux-hardening@vger.kernel.org
+Reviewed-by: Andrzej Hajda <andrzej.hajda@intel.com>
+Reviewed-by: Gwan-gyeong Mun <gwan-gyeong.mun@intel.com>
+Tested-by: Gwan-gyeong Mun <gwan-gyeong.mun@intel.com>
+Signed-off-by: Kees Cook <keescook@chromium.org>
+[ dropped the test portion of the commit as that doesn't apply to
+  5.15.y - gregkh]
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+Signed-off-by: Eliav Farber <farbere@amazon.com>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ include/linux/overflow.h |   72 ++++++++++++++++++++++++++---------------------
+ 1 file changed, 41 insertions(+), 31 deletions(-)
+
+--- a/include/linux/overflow.h
++++ b/include/linux/overflow.h
+@@ -51,40 +51,50 @@ static inline bool __must_check __must_c
+       return unlikely(overflow);
+ }
+-/*
+- * For simplicity and code hygiene, the fallback code below insists on
+- * a, b and *d having the same type (similar to the min() and max()
+- * macros), whereas gcc's type-generic overflow checkers accept
+- * different types. Hence we don't just make check_add_overflow an
+- * alias for __builtin_add_overflow, but add type checks similar to
+- * below.
++/** check_add_overflow() - Calculate addition with overflow checking
++ *
++ * @a: first addend
++ * @b: second addend
++ * @d: pointer to store sum
++ *
++ * Returns 0 on success.
++ *
++ * *@d holds the results of the attempted addition, but is not considered
++ * "safe for use" on a non-zero return value, which indicates that the
++ * sum has overflowed or been truncated.
+  */
+-#define check_add_overflow(a, b, d) __must_check_overflow(({  \
+-      typeof(a) __a = (a);                    \
+-      typeof(b) __b = (b);                    \
+-      typeof(d) __d = (d);                    \
+-      (void) (&__a == &__b);                  \
+-      (void) (&__a == __d);                   \
+-      __builtin_add_overflow(__a, __b, __d);  \
+-}))
++#define check_add_overflow(a, b, d)   \
++      __must_check_overflow(__builtin_add_overflow(a, b, d))
+-#define check_sub_overflow(a, b, d) __must_check_overflow(({  \
+-      typeof(a) __a = (a);                    \
+-      typeof(b) __b = (b);                    \
+-      typeof(d) __d = (d);                    \
+-      (void) (&__a == &__b);                  \
+-      (void) (&__a == __d);                   \
+-      __builtin_sub_overflow(__a, __b, __d);  \
+-}))
++/** check_sub_overflow() - Calculate subtraction with overflow checking
++ *
++ * @a: minuend; value to subtract from
++ * @b: subtrahend; value to subtract from @a
++ * @d: pointer to store difference
++ *
++ * Returns 0 on success.
++ *
++ * *@d holds the results of the attempted subtraction, but is not considered
++ * "safe for use" on a non-zero return value, which indicates that the
++ * difference has underflowed or been truncated.
++ */
++#define check_sub_overflow(a, b, d)   \
++      __must_check_overflow(__builtin_sub_overflow(a, b, d))
+-#define check_mul_overflow(a, b, d) __must_check_overflow(({  \
+-      typeof(a) __a = (a);                    \
+-      typeof(b) __b = (b);                    \
+-      typeof(d) __d = (d);                    \
+-      (void) (&__a == &__b);                  \
+-      (void) (&__a == __d);                   \
+-      __builtin_mul_overflow(__a, __b, __d);  \
+-}))
++/** check_mul_overflow() - Calculate multiplication with overflow checking
++ *
++ * @a: first factor
++ * @b: second factor
++ * @d: pointer to store product
++ *
++ * Returns 0 on success.
++ *
++ * *@d holds the results of the attempted multiplication, but is not
++ * considered "safe for use" on a non-zero return value, which indicates
++ * that the product has overflowed or been truncated.
++ */
++#define check_mul_overflow(a, b, d)   \
++      __must_check_overflow(__builtin_mul_overflow(a, b, d))
+ /** check_shl_overflow() - Calculate a left-shifted value and check overflow
+  *
diff --git a/queue-5.10/overflow-correct-check_shl_overflow-comment.patch b/queue-5.10/overflow-correct-check_shl_overflow-comment.patch
new file mode 100644 (file)
index 0000000..cf650e4
--- /dev/null
@@ -0,0 +1,37 @@
+From stable+bounces-179392-greg=kroah.com@vger.kernel.org Fri Sep 12 20:56:21 2025
+From: Eliav Farber <farbere@amazon.com>
+Date: Fri, 12 Sep 2025 18:55:13 +0000
+Subject: overflow: Correct check_shl_overflow() comment
+To: <luc.vanoostenryck@gmail.com>, <rostedt@goodmis.org>, <mingo@redhat.com>, <natechancellor@gmail.com>, <ndesaulniers@google.com>, <keescook@chromium.org>, <sashal@kernel.org>, <akpm@linux-foundation.org>, <ojeda@kernel.org>, <elver@google.com>, <gregkh@linuxfoundation.org>, <kbusch@kernel.org>, <sj@kernel.org>, <bvanassche@acm.org>, <leon@kernel.org>, <jgg@ziepe.ca>, <linux-kernel@vger.kernel.org>, <linux-sparse@vger.kernel.org>, <clang-built-linux@googlegroups.com>, <stable@vger.kernel.org>
+Cc: <jonnyc@amazon.com>, <farbere@amazon.com>
+Message-ID: <20250912185518.39980-2-farbere@amazon.com>
+
+From: Keith Busch <kbusch@kernel.org>
+
+[ Upstream commit 4578be130a6470d85ff05b13b75a00e6224eeeeb ]
+
+A 'false' return means the value was safely set, so the comment should
+say 'true' for when it is not considered safe.
+
+Cc: Jason Gunthorpe <jgg@ziepe.ca>
+Signed-off-by: Keith Busch <kbusch@kernel.org>
+Signed-off-by: Kees Cook <keescook@chromium.org>
+Signed-off-by: Eliav Farber <farbere@amazon.com>
+Fixes: 0c66847793d1 ("overflow.h: Add arithmetic shift helper")
+Link: https://lore.kernel.org/r/20210401160629.1941787-1-kbusch@kernel.org
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ include/linux/overflow.h |    2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+--- a/include/linux/overflow.h
++++ b/include/linux/overflow.h
+@@ -235,7 +235,7 @@ static inline bool __must_check __must_c
+  * - 'a << s' sets the sign bit, if any, in '*d'.
+  *
+  * '*d' will hold the results of the attempted shift, but is not
+- * considered "safe for use" if false is returned.
++ * considered "safe for use" if true is returned.
+  */
+ #define check_shl_overflow(a, s, d) __must_check_overflow(({          \
+       typeof(a) _a = a;                                               \
index 50bb03257e9d1c03cab2b467515a077fe111108b..22f3119f891671061eb498736f88a351eaa418dc 100644 (file)
@@ -10,3 +10,6 @@ tracing-fix-tracing_marker-may-trigger-page-fault-du.patch
 nfsv4-flexfiles-fix-layout-merge-mirror-check.patch
 s390-cpum_cf-deny-all-sampling-events-by-counter-pmu.patch
 tcp_bpf-call-sk_msg_free-when-tcp_bpf_send_verdict-f.patch
+overflow-correct-check_shl_overflow-comment.patch
+compiler.h-drop-fallback-overflow-checkers.patch
+overflow-allow-mixed-type-arguments.patch