Skip to content

Commit bd03219

Browse files
YsuOSaloktiwa
authored andcommitted
nfc: nci: Fix uninit-value in nci_rx_work
[ Upstream commit e4a87ab ] 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]> Signed-off-by: Sasha Levin <[email protected]> FOF: 0724 Signed-off-by: Alok Tiwari <[email protected]>
1 parent 0d72639 commit bd03219

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
@@ -1449,6 +1449,19 @@ int nci_core_ntf_packet(struct nci_dev *ndev, __u16 opcode,
14491449
ndev->ops->n_core_ops);
14501450
}
14511451

1452+
static bool nci_valid_size(struct sk_buff *skb)
1453+
{
1454+
unsigned int hdr_size = NCI_CTRL_HDR_SIZE;
1455+
BUILD_BUG_ON(NCI_CTRL_HDR_SIZE != NCI_DATA_HDR_SIZE);
1456+
1457+
if (skb->len < hdr_size ||
1458+
!nci_plen(skb->data) ||
1459+
skb->len < hdr_size + nci_plen(skb->data)) {
1460+
return false;
1461+
}
1462+
return true;
1463+
}
1464+
14521465
/* ---- NCI TX Data worker thread ---- */
14531466

14541467
static void nci_tx_work(struct work_struct *work)
@@ -1499,7 +1512,7 @@ static void nci_rx_work(struct work_struct *work)
14991512
nfc_send_to_raw_sock(ndev->nfc_dev, skb,
15001513
RAW_PAYLOAD_NCI, NFC_DIRECTION_RX);
15011514

1502-
if (!nci_plen(skb->data)) {
1515+
if (!nci_valid_size(skb)) {
15031516
kfree_skb(skb);
15041517
kcov_remote_stop();
15051518
break;

0 commit comments

Comments
 (0)