Skip to content

Commit 7bd4b0c

Browse files
committed
nfc: nci: free skb on nci_transceive early error paths
nci_transceive() takes ownership of the skb passed by the caller, but the -EPROTO, -EINVAL, and -EBUSY error paths return without freeing it. Due to issues clearing NCI_DATA_EXCHANGE fixed by subsequent changes the nci/nci_dev selftest hits the error path occasionally in NIPA, and kmemleak detects leaks: unreferenced object 0xff11000015ce6a40 (size 640): comm "nci_dev", pid 3954, jiffies 4295441246 hex dump (first 32 bytes): 6b 6b 6b 6b 00 a4 00 0c 02 e1 03 6b 6b 6b 6b 6b kkkk.......kkkkk 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b kkkkkkkkkkkkkkkk backtrace (crc 7c40cc2a): kmem_cache_alloc_node_noprof+0x492/0x630 __alloc_skb+0x11e/0x5f0 alloc_skb_with_frags+0xc6/0x8f0 sock_alloc_send_pskb+0x326/0x3f0 nfc_alloc_send_skb+0x94/0x1d0 rawsock_sendmsg+0x162/0x4c0 do_syscall_64+0x117/0xfc0 Fixes: 6a2968a ("NFC: basic NCI protocol implementation") Reviewed-by: Joe Damato <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 40bf00e commit 7bd4b0c

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

net/nfc/nci/core.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,18 +1035,23 @@ static int nci_transceive(struct nfc_dev *nfc_dev, struct nfc_target *target,
10351035
struct nci_conn_info *conn_info;
10361036

10371037
conn_info = ndev->rf_conn_info;
1038-
if (!conn_info)
1038+
if (!conn_info) {
1039+
kfree_skb(skb);
10391040
return -EPROTO;
1041+
}
10401042

10411043
pr_debug("target_idx %d, len %d\n", target->idx, skb->len);
10421044

10431045
if (!ndev->target_active_prot) {
10441046
pr_err("unable to exchange data, no active target\n");
1047+
kfree_skb(skb);
10451048
return -EINVAL;
10461049
}
10471050

1048-
if (test_and_set_bit(NCI_DATA_EXCHANGE, &ndev->flags))
1051+
if (test_and_set_bit(NCI_DATA_EXCHANGE, &ndev->flags)) {
1052+
kfree_skb(skb);
10491053
return -EBUSY;
1054+
}
10501055

10511056
/* store cb and context to be used on receiving data */
10521057
conn_info->data_exchange_cb = cb;

0 commit comments

Comments
 (0)