Commit Graph

26343 Commits

Author SHA1 Message Date
Luiz Augusto von Dentz
2ae3ce9e6d btproxy: Attempt to bind the next index
If no specific index is given attempt to bind the next index if the
current one is already in use.
2022-02-25 15:35:03 -08:00
Nicolas Fella
bf09e1f048 neard: Fix reading State message
dbus_message_iter_recurse only makese sense for container types, this is a string.

Fixes: https://github.com/bluez/bluez/issues/300
2022-02-24 13:57:59 -08:00
Fabrice Fontaine
58dec00edc src/shared/util.h: include sys/types.h
Include sys/types.h to avoid the following build failure on musl raised
since commit fb57ad9b9d:

In file included from src/shared/queue.c:15:
./src/shared/util.h:106:1: error: unknown type name 'ssize_t';
did you mean 'size_t'?
  106 | ssize_t util_getrandom(void *buf, size_t buflen, unsigned int flags);
      | ^~~~~~~
      | size_t

Fixes:
 - http://autobuild.buildroot.org/results/83eaeb3863040645409f5787fdbdde79385c5257
2022-02-24 13:56:30 -08:00
Fabrice Delliaux
65302d98e1 error: Fix typo
s/suuported/supported
2022-02-24 13:55:40 -08:00
Joseph Hwang
d89af9acb7 monitor: fix division by zero about conn->tx_pkt_med
In a connection without outgoing traffic, conn->tx_num will remain 0.
In this case, conn->tx_pkt_med should be simply 0 without calculating
"conn->tx_bytes / conn->tx_num".

This was likely to happen, for example, when "btmon -w btsnoop.log"
was launched in the middle of a LE mouse connection, and a number of
incoming ACL Data RX were received as the mouse movements.  When
running "btmon -a btsnoop.log", it would encounter this error.

Reviewed-by: Alain Michaud <alainm@chromium.org>
Reviewed-by: Yun-Hao Chung <howardchung@chromium.org>
Reviewed-by: Shuo-Peng Liao <deanliao@chromium.org>
2022-02-23 08:57:33 -08:00
Bastien Nocera
b086260ac6 adapter-api: Document per-client discovery sessions
The fact that each client can start its own discovery wasn't clear from
the documentation and only becomes obvious when reading the sources.
2022-02-23 08:57:23 -08:00
Luiz Augusto von Dentz
2e4627c3c9 player: Fix Track being emitted with empty metadata
This sometimes causes the Track to be schedule while some metadata are
still pending, also don't remove the Duration from track when updating
its metadata since Duration is typically updated by player status rather
than metadata.

Fixes: https://github.com/bluez/bluez/issues/291
2022-02-22 11:38:19 -08:00
Tedd Ho-Jeong An
8fe1e5e165 gobex: Fix read from pointer after free
This patch sets the pointer to null after free since the g_free(p)
doesn't set the pointer to NULL.

This is reported by the Coverity.

Fixes: 7e7d826aa1 ("gobex: Print error if data cannot be written")
2022-02-18 13:25:57 -08:00
Michael Nosthoff
51c34da9d6 Makefile.tools: remove duplicate link entry 2022-02-18 13:25:43 -08:00
Tedd Ho-Jeong An
840ca1e7f1 shared: Fix the incorrect type with bit shift
This patch fixes the following runtime error:

$ sudo ./monitor/btmon -w test.btsnoop
  Bluetooth monitor ver 5.63
  src/shared/btsnoop.c:339:18: runtime error: left shift of 65535 by 16 places cannot be represented in type 'int'
2022-02-18 13:25:31 -08:00
Luiz Augusto von Dentz
afefbb4872 main.conf: Fix parsing of mode options
This replace the use of g_key_file_get_integer, which is limited to
only decimal values, to g_key_file_get_string and then use strtol to
convert the string value to integer.

Fixes: https://github.com/bluez/bluez/issues/293
2022-02-18 13:17:00 -08:00
Luiz Augusto von Dentz
d96c2fd877 adapter: Fix allowing multiple adapters with the same address
The bdaddr of an adapter is used for its unique storage path so having
multiple adapters with the same address would likely cause problems
with its storage as they would be shared.
2022-02-16 15:16:48 -08:00
Luiz Augusto von Dentz
a1cdd683df main.conf: Introduce MaxControllers
This introduces MaxControllers which can be used to limit the number of
adapters exposed in the system.
2022-02-16 15:16:29 -08:00
Michael Nosthoff
ec8c8f22ef tools/mesh-cfgtest: include limits.h
mesh-cfgtest.c uses MAX_PATH so it should include limits.h.

fixes compilation error with musl-based toolchains.
2022-02-16 10:30:12 -08:00
Daniel Trnka
e6b7d537d7 adapter: battery provider for non-LE controllers
Enable battery provider dbus interface BatteryProviderManager1 for
non-LE controllers, so external clients like pipewire can provide
battery information for bluetooth headsets on non-LE controllers.

Reviewed-by: Sonny Sasaka <sonnysasaka@chromium.org>
2022-02-15 13:54:39 -08:00
Fabrice Fontaine
fb57ad9b9d build: Fix errors with glibc < 2.25
getrandom and sys/random.h are only available since glibc 2.25:
https://www.gnu.org/software/gnulib/manual/html_node/sys_002frandom_002eh.html
resulting in the following build failures since version 5.63 and
https://git.kernel.org/pub/scm/bluetooth/bluez.git/log/?qt=grep&q=getrandom:

plugins/autopair.c:20:24: fatal error: sys/random.h: No such file or directory
 #include <sys/random.h>
                        ^

To fix this build failure, add util_getrandom and a fallback (borrowed
from pipewire and licensed under MIT):
https://gitlab.freedesktop.org/pipewire/pipewire/-/blob/master/src/pipewire/utils.c

Fixes:
 - http://autobuild.buildroot.org/results/6b8870d12e0804d6154230a7322c49416c1dc0e2
2022-02-15 13:36:35 -08:00
Yun-Hao Chung
b5ff08b267 lib: fix hci_strtolm crash
|str| can be NULL in the case of reading lm value. Calling strcasestr
could lead to a crash.

Reviewed-by: Archie Pusaka <apusaka@chromium.org>
2022-02-15 13:31:42 -08:00
Luiz Augusto von Dentz
6c9c4b7c3a rfcomm-tester: Increase amount of data from 8k to 32k
This forces the behavior where not all data can be written at once so it
is able to reproduce the from [1].

[1]https://bugzilla.kernel.org/show_bug.cgi?id=215594
2022-02-14 17:47:13 -08:00
Luiz Augusto von Dentz
7e7d826aa1 gobex: Print error if data cannot be written
This makes sure that if the data cannot be written it fails and the
error is properly printed.
2022-02-14 15:40:40 -08:00
Luiz Augusto von Dentz
47bea5418c obexctl: Add optional argument channel to connect command
This adds a third argument to connect command so a channel can be passed
to CreateSession which is useful since it possible to force a specific
RFCOMM channel.
2022-02-14 15:15:20 -08:00
Tedd Ho-Jeong An
002c0c9eda profiles: Fix the reusing gerror without re-initialization
When the GError variable is freeed with g_error_free(), it is not set to
NULL and reusing the same variable again can cause the seg_fault because
it is still pointing the old memory address which is freed.

This patch relaces the g_error_free() to g_clear_error() which frees the
variable and set it to NULL if the variable is used in the function
again.

Fixes: 4ad622d592 ("profiles/a2dp: Fix unchecked return value")
2022-02-11 14:17:27 -08:00
Tedd Ho-Jeong An
8b69a634f4 device: Fix the reusing gerror without re-initialization
When the GError variable is freeed with g_error_free(), it is not set to
NULL and reusing the same variable again can cause the seg_fault because
it is still pointing the old memory address which is freed.

This patch relaces the g_error_free() to g_clear_error() which frees the
variable and set it to NULL if the variable is used in the function
again.

Fixes: 6a154cd080 ("device: Fix unchecked return value")
2022-02-11 14:17:27 -08:00
Tedd Ho-Jeong An
b4e74f7bd0 adapter: Fix the reusing gerror without re-initialization
When the GError variable is freeed with g_error_free(), it is not set to
NULL and reusing the same variable again can cause the seg_fault because
it is still pointing the old memory address which is freed.

This patch relaces the g_error_free() to g_clear_error() which frees the
variable and set it to NULL if the variable is used in the function
again.

Fixes: 2287c517ca ("adapter: Fix unchecked return value")
Fixes: https://github.com/bluez/bluez/issues/276
2022-02-11 14:17:27 -08:00
Luiz Augusto von Dentz
24d986e72d device: Fix crash when removing device
Calling btd_adapter_remove_device from device_remove_connection can
cause a crash, so instead of removing it immediatelly this set a the
temporary timeout to 0.

Fixes: https://github.com/bluez/bluez/issues/290
2022-02-10 14:55:20 -08: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
Luiz Augusto von Dentz
f3ddc74442 uuid: Fix crashing if a NULL string is passed to bt_string_to_uuid
bt_string_to_uuid shall chack if the string is valid before attempting
to access its contents.
2022-02-09 16:03:45 -08:00
Luiz Augusto von Dentz
c70b23d33b adapter: Fix crash when storing link key
The following trace can be observed sometimes when pairing 2 emulator
instances:

 src/adapter.c:store_link_key() Unable to load key file from
 /var/lib/bluetooth/9C:DA:3E:F2:8E:46/9C:B6:D0:8A:A0:0C/info: (No
such file or directory)
 GLib: g_file_set_contents: assertion 'error == NULL ||
*error == NULL' failed
 ++++++++ backtrace ++++++++
 #1  btd_backtrace+0x28a (src/backtrace.c:59) [0x7f65bb5ab53a]
 #2  g_logv+0x21c (/usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6400.6)
 [0x7f65ba3f955c]
 #3  g_log+0x93 (/usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6400.6)
 [0x7f65ba3f9743]
 #4  g_file_set_contents+0x68
(/usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6400.6) [0x7f65ba3dca68]
 #5  store_link_key+0x30a (src/adapter.c:8235) [0x7f65bb61839a]
 #6  new_link_key_callback+0x474 (src/adapter.c:8285) [0x7f65bb62c904]
 #7  queue_foreach+0x164 (src/shared/queue.c:203) [0x7f65bb722e34]
 #8  can_read_data+0x59f (src/shared/mgmt.c:343) [0x7f65bb72e09f]
 #9  watch_callback+0x112 (src/shared/io-glib.c:162) [0x7f65bb78acb2]
 #10 g_main_context_dispatch+0x14e
(/usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6400.6) [0x7f65ba3f204e]
2022-02-09 15:56:11 -08:00
Luiz Augusto von Dentz
ec5209afea rfcomm-tester: Add test to write big chunks of data
This attempts to test traffic similar to OBEX using big chunk of data.
2022-02-09 15:43:05 -08:00
Luiz Augusto von Dentz
bfc6cf43c8 bthost: Increase number of credits
This increase the number of credits so bigger packets can be sent by
the likes of rfcomm-tester.
2022-02-09 15:43:03 -08:00
Luiz Augusto von Dentz
9f081972cb bthost: Fix length calculation for RFCOMM header
This fixes the length calculation for large packets that requires more
than 1 byte.
2022-02-09 15:43:02 -08:00
Luiz Augusto von Dentz
e700d5526c bthost: Fix not handling ACL fragmentation
Large packets requires the support of ACL fragmentation in order to be
properly processed.
2022-02-09 15:42:45 -08:00
Luiz Augusto von Dentz
d84b9950fe bootstrap-configure: Don't enable admin plugin by default
Admin plugin doesn't work properly when there are multiple adapters in
the system.
2022-02-09 15:42:45 -08:00
Luiz Augusto von Dentz
264177eb4a adv_monitor: Fix spamming errors
If advertising manager is not enabled don't log any error on
btd_adapter_update_found_device, also change
btd_adv_monitor_offload_supported to btd_adv_monitor_offload_enabled
since that is checking if the features has been enabled rather than it
is just supported.

Fixes: https://github.com/bluez/bluez/issues/286
2022-02-08 13:15:59 -08:00
Luiz Augusto von Dentz
19448b9cb8 gdbus: Emit InterfacesAdded of parents objects first
This makes InterfacesAdded respect the object hierarchy in case its
parent has pending interfaces to be added.

Fixes: https://github.com/bluez/bluez/issues/272
Fixes: https://github.com/bluez/bluez/issues/284
Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1534857
Fixes: https://bugs.archlinux.org/task/57464
2022-02-04 13:13:28 -08:00
Michał Lowas-Rzechonek
3f72b45150 mesh: Skip unneeded logs 2022-02-04 12:12:27 -08:00
Michał Lowas-Rzechonek
7083cad2fb mesh: Make key_aid and net_key_id naming consistent
- key_aid refers to application key AID
- net_key_id refers to unique, internal id of the network key, used in
  net-keys.h

Also, remove unused mesh_frnd_pkt struct.
2022-02-04 12:12:27 -08:00
Brian Gix
c2c0bff891 mesh: Fix sequence number of message in friend queue
As pointed out by https://github.com/bluez/bluez/issues/250, the last
segment of a multi-segmented message added to Friend Queue was getting
reset to the seqAuth value incorrectly. The correct sequence was set
within the preceding for loop.
2022-02-04 11:45:02 -08:00
Luiz Augusto von Dentz
c1e12f4da6 btdev: Fix response to BT_HCI_CMD_LE_REMOVE_CIG
BT_HCI_CMD_LE_REMOVE_CIG should respond with the CIG ID from the
command instead of always responding with 0x00.
2022-01-31 16:37:27 -08:00
Luiz Augusto von Dentz
8c6ff341bb btdev: Fix command status of BT_HCI_CMD_LE_TERM_BIG
The status was reporting BT_HCI_CMD_DISCONNECT instead of
BT_HCI_CMD_LE_TERM_BIG.
2022-01-31 16:37:27 -08:00
Luiz Augusto von Dentz
0cf3bbbf94 monitor: Fix misaligment errors when parsing BIG/CIG events
This fixes erros such as:

  monitor/packet.c:8129:2: runtime error: load of misaligned address
  0x55956a438f2d for type 'const uint16_t', which requires 2 byte
  alignment
2022-01-31 16:37:27 -08:00
Bastien Nocera
340a7b9785 systemd: More lockdown
bluetoothd does not need to execute mapped memory, or real-time
access, so block those.
2022-01-31 10:37:55 -08:00
Bastien Nocera
442d211b5f systemd: Add more filesystem lockdown
We can only access the configuration file as read-only and read-write
to the Bluetooth cache directory and sub-directories.
2022-01-31 10:37:55 -08:00
Craig Andrews
8d2db81eb7 systemd: Add PrivateTmp and NoNewPrivileges options
PrivateTmp makes bluetoothd's /tmp and /var/tmp be inside a different
namespace. This is useful to secure access to temporary files of the
process.

NoNewPrivileges ensures that service process and all its children
can never gain new privileges through execve(), lowering the risk of
possible privilege escalations.
2022-01-31 10:37:54 -08:00
Bastien Nocera
caeabc4127 build: Always define confdir and statedir
As we will need those paths to lock down on them.
2022-01-31 10:37:54 -08:00
Luiz Augusto von Dentz
5f378404bf adapter: Remove custom MGMT send/reply timeout
This removes the custom MGMT send/reply timeout since bt_mgmt itself
can handle them itself and it actually start the timer only when the
command is actually sent to the kernel rather then when it is queued.

Fixes: https://github.com/bluez/bluez/issues/275
2022-01-28 13:03:28 -08:00
Luiz Augusto von Dentz
faad125c55 shared/mgmt: Add request timeout handling
This adds request timeout handling when using mgmt_send_timeout and
mgmt_reply_timeout, the timeout is applied to the request only when it
is actually transmitted and not while queued.
2022-01-27 18:03:00 -08:00
Luiz Augusto von Dentz
57d33535d5 btdev: Add implementation for BT_HCI_CMD_LE_TERM_BIG
This adds handler for BT_HCI_CMD_LE_TERM_BIG and generate
BT_HCI_EVT_LE_BIG_TERMINATE to indicate to the host stack that the
BIG has been terminated.
2022-01-27 17:42:16 -08:00
Luiz Augusto von Dentz
80e8c846c0 gatt: Make use of gatt_db_attribute_notify
This makes use of gatt_db_attribute_notify to send indications of
Service Changed.
2022-01-27 17:21:45 -08:00
Luiz Augusto von Dentz
b86412b6fe shared/gatt-db: Introduce gatt_db_attribute_notify
This introduces gatt_db_attribute_notify which can be used to trigger a
notification using the callback set by gatt_db_ccc_register.
2022-01-27 17:10:22 -08:00
Luiz Augusto von Dentz
88e062f143 gatt: Make use of gatt_db_service_add_ccc
This uses gatt_db_service_add_ccc and gatt_db_ccc_register so any ccc
registered with the use of the former gets proper state tracking.
2022-01-21 12:40:10 -08:00