Skip to content
Commit 0254f31a authored by Martin Faltesek's avatar Martin Faltesek Committed by Jakub Kicinski
Browse files

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: default avatarDenis Efremov <denis.e.efremov@oracle.com>
Reviewed-by: default avatarGuenter Roeck <groeck@google.com>
Fixes: 5d1ceb7f

 ("NFC: st21nfcb: Add HCI transaction event support")
Signed-off-by: default avatarMartin Faltesek <mfaltesek@google.com>
Reviewed-by: default avatarKrzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 440f2ae9
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment