Bug 204201

Summary: bluez segfault when CCD are present in two different HOG service
Product: Drivers Reporter: Mathieu Stephan (mathieu.stephan)
Component: BluetoothAssignee: networking_wireless (networking_wireless)
Status: NEW ---    
Severity: normal CC: mathieu.stephan
Priority: P1    
Hardware: All   
OS: Linux   
Kernel Version: 5.2 Subsystem:
Regression: No Bisected commit-id:
Attachments: callstacks

Description Mathieu Stephan 2019-07-17 09:53:30 UTC
Created attachment 283773 [details]
callstacks

Hello everyone,

We are currently developing a device that contains two HID services.
That device, as it is right now, is properly functioning on Windows & Android.
However, when pairing the device on Linux running bluez 5.50 we do get segfaults (see attached files).
Our bluetooth device has 4 services : 1 battery service, 2 HID Over Gatt services and 1 device information service.
With trial and error, we managed to find that we wouldn't get any crash as long as only 1 HOG service was present.

Here's the interesting part. The two HOG services are made as follows:
- standard keyboard over gatt: protocole mode / report map / 1 INPUT report / boot INPUT + OUTPUT / HID information / HID Control point
- raw HID over gatt : report map / 1 INPUT report / 1 OUTPUT report / HID information / HID control point

Looking at the write_ccc in the call stacks we wondered if the callbacks subscribing to notifications for the INPUT reports were causing this issue.

We therefore changed the raw HID over gatt (and its report map) to remove the INPUT report and change it into 1 OUTPUT report (leading to 2 OUTPUT reports): no crash.

We therefore hypothesize that the segfault occurs when subscribing to notification on a second HOG service..
Comment 1 Mathieu Stephan 2019-08-05 04:56:38 UTC

Hello,

We have done some further investigation.
During device pairing bluez is crashing.
From debugging I can see the 2 hog services with the correct attributes, then one of the 2 hog services is reaching ref_count 0, hence it is getting freed, but on the next read bluez is trying to use a corrupted hog service and during reading its attributes we are receiving the segfault.
With normal behavior the next step would be "Report characteristic descriptor written: notifications enabled", but crashes right before that.