Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

overflow: add range_overflows() and range_end_overflows()

Move the range_overflows() and range_end_overflows() along with the _t
variants over from drm/i915 and drm/buddy to overflow.h.

Cc: Kees Cook <kees@kernel.org>
Cc: "Gustavo A. R. Silva" <gustavoars@kernel.org>
Cc: linux-hardening@vger.kernel.org
Reviewed-by: Kees Cook <kees@kernel.org>
Reviewed-by: Jouni Högander <jouni.hogander@intel.com>
Acked-by: Thomas Zimmermann <tzimmermann@suse.de>
Link: https://lore.kernel.org/r/20250829174601.2163064-3-jani.nikula@intel.com
Signed-off-by: Jani Nikula <jani.nikula@intel.com>

+70 -79
-70
drivers/gpu/drm/i915/i915_utils.h
··· 67 67 drm_err(&(i915)->drm, fmt, ##__VA_ARGS__); \ 68 68 }) 69 69 70 - /** 71 - * range_overflows() - Check if a range is out of bounds 72 - * @start: Start of the range. 73 - * @size: Size of the range. 74 - * @max: Exclusive upper boundary. 75 - * 76 - * A strict check to determine if the range [@start, @start + @size) is 77 - * invalid with respect to the allowable range [0, @max). Any range 78 - * starting at or beyond @max is considered an overflow, even if @size is 0. 79 - * 80 - * Returns: true if the range is out of bounds. 81 - */ 82 - #define range_overflows(start, size, max) ({ \ 83 - typeof(start) start__ = (start); \ 84 - typeof(size) size__ = (size); \ 85 - typeof(max) max__ = (max); \ 86 - (void)(&start__ == &size__); \ 87 - (void)(&start__ == &max__); \ 88 - start__ >= max__ || size__ > max__ - start__; \ 89 - }) 90 - 91 - /** 92 - * range_overflows_t() - Check if a range is out of bounds 93 - * @type: Data type to use. 94 - * @start: Start of the range. 95 - * @size: Size of the range. 96 - * @max: Exclusive upper boundary. 97 - * 98 - * Same as range_overflows() but forcing the parameters to @type. 99 - * 100 - * Returns: true if the range is out of bounds. 101 - */ 102 - #define range_overflows_t(type, start, size, max) \ 103 - range_overflows((type)(start), (type)(size), (type)(max)) 104 - 105 - /** 106 - * range_end_overflows() - Check if a range's endpoint is out of bounds 107 - * @start: Start of the range. 108 - * @size: Size of the range. 109 - * @max: Exclusive upper boundary. 110 - * 111 - * Checks only if the endpoint of a range (@start + @size) exceeds @max. 112 - * Unlike range_overflows(), a zero-sized range at the boundary (@start == @max) 113 - * is not considered an overflow. Useful for iterator-style checks. 114 - * 115 - * Returns: true if the endpoint exceeds the boundary. 116 - */ 117 - #define range_end_overflows(start, size, max) ({ \ 118 - typeof(start) start__ = (start); \ 119 - typeof(size) size__ = (size); \ 120 - typeof(max) max__ = (max); \ 121 - (void)(&start__ == &size__); \ 122 - (void)(&start__ == &max__); \ 123 - start__ > max__ || size__ > max__ - start__; \ 124 - }) 125 - 126 - /** 127 - * range_end_overflows_t() - Check if a range's endpoint is out of bounds 128 - * @type: Data type to use. 129 - * @start: Start of the range. 130 - * @size: Size of the range. 131 - * @max: Exclusive upper boundary. 132 - * 133 - * Same as range_end_overflows() but forcing the parameters to @type. 134 - * 135 - * Returns: true if the endpoint exceeds the boundary. 136 - */ 137 - #define range_end_overflows_t(type, start, size, max) \ 138 - range_end_overflows((type)(start), (type)(size), (type)(max)) 139 - 140 70 #define ptr_mask_bits(ptr, n) ({ \ 141 71 unsigned long __v = (unsigned long)(ptr); \ 142 72 (typeof(ptr))(__v & -BIT(n)); \
-9
include/drm/drm_buddy.h
··· 13 13 14 14 #include <drm/drm_print.h> 15 15 16 - #define range_overflows(start, size, max) ({ \ 17 - typeof(start) start__ = (start); \ 18 - typeof(size) size__ = (size); \ 19 - typeof(max) max__ = (max); \ 20 - (void)(&start__ == &size__); \ 21 - (void)(&start__ == &max__); \ 22 - start__ >= max__ || size__ > max__ - start__; \ 23 - }) 24 - 25 16 #define DRM_BUDDY_RANGE_ALLOCATION BIT(0) 26 17 #define DRM_BUDDY_TOPDOWN_ALLOCATION BIT(1) 27 18 #define DRM_BUDDY_CONTIGUOUS_ALLOCATION BIT(2)
+70
include/linux/overflow.h
··· 239 239 __overflows_type(n, T)) 240 240 241 241 /** 242 + * range_overflows() - Check if a range is out of bounds 243 + * @start: Start of the range. 244 + * @size: Size of the range. 245 + * @max: Exclusive upper boundary. 246 + * 247 + * A strict check to determine if the range [@start, @start + @size) is 248 + * invalid with respect to the allowable range [0, @max). Any range 249 + * starting at or beyond @max is considered an overflow, even if @size is 0. 250 + * 251 + * Returns: true if the range is out of bounds. 252 + */ 253 + #define range_overflows(start, size, max) ({ \ 254 + typeof(start) start__ = (start); \ 255 + typeof(size) size__ = (size); \ 256 + typeof(max) max__ = (max); \ 257 + (void)(&start__ == &size__); \ 258 + (void)(&start__ == &max__); \ 259 + start__ >= max__ || size__ > max__ - start__; \ 260 + }) 261 + 262 + /** 263 + * range_overflows_t() - Check if a range is out of bounds 264 + * @type: Data type to use. 265 + * @start: Start of the range. 266 + * @size: Size of the range. 267 + * @max: Exclusive upper boundary. 268 + * 269 + * Same as range_overflows() but forcing the parameters to @type. 270 + * 271 + * Returns: true if the range is out of bounds. 272 + */ 273 + #define range_overflows_t(type, start, size, max) \ 274 + range_overflows((type)(start), (type)(size), (type)(max)) 275 + 276 + /** 277 + * range_end_overflows() - Check if a range's endpoint is out of bounds 278 + * @start: Start of the range. 279 + * @size: Size of the range. 280 + * @max: Exclusive upper boundary. 281 + * 282 + * Checks only if the endpoint of a range (@start + @size) exceeds @max. 283 + * Unlike range_overflows(), a zero-sized range at the boundary (@start == @max) 284 + * is not considered an overflow. Useful for iterator-style checks. 285 + * 286 + * Returns: true if the endpoint exceeds the boundary. 287 + */ 288 + #define range_end_overflows(start, size, max) ({ \ 289 + typeof(start) start__ = (start); \ 290 + typeof(size) size__ = (size); \ 291 + typeof(max) max__ = (max); \ 292 + (void)(&start__ == &size__); \ 293 + (void)(&start__ == &max__); \ 294 + start__ > max__ || size__ > max__ - start__; \ 295 + }) 296 + 297 + /** 298 + * range_end_overflows_t() - Check if a range's endpoint is out of bounds 299 + * @type: Data type to use. 300 + * @start: Start of the range. 301 + * @size: Size of the range. 302 + * @max: Exclusive upper boundary. 303 + * 304 + * Same as range_end_overflows() but forcing the parameters to @type. 305 + * 306 + * Returns: true if the endpoint exceeds the boundary. 307 + */ 308 + #define range_end_overflows_t(type, start, size, max) \ 309 + range_end_overflows((type)(start), (type)(size), (type)(max)) 310 + 311 + /** 242 312 * castable_to_type - like __same_type(), but also allows for casted literals 243 313 * 244 314 * @n: variable or constant value