summaryrefslogtreecommitdiff
path: root/net/core
diff options
context:
space:
mode:
authorLen Baker <len.baker@gmx.com>2021-10-11 11:01:00 +0200
committerDavid S. Miller <davem@davemloft.net>2021-10-12 11:23:11 +0100
commit7bb39a394490c0690dc7304f2f0345539d590d2b (patch)
tree254d06ce66486cec8db696859b2a7f8a6c9d9c76 /net/core
parent249ae9495b0398c6d21fc7dfdd18ff5e36cf27e2 (diff)
net: hns: Prefer struct_size over open coded arithmetic
As noted in the "Deprecated Interfaces, Language Features, Attributes, and Conventions" documentation [1], size calculations (especially multiplication) should not be performed in memory allocator (or similar) function arguments due to the risk of them overflowing. This could lead to values wrapping around and a smaller allocation being made than the caller was expecting. Using those allocations could lead to linear overflows of heap memory and other misbehaviors. So, take the opportunity to refactor the hnae_handle structure to switch the last member to flexible array, changing the code accordingly. Also, fix the comment in the hnae_vf_cb structure to inform that the ae_handle member must be the last member. Then, use the struct_size() helper to do the arithmetic instead of the argument "size + count * size" in the kzalloc() function. This code was detected with the help of Coccinelle and audited and fixed manually. [1] https://www.kernel.org/doc/html/latest/process/deprecated.html#open-coded-arithmetic-in-allocator-arguments Signed-off-by: Len Baker <len.baker@gmx.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/core')
0 files changed, 0 insertions, 0 deletions