Skip to contentSkip to conversation

Bluetooth: Collect kcov coverage from hci_rx_work

PATCH Applied Tamas Koczka 3 participants 3 messages Jul 14, 2022

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 Bluetooth: Collect kcov coverage from hci_rx_work

Annotate hci_rx_work() with kcov_remote_start() and kcov_remote_stop() calls, so remote KCOV coverage is collected while processing the rx_q queue which is the main incoming Bluetooth packet queue.

Coverage is associated with the thread which created the packet skb.

The collected extra coverage helps kernel fuzzing efforts in finding vulnerabilities.

This change only has effect if the kernel is compiled with CONFIG_KCOV, otherwise kcov_ functions don't do anything.

---
Changelog since v1:
- add comment about why kcov_remote functions are called

v1: https://lore.kernel.org/all/[email protected]/

Note: this is a resubmission of https://lore.kernel.org/netdev/CAPUC6bJbVMPn1FMLYnXg2GUX4ikesMSRjj=oPOOrS5H2DOx_bA@mail.gmail.com/T/

 net/bluetooth/hci_core.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
net/bluetooth/hci_core.c +9 -1
index 45c2dd2e1590..0af43844c55a 100644
@@ -29,6 +29,7 @@
 #include <linux/rfkill.h>
 #include <linux/debugfs.h>
 #include <linux/crypto.h>
+#include <linux/kcov.h>
 #include <linux/property.h>
 #include <linux/suspend.h>
 #include <linux/wait.h>
@@ -3780,7 +3781,14 @@ static void hci_rx_work(struct work_struct *work)
 
 	BT_DBG("%s", hdev->name);
 
-	while ((skb = skb_dequeue(&hdev->rx_q))) {
+	/* The kcov_remote functions used for collecting packet parsing
+	 * coverage information from this background thread and associate
+	 * the coverage with the syscall's thread which originally injected
+	 * the packet. This helps fuzzing the kernel.
+	 */
+	for (; (skb = skb_dequeue(&hdev->rx_q)); kcov_remote_stop()) {
+		kcov_remote_start_common(skb_get_kcov_handle(skb));
+
 		/* Send copy to monitor */
 		hci_send_to_monitor(hdev, skb);
 
Signature · 1 line
2.37.0.144.g8ac04bfd2-goog
#1 lore raw

This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list. This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=659660

---Test result---

Test Summary:

CheckPatch                    PASS      1.26 seconds
GitLint                       FAIL      0.56 seconds
SubjectPrefix                 PASS      0.39 seconds
BuildKernel                   PASS      31.70 seconds
BuildKernel32                 PASS      27.34 seconds
Incremental Build with patchesPASS      37.80 seconds
TestRunner: Setup             PASS      468.97 seconds
TestRunner: l2cap-tester      PASS      16.30 seconds
TestRunner: bnep-tester       PASS      5.46 seconds
TestRunner: mgmt-tester       PASS      95.42 seconds
TestRunner: rfcomm-tester     PASS      8.90 seconds
TestRunner: sco-tester        PASS      8.60 seconds
TestRunner: smp-tester        PASS      8.65 seconds
TestRunner: userchan-tester   PASS      5.65 seconds

Details
##############################
Test: GitLint - FAIL - 0.56 seconds
Run gitlint with rule in .gitlint
[v2] Bluetooth: Collect kcov coverage from hci_rx_work
24: B1 Line exceeds max length (132>80): "Note: this is a resubmission of https://lore.kernel.org/netdev/CAPUC6bJbVMPn1FMLYnXg2GUX4ikesMSRjj=oPOOrS5H2DOx_bA@mail.gmail.com/T/"

---
Regards,
Linux Bluetooth

#2 lore raw
In reply to Tamas Koczka
This patch was applied to bluetooth/bluetooth-next.git (master) by Luiz Augusto von Dentz <[email protected]>:

Hello:

This patch was applied to bluetooth/bluetooth-next.git (master) by Luiz Augusto von Dentz <[email protected]>:

Quoted 10 lines · On Thu, 14 Jul 2022 10:48:14 +0000 you wrote:

Annotate hci_rx_work() with kcov_remote_start() and kcov_remote_stop() calls, so remote KCOV coverage is collected while processing the rx_q queue which is the main incoming Bluetooth packet queue.

Coverage is associated with the thread which created the packet skb.

The collected extra coverage helps kernel fuzzing efforts in finding vulnerabilities.

[...]

Here is the summary with links:
- [v2] Bluetooth: Collect kcov coverage from hci_rx_work

    https://git.kernel.org/bluetooth/bluetooth-next/c/b28a31ebc74f

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html