android_kernel_asus_sm8350/drivers/nfc
Martin Faltesek 76101f1b7f nfc: st21nfca: fix incorrect sizing calculations in EVT_TRANSACTION
commit f2e19b36593caed4c977c2f55aeba7408aeb2132 upstream.

The transaction buffer is allocated by using the size of the packet buf,
and subtracting two which seem 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.

The last validation check for transaction->params_len is also incorrect
since it employs the same accounting error.

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 those checks are
moved ahead of memory allocation.

Fixes: 26fc6c7f02 ("NFC: st21nfca: Add HCI transaction event support")
Fixes: 4fbcc1a4cb20 ("nfc: st21nfca: Fix potential buffer overflows in EVT_TRANSACTION")
Cc: stable@vger.kernel.org
Signed-off-by: Martin Faltesek <mfaltesek@google.com>
Reviewed-by: Guenter Roeck <groeck@chromium.org>
Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2022-06-22 14:11:02 +02:00
..
fdp NFC: fdp: Fix a signedness bug in fdp_nci_send_patch() 2020-04-01 11:01:38 +02:00
microread treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 399 2019-06-05 17:37:12 +02:00
nfcmrvl nfc: nfcmrvl: main: reorder destructive operations in nfcmrvl_nci_unregister_dev to avoid bugs 2022-05-12 12:23:44 +02:00
nxp-nci NFC: nxp-nci: Fix probing without ACPI 2019-12-31 16:41:49 +01:00
pn533 nfc: pn533: Fix double free when pn533_fill_fragment_skbs() fails 2021-11-17 09:48:47 +01:00
pn544 nfc: pn544: Fix occasional HW initialization failure 2020-03-05 16:43:32 +01:00
s3fwrn5 nfc: s3fwrn5: Release the nfc firmware 2020-12-30 11:51:26 +01:00
st21nfca nfc: st21nfca: fix incorrect sizing calculations in EVT_TRANSACTION 2022-06-22 14:11:02 +02:00
st95hf NFC: st95hf: Fix memleak in st95hf_in_send_cmd 2020-09-17 13:47:45 +02:00
st-nci st_nci_hci_connectivity_event_received: null check the allocation 2019-07-25 11:48:06 -07:00
Kconfig treewide: Add SPDX license identifier - Makefile/Kconfig 2019-05-21 10:50:46 +02:00
Makefile
mei_phy.c nfc/mei: convert to SPDX license tags 2019-03-28 02:07:54 +09:00
mei_phy.h
nfcsim.c nfc: nfcsim: fix use after free during module unload 2021-08-04 12:27:38 +02:00
port100.c NFC: port100: fix use-after-free in port100_send_complete 2022-03-16 13:21:46 +01:00
trf7970a.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 417 2019-06-05 17:37:15 +02:00