kernel_samsung_a53x/net/sctp
Erick Archer 21283c01e0 sctp: prefer struct_size over open coded arithmetic
[ Upstream commit e5c5f3596de224422561d48eba6ece5210d967b3 ]

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: https://github.com/KSPP/linux/issues/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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2024-11-19 14:19:40 +01:00
..
associola.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
auth.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
bind_addr.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
chunk.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
debug.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
diag.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
endpointola.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
input.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
inqueue.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
ipv6.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
Kconfig Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
Makefile Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
objcnt.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
offload.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
output.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
outqueue.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
primitive.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
proc.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
protocol.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
sm_make_chunk.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
sm_sideeffect.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
sm_statefuns.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
sm_statetable.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
socket.c sctp: prefer struct_size over open coded arithmetic 2024-11-19 14:19:40 +01:00
stream.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
stream_interleave.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
stream_sched.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
stream_sched_prio.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
stream_sched_rr.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
sysctl.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
transport.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
tsnmap.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
ulpevent.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
ulpqueue.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00