]> git.baikalelectronics.ru Git - kernel.git/commit
nfc: st21nfca: fix incorrect sizing calculations in EVT_TRANSACTION
authorMartin Faltesek <mfaltesek@google.com>
Tue, 7 Jun 2022 02:57:29 +0000 (21:57 -0500)
committerJakub Kicinski <kuba@kernel.org>
Wed, 8 Jun 2022 17:17:17 +0000 (10:17 -0700)
commitf2e19b36593caed4c977c2f55aeba7408aeb2132
treef6fd7b5ae50d0a30e0f4e87fe4b3b1aeeb31c945
parent996419e0594abb311fb958553809f24f38e7abbe
nfc: st21nfca: fix incorrect sizing calculations in EVT_TRANSACTION

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: 26fc6c7f02cb ("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>
drivers/nfc/st21nfca/se.c