Skip to content

monitor: Fix reads beyond advertising data

Roland Schober linux-bluetooth 2 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest6 patches 1 replyIn review
  2. v15 patches 2 repliesSuperseded

Changes in v2 from the cover letter

- Add patch 5. Copilot found that the fix of the Public Broadcast Announcements, now patch 6, lets them reach the Program Info decoding, which reads beyond the string.
- Rebase.

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/6monitor: Fix overflow of the name buffer in print_eirmonitor/packet.c+1 -11 reply
2/6monitor: Fix reading Flags beyond empty AD structuresmonitor/packet.c+4 -00 replies
3/6monitor: Fix reading beyond a short Mesh Beaconmonitor/packet.c+2 -20 replies
4/6monitor: Fix reading beyond the Apple manufacturer datamonitor/packet.c+4 -60 replies
5/6shared/bap: Fix reading beyond the Program Infosrc/shared/bap-debug.c+1 -10 replies
6/6monitor: Fix decoding of Public Broadcast Announcementsmonitor/packet.c+7 -20 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v2 yet.

Read the v2 thread

Cover letter [PATCH BlueZ v2 0/6] monitor: Fix reads beyond advertising data

print_eir() and the decoders it calls take advertising data, which a remote device chooses. This series fixes six places where btmon reads or writes beyond that data, or decodes it from the wrong place:

- a Shortened Local Name, Complete Local Name or Broadcast Name of 240 or more octets is copied beyond a buffer of 239 octets,
- the Flags and the Security Manager OOB Flags are read from an AD structure which has no data,
- an Unprovisioned Device Beacon of 18 octets is decoded although its OOB Information lacks an octet,
- the Apple identifier is printed as a string which nothing terminates,
- the Program Info metadata is printed without a limit to its length,
- a Public Broadcast Announcement is reported as invalid when it is well formed, and decoded from uninitialised variables when it is too short.

Copilot found the first one in its review of "monitor: Decode Periodic Advertising with Responses" v4, whose new decoders hand advertising data to print_eir() as well. The bug is older than that series and can be reached without it, e.g. by an LE Periodic Advertising Report, so the fixes come as a series of their own. A v5 of the decoding series will follow on top of it.

The others were found by feeding print_eir() one AD structure of every type with every length up to 250 octets, in a buffer of exactly that size with AddressSanitizer, and by review. The same test passes with the series applied. The reads of patches 1 to 5 show there as AddressSanitizer reports; patch 6 was tested with hand-made btsnoop traces only.

For v2 the advertising data was also fuzzed with libFuzzer and AddressSanitizer, part of the time with UndefinedBehaviorSanitizer as well, as LE advertising data and as an Extended Inquiry Response. Without the series it finds the reads of patches 1 to 5 within a minute, the one of patch 5 through a Basic Audio Announcement. With it, more than 200 million inputs, which run every line of print_eir(), found nothing.

v2:
- Add patch 5. Copilot found that the fix of the Public Broadcast Announcements, now patch 6, lets them reach the Program Info decoding, which reads beyond the string.
- Rebase.

Roland Schober (6):
monitor: Fix overflow of the name buffer in print_eir
monitor: Fix reading Flags beyond empty AD structures
monitor: Fix reading beyond a short Mesh Beacon
monitor: Fix reading beyond the Apple manufacturer data shared/bap: Fix reading beyond the Program Info
monitor: Fix decoding of Public Broadcast Announcements

 monitor/packet.c       | 29 ++++++++++++++++++-----------
 src/shared/bap-debug.c |  2 +-
 2 files changed, 19 insertions(+), 12 deletions(-)
Signature · 1 line
2.47.3