Skip to content

Commit

Permalink
nfc: pn533: Fix double free when pn533_fill_fragment_skbs() fails
Browse files Browse the repository at this point in the history
[ Upstream commit 9fec40f ]

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 in error path of pn533_fill_fragment_skbs.

Fixes: 963a82e ("NFC: pn533: Split large Tx frames in chunks")
Fixes: 93ad420 ("NFC: pn533: Target mode Tx fragmentation support")
Signed-off-by: Chengfeng Ye <cyeaa@connect.ust.hk>
Reviewed-by: Dan Carpenter <dan.carpenter@oracle.com>
Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
Y-chav authored and gregkh committed Nov 18, 2021
1 parent 9f0e683 commit 727c812
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions drivers/nfc/pn533/pn533.c
Expand Up @@ -2258,7 +2258,7 @@ static int pn533_fill_fragment_skbs(struct pn533 *dev, struct sk_buff *skb)
frag = pn533_alloc_skb(dev, frag_size);
if (!frag) {
skb_queue_purge(&dev->fragment_skb);
break;
return -ENOMEM;
}

if (!dev->tgt_mode) {
Expand Down Expand Up @@ -2329,7 +2329,7 @@ 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)
if (rc < 0)
goto error;

skb = skb_dequeue(&dev->fragment_skb);
Expand Down Expand Up @@ -2401,7 +2401,7 @@ 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)
if (rc < 0)
goto error;

/* get the first skb */
Expand Down

0 comments on commit 727c812

Please sign in to comment.