From: Chengfeng Ye <cyeaa@connect.ust.hk>
To: krzysztof.kozlowski@canonical.com, davem@davemloft.net,
kuba@kernel.org, wengjianfeng@yulong.com,
dan.carpenter@oracle.com
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
Chengfeng Ye <cyeaa@connect.ust.hk>
Subject: [PATCH] nfc: pn533: Fix double free when pn533_fill_fragment_skbs() fails
Date: Fri, 5 Nov 2021 06:18:51 -0700 [thread overview]
Message-ID: <20211105131851.30256-1-cyeaa@connect.ust.hk> (raw)
skb is already freed by dev_kfree_skb in pn533_fill_fragment_skbs,
but follow error handler branch when pn533_fill_fragment_skbs()
fails, skb is freed again, results in double free issue. Fix this
by not free skb when pn533_fill_fragment_skbs() return value <= 0.
Signed-off-by: Chengfeng Ye <cyeaa@connect.ust.hk>
---
drivers/nfc/pn533/pn533.c | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/drivers/nfc/pn533/pn533.c b/drivers/nfc/pn533/pn533.c
index 787bcbd290f7..226ae4357f7f 100644
--- a/drivers/nfc/pn533/pn533.c
+++ b/drivers/nfc/pn533/pn533.c
@@ -2285,8 +2285,10 @@ static int pn533_transceive(struct nfc_dev *nfc_dev,
/* jumbo frame ? */
if (skb->len > PN533_CMD_DATAEXCH_DATA_MAXLEN) {
rc = pn533_fill_fragment_skbs(dev, skb);
- if (rc <= 0)
- goto error;
+ if (rc <= 0) {
+ kfree(arg);
+ return rc;
+ }
skb = skb_dequeue(&dev->fragment_skb);
if (!skb) {
@@ -2353,8 +2355,11 @@ static int pn533_tm_send(struct nfc_dev *nfc_dev, struct sk_buff *skb)
/* let's split in multiple chunks if size's too big */
if (skb->len > PN533_CMD_DATAEXCH_DATA_MAXLEN) {
rc = pn533_fill_fragment_skbs(dev, skb);
- if (rc <= 0)
- goto error;
+ if (rc <= 0) {
+ if (rc < 0)
+ skb_queue_purge(&dev->fragment_skb);
+ return rc;
+ }
/* get the first skb */
skb = skb_dequeue(&dev->fragment_skb);
--
2.17.1
reply other threads:[~2021-11-05 13:19 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20211105131851.30256-1-cyeaa@connect.ust.hk \
--to=cyeaa@connect.ust.hk \
--cc=dan.carpenter@oracle.com \
--cc=davem@davemloft.net \
--cc=krzysztof.kozlowski@canonical.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=wengjianfeng@yulong.com \
/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).