Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#15562 closed bug (fixed)

BMidiLocalProducer::SprayData KDLs when passing a buffer that's too big for a single MIDI message

Reported by: nilsding Owned by: korli
Priority: normal Milestone: R1/beta2
Component: Drivers/MIDI/usb_midi Version: R1/Development
Keywords: Cc:
Blocked By: Blocking:
Platform: All

Description

Backstory: I was hacking on QMidi a bit until I reached the part of adding my changes to the Haiku portion of the library, where I observed that sending a ProgramChange MIDI message results in a KDL almost immediately.

Out of curiosity, I dug down deeper and added some more debugging printfs to the usb_midi driver (see also: additional-usb_midi-logs.patch).
Looking at the debug output (full kernel output attached as haiku.log) it became obvious to me that the xfer_bytes variable underflows (as it tries to transmit 3 bytes for a message that which requires 2), and therefore the memset that occurs in the most inner loop of usb_midi_write causes a page fault at some region in memory.

I then adapted the call to BMidiLocalProducer::SprayData to set a buffer size of 2 for the ProgramChange (0xC0) message, and 3 otherwise (it would still KDL on ChannelPressure 0xD0 ones). With that in place the usb_midi driver no longer causes a KDL, but I reckon it should not cause a KDL in first place, regardless of the buffer size.

I have attached a small(-ish ;-)) re-production program which reuses some of the code found in the Haiku part of QMidi. Read the header comment of midi_kdl_repro.cpp for compile instructions.

Tried this on hrev53636 x86, but I assume this bug appears on other platforms as well.

Attachments (3)

haiku.log (684.3 KB ) - added by nilsding 4 years ago.
haiku.log
additional-usb_midi-logs.patch (4.3 KB ) - added by nilsding 4 years ago.
additional log statements for usb_midi
midi_kdl_repro.cpp (4.0 KB ) - added by nilsding 4 years ago.
testing program that causes a KDL

Download all attachments as: .zip

Change History (8)

by nilsding, 4 years ago

Attachment: haiku.log added

haiku.log

by nilsding, 4 years ago

additional log statements for usb_midi

by nilsding, 4 years ago

Attachment: midi_kdl_repro.cpp added

testing program that causes a KDL

comment:1 by diver, 4 years ago

Component: - GeneralDrivers/MIDI/usb_midi
Keywords: usb_midi removed
Owner: changed from nobody to korli
Platform: x86All

comment:3 by korli, 4 years ago

in the view of the driver this program tries to send a buffer of two packets, the second one being truncated. maybe it would be simpler to avoid sending such truncated packets.

comment:4 by korli, 4 years ago

Resolution: fixed
Status: newclosed

Fix applied in hrev54135 Please check with hrev54135 or newer.

comment:5 by nielx, 4 years ago

Milestone: UnscheduledR1/beta2

Assign tickets with status=closed and resolution=fixed within the R1/beta2 development window to the R1/beta2 Milestone

Note: See TracTickets for help on using tickets.