stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Martin Faltesek <mfaltesek@google.com>
To: martin.faltesek@gmail.com
Cc: Martin Faltesek <mfaltesek@google.com>, stable@vger.kernel.org
Subject: [PATCH net v3 2/3] nfc: st21nfca: fix memory leaks in EVT_TRANSACTION handling
Date: Mon,  6 Jun 2022 21:41:16 -0500	[thread overview]
Message-ID: <20220607024117.1344044-3-mfaltesek@google.com> (raw)
In-Reply-To: <20220607024117.1344044-1-mfaltesek@google.com>

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

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>
---
 drivers/nfc/st21nfca/se.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/drivers/nfc/st21nfca/se.c b/drivers/nfc/st21nfca/se.c
index 9645777f2544..8e1113ce139b 100644
--- a/drivers/nfc/st21nfca/se.c
+++ b/drivers/nfc/st21nfca/se.c
@@ -326,22 +326,29 @@ int st21nfca_connectivity_event_received(struct nfc_hci_dev *hdev, u8 host,
 		transaction->aid_len = skb->data[1];
 
 		/* 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;
+		}
 
 		memcpy(transaction->aid, &skb->data[2],
 		       transaction->aid_len);
 
 		/* Check next byte is PARAMETERS tag (82) */
 		if (skb->data[transaction->aid_len + 2] !=
-		    NFC_EVT_TRANSACTION_PARAMS_TAG)
+		    NFC_EVT_TRANSACTION_PARAMS_TAG) {
+			devm_kfree(dev, transaction);
 			return -EPROTO;
+		}
 
 		transaction->params_len = skb->data[transaction->aid_len + 3];
 
 		/* 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;
+		}
 
 		memcpy(transaction->params, skb->data +
 		       transaction->aid_len + 4, transaction->params_len);
-- 
2.36.1.255.ge46751e96f-goog


  parent reply	other threads:[~2022-06-07  2:41 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20220607024117.1344044-1-mfaltesek@google.com>
2022-06-07  2:41 ` [PATCH net v3 1/3] nfc: st21nfca: fix incorrect validating logic in EVT_TRANSACTION Martin Faltesek
2022-06-07  2:41 ` Martin Faltesek [this message]
2022-06-07  2:41 ` [PATCH net v3 3/3] nfc: st21nfca: fix incorrect sizing calculations " Martin Faltesek
     [not found] <20220607024819.1667984-1-mfaltesek@google.com>
2022-06-07  2:48 ` [PATCH net v3 2/3] nfc: st21nfca: fix memory leaks in EVT_TRANSACTION handling Martin Faltesek
     [not found] <20220607025519.1670876-1-mfaltesek@google.com>
2022-06-07  2:55 ` Martin Faltesek
     [not found] <20220607025729.1673212-1-mfaltesek@google.com>
2022-06-07  2:57 ` Martin Faltesek
2022-06-07 15:07   ` Guenter Roeck
2022-06-07 17:15   ` Krzysztof Kozlowski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220607024117.1344044-3-mfaltesek@google.com \
    --to=mfaltesek@google.com \
    --cc=martin.faltesek@gmail.com \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).