Commit Graph

29 Commits

Author SHA1 Message Date
Emil Velikov
f8e0270a7a monitor: const annotate type_table and related API 2024-01-19 15:43:18 -05:00
Emil Velikov
4630f3fba0 monitor: const annotate misc arrays 2024-01-19 15:43:15 -05:00
Tedd Ho-Jeong An
053a1d4bdb monitor/sdp: Fixes out-of-bounds array access
This patch fixes the out-of-bounds array access caught by the ASAN.

monitor/sdp.c:497:19: runtime error: index 8 out of bounds for type
'cont_data [8]'
=================================================================
==4180==ERROR: AddressSanitizer: global-buffer-overflow on address
0x7fe2d271a542 at pc 0x7fe2d174a57d bp 0x7ffc6dcac1d0 sp 0x7ffc6dcab978
WRITE of size 9 at 0x7fe2d271a542 thread T0
    #0 0x7fe2d174a57c  (/lib/x86_64-linux-gnu/libasan.so.5+0x9b57c)
    #1 0x7fe2d23bae85 in search_attr_rsp monitor/sdp.c:692
    #2 0x7fe2d23be3f1 in sdp_packet monitor/sdp.c:771
    #3 0x7fe2d23b004c in l2cap_frame monitor/l2cap.c:3247
    #4 0x7fe2d23b3d9c in l2cap_packet monitor/l2cap.c:3312
    #5 0x7fe2d237d5c3 in packet_hci_acldata monitor/packet.c:11638
    #6 0x7fe2d2381876 in packet_monitor monitor/packet.c:3967
    #7 0x7fe2d230b285 in data_callback monitor/control.c:973
    #8 0x7fe2d2447029 in mainloop_run src/shared/mainloop.c:106
    #9 0x7fe2d2449306 in mainloop_run_with_signal src/shared/mainloop-notify.c:188
    #10 0x7fe2d230324a in main monitor/main.c:290
    #11 0x7fe2d0b440b2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x270b2)
    #12 0x7fe2d2303b7d in _start (/home/han1/work/dev/bluez/monitor/btmon+0x1dbb7d)

0x7fe2d271a542 is located 30 bytes to the left of global variable 'tid_list'
defined in 'monitor/sdp.c:43:24' (0x7fe2d271a560) of size 384
0x7fe2d271a542 is located 2 bytes to the right of global variable 'cont_list'
defined in 'monitor/sdp.c:424:25' (0x7fe2d271a400) of size 320
SUMMARY: AddressSanitizer: global-buffer-overflow
(/lib/x86_64-linux-gnu/libasan.so.5+0x9b57c)
...
==4180==ABORTING
2022-02-10 14:23:55 -08:00
Tedd Ho-Jeong An
9dec682a40 monitor: Add SPDX License Identifier
This patch adds SPDX License Identifier and removes the license text.

-------------------------------------
       License            COUNT
-------------------------------------
 LGPL-2.1-or-later    :     47

License: LGPL-2.1-or-later
   monitor/bt.h
   monitor/hcidump.h
   monitor/avdtp.h
   monitor/crc.c
   monitor/sdp.c
   monitor/hwdb.c
   monitor/intel.h
   monitor/avctp.c
   monitor/control.h
   monitor/display.c
   monitor/a2dp.c
   monitor/ll.c
   monitor/ll.h
   monitor/jlink.h
   monitor/broadcom.h
   monitor/lmp.c
   monitor/keys.c
   monitor/ellisys.c
   monitor/main.c
   monitor/ellisys.h
   monitor/hwdb.h
   monitor/display.h
   monitor/jlink.c
   monitor/rfcomm.h
   monitor/packet.c
   monitor/crc.h
   monitor/keys.h
   monitor/sdp.h
   monitor/rfcomm.c
   monitor/avdtp.c
   monitor/a2dp.h
   monitor/avctp.h
   monitor/vendor.h
   monitor/hcidump.c
   monitor/intel.c
   monitor/tty.h
   monitor/control.c
   monitor/lmp.h
   monitor/analyze.c
   monitor/bnep.c
   monitor/l2cap.c
   monitor/vendor.c
   monitor/packet.h
   monitor/broadcom.c
   monitor/analyze.h
   monitor/l2cap.h
   monitor/bnep.h
2020-09-21 16:19:35 -07:00
Marcel Holtmann
261948090e build: Move declaration of _GNU_SOURCE back into individual source files 2018-12-06 21:28:18 +01:00
Luiz Augusto von Dentz
2657fed2ce monitor: Decode error response
This adds decoding for the error code in the error response:

> test-sdp: User Data RX
      Channel: 0 len 7 [PSM 1 mode 0] {chan 0}
      SDP: Error Response (0x01) tid 2 len 2
        Error code: Invalid Continuation State (0x0005)
2018-11-02 13:09:27 +02:00
Matias Karhumaa
3ebf246be6 btmon: fix segfault caused by buffer over-read
Fix segfault caused by buffer over-read in service_rsp function of
monitor/sdp.c.

This bug can be triggered locally reading malformed btmon capture file
and also over the air by sending specifically crafted SDP Search
Attribute response to device running btmon.

Bug was found by fuzzing btmon with AFL.
2018-10-18 19:10:36 +03:00
Matias Karhumaa
800257a5aa btmon: fix segfault caused by integer underflow
Fix segfault caused by integer underflow in decode_data_element function
of monitor/sdp.c.

Fix is to check that elemlen is not bigger than size before subtracting
elemlen from size. Also search_bytes + attr_bytes should not be bigger
than frame->size.

This bug can be triggered locally reading malformed btmon capture file
and also over the air by sending specifically crafted SDP Search
Attribute response to device running btmon.

This bug was found by fuzzing btmon with AFL.
2018-10-18 19:10:32 +03:00
Matias Karhumaa
b9085d74f1 btmon: fix segfault caused by buffer overflow
Buffer overflow vulnerability in monitor/sdp.c SDP continuation handling
caused btmon to crash. This happens in global static buffer which makes
it non-trivial to exploit.

This is nasty bug in a way that this can be triggered also over the air
by sending malformed SDP Search Attribute request to device running
btmon.

This crash was foung by fuzzing btmon with AFL. Seems to be reproducible
also with Synopsys Defensics SDP Server suite.
2018-10-18 19:10:26 +03:00
Johan Hedberg
8f90b38846 monitor: Fix uuid.h includes
Commit e0e7eb08d5 tried to fix this, but
missed most of the files concerned.

Without the fix an out-of-tree build (e.g. make distcheck) will throw
errors like this:

  CC       monitor/l2cap.o
../monitor/l2cap.c:41:18: fatal error: uuid.h: No such file or directory
 #include "uuid.h"
2017-12-26 22:47:24 +02:00
Luiz Augusto von Dentz
7a03b61ee8 tools: Remove monitor/uuid.{c,h}
Use the shared/util.h helpers instead.
2017-12-21 10:08:22 -02:00
Marcel Holtmann
d9e800cbc9 monitor: Use local includes for libbluetooth headers 2015-02-12 21:52:00 +01:00
Luiz Augusto von Dentz
1b42893a9a monitor: Fix warnings when using l2cap_frame_get* 2014-08-29 13:01:11 +03:00
Luiz Augusto von Dentz
0cda9502f7 monitor/sdp: Make use of l2cap_frame_get* 2014-08-25 11:33:51 +03:00
Luiz Augusto von Dentz
3b8d6b19e6 monitor: Add mode and channel to struct l2cap_frame
This make it simpler to pass it around.
2014-07-31 15:35:04 +03:00
Szymon Janc
2316c1ebe4 monitor: Fix crash when parsing SDP
get_tid() may return NULL if bogus tid is passed.
This fix following crash:

Invalid write of size 1
   at 0x4A0A643: memcpy@@GLIBC_2.14 (in /usr/lib64/valgrind/
     vgpreload_memcheck-amd64-linux.so)
   by 0x4218E4: search_attr_req (sdp.c:413)
   by 0x42214D: sdp_packet (sdp.c:748)
   by 0x41ED09: l2cap_frame (l2cap.c:2632)
   by 0x414D51: packet_hci_acldata (packet.c:7713)
   by 0x415133: packet_monitor (packet.c:3332)
   by 0x404AEC: control_reader (control.c:911)
   by 0x40231A: main (main.c:197)
 Address 0x6 is not stack'd, malloc'd or (recently) free'd

Process terminating with default action of signal 11 (SIGSEGV)
 Access not within mapped region at address 0x6
   at 0x4A0A643: memcpy@@GLIBC_2.14 (in /usr/lib64/valgrind/
     vgpreload_memcheck-amd64-linux.so)
   by 0x4218E4: search_attr_req (sdp.c:413)
   by 0x42214D: sdp_packet (sdp.c:748)
   by 0x41ED09: l2cap_frame (l2cap.c:2632)
   by 0x414D51: packet_hci_acldata (packet.c:7713)
   by 0x415133: packet_monitor (packet.c:3332)
   by 0x404AEC: control_reader (control.c:911)
   by 0x40231A: main (main.c:197)
2014-06-02 18:28:51 +03:00
Claudio Takahasi
7da5efedae Replace bt_get_be64() by get_be64() 2014-03-24 22:02:47 +02:00
Claudio Takahasi
fbf2103d51 Replace bt_get_be32() by get_be32() 2014-03-24 22:00:38 +02:00
Claudio Takahasi
2c34d92207 Replace bt_get_be16() by get_be16() 2014-03-24 21:59:28 +02:00
Marcel Holtmann
e691f2573a monitor: Update copyright and license details 2014-02-11 10:59:14 -08:00
Szymon Janc
a79f22a45a monitor: Opencode strndupa in print_string
Strndupa is GNU extension. print_string is simple and opencoding
strndupa is not a big loss.

This fix linkage error with bionic library which doesn't provide
strndupa.

target Executable: btmon (out/target/product/grouper/obj/EXECUTABLES/
    btmon_intermediates/LINKED/btmon)
prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.6/bin/../lib/gcc/
    arm-linux-androideabi/4.6.x-google/../../../../
    arm-linux-androideabi/bin/ld: out/target/product/grouper/obj/
    EXECUTABLES/btmon_intermediates/monitor/sdp.o: in function
    print_string:external/bluetooth/bluez/monitor/sdp.c:146: error:
    undefined reference to 'strndupa'
collect2: ld returned 1 exit status
make: *** [out/target/product/grouper/obj/EXECUTABLES/
    btmon_intermediates/LINKED/btmon] Error
2013-08-01 10:53:16 +03:00
Johan Hedberg
b8779d2202 Revert "Ensure config.h is included by using CPPFLAGS"
This reverts commit 8a03376544.

The patch needs to be split up and the gdbus/ changes were bogus
compared to the original commit message.

Conflicts:
	Makefile.am
	Makefile.obexd
	profiles/cyclingspeed/cyclingspeed.c
	profiles/heartrate/heartrate.c
	src/error.c
2012-12-07 12:46:04 +02:00
Lucas De Marchi
8a03376544 Ensure config.h is included by using CPPFLAGS
Instead of trying to include config.h in each file over the tree and
possibly forgetting to include it, give a "-include config.h" argument
to the compiler so it's guaranteed that a) it will be included for all
source files and b) it will be the first header included.

gdbus/ directory is left out, since it would break other projects using
it.
2012-12-05 17:18:07 +02:00
Lucas De Marchi
b84f6f794b build-sys: Define _GNU_SOURCE in config.h
Instead of defining _GNU_SOURCE in each source file (and potentially
forgetting in some), tell the build system we use extensions and let it
define _GNU_SOURCE in config.h.
2012-12-05 17:17:36 +02:00
Marcel Holtmann
f15478ec97 monitor: Handle attribute lists for SDP records 2012-11-21 07:14:06 +01:00
Marcel Holtmann
3beb0c5c08 monitor: Track SDP continuation for attribute lists 2012-11-21 05:35:27 +01:00
Marcel Holtmann
a9953817d3 monitor: Handle UUID-32 and UUID-128 values 2012-11-20 18:01:01 +01:00
Marcel Holtmann
6986e5aa1f monitor: Decode SDP element data structures 2012-11-20 16:12:51 +01:00
Marcel Holtmann
793cc67596 monitor: Add basic decoding for SDP transactions 2012-11-17 01:52:12 +09:00