Commit 996419e0 authored by Martin Faltesek's avatar Martin Faltesek Committed by Jakub Kicinski

nfc: st21nfca: fix memory leaks in EVT_TRANSACTION handling

Error paths do not free previously allocated memory. Add devm_kfree() to
those failure paths.

Fixes: 26fc6c7f ("NFC: st21nfca: Add HCI transaction event support")
Fixes: 4fbcc1a4 ("nfc: st21nfca: Fix potential buffer overflows in EVT_TRANSACTION")
Cc: stable@vger.kernel.org
Signed-off-by: default avatarMartin Faltesek <mfaltesek@google.com>
Reviewed-by: default avatarGuenter Roeck <groeck@chromium.org>
Reviewed-by: default avatarKrzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 77e5fe8f
...@@ -326,22 +326,29 @@ int st21nfca_connectivity_event_received(struct nfc_hci_dev *hdev, u8 host, ...@@ -326,22 +326,29 @@ int st21nfca_connectivity_event_received(struct nfc_hci_dev *hdev, u8 host,
transaction->aid_len = skb->data[1]; transaction->aid_len = skb->data[1];
/* Checking if the length of the AID is valid */ /* Checking if the length of the AID is valid */
if (transaction->aid_len > sizeof(transaction->aid)) if (transaction->aid_len > sizeof(transaction->aid)) {
devm_kfree(dev, transaction);
return -EINVAL; return -EINVAL;
}
memcpy(transaction->aid, &skb->data[2], memcpy(transaction->aid, &skb->data[2],
transaction->aid_len); transaction->aid_len);
/* Check next byte is PARAMETERS tag (82) */ /* Check next byte is PARAMETERS tag (82) */
if (skb->data[transaction->aid_len + 2] != if (skb->data[transaction->aid_len + 2] !=
NFC_EVT_TRANSACTION_PARAMS_TAG) NFC_EVT_TRANSACTION_PARAMS_TAG) {
devm_kfree(dev, transaction);
return -EPROTO; return -EPROTO;
}
transaction->params_len = skb->data[transaction->aid_len + 3]; transaction->params_len = skb->data[transaction->aid_len + 3];
/* Total size is allocated (skb->len - 2) minus fixed array members */ /* Total size is allocated (skb->len - 2) minus fixed array members */
if (transaction->params_len > ((skb->len - 2) - sizeof(struct nfc_evt_transaction))) if (transaction->params_len > ((skb->len - 2) -
sizeof(struct nfc_evt_transaction))) {
devm_kfree(dev, transaction);
return -EINVAL; return -EINVAL;
}
memcpy(transaction->params, skb->data + memcpy(transaction->params, skb->data +
transaction->aid_len + 4, transaction->params_len); transaction->aid_len + 4, transaction->params_len);
......
Markdown is supported
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