linux-stable/scripts/coccinelle/misc
Jacob Keller e754948125 coccinelle: semantic patch to check for potential struct_size calls
include/linux/overflow.h includes helper macros intended for calculating
sizes of allocations. These macros prevent accidental overflow by
saturating at SIZE_MAX.

In general when calculating such sizes use of the macros is preferred. Add
a semantic patch which can detect code patterns which can be replaced by
struct_size.

Note that I set the confidence to medium because this patch doesn't make an
attempt to ensure that the relevant array is actually a flexible array. The
struct_size macro does specifically require a flexible array. In many cases
the detected code could be refactored to a flexible array, but this is not
always possible (such as if there are multiple over-allocations).

Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
Link: https://lore.kernel.org/r/20230227202428.3657443-1-jacob.e.keller@intel.com
Signed-off-by: Kees Cook <keescook@chromium.org>
2024-02-29 13:38:01 -08:00
..
add_namespace.cocci scripts: add dummy report mode to add_namespace.cocci 2020-07-10 14:19:58 +02:00
array_size.cocci treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 505 2019-06-19 17:11:22 +02:00
array_size_dup.cocci coccinelle: misc: add array_size_dup script to detect missed overflow checks 2020-08-04 22:46:58 +02:00
badty.cocci treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 505 2019-06-19 17:11:22 +02:00
boolconv.cocci treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 505 2019-06-19 17:11:22 +02:00
cond_no_effect.cocci treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 505 2019-06-19 17:11:22 +02:00
cstptr.cocci update Coccinelle URL 2022-08-07 21:30:36 +02:00
do_div.cocci coccinelle: semantic patch to check for inappropriate do_div() calls 2021-09-11 22:57:39 +02:00
doubleinit.cocci update Coccinelle URL 2022-08-07 21:30:36 +02:00
excluded_middle.cocci coccinelle: misc: add excluded_middle.cocci script 2020-09-21 19:45:46 +02:00
flexible_array.cocci coccinelle: misc: restrict patch mode in flexible_array.cocci 2021-05-01 21:23:56 +02:00
ifcol.cocci update Coccinelle URL 2022-08-07 21:30:36 +02:00
irqf_oneshot.cocci coccinelle: irqf_oneshot: reduce the severity due to false positives 2021-05-01 21:23:57 +02:00
minmax.cocci coccinelle: misc: minmax: suppress patch generation for err returns 2021-05-01 21:27:10 +02:00
newline_in_nl_msg.cocci update Coccinelle URL 2022-08-07 21:30:36 +02:00
noderef.cocci update Coccinelle URL 2022-08-07 21:30:36 +02:00
of_table.cocci License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
orplus.cocci update Coccinelle URL 2022-08-07 21:30:36 +02:00
returnvar.cocci update Coccinelle URL 2022-08-07 21:30:36 +02:00
semicolon.cocci update Coccinelle URL 2022-08-07 21:30:36 +02:00
struct_size.cocci coccinelle: semantic patch to check for potential struct_size calls 2024-02-29 13:38:01 -08:00
swap.cocci coccinelle: misc: add swap script 2021-05-01 21:23:56 +02:00
test_addr.cocci update Coccinelle URL 2022-08-07 21:30:36 +02:00
uninitialized_var.cocci coccinelle: misc: update uninitialized_var.cocci documentation 2021-05-01 21:23:56 +02:00
warn.cocci update Coccinelle URL 2022-08-07 21:30:36 +02:00