1. 19 3月, 2022 1 次提交
  2. 04 3月, 2022 1 次提交
  3. 03 3月, 2022 1 次提交
  4. 25 2月, 2022 3 次提交
    • L
      Bluetooth: hci_sync: Fix not using conn_timeout · a56a1138
      Luiz Augusto von Dentz 提交于
      When using hci_le_create_conn_sync it shall wait for the conn_timeout
      since the connection complete may take longer than just 2 seconds.
      
      Also fix the masking of HCI_EV_LE_ENHANCED_CONN_COMPLETE and
      HCI_EV_LE_CONN_COMPLETE so they are never both set so we can predict
      which one the controller will use in case of HCI_OP_LE_CREATE_CONN.
      
      Fixes: 6cd29ec6 ("Bluetooth: hci_sync: Wait for proper events when connecting LE")
      Signed-off-by: NLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
      Signed-off-by: NMarcel Holtmann <marcel@holtmann.org>
      a56a1138
    • L
      Bluetooth: hci_sync: Fix hci_update_accept_list_sync · 80740ebb
      Luiz Augusto von Dentz 提交于
      hci_update_accept_list_sync is returning the filter based on the error
      but that gets overwritten by hci_le_set_addr_resolution_enable_sync
      return instead of using the actual result of the likes of
      hci_le_add_accept_list_sync which was intended.
      
      Fixes: ad383c2c ("Bluetooth: hci_sync: Enable advertising when LL privacy is enabled")
      Signed-off-by: NLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
      Signed-off-by: NMarcel Holtmann <marcel@holtmann.org>
      80740ebb
    • L
      Bluetooth: fix data races in smp_unregister(), smp_del_chan() · fa78d2d1
      Lin Ma 提交于
      Previous commit e0448092 ("Bluetooth: defer cleanup of resources
      in hci_unregister_dev()") defers all destructive actions to
      hci_release_dev() to prevent cocurrent problems like NPD, UAF.
      
      However, there are still some exceptions that are ignored.
      
      The smp_unregister() in hci_dev_close_sync() (previously in
      hci_dev_do_close) will release resources like the sensitive channel
      and the smp_dev objects. Consider the situations the device is detaching
      or power down while the kernel is still operating on it, the following
      data race could take place.
      
      thread-A  hci_dev_close_sync  | thread-B  read_local_oob_ext_data
                                    |
      hci_dev_unlock()              |
      ...                           | hci_dev_lock()
      if (hdev->smp_data)           |
        chan = hdev->smp_data       |
                                    | chan = hdev->smp_data (3)
                                    |
        hdev->smp_data = NULL (1)   | if (!chan || !chan->data) (4)
        ...                         |
        smp = chan->data            | smp = chan->data
        if (smp)                    |
          chan->data = NULL (2)     |
          ...                       |
          kfree_sensitive(smp)      |
                                    | // dereference smp trigger UFA
      
      That is, the objects hdev->smp_data and chan->data both suffer from the
      data races. In a preempt-enable kernel, the above schedule (when (3) is
      before (1) and (4) is before (2)) leads to UAF bugs. It can be
      reproduced in the latest kernel and below is part of the report:
      
      [   49.097146] ================================================================
      [   49.097611] BUG: KASAN: use-after-free in smp_generate_oob+0x2dd/0x570
      [   49.097611] Read of size 8 at addr ffff888006528360 by task generate_oob/155
      [   49.097611]
      [   49.097611] Call Trace:
      [   49.097611]  <TASK>
      [   49.097611]  dump_stack_lvl+0x34/0x44
      [   49.097611]  print_address_description.constprop.0+0x1f/0x150
      [   49.097611]  ? smp_generate_oob+0x2dd/0x570
      [   49.097611]  ? smp_generate_oob+0x2dd/0x570
      [   49.097611]  kasan_report.cold+0x7f/0x11b
      [   49.097611]  ? smp_generate_oob+0x2dd/0x570
      [   49.097611]  smp_generate_oob+0x2dd/0x570
      [   49.097611]  read_local_oob_ext_data+0x689/0xc30
      [   49.097611]  ? hci_event_packet+0xc80/0xc80
      [   49.097611]  ? sysvec_apic_timer_interrupt+0x9b/0xc0
      [   49.097611]  ? asm_sysvec_apic_timer_interrupt+0x12/0x20
      [   49.097611]  ? mgmt_init_hdev+0x1c/0x240
      [   49.097611]  ? mgmt_init_hdev+0x28/0x240
      [   49.097611]  hci_sock_sendmsg+0x1880/0x1e70
      [   49.097611]  ? create_monitor_event+0x890/0x890
      [   49.097611]  ? create_monitor_event+0x890/0x890
      [   49.097611]  sock_sendmsg+0xdf/0x110
      [   49.097611]  __sys_sendto+0x19e/0x270
      [   49.097611]  ? __ia32_sys_getpeername+0xa0/0xa0
      [   49.097611]  ? kernel_fpu_begin_mask+0x1c0/0x1c0
      [   49.097611]  __x64_sys_sendto+0xd8/0x1b0
      [   49.097611]  ? syscall_exit_to_user_mode+0x1d/0x40
      [   49.097611]  do_syscall_64+0x3b/0x90
      [   49.097611]  entry_SYSCALL_64_after_hwframe+0x44/0xae
      [   49.097611] RIP: 0033:0x7f5a59f51f64
      ...
      [   49.097611] RAX: ffffffffffffffda RBX: 0000000000000000 RCX: 00007f5a59f51f64
      [   49.097611] RDX: 0000000000000007 RSI: 00007f5a59d6ac70 RDI: 0000000000000006
      [   49.097611] RBP: 0000000000000000 R08: 0000000000000000 R09: 0000000000000000
      [   49.097611] R10: 0000000000000040 R11: 0000000000000246 R12: 00007ffec26916ee
      [   49.097611] R13: 00007ffec26916ef R14: 00007f5a59d6afc0 R15: 00007f5a59d6b700
      
      To solve these data races, this patch places the smp_unregister()
      function in the protected area by the hci_dev_lock(). That is, the
      smp_unregister() function can not be concurrently executed when
      operating functions (most of them are mgmt operations in mgmt.c) hold
      the device lock.
      
      This patch is tested with kernel LOCK DEBUGGING enabled. The price from
      the extended holding time of the device lock is supposed to be low as the
      smp_unregister() function is fairly short and efficient.
      Signed-off-by: NLin Ma <linma@zju.edu.cn>
      Signed-off-by: NMarcel Holtmann <marcel@holtmann.org>
      fa78d2d1
  5. 28 1月, 2022 1 次提交
  6. 11 1月, 2022 1 次提交
  7. 23 12月, 2021 6 次提交
  8. 22 12月, 2021 1 次提交
  9. 08 12月, 2021 3 次提交
  10. 04 12月, 2021 1 次提交
  11. 16 11月, 2021 3 次提交
  12. 02 11月, 2021 2 次提交
  13. 29 10月, 2021 16 次提交
    • L
      Bluetooth: hci_sync: Rework hci_suspend_notifier · 182ee45d
      Luiz Augusto von Dentz 提交于
      This makes hci_suspend_notifier use the hci_*_sync which can be
      executed synchronously which is allowed in the suspend_notifier and
      simplifies a lot of the handling since the status of each command can
      be checked inline so no other work need to be scheduled thus can be
      performed without using of a state machine.
      Signed-off-by: NLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
      Signed-off-by: NMarcel Holtmann <marcel@holtmann.org>
      182ee45d
    • L
      Bluetooth: hci_sync: Rework init stages · d0b13706
      Luiz Augusto von Dentz 提交于
      This moves the init stages to use the hci_sync infra and in addition
      to that have the stages as function tables so it is easier to change
      the command sequence.
      Signed-off-by: NLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
      Signed-off-by: NMarcel Holtmann <marcel@holtmann.org>
      d0b13706
    • B
      Bluetooth: hci_sync: Convert MGMT_OP_SSP · 3244845c
      Brian Gix 提交于
      mgmt-tester paths:
      Set SSP on - Success 2
      Set Device ID - SSP off and Power on
      Signed-off-by: NBrian Gix <brian.gix@intel.com>
      Signed-off-by: NMarcel Holtmann <marcel@holtmann.org>
      3244845c
    • B
      Bluetooth: hci_sync: Convert MGMT_OP_SET_LOCAL_NAME · 6f6ff38a
      Brian Gix 提交于
      Uses existing *_sync functions, but made hci_update_name_sync
      non-static.
      
      mgmt-test paths:
      Set Advertising on - Local name 1
      Set Advertising on - Name + Appear 1
      Set Local Name - Success 1
      Set Local Name - Success 2
      Set Local Name - Success 3
      Add Advertising - Success (Empty ScRsp)
      Add Advertising - Success (Complete name)
      Add Advertising - Success (Shortened name)
      Add Advertising - Success (Short name)
      Add Advertising - Success (Name + data)
      Add Advertising - Invalid Params (Name + data)
      Add Advertising - Success (Name+data+appear)
      Read Ext Controller Info 3
      Read Ext Controller Info 4
      Read Ext Controller Info 5
      Add Ext Advertising - Success (Empty ScRsp)
      Add Ext Advertising - Success (Complete name)
      Add Ext Advertising - Success (Shortened name)
      Add Ext Advertising - Success (Short name)
      Add Ext Advertising - Success (Name + data)
      Add Ext Advertising - Invalid Params (Name + data)
      Add Ext Advertising - Success (Name+data+appear)
      Signed-off-by: NBrian Gix <brian.gix@intel.com>
      Signed-off-by: NMarcel Holtmann <marcel@holtmann.org>
      6f6ff38a
    • B
      Bluetooth: hci_sync: Convert MGMT_OP_READ_LOCAL_OOB_DATA · f892244b
      Brian Gix 提交于
      New functions:
        hci_read_local_oob_data_sync
      
      This function requires all of the data from the cmd cmplt event
      to be passed up to the caller via the skb.
      
      mgmt-tester paths:
      Read Local OOB Data - Not powered
      Read Local OOB Data - Legacy pairing
      Read Local OOB Data - Success SSP
      Read Local OOB Data - Success SC
      Signed-off-by: NBrian Gix <brian.gix@intel.com>
      Signed-off-by: NMarcel Holtmann <marcel@holtmann.org>
      f892244b
    • B
      Bluetooth: hci_sync: Convert MGMT_OP_SET_LE · d81a494c
      Brian Gix 提交于
      Uses:
        hci_disable_advertising_sync
        hci_remove_ext_adv_instance_sync
        hci_write_le_host_supported_sync
        hci_setup_ext_adv_instance_sync
        hci_update_scan_rsp_data_sync
      Signed-off-by: NBrian Gix <brian.gix@intel.com>
      Signed-off-by: NMarcel Holtmann <marcel@holtmann.org>
      d81a494c
    • B
      Bluetooth: hci_sync: Convert MGMT_OP_GET_CLOCK_INFO · 5a750137
      Brian Gix 提交于
      Synchronous version of MGMT_OP_GET_CLOCK_INFO.
      Signed-off-by: NBrian Gix <brian.gix@intel.com>
      Signed-off-by: NMarcel Holtmann <marcel@holtmann.org>
      5a750137
    • B
      Bluetooth: hci_sync: Convert MGMT_OP_SET_SECURE_CONN · 2f2eb0c9
      Brian Gix 提交于
      Synchronous version of MGMT_OP_SET_SECURE_CONN.
      Signed-off-by: NBrian Gix <brian.gix@intel.com>
      Signed-off-by: NMarcel Holtmann <marcel@holtmann.org>
      2f2eb0c9
    • B
      Bluetooth: hci_sync: Convert MGMT_OP_GET_CONN_INFO · 47db6b42
      Brian Gix 提交于
      Synchronous version of MGMT_OP_GET_CONN_INFO
      
      Implements:
        hci_read_rssi_sync
        hci_read_tx_power_sync
      Signed-off-by: NBrian Gix <brian.gix@intel.com>
      Signed-off-by: NMarcel Holtmann <marcel@holtmann.org>
      47db6b42
    • B
      Bluetooth: hci_sync: Enable synch'd set_bredr · 451d95a9
      Brian Gix 提交于
      Uses previously written:
        hci_write_fast_connectable_sync
        hci_update_scan_sync
        hci_update_adv_data_sync
      Signed-off-by: NBrian Gix <brian.gix@intel.com>
      Signed-off-by: NMarcel Holtmann <marcel@holtmann.org>
      451d95a9
    • B
      Bluetooth: hci_sync: Convert MGMT_OP_SET_FAST_CONNECTABLE · 353a0249
      Brian Gix 提交于
      This creates a synchronized Write Fast Connectable call and attaches it
      to the MGMT_OP_SET_FAST_CONNECTABLE management opcode.
      Signed-off-by: NBrian Gix <brian.gix@intel.com>
      Signed-off-by: NMarcel Holtmann <marcel@holtmann.org>
      353a0249
    • L
      Bluetooth: hci_sync: Convert MGMT_OP_START_DISCOVERY · abfeea47
      Luiz Augusto von Dentz 提交于
      This make use of hci_cmd_sync_queue for MGMT_OP_START_DISCOVERY,
      MGMT_OP_START_SERVICE_DISCOVERY and MGMT_OP_STOP_DISCOVERY to use
      hci_cmd_sync_queue so they no longer depend on hdev->discov_update work
      to send any commands.
      
      Tested with:
      
      tools/mgmt-tester -s "Start Discovery"
      
      Test Summary
      ------------
      Start Discovery - Not powered 1                      Passed
      Start Discovery - Invalid parameters 1               Passed
      Start Discovery - Not supported 1                    Passed
      Start Discovery - Success 1                          Passed
      Start Discovery - Success 2                          Passed
      Start Discovery - Power Off 1                        Passed
      Start Discovery BREDR LE - (Ext Scan Enable)         Passed
      Start Discovery LE - (Ext Scan Enable)               Passed
      Start Discovery LE - (Ext Scan Param)                Passed
      Start Discovery - (2m, Scan Param)                   Passed
      Start Discovery - (coded, Scan Param)                Passed
      Start Discovery - (1m, 2m, coded, Scan Param)        Passed
      LL Privacy - Start Discovery 1 (Disable RL)          Passed
      LL Privacy - Start Discovery 2 (Disable RL)          Passed
      Total: 14, Passed: 14 (100.0%), Failed: 0, Not Run: 0
      
      tools/mgmt-tester -s "Start Service"
      
      Test Summary
      ------------
      Start Service Discovery - Not powered 1              Passed
      Start Service Discovery - Invalid parameters 1       Passed
      Start Service Discovery - Not supported 1            Passed
      Start Service Discovery - Success 1                  Passed
      Start Service Discovery - Success 2                  Passed
      Total: 5, Passed: 5 (100.0%), Failed: 0, Not Run: 0
      
      tools/mgmt-tester -s "Stop Discovery"
      
      Test Summary
      ------------
      Stop Discovery - Success 1                           Passed
      Stop Discovery - BR/EDR (Inquiry) Success 1          Passed
      Stop Discovery - Rejected 1                          Passed
      Stop Discovery - Invalid parameters 1                Passed
      Stop Discovery - (Ext Scan Disable)                  Passed
      Total: 5, Passed: 5 (100.0%), Failed: 0, Not Run: 0
      Signed-off-by: NLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
      Signed-off-by: NMarcel Holtmann <marcel@holtmann.org>
      abfeea47
    • L
      Bluetooth: hci_sync: Convert MGMT_SET_POWERED · cf75ad8b
      Luiz Augusto von Dentz 提交于
      This make use of hci_cmd_sync_queue when MGMT_SET_POWERED is used so all
      commands are run within hdev->cmd_sync_work instead of
      hdev->power_on_work and hdev->power_off_work.
      
      In addition to that the power on sequence now takes into account if
      local IRK needs to be programmed in the resolving list.
      
      Tested with:
      
      tools/mgmt-tester -s "Set powered"
      
      Test Summary
      ------------
      Set powered on - Success                             Passed
      Set powered on - Invalid parameters 1                Passed
      Set powered on - Invalid parameters 2                Passed
      Set powered on - Invalid parameters 3                Passed
      Set powered on - Invalid index                       Passed
      Set powered on - Privacy and Advertising             Passed
      Set powered off - Success                            Passed
      Set powered off - Class of Device                    Passed
      Set powered off - Invalid parameters 1               Passed
      Set powered off - Invalid parameters 2               Passed
      Set powered off - Invalid parameters 3               Passed
      Total: 11, Passed: 11 (100.0%), Failed: 0, Not Run: 0
      Signed-off-by: NLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
      Signed-off-by: NMarcel Holtmann <marcel@holtmann.org>
      cf75ad8b
    • L
      Bluetooth: hci_sync: Rework background scan · 5bee2fd6
      Luiz Augusto von Dentz 提交于
      This replaces the use of hci_update_background_scan with
      hci_update_passive_scan which runs from cmd_work_sync and deal properly
      with resolving list when LL privacy is enabled.
      Signed-off-by: NLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
      Signed-off-by: NMarcel Holtmann <marcel@holtmann.org>
      5bee2fd6
    • L
      Bluetooth: hci_sync: Enable advertising when LL privacy is enabled · ad383c2c
      Luiz Augusto von Dentz 提交于
      This enables advertising when LL privacy is enabled and changes the
      command sequence when resolving list is updated to also account for when
      advertising is enabled using the following sequence:
      
      If there are devices to scan:
      
      Disable Scanning -> Update Accept List ->
      use_ll_privacy((Disable Advertising) -> Disable Resolving List ->
      Update Resolving List -> Enable Resolving List -> (Enable Advertising)) ->
      Enable Scanning
      
      Otherwise:
      
      Disable Scanning
      
      Errors during the Update Accept List stage are handled gracefully by
      restoring any previous state (e.g. advertising) and disabling the use of
      accept list as either accept list or resolving list could not be
      updated.
      
      Tested with:
      
      mgmt-tester -s "LL Privacy"
      
      Test Summary
      ------------
      LL Privacy - Add Device 1 (Add to WL)                Passed
      LL Privacy - Add Device 2 (Add to RL)                Passed
      LL Privacy - Add Device 3 (Enable RL)                Passed
      LL Privacy - Add Device 4 (2 Devices to WL)          Passed
      LL Privacy - Add Device 5 (2 Devices to RL)          Passed
      LL Privacy - Add Device 6 (RL is full)               Passed
      LL Privacy - Add Device 7 (WL is full)               Passed
      LL Privacy - Add Device 8 (Disable Adv)              Passed
      LL Privacy - Add Device 9 (Multi Adv)                Passed
      LL Privacy - Add Device 10 (Multi Dev and Multi Adv) Passed
      LL Privacy - Remove Device 1 (Remove from WL)        Passed
      LL Privacy - Remove Device 2 (Remove from RL)        Passed
      LL Privacy - Remove Device 3 (Disable RL)            Passed
      LL Privacy - Remove Device 4 (Disable Adv)           Passed
      LL Privacy - Remove Device 5 (Multi Adv)             Passed
      LL Privacy - Start Discovery 1 (Disable RL)          Passed
      LL Privacy - Start Discovery 2 (Disable RL)          Passed
      Total: 18, Passed: 18 (100.0%), Failed: 0, Not Run: 0
      Signed-off-by: NLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
      Signed-off-by: NMarcel Holtmann <marcel@holtmann.org>
      ad383c2c
    • L
      Bluetooth: hci_sync: Make use of hci_cmd_sync_queue set 3 · e8907f76
      Luiz Augusto von Dentz 提交于
      This make use of hci_cmd_sync_queue for the following MGMT commands:
      
          Add Device
          Remove Device
      
      Tested with:
      
      mgmt-tester -s "Add Device"
      
      Test Summary
      ------------
      Add Device - Invalid Params 1                        Passed
      Add Device - Invalid Params 2                        Passed
      Add Device - Invalid Params 3                        Passed
      Add Device - Invalid Params 4                        Passed
      Add Device - Success 1                               Passed
      Add Device - Success 2                               Passed
      Add Device - Success 3                               Passed
      Add Device - Success 4                               Passed
      Add Device - Success 5                               Passed
      Add Device - Success 6 - Add to whitelist            Passed
      Add Device - Success 7 - Add to resolv list          Passed
      Add Device - Success 8 - Enable resolv list          Passed
      Total: 12, Passed: 12 (100.0%), Failed: 0, Not Run: 0
      Overall execution time: 0.209 seconds
      
      mgmt-tester -s "Remove Device"
      
      Test Summary
      ------------
      Remove Device - Invalid Params 1                     Passed
      Remove Device - Invalid Params 2                     Passed
      Remove Device - Invalid Params 3                     Passed
      Remove Device - Success 1                            Passed
      Remove Device - Success 2                            Passed
      Remove Device - Success 3                            Passed
      Remove Device - Success 4                            Passed
      Remove Device - Success 5                            Passed
      Remove Device - Success 6 - All Devices              Passed
      Remove Device - Success 7 - Remove from whitelist    Passed
      Remove Device - Success 8 - Remove from resolv list  Passed
      Total: 11, Passed: 11 (100.0%), Failed: 0, Not Run: 0
      Overall execution time: 4.26 seconds
      Signed-off-by: NLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
      Signed-off-by: NMarcel Holtmann <marcel@holtmann.org>
      e8907f76