Skip to content

Commit 7e8cdc9

Browse files
dvyukovdavem330
authored andcommitted
nfc: Add KCOV annotations
Add remote KCOV annotations for NFC processing that is done in background threads. This enables efficient coverage-guided fuzzing of the NFC subsystem. The intention is to add annotations to background threads that process skb's that were allocated in syscall context (thus have a KCOV handle associated with the current fuzz test). This includes nci_recv_frame() that is called by the virtual nci driver in the syscall context. Signed-off-by: Dmitry Vyukov <[email protected]> Cc: Bongsu Jeon <[email protected]> Cc: Krzysztof Kozlowski <[email protected]> Cc: [email protected] Signed-off-by: David S. Miller <[email protected]>
1 parent 82fd151 commit 7e8cdc9

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

net/nfc/nci/core.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <linux/sched.h>
2525
#include <linux/bitops.h>
2626
#include <linux/skbuff.h>
27+
#include <linux/kcov.h>
2728

2829
#include "../nfc.h"
2930
#include <net/nfc/nci.h>
@@ -1472,6 +1473,7 @@ static void nci_tx_work(struct work_struct *work)
14721473
skb = skb_dequeue(&ndev->tx_q);
14731474
if (!skb)
14741475
return;
1476+
kcov_remote_start_common(skb_get_kcov_handle(skb));
14751477

14761478
/* Check if data flow control is used */
14771479
if (atomic_read(&conn_info->credits_cnt) !=
@@ -1487,6 +1489,7 @@ static void nci_tx_work(struct work_struct *work)
14871489

14881490
mod_timer(&ndev->data_timer,
14891491
jiffies + msecs_to_jiffies(NCI_DATA_TIMEOUT));
1492+
kcov_remote_stop();
14901493
}
14911494
}
14921495

@@ -1497,7 +1500,8 @@ static void nci_rx_work(struct work_struct *work)
14971500
struct nci_dev *ndev = container_of(work, struct nci_dev, rx_work);
14981501
struct sk_buff *skb;
14991502

1500-
while ((skb = skb_dequeue(&ndev->rx_q))) {
1503+
for (; (skb = skb_dequeue(&ndev->rx_q)); kcov_remote_stop()) {
1504+
kcov_remote_start_common(skb_get_kcov_handle(skb));
15011505

15021506
/* Send copy to sniffer */
15031507
nfc_send_to_raw_sock(ndev->nfc_dev, skb,
@@ -1551,6 +1555,7 @@ static void nci_cmd_work(struct work_struct *work)
15511555
if (!skb)
15521556
return;
15531557

1558+
kcov_remote_start_common(skb_get_kcov_handle(skb));
15541559
atomic_dec(&ndev->cmd_cnt);
15551560

15561561
pr_debug("NCI TX: MT=cmd, PBF=%d, GID=0x%x, OID=0x%x, plen=%d\n",
@@ -1563,6 +1568,7 @@ static void nci_cmd_work(struct work_struct *work)
15631568

15641569
mod_timer(&ndev->cmd_timer,
15651570
jiffies + msecs_to_jiffies(NCI_CMD_TIMEOUT));
1571+
kcov_remote_stop();
15661572
}
15671573
}
15681574

net/nfc/nci/hci.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <net/nfc/nci.h>
1515
#include <net/nfc/nci_core.h>
1616
#include <linux/nfc.h>
17+
#include <linux/kcov.h>
1718

1819
struct nci_data {
1920
u8 conn_id;
@@ -409,7 +410,8 @@ static void nci_hci_msg_rx_work(struct work_struct *work)
409410
const struct nci_hcp_message *message;
410411
u8 pipe, type, instruction;
411412

412-
while ((skb = skb_dequeue(&hdev->msg_rx_queue)) != NULL) {
413+
for (; (skb = skb_dequeue(&hdev->msg_rx_queue)); kcov_remote_stop()) {
414+
kcov_remote_start_common(skb_get_kcov_handle(skb));
413415
pipe = NCI_HCP_MSG_GET_PIPE(skb->data[0]);
414416
skb_pull(skb, NCI_HCI_HCP_PACKET_HEADER_LEN);
415417
message = (struct nci_hcp_message *)skb->data;

net/nfc/rawsock.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <net/tcp_states.h>
1313
#include <linux/nfc.h>
1414
#include <linux/export.h>
15+
#include <linux/kcov.h>
1516

1617
#include "nfc.h"
1718

@@ -189,6 +190,7 @@ static void rawsock_tx_work(struct work_struct *work)
189190
}
190191

191192
skb = skb_dequeue(&sk->sk_write_queue);
193+
kcov_remote_start_common(skb_get_kcov_handle(skb));
192194

193195
sock_hold(sk);
194196
rc = nfc_data_exchange(dev, target_idx, skb,
@@ -197,6 +199,7 @@ static void rawsock_tx_work(struct work_struct *work)
197199
rawsock_report_error(sk, rc);
198200
sock_put(sk);
199201
}
202+
kcov_remote_stop();
200203
}
201204

202205
static int rawsock_sendmsg(struct socket *sock, struct msghdr *msg, size_t len)

0 commit comments

Comments
 (0)