Commit e5c5f35
sctp: prefer struct_size over open coded arithmetic
This is an effort to get rid of all multiplications from allocation
functions in order to prevent integer overflows [1][2].
As the "ids" variable is a pointer to "struct sctp_assoc_ids" and this
structure ends in a flexible array:
struct sctp_assoc_ids {
[...]
sctp_assoc_t gaids_assoc_id[];
};
the preferred way in the kernel is to use the struct_size() helper to
do the arithmetic instead of the calculation "size + size * count" in
the kmalloc() function.
Also, refactor the code adding the "ids_size" variable to avoid sizing
twice.
This way, the code is more readable and safer.
This code was detected with the help of Coccinelle, and audited and
modified manually.
Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#open-coded-arithmetic-in-allocator-arguments [1]
Link: KSPP/linux#160 [2]
Signed-off-by: Erick Archer <erick.archer@outlook.com>
Acked-by: Xin Long <lucien.xin@gmail.com>
Reviewed-by: Kees Cook <keescook@chromium.org>
Link: https://lore.kernel.org/r/PAXPR02MB724871DB78375AB06B5171C88B152@PAXPR02MB7248.eurprd02.prod.outlook.com
Signed-off-by: Paolo Abeni <pabeni@redhat.com>1 parent 9f02bb6 commit e5c5f35
1 file changed
+4
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7119 | 7119 | | |
7120 | 7120 | | |
7121 | 7121 | | |
| 7122 | + | |
7122 | 7123 | | |
7123 | 7124 | | |
7124 | 7125 | | |
| |||
7131 | 7132 | | |
7132 | 7133 | | |
7133 | 7134 | | |
7134 | | - | |
| 7135 | + | |
| 7136 | + | |
7135 | 7137 | | |
7136 | 7138 | | |
7137 | | - | |
7138 | | - | |
| 7139 | + | |
7139 | 7140 | | |
7140 | 7141 | | |
7141 | 7142 | | |
| |||
0 commit comments