Skip to content

Commit e4a87ab

Browse files
YsuOSdavem330
authored andcommitted
nfc: nci: Fix uninit-value in nci_rx_work
syzbot reported the following uninit-value access issue [1] nci_rx_work() parses received packet from ndev->rx_q. It should be validated header size, payload size and total packet size before processing the packet. If an invalid packet is detected, it should be silently discarded. Fixes: d24b035 ("nfc: nci: Fix uninit-value in nci_dev_up and nci_ntf_packet") Reported-and-tested-by: [email protected] Closes: https://syzkaller.appspot.com/bug?extid=d7b4dc6cd50410152534 [1] Signed-off-by: Ryosuke Yasuoka <[email protected]> Reviewed-by: Krzysztof Kozlowski <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent cc563e7 commit e4a87ab

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

net/nfc/nci/core.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1463,6 +1463,19 @@ int nci_core_ntf_packet(struct nci_dev *ndev, __u16 opcode,
14631463
ndev->ops->n_core_ops);
14641464
}
14651465

1466+
static bool nci_valid_size(struct sk_buff *skb)
1467+
{
1468+
BUILD_BUG_ON(NCI_CTRL_HDR_SIZE != NCI_DATA_HDR_SIZE);
1469+
unsigned int hdr_size = NCI_CTRL_HDR_SIZE;
1470+
1471+
if (skb->len < hdr_size ||
1472+
!nci_plen(skb->data) ||
1473+
skb->len < hdr_size + nci_plen(skb->data)) {
1474+
return false;
1475+
}
1476+
return true;
1477+
}
1478+
14661479
/* ---- NCI TX Data worker thread ---- */
14671480

14681481
static void nci_tx_work(struct work_struct *work)
@@ -1516,7 +1529,7 @@ static void nci_rx_work(struct work_struct *work)
15161529
nfc_send_to_raw_sock(ndev->nfc_dev, skb,
15171530
RAW_PAYLOAD_NCI, NFC_DIRECTION_RX);
15181531

1519-
if (!nci_plen(skb->data)) {
1532+
if (!nci_valid_size(skb)) {
15201533
kfree_skb(skb);
15211534
kcov_remote_stop();
15221535
break;

0 commit comments

Comments
 (0)