linux/drivers/nfc/st-nci
Martin Faltesek 0254f31a7d nfc: st-nci: fix incorrect sizing calculations in EVT_TRANSACTION
The transaction buffer is allocated by using the size of the packet buf,
and subtracting two which seems intended to remove the two tags which are
not present in the target structure. This calculation leads to under
counting memory because of differences between the packet contents and the
target structure. The aid_len field is a u8 in the packet, but a u32 in
the structure, resulting in at least 3 bytes always being under counted.
Further, the aid data is a variable length field in the packet, but fixed
in the structure, so if this field is less than the max, the difference is
added to the under counting.

To fix, perform validation checks progressively to safely reach the
next field, to determine the size of both buffers and verify both tags.
Once all validation checks pass, allocate the buffer and copy the data.
This eliminates freeing memory on the error path, as validation checks are
moved ahead of memory allocation.

Reported-by: Denis Efremov <denis.e.efremov@oracle.com>
Reviewed-by: Guenter Roeck <groeck@google.com>
Fixes: 5d1ceb7f5e ("NFC: st21nfcb: Add HCI transaction event support")
Signed-off-by: Martin Faltesek <mfaltesek@google.com>
Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2022-11-23 20:01:50 -08:00
..
core.c nfc: st-nci: remove unused header includes 2021-08-26 09:13:36 +01:00
i2c.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
Kconfig treewide: replace '---help---' in Kconfig files with 'help' 2020-06-14 01:57:21 +09:00
Makefile
ndlc.c nfc: st-nci: drop unneeded debug prints 2021-10-11 17:00:51 -07:00
ndlc.h nfc: constify nfc_phy_ops 2021-07-25 09:21:21 +01:00
se.c nfc: st-nci: fix incorrect sizing calculations in EVT_TRANSACTION 2022-11-23 20:01:50 -08:00
spi.c spi: make remove callback a void function 2022-02-09 13:00:45 +00:00
st-nci.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 399 2019-06-05 17:37:12 +02:00
vendor_cmds.c nfc: use *_set_vendor_cmds() helpers 2022-01-27 13:53:26 +00:00