diff mbox series

[v2] Bluetooth: Collect kcov coverage from hci_rx_work

Message ID 20220607104015.2126118-1-poprdi@google.com (mailing list archive)
State New, archived
Headers show
Series [v2] Bluetooth: Collect kcov coverage from hci_rx_work | expand

Checks

Context Check Description
tedd_an/pre-ci_am success Success
tedd_an/checkpatch success Checkpatch PASS
tedd_an/gitlint success Gitlint PASS
tedd_an/subjectprefix success PASS
tedd_an/buildkernel success Build Kernel PASS
tedd_an/buildkernel32 success Build Kernel32 PASS
tedd_an/incremental_build success Pass
tedd_an/testrunnersetup success Test Runner Setup PASS
tedd_an/testrunnerl2cap-tester success Total: 40, Passed: 40 (100.0%), Failed: 0, Not Run: 0
tedd_an/testrunnerbnep-tester success Total: 1, Passed: 1 (100.0%), Failed: 0, Not Run: 0
tedd_an/testrunnermgmt-tester success Total: 493, Passed: 493 (100.0%), Failed: 0, Not Run: 0
tedd_an/testrunnerrfcomm-tester success Total: 10, Passed: 10 (100.0%), Failed: 0, Not Run: 0
tedd_an/testrunnersco-tester success Total: 12, Passed: 12 (100.0%), Failed: 0, Not Run: 0
tedd_an/testrunnersmp-tester success Total: 8, Passed: 8 (100.0%), Failed: 0, Not Run: 0
tedd_an/testrunneruserchan-tester success Total: 4, Passed: 4 (100.0%), Failed: 0, Not Run: 0

Commit Message

Tamas Koczka June 7, 2022, 10:40 a.m. UTC
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.

Signed-off-by: Tamas Koczka <poprdi@google.com>
---
Changelog since v1:
 - add comment about why kcov_remote functions are called

v1: https://lore.kernel.org/all/20220517094532.2729049-1-poprdi@google.com/

 net/bluetooth/hci_core.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

Comments

bluez.test.bot@gmail.com June 7, 2022, 11:04 a.m. UTC | #1
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=647954

---Test result---

Test Summary:
CheckPatch                    PASS      1.24 seconds
GitLint                       PASS      0.84 seconds
SubjectPrefix                 PASS      0.62 seconds
BuildKernel                   PASS      30.66 seconds
BuildKernel32                 PASS      27.33 seconds
Incremental Build with patchesPASS      37.37 seconds
TestRunner: Setup             PASS      467.41 seconds
TestRunner: l2cap-tester      PASS      17.70 seconds
TestRunner: bnep-tester       PASS      5.98 seconds
TestRunner: mgmt-tester       PASS      100.14 seconds
TestRunner: rfcomm-tester     PASS      9.56 seconds
TestRunner: sco-tester        PASS      9.27 seconds
TestRunner: smp-tester        PASS      9.32 seconds
TestRunner: userchan-tester   PASS      6.25 seconds



---
Regards,
Linux Bluetooth
Tamas Koczka June 7, 2022, 11:44 a.m. UTC | #2
Hello Marcel,

I added some comments into the code about what the kcov_remote calls do and
why they were implemented and I also added some reasoning to the commit
message.

I did not mention in the commit but these functions only run if the kernel
is compiled with CONFIG_KCOV.

Thank you again for reviewing the patch!

--
Tamas

On Tue, Jun 7, 2022 at 12:40 PM Tamas Koczka <poprdi@google.com> 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.
>
> Signed-off-by: Tamas Koczka <poprdi@google.com>
> ---
> Changelog since v1:
>  - add comment about why kcov_remote functions are called
>
> v1: https://lore.kernel.org/all/20220517094532.2729049-1-poprdi@google.com/
>
>  net/bluetooth/hci_core.c | 10 +++++++++-
>  1 file changed, 9 insertions(+), 1 deletion(-)
>
> diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
> index 45c2dd2e1590..0af43844c55a 100644
> --- a/net/bluetooth/hci_core.c
> +++ b/net/bluetooth/hci_core.c
> @@ -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);
>
> --
> 2.36.1.255.ge46751e96f-goog
>
Tamas Koczka June 14, 2022, 1:34 p.m. UTC | #3
Hello Marcel,

I hope this was the change you originally requested, and I did not
misunderstand anything, but if you need any additional modification to
the code or the commit, please feel free to let me know!

Thank you,
Tamas

On Tue, Jun 7, 2022 at 1:44 PM Tamás Koczka <poprdi@google.com> wrote:
>
> Hello Marcel,
>
> I added some comments into the code about what the kcov_remote calls do and
> why they were implemented and I also added some reasoning to the commit
> message.
>
> I did not mention in the commit but these functions only run if the kernel
> is compiled with CONFIG_KCOV.
>
> Thank you again for reviewing the patch!
>
> --
> Tamas
>
> On Tue, Jun 7, 2022 at 12:40 PM Tamas Koczka <poprdi@google.com> 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.
> >
> > Signed-off-by: Tamas Koczka <poprdi@google.com>
> > ---
> > Changelog since v1:
> >  - add comment about why kcov_remote functions are called
> >
> > v1: https://lore.kernel.org/all/20220517094532.2729049-1-poprdi@google.com/
> >
> >  net/bluetooth/hci_core.c | 10 +++++++++-
> >  1 file changed, 9 insertions(+), 1 deletion(-)
> >
> > diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
> > index 45c2dd2e1590..0af43844c55a 100644
> > --- a/net/bluetooth/hci_core.c
> > +++ b/net/bluetooth/hci_core.c
> > @@ -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);
> >
> > --
> > 2.36.1.255.ge46751e96f-goog
> >
Aleksandr Nogikh June 22, 2022, 10:20 a.m. UTC | #4
(Resending the reply I sent to the v1 of the patch. I sent it by
mistake with HTML content, so it did not reach lore.)

I checked out v5.18.1, applied this patch and fuzzed it with syzkaller
for a day. The fuzzer was indeed able to find and report more coverage
of the BT subsystem than without the patch.

Tested-by: Aleksandr Nogikh <nogikh@google.com>


On Tue, Jun 14, 2022 at 3:34 PM Tamás Koczka <poprdi@google.com> wrote:
>
> Hello Marcel,
>
> I hope this was the change you originally requested, and I did not
> misunderstand anything, but if you need any additional modification to
> the code or the commit, please feel free to let me know!
>
> Thank you,
> Tamas
>
> On Tue, Jun 7, 2022 at 1:44 PM Tamás Koczka <poprdi@google.com> wrote:
> >
> > Hello Marcel,
> >
> > I added some comments into the code about what the kcov_remote calls do and
> > why they were implemented and I also added some reasoning to the commit
> > message.
> >
> > I did not mention in the commit but these functions only run if the kernel
> > is compiled with CONFIG_KCOV.
> >
> > Thank you again for reviewing the patch!
> >
> > --
> > Tamas
> >
> > On Tue, Jun 7, 2022 at 12:40 PM Tamas Koczka <poprdi@google.com> 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.
> > >
> > > Signed-off-by: Tamas Koczka <poprdi@google.com>
> > > ---
> > > Changelog since v1:
> > >  - add comment about why kcov_remote functions are called
> > >
> > > v1: https://lore.kernel.org/all/20220517094532.2729049-1-poprdi@google.com/
> > >
> > >  net/bluetooth/hci_core.c | 10 +++++++++-
> > >  1 file changed, 9 insertions(+), 1 deletion(-)
> > >
> > > diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
> > > index 45c2dd2e1590..0af43844c55a 100644
> > > --- a/net/bluetooth/hci_core.c
> > > +++ b/net/bluetooth/hci_core.c
> > > @@ -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);
> > >
> > > --
> > > 2.36.1.255.ge46751e96f-goog
> > >
Dmitry Vyukov June 23, 2022, 9:18 a.m. UTC | #5
On Wed, 22 Jun 2022 at 12:20, Aleksandr Nogikh <nogikh@google.com> wrote:
>
> (Resending the reply I sent to the v1 of the patch. I sent it by
> mistake with HTML content, so it did not reach lore.)
>
> I checked out v5.18.1, applied this patch and fuzzed it with syzkaller
> for a day. The fuzzer was indeed able to find and report more coverage
> of the BT subsystem than without the patch.
>
> Tested-by: Aleksandr Nogikh <nogikh@google.com>
>
>
> On Tue, Jun 14, 2022 at 3:34 PM Tamás Koczka <poprdi@google.com> wrote:
> >
> > Hello Marcel,
> >
> > I hope this was the change you originally requested, and I did not
> > misunderstand anything, but if you need any additional modification to
> > the code or the commit, please feel free to let me know!
> >
> > Thank you,
> > Tamas
> >
> > On Tue, Jun 7, 2022 at 1:44 PM Tamás Koczka <poprdi@google.com> wrote:
> > >
> > > Hello Marcel,
> > >
> > > I added some comments into the code about what the kcov_remote calls do and
> > > why they were implemented and I also added some reasoning to the commit
> > > message.
> > >
> > > I did not mention in the commit but these functions only run if the kernel
> > > is compiled with CONFIG_KCOV.
> > >
> > > Thank you again for reviewing the patch!
> > >
> > > --
> > > Tamas
> > >
> > > On Tue, Jun 7, 2022 at 12:40 PM Tamas Koczka <poprdi@google.com> 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.
> > > >
> > > > Signed-off-by: Tamas Koczka <poprdi@google.com>
> > > > ---
> > > > Changelog since v1:
> > > >  - add comment about why kcov_remote functions are called
> > > >
> > > > v1: https://lore.kernel.org/all/20220517094532.2729049-1-poprdi@google.com/
> > > >
> > > >  net/bluetooth/hci_core.c | 10 +++++++++-
> > > >  1 file changed, 9 insertions(+), 1 deletion(-)
> > > >
> > > > diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
> > > > index 45c2dd2e1590..0af43844c55a 100644
> > > > --- a/net/bluetooth/hci_core.c
> > > > +++ b/net/bluetooth/hci_core.c
> > > > @@ -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);

Looks good to me.
Anything else needed to merge this patch?

Reviewed-by: Dmitry Vyukov <dvyukov@google.com>
Tamas Koczka July 4, 2022, 12:52 p.m. UTC | #6
Hello,

If you need any clarification about the patch or if you have questions
or if the patch needs to be modified, please feel free to tell me.

Basically the patch should not have any effect on a kernel which is
not compiled with CONFIG_KCOV and we'd like to use the patch to make
the coverage of the hci_rx_work background thread visible to
Syzkaller, because the BT packet parsing / handling logic happens
there and this way Syzkaller will be able to more effectively mutate
the packets used for fuzzing, hopefully reaching new code paths, maybe
discovering and reporting new vulnerabilities before they reach the
mainline.

Thank you,
Tamas


On Thu, Jun 23, 2022 at 11:18 AM Dmitry Vyukov <dvyukov@google.com> wrote:
>
> On Wed, 22 Jun 2022 at 12:20, Aleksandr Nogikh <nogikh@google.com> wrote:
> >
> > (Resending the reply I sent to the v1 of the patch. I sent it by
> > mistake with HTML content, so it did not reach lore.)
> >
> > I checked out v5.18.1, applied this patch and fuzzed it with syzkaller
> > for a day. The fuzzer was indeed able to find and report more coverage
> > of the BT subsystem than without the patch.
> >
> > Tested-by: Aleksandr Nogikh <nogikh@google.com>
> >
> >
> > On Tue, Jun 14, 2022 at 3:34 PM Tamás Koczka <poprdi@google.com> wrote:
> > >
> > > Hello Marcel,
> > >
> > > I hope this was the change you originally requested, and I did not
> > > misunderstand anything, but if you need any additional modification to
> > > the code or the commit, please feel free to let me know!
> > >
> > > Thank you,
> > > Tamas
> > >
> > > On Tue, Jun 7, 2022 at 1:44 PM Tamás Koczka <poprdi@google.com> wrote:
> > > >
> > > > Hello Marcel,
> > > >
> > > > I added some comments into the code about what the kcov_remote calls do and
> > > > why they were implemented and I also added some reasoning to the commit
> > > > message.
> > > >
> > > > I did not mention in the commit but these functions only run if the kernel
> > > > is compiled with CONFIG_KCOV.
> > > >
> > > > Thank you again for reviewing the patch!
> > > >
> > > > --
> > > > Tamas
> > > >
> > > > On Tue, Jun 7, 2022 at 12:40 PM Tamas Koczka <poprdi@google.com> 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.
> > > > >
> > > > > Signed-off-by: Tamas Koczka <poprdi@google.com>
> > > > > ---
> > > > > Changelog since v1:
> > > > >  - add comment about why kcov_remote functions are called
> > > > >
> > > > > v1: https://lore.kernel.org/all/20220517094532.2729049-1-poprdi@google.com/
> > > > >
> > > > >  net/bluetooth/hci_core.c | 10 +++++++++-
> > > > >  1 file changed, 9 insertions(+), 1 deletion(-)
> > > > >
> > > > > diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
> > > > > index 45c2dd2e1590..0af43844c55a 100644
> > > > > --- a/net/bluetooth/hci_core.c
> > > > > +++ b/net/bluetooth/hci_core.c
> > > > > @@ -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);
>
> Looks good to me.
> Anything else needed to merge this patch?
>
> Reviewed-by: Dmitry Vyukov <dvyukov@google.com>
diff mbox series

Patch

diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index 45c2dd2e1590..0af43844c55a 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -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);