26 Sep, 2020

1 commit


11 Jul, 2020

1 commit

  • Replace the existing /* fall through */ comments and its variants with
    the new pseudo-keyword macro fallthrough[1]. Also, remove unnecessary
    fall-through markings when it is the case.

    [1] https://www.kernel.org/doc/html/latest/process/deprecated.html?highlight=fallthrough#implicit-switch-case-fall-through

    Signed-off-by: Gustavo A. R. Silva
    Signed-off-by: Marcel Holtmann

    Gustavo A. R. Silva
     

18 Jun, 2020

1 commit

  • If user decides to cancel the ongoing pairing process (e.g. by clicking
    the cancel button on pairing/passkey window), abort any ongoing pairing
    and then terminate the link if it was created because of the pair
    device action.

    Signed-off-by: Manish Mandlik
    Signed-off-by: Marcel Holtmann
    Signed-off-by: Johan Hedberg

    Manish Mandlik
     

11 May, 2020

1 commit

  • Fix 2 typos in L2CAP_CREDIT_BASED_CONNECTION_REQ (0x17) handling function, that
    cause BlueZ answer with L2CAP_CR_LE_INVALID_PARAMS or L2CAP_CR_LE_INVALID_SCID
    error on a correct ECRED connection request.

    Enchanced Credit Based Mode support was recently introduced with the commit
    15f02b91056253e8cdc592888f431da0731337b8 ("Bluetooth: L2CAP: Add initial code
    for Enhanced Credit Based Mode").

    Signed-off-by: Konstantin Forostyan
    Signed-off-by: Marcel Holtmann

    Konstantin Forostyan
     

26 Mar, 2020

1 commit


15 Mar, 2020

1 commit

  • net/bluetooth/l2cap_core.c: In function l2cap_ecred_conn_req:
    net/bluetooth/l2cap_core.c:5848:6: warning: variable credits set but not used [-Wunused-but-set-variable]

    commit 15f02b910562 ("Bluetooth: L2CAP: Add initial code for Enhanced Credit Based Mode")
    involved this unused variable, remove it.

    Reported-by: Hulk Robot
    Signed-off-by: YueHaibing
    Signed-off-by: Marcel Holtmann

    YueHaibing
     

12 Mar, 2020

1 commit

  • According to Core Spec Version 5.2 | Vol 3, Part A 6.1.5,
    the incoming L2CAP_ConfigReq should be handled during
    OPEN state.

    The section below shows the btmon trace when running
    L2CAP/COS/CFD/BV-12-C before and after this change.

    === Before ===
    ...
    > ACL Data RX: Handle 256 flags 0x02 dlen 12 #22
    L2CAP: Connection Request (0x02) ident 2 len 4
    PSM: 1 (0x0001)
    Source CID: 65
    < ACL Data TX: Handle 256 flags 0x00 dlen 16 #23
    L2CAP: Connection Response (0x03) ident 2 len 8
    Destination CID: 64
    Source CID: 65
    Result: Connection successful (0x0000)
    Status: No further information available (0x0000)
    < ACL Data TX: Handle 256 flags 0x00 dlen 12 #24
    L2CAP: Configure Request (0x04) ident 2 len 4
    Destination CID: 65
    Flags: 0x0000
    > HCI Event: Number of Completed Packets (0x13) plen 5 #25
    Num handles: 1
    Handle: 256
    Count: 1
    > HCI Event: Number of Completed Packets (0x13) plen 5 #26
    Num handles: 1
    Handle: 256
    Count: 1
    > ACL Data RX: Handle 256 flags 0x02 dlen 16 #27
    L2CAP: Configure Request (0x04) ident 3 len 8
    Destination CID: 64
    Flags: 0x0000
    Option: Unknown (0x10) [hint]
    01 00 ..
    < ACL Data TX: Handle 256 flags 0x00 dlen 18 #28
    L2CAP: Configure Response (0x05) ident 3 len 10
    Source CID: 65
    Flags: 0x0000
    Result: Success (0x0000)
    Option: Maximum Transmission Unit (0x01) [mandatory]
    MTU: 672
    > HCI Event: Number of Completed Packets (0x13) plen 5 #29
    Num handles: 1
    Handle: 256
    Count: 1
    > ACL Data RX: Handle 256 flags 0x02 dlen 14 #30
    L2CAP: Configure Response (0x05) ident 2 len 6
    Source CID: 64
    Flags: 0x0000
    Result: Success (0x0000)
    > ACL Data RX: Handle 256 flags 0x02 dlen 20 #31
    L2CAP: Configure Request (0x04) ident 3 len 12
    Destination CID: 64
    Flags: 0x0000
    Option: Unknown (0x10) [hint]
    01 00 91 02 11 11 ......
    < ACL Data TX: Handle 256 flags 0x00 dlen 14 #32
    L2CAP: Command Reject (0x01) ident 3 len 6
    Reason: Invalid CID in request (0x0002)
    Destination CID: 64
    Source CID: 65
    > HCI Event: Number of Completed Packets (0x13) plen 5 #33
    Num handles: 1
    Handle: 256
    Count: 1
    ...
    === After ===
    ...
    > ACL Data RX: Handle 256 flags 0x02 dlen 12 #22
    L2CAP: Connection Request (0x02) ident 2 len 4
    PSM: 1 (0x0001)
    Source CID: 65
    < ACL Data TX: Handle 256 flags 0x00 dlen 16 #23
    L2CAP: Connection Response (0x03) ident 2 len 8
    Destination CID: 64
    Source CID: 65
    Result: Connection successful (0x0000)
    Status: No further information available (0x0000)
    < ACL Data TX: Handle 256 flags 0x00 dlen 12 #24
    L2CAP: Configure Request (0x04) ident 2 len 4
    Destination CID: 65
    Flags: 0x0000
    > HCI Event: Number of Completed Packets (0x13) plen 5 #25
    Num handles: 1
    Handle: 256
    Count: 1
    > HCI Event: Number of Completed Packets (0x13) plen 5 #26
    Num handles: 1
    Handle: 256
    Count: 1
    > ACL Data RX: Handle 256 flags 0x02 dlen 16 #27
    L2CAP: Configure Request (0x04) ident 3 len 8
    Destination CID: 64
    Flags: 0x0000
    Option: Unknown (0x10) [hint]
    01 00 ..
    < ACL Data TX: Handle 256 flags 0x00 dlen 18 #28
    L2CAP: Configure Response (0x05) ident 3 len 10
    Source CID: 65
    Flags: 0x0000
    Result: Success (0x0000)
    Option: Maximum Transmission Unit (0x01) [mandatory]
    MTU: 672
    > HCI Event: Number of Completed Packets (0x13) plen 5 #29
    Num handles: 1
    Handle: 256
    Count: 1
    > ACL Data RX: Handle 256 flags 0x02 dlen 14 #30
    L2CAP: Configure Response (0x05) ident 2 len 6
    Source CID: 64
    Flags: 0x0000
    Result: Success (0x0000)
    > ACL Data RX: Handle 256 flags 0x02 dlen 20 #31
    L2CAP: Configure Request (0x04) ident 3 len 12
    Destination CID: 64
    Flags: 0x0000
    Option: Unknown (0x10) [hint]
    01 00 91 02 11 11 .....
    < ACL Data TX: Handle 256 flags 0x00 dlen 18 #32
    L2CAP: Configure Response (0x05) ident 3 len 10
    Source CID: 65
    Flags: 0x0000
    Result: Success (0x0000)
    Option: Maximum Transmission Unit (0x01) [mandatory]
    MTU: 672
    < ACL Data TX: Handle 256 flags 0x00 dlen 12 #33
    L2CAP: Configure Request (0x04) ident 3 len 4
    Destination CID: 65
    Flags: 0x0000
    > HCI Event: Number of Completed Packets (0x13) plen 5 #34
    Num handles: 1
    Handle: 256
    Count: 1
    > HCI Event: Number of Completed Packets (0x13) plen 5 #35
    Num handles: 1
    Handle: 256
    Count: 1
    ...

    Signed-off-by: Howard Chung
    Signed-off-by: Marcel Holtmann

    Howard Chung
     

08 Mar, 2020

3 commits


29 Jan, 2020

1 commit

  • There is no lock preventing both l2cap_sock_release() and
    chan->ops->close() from running at the same time.

    If we consider Thread A running l2cap_chan_timeout() and Thread B running
    l2cap_sock_release(), expected behavior is:
    A::l2cap_chan_timeout()->l2cap_chan_close()->l2cap_sock_teardown_cb()
    A::l2cap_chan_timeout()->l2cap_sock_close_cb()->l2cap_sock_kill()
    B::l2cap_sock_release()->sock_orphan()
    B::l2cap_sock_release()->l2cap_sock_kill()

    where,
    sock_orphan() clears "sk->sk_socket" and l2cap_sock_teardown_cb() marks
    socket as SOCK_ZAPPED.

    In l2cap_sock_kill(), there is an "if-statement" that checks if both
    sock_orphan() and sock_teardown() has been run i.e. sk->sk_socket is NULL
    and socket is marked as SOCK_ZAPPED. Socket is killed if the condition is
    satisfied.

    In the race condition, following occurs:
    A::l2cap_chan_timeout()->l2cap_chan_close()->l2cap_sock_teardown_cb()
    B::l2cap_sock_release()->sock_orphan()
    B::l2cap_sock_release()->l2cap_sock_kill()
    A::l2cap_chan_timeout()->l2cap_sock_close_cb()->l2cap_sock_kill()

    In this scenario, "if-statement" is true in both B::l2cap_sock_kill() and
    A::l2cap_sock_kill() and we hit "refcount: underflow; use-after-free" bug.

    Similar condition occurs at other places where teardown/sock_kill is
    happening:
    l2cap_disconnect_rsp()->l2cap_chan_del()->l2cap_sock_teardown_cb()
    l2cap_disconnect_rsp()->l2cap_sock_close_cb()->l2cap_sock_kill()

    l2cap_conn_del()->l2cap_chan_del()->l2cap_sock_teardown_cb()
    l2cap_conn_del()->l2cap_sock_close_cb()->l2cap_sock_kill()

    l2cap_disconnect_req()->l2cap_chan_del()->l2cap_sock_teardown_cb()
    l2cap_disconnect_req()->l2cap_sock_close_cb()->l2cap_sock_kill()

    l2cap_sock_cleanup_listen()->l2cap_chan_close()->l2cap_sock_teardown_cb()
    l2cap_sock_cleanup_listen()->l2cap_sock_kill()

    Protect teardown/sock_kill and orphan/sock_kill by adding hold_lock on
    l2cap channel to ensure that the socket is killed only after marked as
    zapped and orphan.

    Signed-off-by: Manish Mandlik
    Signed-off-by: Marcel Holtmann

    Manish Mandlik
     

09 Jan, 2020

1 commit


04 Jan, 2020

1 commit

  • This enables the code to set the input MTU using the underline link
    packet types when set to 0, previously this would likely be rejected by
    the remote peer since it would be bellow the minimal of 48 for BR/EDR
    or 23 for LE, that way it shall be safe to use 0 without causing any
    side effects.

    This is convenient for the likes of A2DP transport, see:

    https://habr.com/en/post/456182/

    Signed-off-by: Luiz Augusto von Dentz
    Signed-off-by: Marcel Holtmann

    Luiz Augusto von Dentz
     

19 Nov, 2019

1 commit

  • We used to take a lock in amp_physical_cfm() but then we moved it to
    the caller function. Unfortunately the unlock on this error path was
    overlooked so it leads to a double unlock.

    Fixes: a514b17fab51 ("Bluetooth: Refactor locking in amp_physical_cfm")
    Signed-off-by: Dan Carpenter
    Signed-off-by: Marcel Holtmann

    Dan Carpenter
     

05 Sep, 2019

1 commit

  • This reverts commit c49a8682fc5d298d44e8d911f4fa14690ea9485e.

    There are devices which require low connection intervals for usable operation
    including keyboards and mice. Forcing a static connection interval for
    these types of devices has an impact in latency and causes a regression.

    Signed-off-by: Marcel Holtmann
    Signed-off-by: Johan Hedberg

    Marcel Holtmann
     

17 Aug, 2019

1 commit


12 Jul, 2019

1 commit

  • Pull networking updates from David Miller:
    "Some highlights from this development cycle:

    1) Big refactoring of ipv6 route and neigh handling to support
    nexthop objects configurable as units from userspace. From David
    Ahern.

    2) Convert explored_states in BPF verifier into a hash table,
    significantly decreased state held for programs with bpf2bpf
    calls, from Alexei Starovoitov.

    3) Implement bpf_send_signal() helper, from Yonghong Song.

    4) Various classifier enhancements to mvpp2 driver, from Maxime
    Chevallier.

    5) Add aRFS support to hns3 driver, from Jian Shen.

    6) Fix use after free in inet frags by allocating fqdirs dynamically
    and reworking how rhashtable dismantle occurs, from Eric Dumazet.

    7) Add act_ctinfo packet classifier action, from Kevin
    Darbyshire-Bryant.

    8) Add TFO key backup infrastructure, from Jason Baron.

    9) Remove several old and unused ISDN drivers, from Arnd Bergmann.

    10) Add devlink notifications for flash update status to mlxsw driver,
    from Jiri Pirko.

    11) Lots of kTLS offload infrastructure fixes, from Jakub Kicinski.

    12) Add support for mv88e6250 DSA chips, from Rasmus Villemoes.

    13) Various enhancements to ipv6 flow label handling, from Eric
    Dumazet and Willem de Bruijn.

    14) Support TLS offload in nfp driver, from Jakub Kicinski, Dirk van
    der Merwe, and others.

    15) Various improvements to axienet driver including converting it to
    phylink, from Robert Hancock.

    16) Add PTP support to sja1105 DSA driver, from Vladimir Oltean.

    17) Add mqprio qdisc offload support to dpaa2-eth, from Ioana
    Radulescu.

    18) Add devlink health reporting to mlx5, from Moshe Shemesh.

    19) Convert stmmac over to phylink, from Jose Abreu.

    20) Add PTP PHC (Physical Hardware Clock) support to mlxsw, from
    Shalom Toledo.

    21) Add nftables SYNPROXY support, from Fernando Fernandez Mancera.

    22) Convert tcp_fastopen over to use SipHash, from Ard Biesheuvel.

    23) Track spill/fill of constants in BPF verifier, from Alexei
    Starovoitov.

    24) Support bounded loops in BPF, from Alexei Starovoitov.

    25) Various page_pool API fixes and improvements, from Jesper Dangaard
    Brouer.

    26) Just like ipv4, support ref-countless ipv6 route handling. From
    Wei Wang.

    27) Support VLAN offloading in aquantia driver, from Igor Russkikh.

    28) Add AF_XDP zero-copy support to mlx5, from Maxim Mikityanskiy.

    29) Add flower GRE encap/decap support to nfp driver, from Pieter
    Jansen van Vuuren.

    30) Protect against stack overflow when using act_mirred, from John
    Hurley.

    31) Allow devmap map lookups from eBPF, from Toke Høiland-Jørgensen.

    32) Use page_pool API in netsec driver, Ilias Apalodimas.

    33) Add Google gve network driver, from Catherine Sullivan.

    34) More indirect call avoidance, from Paolo Abeni.

    35) Add kTLS TX HW offload support to mlx5, from Tariq Toukan.

    36) Add XDP_REDIRECT support to bnxt_en, from Andy Gospodarek.

    37) Add MPLS manipulation actions to TC, from John Hurley.

    38) Add sending a packet to connection tracking from TC actions, and
    then allow flower classifier matching on conntrack state. From
    Paul Blakey.

    39) Netfilter hw offload support, from Pablo Neira Ayuso"

    * git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next: (2080 commits)
    net/mlx5e: Return in default case statement in tx_post_resync_params
    mlx5: Return -EINVAL when WARN_ON_ONCE triggers in mlx5e_tls_resync().
    net: dsa: add support for BRIDGE_MROUTER attribute
    pkt_sched: Include const.h
    net: netsec: remove static declaration for netsec_set_tx_de()
    net: netsec: remove superfluous if statement
    netfilter: nf_tables: add hardware offload support
    net: flow_offload: rename tc_cls_flower_offload to flow_cls_offload
    net: flow_offload: add flow_block_cb_is_busy() and use it
    net: sched: remove tcf block API
    drivers: net: use flow block API
    net: sched: use flow block API
    net: flow_offload: add flow_block_cb_{priv, incref, decref}()
    net: flow_offload: add list handling functions
    net: flow_offload: add flow_block_cb_alloc() and flow_block_cb_free()
    net: flow_offload: rename TCF_BLOCK_BINDER_TYPE_* to FLOW_BLOCK_BINDER_TYPE_*
    net: flow_offload: rename TC_BLOCK_{UN}BIND to FLOW_BLOCK_{UN}BIND
    net: flow_offload: add flow_block_cb_setup_simple()
    net: hisilicon: Add an tx_desc to adapt HI13X1_GMAC
    net: hisilicon: Add an rx_desc to adapt HI13X1_GMAC
    ...

    Linus Torvalds
     

06 Jul, 2019

3 commits

  • The spec defines PSM and LE_PSM as different domains so a listen on the
    same PSM is valid if the address type points to a different bearer.

    Signed-off-by: Luiz Augusto von Dentz
    Signed-off-by: Marcel Holtmann

    Luiz Augusto von Dentz
     
  • Problem: The Linux Bluetooth stack yields complete control over the BLE
    connection interval to the remote device.

    The Linux Bluetooth stack provides access to the BLE connection interval
    min and max values through /sys/kernel/debug/bluetooth/hci0/
    conn_min_interval and /sys/kernel/debug/bluetooth/hci0/conn_max_interval.
    These values are used for initial BLE connections, but the remote device
    has the ability to request a connection parameter update. In the event
    that the remote side requests to change the connection interval, the Linux
    kernel currently only validates that the desired value is within the
    acceptable range in the Bluetooth specification (6 - 3200, corresponding to
    7.5ms - 4000ms). There is currently no validation that the desired value
    requested by the remote device is within the min/max limits specified in
    the conn_min_interval/conn_max_interval configurations. This essentially
    leads to Linux yielding complete control over the connection interval to
    the remote device.

    The proposed patch adds a verification step to the connection parameter
    update mechanism, ensuring that the desired value is within the min/max
    bounds of the current connection. If the desired value is outside of the
    current connection min/max values, then the connection parameter update
    request is rejected and the negative response is returned to the remote
    device. Recall that the initial connection is established using the local
    conn_min_interval/conn_max_interval values, so this allows the Linux
    administrator to retain control over the BLE connection interval.

    The one downside that I see is that the current default Linux values for
    conn_min_interval and conn_max_interval typically correspond to 30ms and
    50ms respectively. If this change were accepted, then it is feasible that
    some devices would no longer be able to negotiate to their desired
    connection interval values. This might be remedied by setting the default
    Linux conn_min_interval and conn_max_interval values to the widest
    supported range (6 - 3200 / 7.5ms - 4000ms). This could lead to the same
    behavior as the current implementation, where the remote device could
    request to change the connection interval value to any value that is
    permitted by the Bluetooth specification, and Linux would accept the
    desired value.

    Signed-off-by: Carey Sonsino
    Signed-off-by: Marcel Holtmann

    csonsino
     
  • Because of both sides doing L2CAP disconnection at the same time, it
    was possible to receive L2CAP Disconnection Response with CID that was
    already freed. That caused problems if CID was already reused and L2CAP
    Connection Request with same CID was sent out. Before this patch kernel
    deleted channel context regardless of the state of the channel.

    Example where leftover Disconnection Response (frame #402) causes local
    device to delete L2CAP channel which was not yet connected. This in
    turn confuses remote device's stack because same CID is re-used without
    properly disconnecting.

    Btmon capture before patch:
    ** snip **
    > ACL Data RX: Handle 43 flags 0x02 dlen 8 #394 [hci1] 10.748949
    Channel: 65 len 4 [PSM 3 mode 0] {chan 2}
    RFCOMM: Disconnect (DISC) (0x43)
    Address: 0x03 cr 1 dlci 0x00
    Control: 0x53 poll/final 1
    Length: 0
    FCS: 0xfd
    < ACL Data TX: Handle 43 flags 0x00 dlen 8 #395 [hci1] 10.749062
    Channel: 65 len 4 [PSM 3 mode 0] {chan 2}
    RFCOMM: Unnumbered Ack (UA) (0x63)
    Address: 0x03 cr 1 dlci 0x00
    Control: 0x73 poll/final 1
    Length: 0
    FCS: 0xd7
    < ACL Data TX: Handle 43 flags 0x00 dlen 12 #396 [hci1] 10.749073
    L2CAP: Disconnection Request (0x06) ident 17 len 4
    Destination CID: 65
    Source CID: 65
    > HCI Event: Number of Completed Packets (0x13) plen 5 #397 [hci1] 10.752391
    Num handles: 1
    Handle: 43
    Count: 1
    > HCI Event: Number of Completed Packets (0x13) plen 5 #398 [hci1] 10.753394
    Num handles: 1
    Handle: 43
    Count: 1
    > ACL Data RX: Handle 43 flags 0x02 dlen 12 #399 [hci1] 10.756499
    L2CAP: Disconnection Request (0x06) ident 26 len 4
    Destination CID: 65
    Source CID: 65
    < ACL Data TX: Handle 43 flags 0x00 dlen 12 #400 [hci1] 10.756548
    L2CAP: Disconnection Response (0x07) ident 26 len 4
    Destination CID: 65
    Source CID: 65
    < ACL Data TX: Handle 43 flags 0x00 dlen 12 #401 [hci1] 10.757459
    L2CAP: Connection Request (0x02) ident 18 len 4
    PSM: 1 (0x0001)
    Source CID: 65
    > ACL Data RX: Handle 43 flags 0x02 dlen 12 #402 [hci1] 10.759148
    L2CAP: Disconnection Response (0x07) ident 17 len 4
    Destination CID: 65
    Source CID: 65
    = bluetoothd: 00:1E:AB:4C:56:54: error updating services: Input/o.. 10.759447
    > HCI Event: Number of Completed Packets (0x13) plen 5 #403 [hci1] 10.759386
    Num handles: 1
    Handle: 43
    Count: 1
    > ACL Data RX: Handle 43 flags 0x02 dlen 12 #404 [hci1] 10.760397
    L2CAP: Connection Request (0x02) ident 27 len 4
    PSM: 3 (0x0003)
    Source CID: 65
    < ACL Data TX: Handle 43 flags 0x00 dlen 16 #405 [hci1] 10.760441
    L2CAP: Connection Response (0x03) ident 27 len 8
    Destination CID: 65
    Source CID: 65
    Result: Connection successful (0x0000)
    Status: No further information available (0x0000)
    < ACL Data TX: Handle 43 flags 0x00 dlen 27 #406 [hci1] 10.760449
    L2CAP: Configure Request (0x04) ident 19 len 19
    Destination CID: 65
    Flags: 0x0000
    Option: Maximum Transmission Unit (0x01) [mandatory]
    MTU: 1013
    Option: Retransmission and Flow Control (0x04) [mandatory]
    Mode: Basic (0x00)
    TX window size: 0
    Max transmit: 0
    Retransmission timeout: 0
    Monitor timeout: 0
    Maximum PDU size: 0
    > HCI Event: Number of Completed Packets (0x13) plen 5 #407 [hci1] 10.761399
    Num handles: 1
    Handle: 43
    Count: 1
    > ACL Data RX: Handle 43 flags 0x02 dlen 16 #408 [hci1] 10.762942
    L2CAP: Connection Response (0x03) ident 18 len 8
    Destination CID: 66
    Source CID: 65
    Result: Connection successful (0x0000)
    Status: No further information available (0x0000)
    *snip*

    Similar case after the patch:
    *snip*
    > ACL Data RX: Handle 43 flags 0x02 dlen 8 #22702 [hci0] 1664.411056
    Channel: 65 len 4 [PSM 3 mode 0] {chan 3}
    RFCOMM: Disconnect (DISC) (0x43)
    Address: 0x03 cr 1 dlci 0x00
    Control: 0x53 poll/final 1
    Length: 0
    FCS: 0xfd
    < ACL Data TX: Handle 43 flags 0x00 dlen 8 #22703 [hci0] 1664.411136
    Channel: 65 len 4 [PSM 3 mode 0] {chan 3}
    RFCOMM: Unnumbered Ack (UA) (0x63)
    Address: 0x03 cr 1 dlci 0x00
    Control: 0x73 poll/final 1
    Length: 0
    FCS: 0xd7
    < ACL Data TX: Handle 43 flags 0x00 dlen 12 #22704 [hci0] 1664.411143
    L2CAP: Disconnection Request (0x06) ident 11 len 4
    Destination CID: 65
    Source CID: 65
    > HCI Event: Number of Completed Pac.. (0x13) plen 5 #22705 [hci0] 1664.414009
    Num handles: 1
    Handle: 43
    Count: 1
    > HCI Event: Number of Completed Pac.. (0x13) plen 5 #22706 [hci0] 1664.415007
    Num handles: 1
    Handle: 43
    Count: 1
    > ACL Data RX: Handle 43 flags 0x02 dlen 12 #22707 [hci0] 1664.418674
    L2CAP: Disconnection Request (0x06) ident 17 len 4
    Destination CID: 65
    Source CID: 65
    < ACL Data TX: Handle 43 flags 0x00 dlen 12 #22708 [hci0] 1664.418762
    L2CAP: Disconnection Response (0x07) ident 17 len 4
    Destination CID: 65
    Source CID: 65
    < ACL Data TX: Handle 43 flags 0x00 dlen 12 #22709 [hci0] 1664.421073
    L2CAP: Connection Request (0x02) ident 12 len 4
    PSM: 1 (0x0001)
    Source CID: 65
    > ACL Data RX: Handle 43 flags 0x02 dlen 12 #22710 [hci0] 1664.421371
    L2CAP: Disconnection Response (0x07) ident 11 len 4
    Destination CID: 65
    Source CID: 65
    > HCI Event: Number of Completed Pac.. (0x13) plen 5 #22711 [hci0] 1664.424082
    Num handles: 1
    Handle: 43
    Count: 1
    > HCI Event: Number of Completed Pac.. (0x13) plen 5 #22712 [hci0] 1664.425040
    Num handles: 1
    Handle: 43
    Count: 1
    > ACL Data RX: Handle 43 flags 0x02 dlen 12 #22713 [hci0] 1664.426103
    L2CAP: Connection Request (0x02) ident 18 len 4
    PSM: 3 (0x0003)
    Source CID: 65
    < ACL Data TX: Handle 43 flags 0x00 dlen 16 #22714 [hci0] 1664.426186
    L2CAP: Connection Response (0x03) ident 18 len 8
    Destination CID: 66
    Source CID: 65
    Result: Connection successful (0x0000)
    Status: No further information available (0x0000)
    < ACL Data TX: Handle 43 flags 0x00 dlen 27 #22715 [hci0] 1664.426196
    L2CAP: Configure Request (0x04) ident 13 len 19
    Destination CID: 65
    Flags: 0x0000
    Option: Maximum Transmission Unit (0x01) [mandatory]
    MTU: 1013
    Option: Retransmission and Flow Control (0x04) [mandatory]
    Mode: Basic (0x00)
    TX window size: 0
    Max transmit: 0
    Retransmission timeout: 0
    Monitor timeout: 0
    Maximum PDU size: 0
    > ACL Data RX: Handle 43 flags 0x02 dlen 16 #22716 [hci0] 1664.428804
    L2CAP: Connection Response (0x03) ident 12 len 8
    Destination CID: 66
    Source CID: 65
    Result: Connection successful (0x0000)
    Status: No further information available (0x0000)
    *snip*

    Fix is to check that channel is in state BT_DISCONN before deleting the
    channel.

    This bug was found while fuzzing Bluez's OBEX implementation using
    Synopsys Defensics.

    Reported-by: Matti Kamunen
    Reported-by: Ari Timonen
    Signed-off-by: Matias Karhumaa
    Signed-off-by: Marcel Holtmann

    Matias Karhumaa
     

03 Jul, 2019

1 commit

  • Fix minimum encryption key size check so that HCI_MIN_ENC_KEY_SIZE is
    also allowed as stated in the comment.

    This bug caused connection problems with devices having maximum
    encryption key size of 7 octets (56-bit).

    Fixes: 693cd8ce3f88 ("Bluetooth: Fix regression with minimum encryption key size alignment")
    Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=203997
    Signed-off-by: Matias Karhumaa
    Cc: stable@vger.kernel.org
    Signed-off-by: Marcel Holtmann
    Signed-off-by: Linus Torvalds

    Matias Karhumaa
     

23 Jun, 2019

1 commit

  • When trying to align the minimum encryption key size requirement for
    Bluetooth connections, it turns out doing this in a central location in
    the HCI connection handling code is not possible.

    Original Bluetooth version up to 2.0 used a security model where the
    L2CAP service would enforce authentication and encryption. Starting
    with Bluetooth 2.1 and Secure Simple Pairing that model has changed into
    that the connection initiator is responsible for providing an encrypted
    ACL link before any L2CAP communication can happen.

    Now connecting Bluetooth 2.1 or later devices with Bluetooth 2.0 and
    before devices are causing a regression. The encryption key size check
    needs to be moved out of the HCI connection handling into the L2CAP
    channel setup.

    To achieve this, the current check inside hci_conn_security() has been
    moved into l2cap_check_enc_key_size() helper function and then called
    from four decisions point inside L2CAP to cover all combinations of
    Secure Simple Pairing enabled devices and device using legacy pairing
    and legacy service security model.

    Fixes: d5bb334a8e17 ("Bluetooth: Align minimum encryption key size for LE and BR/EDR connections")
    Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=203643
    Signed-off-by: Marcel Holtmann
    Cc: stable@vger.kernel.org
    Signed-off-by: Linus Torvalds

    Marcel Holtmann
     

24 Apr, 2019

1 commit

  • l2cap_le_flowctl_init was reseting the tx_credits which works only for
    outgoing connection since that set the tx_credits on the response, for
    incoming connections that was not the case which leaves the channel
    without any credits causing it to be suspended.

    Signed-off-by: Luiz Augusto von Dentz
    Signed-off-by: Marcel Holtmann
    Cc: stable@vger.kernel.org # 4.20+

    Luiz Augusto von Dentz
     

24 Jan, 2019

1 commit

  • In preparation to enabling -Wimplicit-fallthrough, mark switch cases
    where we are expecting to fall through.

    This patch fixes the following warnings:

    net/bluetooth/rfcomm/core.c:479:6: warning: this statement may fall through [-Wimplicit-fallthrough=]
    net/bluetooth/l2cap_core.c:4223:6: warning: this statement may fall through [-Wimplicit-fallthrough=]

    Warning level 3 was used: -Wimplicit-fallthrough=3

    This patch is part of the ongoing efforts to enabling
    -Wimplicit-fallthrough.

    Signed-off-by: Gustavo A. R. Silva
    Signed-off-by: Marcel Holtmann

    Gustavo A. R. Silva
     

23 Jan, 2019

2 commits

  • The function l2cap_get_conf_opt will return L2CAP_CONF_OPT_SIZE + opt->len
    as length value. The opt->len however is in control over the remote user
    and can be used by an attacker to gain access beyond the bounds of the
    actual packet.

    To prevent any potential leak of heap memory, it is enough to check that
    the resulting len calculation after calling l2cap_get_conf_opt is not
    below zero. A well formed packet will always return >= 0 here and will
    end with the length value being zero after the last option has been
    parsed. In case of malformed packets messing with the opt->len field the
    length value will become negative. If that is the case, then just abort
    and ignore the option.

    In case an attacker uses a too short opt->len value, then garbage will
    be parsed, but that is protected by the unknown option handling and also
    the option parameter size checks.

    Signed-off-by: Marcel Holtmann
    Reviewed-by: Greg Kroah-Hartman
    Signed-off-by: Johan Hedberg

    Marcel Holtmann
     
  • When doing option parsing for standard type values of 1, 2 or 4 octets,
    the value is converted directly into a variable instead of a pointer. To
    avoid being tricked into being a pointer, check that for these option
    types that sizes actually match. In L2CAP every option is fixed size and
    thus it is prudent anyway to ensure that the remote side sends us the
    right option size along with option paramters.

    If the option size is not matching the option type, then that option is
    silently ignored. It is a protocol violation and instead of trying to
    give the remote attacker any further hints just pretend that option is
    not present and proceed with the default values. Implementation
    following the specification and its qualification procedures will always
    use the correct size and thus not being impacted here.

    To keep the code readable and consistent accross all options, a few
    cosmetic changes were also required.

    Signed-off-by: Marcel Holtmann
    Reviewed-by: Greg Kroah-Hartman
    Signed-off-by: Johan Hedberg

    Marcel Holtmann
     

19 Dec, 2018

1 commit


14 Oct, 2018

2 commits

  • L2CAP: New result values
    0x0006 - Connection refused – Invalid Source CID
    0x0007 - Connection refused – Source CID already allocated

    As per the ESR08_V1.0.0, 1.11.2 Erratum 3253, Page No. 54,
    "Remote CID invalid Issue".
    Applies to Core Specification versions: V5.0, V4.2, v4.1, v4.0, and v3.0 + HS
    Vol 3, Part A, Section 4.2, 4.3, 4.14, 4.15.

    Core Specification Version 5.0, Page No.1753, Table 4.6 and
    Page No. 1767, Table 4.14

    New result values are added to l2cap connect/create channel response as
    0x0006 - Connection refused – Invalid Source CID
    0x0007 - Connection refused – Source CID already allocated

    Signed-off-by: Mallikarjun Phulari
    Signed-off-by: Marcel Holtmann

    Mallikarjun Phulari
     
  • Add the result values specific to L2CAP LE credit based connections
    and change the old result values wherever they were used.

    Signed-off-by: Mallikarjun Phulari
    Signed-off-by: Marcel Holtmann

    Mallikarjun Phulari
     

27 Sep, 2018

3 commits

  • If the remote is not able to fully utilize the MPS choosen recalculate
    the credits based on the actual amount it is sending that way it can
    still send packets of MTU size without credits dropping to 0.

    Signed-off-by: Luiz Augusto von Dentz
    Signed-off-by: Marcel Holtmann

    Luiz Augusto von Dentz
     
  • Give enough rx credits for a full packet instead of using an arbitrary
    number which may not be enough depending on the MTU and MPS which can
    cause interruptions while waiting for more credits, also remove
    debugfs entry for l2cap_le_max_credits.

    With these changes the credits are restored after each SDU is received
    instead of using fixed threshold, this way it is garanteed that there
    will always be enough credits to send a packet without waiting more
    credits to arrive.

    Signed-off-by: Luiz Augusto von Dentz
    Signed-off-by: Marcel Holtmann

    Luiz Augusto von Dentz
     
  • This ensures the MPS can fit in a single HCI fragment so each
    segment don't have to be reassembled at HCI level, in addition to
    that also remove the debugfs entry to configure the MPS.

    Signed-off-by: Luiz Augusto von Dentz
    Signed-off-by: Marcel Holtmann

    Luiz Augusto von Dentz
     

13 Jun, 2018

1 commit

  • The kmalloc() function has a 2-factor argument form, kmalloc_array(). This
    patch replaces cases of:

    kmalloc(a * b, gfp)

    with:
    kmalloc_array(a * b, gfp)

    as well as handling cases of:

    kmalloc(a * b * c, gfp)

    with:

    kmalloc(array3_size(a, b, c), gfp)

    as it's slightly less ugly than:

    kmalloc_array(array_size(a, b), c, gfp)

    This does, however, attempt to ignore constant size factors like:

    kmalloc(4 * 1024, gfp)

    though any constants defined via macros get caught up in the conversion.

    Any factors with a sizeof() of "unsigned char", "char", and "u8" were
    dropped, since they're redundant.

    The tools/ directory was manually excluded, since it has its own
    implementation of kmalloc().

    The Coccinelle script used for this was:

    // Fix redundant parens around sizeof().
    @@
    type TYPE;
    expression THING, E;
    @@

    (
    kmalloc(
    - (sizeof(TYPE)) * E
    + sizeof(TYPE) * E
    , ...)
    |
    kmalloc(
    - (sizeof(THING)) * E
    + sizeof(THING) * E
    , ...)
    )

    // Drop single-byte sizes and redundant parens.
    @@
    expression COUNT;
    typedef u8;
    typedef __u8;
    @@

    (
    kmalloc(
    - sizeof(u8) * (COUNT)
    + COUNT
    , ...)
    |
    kmalloc(
    - sizeof(__u8) * (COUNT)
    + COUNT
    , ...)
    |
    kmalloc(
    - sizeof(char) * (COUNT)
    + COUNT
    , ...)
    |
    kmalloc(
    - sizeof(unsigned char) * (COUNT)
    + COUNT
    , ...)
    |
    kmalloc(
    - sizeof(u8) * COUNT
    + COUNT
    , ...)
    |
    kmalloc(
    - sizeof(__u8) * COUNT
    + COUNT
    , ...)
    |
    kmalloc(
    - sizeof(char) * COUNT
    + COUNT
    , ...)
    |
    kmalloc(
    - sizeof(unsigned char) * COUNT
    + COUNT
    , ...)
    )

    // 2-factor product with sizeof(type/expression) and identifier or constant.
    @@
    type TYPE;
    expression THING;
    identifier COUNT_ID;
    constant COUNT_CONST;
    @@

    (
    - kmalloc
    + kmalloc_array
    (
    - sizeof(TYPE) * (COUNT_ID)
    + COUNT_ID, sizeof(TYPE)
    , ...)
    |
    - kmalloc
    + kmalloc_array
    (
    - sizeof(TYPE) * COUNT_ID
    + COUNT_ID, sizeof(TYPE)
    , ...)
    |
    - kmalloc
    + kmalloc_array
    (
    - sizeof(TYPE) * (COUNT_CONST)
    + COUNT_CONST, sizeof(TYPE)
    , ...)
    |
    - kmalloc
    + kmalloc_array
    (
    - sizeof(TYPE) * COUNT_CONST
    + COUNT_CONST, sizeof(TYPE)
    , ...)
    |
    - kmalloc
    + kmalloc_array
    (
    - sizeof(THING) * (COUNT_ID)
    + COUNT_ID, sizeof(THING)
    , ...)
    |
    - kmalloc
    + kmalloc_array
    (
    - sizeof(THING) * COUNT_ID
    + COUNT_ID, sizeof(THING)
    , ...)
    |
    - kmalloc
    + kmalloc_array
    (
    - sizeof(THING) * (COUNT_CONST)
    + COUNT_CONST, sizeof(THING)
    , ...)
    |
    - kmalloc
    + kmalloc_array
    (
    - sizeof(THING) * COUNT_CONST
    + COUNT_CONST, sizeof(THING)
    , ...)
    )

    // 2-factor product, only identifiers.
    @@
    identifier SIZE, COUNT;
    @@

    - kmalloc
    + kmalloc_array
    (
    - SIZE * COUNT
    + COUNT, SIZE
    , ...)

    // 3-factor product with 1 sizeof(type) or sizeof(expression), with
    // redundant parens removed.
    @@
    expression THING;
    identifier STRIDE, COUNT;
    type TYPE;
    @@

    (
    kmalloc(
    - sizeof(TYPE) * (COUNT) * (STRIDE)
    + array3_size(COUNT, STRIDE, sizeof(TYPE))
    , ...)
    |
    kmalloc(
    - sizeof(TYPE) * (COUNT) * STRIDE
    + array3_size(COUNT, STRIDE, sizeof(TYPE))
    , ...)
    |
    kmalloc(
    - sizeof(TYPE) * COUNT * (STRIDE)
    + array3_size(COUNT, STRIDE, sizeof(TYPE))
    , ...)
    |
    kmalloc(
    - sizeof(TYPE) * COUNT * STRIDE
    + array3_size(COUNT, STRIDE, sizeof(TYPE))
    , ...)
    |
    kmalloc(
    - sizeof(THING) * (COUNT) * (STRIDE)
    + array3_size(COUNT, STRIDE, sizeof(THING))
    , ...)
    |
    kmalloc(
    - sizeof(THING) * (COUNT) * STRIDE
    + array3_size(COUNT, STRIDE, sizeof(THING))
    , ...)
    |
    kmalloc(
    - sizeof(THING) * COUNT * (STRIDE)
    + array3_size(COUNT, STRIDE, sizeof(THING))
    , ...)
    |
    kmalloc(
    - sizeof(THING) * COUNT * STRIDE
    + array3_size(COUNT, STRIDE, sizeof(THING))
    , ...)
    )

    // 3-factor product with 2 sizeof(variable), with redundant parens removed.
    @@
    expression THING1, THING2;
    identifier COUNT;
    type TYPE1, TYPE2;
    @@

    (
    kmalloc(
    - sizeof(TYPE1) * sizeof(TYPE2) * COUNT
    + array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
    , ...)
    |
    kmalloc(
    - sizeof(TYPE1) * sizeof(THING2) * (COUNT)
    + array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
    , ...)
    |
    kmalloc(
    - sizeof(THING1) * sizeof(THING2) * COUNT
    + array3_size(COUNT, sizeof(THING1), sizeof(THING2))
    , ...)
    |
    kmalloc(
    - sizeof(THING1) * sizeof(THING2) * (COUNT)
    + array3_size(COUNT, sizeof(THING1), sizeof(THING2))
    , ...)
    |
    kmalloc(
    - sizeof(TYPE1) * sizeof(THING2) * COUNT
    + array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
    , ...)
    |
    kmalloc(
    - sizeof(TYPE1) * sizeof(THING2) * (COUNT)
    + array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
    , ...)
    )

    // 3-factor product, only identifiers, with redundant parens removed.
    @@
    identifier STRIDE, SIZE, COUNT;
    @@

    (
    kmalloc(
    - (COUNT) * STRIDE * SIZE
    + array3_size(COUNT, STRIDE, SIZE)
    , ...)
    |
    kmalloc(
    - COUNT * (STRIDE) * SIZE
    + array3_size(COUNT, STRIDE, SIZE)
    , ...)
    |
    kmalloc(
    - COUNT * STRIDE * (SIZE)
    + array3_size(COUNT, STRIDE, SIZE)
    , ...)
    |
    kmalloc(
    - (COUNT) * (STRIDE) * SIZE
    + array3_size(COUNT, STRIDE, SIZE)
    , ...)
    |
    kmalloc(
    - COUNT * (STRIDE) * (SIZE)
    + array3_size(COUNT, STRIDE, SIZE)
    , ...)
    |
    kmalloc(
    - (COUNT) * STRIDE * (SIZE)
    + array3_size(COUNT, STRIDE, SIZE)
    , ...)
    |
    kmalloc(
    - (COUNT) * (STRIDE) * (SIZE)
    + array3_size(COUNT, STRIDE, SIZE)
    , ...)
    |
    kmalloc(
    - COUNT * STRIDE * SIZE
    + array3_size(COUNT, STRIDE, SIZE)
    , ...)
    )

    // Any remaining multi-factor products, first at least 3-factor products,
    // when they're not all constants...
    @@
    expression E1, E2, E3;
    constant C1, C2, C3;
    @@

    (
    kmalloc(C1 * C2 * C3, ...)
    |
    kmalloc(
    - (E1) * E2 * E3
    + array3_size(E1, E2, E3)
    , ...)
    |
    kmalloc(
    - (E1) * (E2) * E3
    + array3_size(E1, E2, E3)
    , ...)
    |
    kmalloc(
    - (E1) * (E2) * (E3)
    + array3_size(E1, E2, E3)
    , ...)
    |
    kmalloc(
    - E1 * E2 * E3
    + array3_size(E1, E2, E3)
    , ...)
    )

    // And then all remaining 2 factors products when they're not all constants,
    // keeping sizeof() as the second factor argument.
    @@
    expression THING, E1, E2;
    type TYPE;
    constant C1, C2, C3;
    @@

    (
    kmalloc(sizeof(THING) * C2, ...)
    |
    kmalloc(sizeof(TYPE) * C2, ...)
    |
    kmalloc(C1 * C2 * C3, ...)
    |
    kmalloc(C1 * C2, ...)
    |
    - kmalloc
    + kmalloc_array
    (
    - sizeof(TYPE) * (E2)
    + E2, sizeof(TYPE)
    , ...)
    |
    - kmalloc
    + kmalloc_array
    (
    - sizeof(TYPE) * E2
    + E2, sizeof(TYPE)
    , ...)
    |
    - kmalloc
    + kmalloc_array
    (
    - sizeof(THING) * (E2)
    + E2, sizeof(THING)
    , ...)
    |
    - kmalloc
    + kmalloc_array
    (
    - sizeof(THING) * E2
    + E2, sizeof(THING)
    , ...)
    |
    - kmalloc
    + kmalloc_array
    (
    - (E1) * E2
    + E1, E2
    , ...)
    |
    - kmalloc
    + kmalloc_array
    (
    - (E1) * (E2)
    + E1, E2
    , ...)
    |
    - kmalloc
    + kmalloc_array
    (
    - E1 * E2
    + E1, E2
    , ...)
    )

    Signed-off-by: Kees Cook

    Kees Cook
     

03 Apr, 2018

1 commit

  • Local random address needs to be updated before creating connection if
    RPA from LE Direct Advertising Report was resolved in host. Otherwise
    remote device might ignore connection request due to address mismatch.

    This was affecting following qualification test cases:
    GAP/CONN/SCEP/BV-03-C, GAP/CONN/GCEP/BV-05-C, GAP/CONN/DCEP/BV-05-C

    Before patch:
    < HCI Command: LE Set Random Address (0x08|0x0005) plen 6 #11350 [hci0] 84680.231216
    Address: 56:BC:E8:24:11:68 (Resolvable)
    Identity type: Random (0x01)
    Identity: F2:F1:06:3D:9C:42 (Static)
    > HCI Event: Command Complete (0x0e) plen 4 #11351 [hci0] 84680.246022
    LE Set Random Address (0x08|0x0005) ncmd 1
    Status: Success (0x00)
    < HCI Command: LE Set Scan Parameters (0x08|0x000b) plen 7 #11352 [hci0] 84680.246417
    Type: Passive (0x00)
    Interval: 60.000 msec (0x0060)
    Window: 30.000 msec (0x0030)
    Own address type: Random (0x01)
    Filter policy: Accept all advertisement, inc. directed unresolved RPA (0x02)
    > HCI Event: Command Complete (0x0e) plen 4 #11353 [hci0] 84680.248854
    LE Set Scan Parameters (0x08|0x000b) ncmd 1
    Status: Success (0x00)
    < HCI Command: LE Set Scan Enable (0x08|0x000c) plen 2 #11354 [hci0] 84680.249466
    Scanning: Enabled (0x01)
    Filter duplicates: Enabled (0x01)
    > HCI Event: Command Complete (0x0e) plen 4 #11355 [hci0] 84680.253222
    LE Set Scan Enable (0x08|0x000c) ncmd 1
    Status: Success (0x00)
    > HCI Event: LE Meta Event (0x3e) plen 18 #11356 [hci0] 84680.458387
    LE Direct Advertising Report (0x0b)
    Num reports: 1
    Event type: Connectable directed - ADV_DIRECT_IND (0x01)
    Address type: Random (0x01)
    Address: 53:38:DA:46:8C:45 (Resolvable)
    Identity type: Public (0x00)
    Identity: 11:22:33:44:55:66 (OUI 11-22-33)
    Direct address type: Random (0x01)
    Direct address: 7C:D6:76:8C:DF:82 (Resolvable)
    Identity type: Random (0x01)
    Identity: F2:F1:06:3D:9C:42 (Static)
    RSSI: -74 dBm (0xb6)
    < HCI Command: LE Set Scan Enable (0x08|0x000c) plen 2 #11357 [hci0] 84680.458737
    Scanning: Disabled (0x00)
    Filter duplicates: Disabled (0x00)
    > HCI Event: Command Complete (0x0e) plen 4 #11358 [hci0] 84680.469982
    LE Set Scan Enable (0x08|0x000c) ncmd 1
    Status: Success (0x00)
    < HCI Command: LE Create Connection (0x08|0x000d) plen 25 #11359 [hci0] 84680.470444
    Scan interval: 60.000 msec (0x0060)
    Scan window: 60.000 msec (0x0060)
    Filter policy: White list is not used (0x00)
    Peer address type: Random (0x01)
    Peer address: 53:38:DA:46:8C:45 (Resolvable)
    Identity type: Public (0x00)
    Identity: 11:22:33:44:55:66 (OUI 11-22-33)
    Own address type: Random (0x01)
    Min connection interval: 30.00 msec (0x0018)
    Max connection interval: 50.00 msec (0x0028)
    Connection latency: 0 (0x0000)
    Supervision timeout: 420 msec (0x002a)
    Min connection length: 0.000 msec (0x0000)
    Max connection length: 0.000 msec (0x0000)
    > HCI Event: Command Status (0x0f) plen 4 #11360 [hci0] 84680.474971
    LE Create Connection (0x08|0x000d) ncmd 1
    Status: Success (0x00)
    < HCI Command: LE Create Connection Cancel (0x08|0x000e) plen 0 #11361 [hci0] 84682.545385
    > HCI Event: Command Complete (0x0e) plen 4 #11362 [hci0] 84682.551014
    LE Create Connection Cancel (0x08|0x000e) ncmd 1
    Status: Success (0x00)
    > HCI Event: LE Meta Event (0x3e) plen 19 #11363 [hci0] 84682.551074
    LE Connection Complete (0x01)
    Status: Unknown Connection Identifier (0x02)
    Handle: 0
    Role: Master (0x00)
    Peer address type: Public (0x00)
    Peer address: 00:00:00:00:00:00 (OUI 00-00-00)
    Connection interval: 0.00 msec (0x0000)
    Connection latency: 0 (0x0000)
    Supervision timeout: 0 msec (0x0000)
    Master clock accuracy: 0x00

    After patch:
    < HCI Command: LE Set Scan Parameters (0x08|0x000b) plen 7 #210 [hci0] 667.152459
    Type: Passive (0x00)
    Interval: 60.000 msec (0x0060)
    Window: 30.000 msec (0x0030)
    Own address type: Random (0x01)
    Filter policy: Accept all advertisement, inc. directed unresolved RPA (0x02)
    > HCI Event: Command Complete (0x0e) plen 4 #211 [hci0] 667.153613
    LE Set Scan Parameters (0x08|0x000b) ncmd 1
    Status: Success (0x00)
    < HCI Command: LE Set Scan Enable (0x08|0x000c) plen 2 #212 [hci0] 667.153704
    Scanning: Enabled (0x01)
    Filter duplicates: Enabled (0x01)
    > HCI Event: Command Complete (0x0e) plen 4 #213 [hci0] 667.154584
    LE Set Scan Enable (0x08|0x000c) ncmd 1
    Status: Success (0x00)
    > HCI Event: LE Meta Event (0x3e) plen 18 #214 [hci0] 667.182619
    LE Direct Advertising Report (0x0b)
    Num reports: 1
    Event type: Connectable directed - ADV_DIRECT_IND (0x01)
    Address type: Random (0x01)
    Address: 50:52:D9:A6:48:A0 (Resolvable)
    Identity type: Public (0x00)
    Identity: 11:22:33:44:55:66 (OUI 11-22-33)
    Direct address type: Random (0x01)
    Direct address: 7C:C1:57:A5:B7:A8 (Resolvable)
    Identity type: Random (0x01)
    Identity: F4:28:73:5D:38:B0 (Static)
    RSSI: -70 dBm (0xba)
    < HCI Command: LE Set Scan Enable (0x08|0x000c) plen 2 #215 [hci0] 667.182704
    Scanning: Disabled (0x00)
    Filter duplicates: Disabled (0x00)
    > HCI Event: Command Complete (0x0e) plen 4 #216 [hci0] 667.183599
    LE Set Scan Enable (0x08|0x000c) ncmd 1
    Status: Success (0x00)
    < HCI Command: LE Set Random Address (0x08|0x0005) plen 6 #217 [hci0] 667.183645
    Address: 7C:C1:57:A5:B7:A8 (Resolvable)
    Identity type: Random (0x01)
    Identity: F4:28:73:5D:38:B0 (Static)
    > HCI Event: Command Complete (0x0e) plen 4 #218 [hci0] 667.184590
    LE Set Random Address (0x08|0x0005) ncmd 1
    Status: Success (0x00)
    < HCI Command: LE Create Connection (0x08|0x000d) plen 25 #219 [hci0] 667.184613
    Scan interval: 60.000 msec (0x0060)
    Scan window: 60.000 msec (0x0060)
    Filter policy: White list is not used (0x00)
    Peer address type: Random (0x01)
    Peer address: 50:52:D9:A6:48:A0 (Resolvable)
    Identity type: Public (0x00)
    Identity: 11:22:33:44:55:66 (OUI 11-22-33)
    Own address type: Random (0x01)
    Min connection interval: 30.00 msec (0x0018)
    Max connection interval: 50.00 msec (0x0028)
    Connection latency: 0 (0x0000)
    Supervision timeout: 420 msec (0x002a)
    Min connection length: 0.000 msec (0x0000)
    Max connection length: 0.000 msec (0x0000)
    > HCI Event: Command Status (0x0f) plen 4 #220 [hci0] 667.186558
    LE Create Connection (0x08|0x000d) ncmd 1
    Status: Success (0x00)
    > HCI Event: LE Meta Event (0x3e) plen 19 #221 [hci0] 667.485824
    LE Connection Complete (0x01)
    Status: Success (0x00)
    Handle: 0
    Role: Master (0x00)
    Peer address type: Random (0x01)
    Peer address: 50:52:D9:A6:48:A0 (Resolvable)
    Identity type: Public (0x00)
    Identity: 11:22:33:44:55:66 (OUI 11-22-33)
    Connection interval: 50.00 msec (0x0028)
    Connection latency: 0 (0x0000)
    Supervision timeout: 420 msec (0x002a)
    Master clock accuracy: 0x07
    @ MGMT Event: Device Connected (0x000b) plen 13 {0x0002} [hci0] 667.485996
    LE Address: 11:22:33:44:55:66 (OUI 11-22-33)
    Flags: 0x00000000
    Data length: 0

    Signed-off-by: Szymon Janc
    Signed-off-by: Marcel Holtmann
    Cc: stable@vger.kernel.org

    Szymon Janc
     

05 Jan, 2018

1 commit

  • In the function l2cap_parse_conf_rsp and in the function
    l2cap_parse_conf_req the following variable is declared without
    initialization:

    struct l2cap_conf_efs efs;

    In addition, when parsing input configuration parameters in both of
    these functions, the switch case for handling EFS elements may skip the
    memcpy call that will write to the efs variable:

    ...
    case L2CAP_CONF_EFS:
    if (olen == sizeof(efs))
    memcpy(&efs, (void *)val, olen);
    ...

    The olen in the above if is attacker controlled, and regardless of that
    if, in both of these functions the efs variable would eventually be
    added to the outgoing configuration request that is being built:

    l2cap_add_conf_opt(&ptr, L2CAP_CONF_EFS, sizeof(efs), (unsigned long) &efs);

    So by sending a configuration request, or response, that contains an
    L2CAP_CONF_EFS element, but with an element length that is not
    sizeof(efs) - the memcpy to the uninitialized efs variable can be
    avoided, and the uninitialized variable would be returned to the
    attacker (16 bytes).

    This issue has been assigned CVE-2017-1000410

    Cc: Marcel Holtmann
    Cc: Gustavo Padovan
    Cc: Johan Hedberg
    Cc: stable
    Signed-off-by: Ben Seri
    Signed-off-by: Greg Kroah-Hartman

    Ben Seri
     

10 Sep, 2017

1 commit


16 Jun, 2017

2 commits

  • It seems like a historic accident that these return unsigned char *,
    and in many places that means casts are required, more often than not.

    Make these functions (skb_put, __skb_put and pskb_put) return void *
    and remove all the casts across the tree, adding a (u8 *) cast only
    where the unsigned char pointer was used directly, all done with the
    following spatch:

    @@
    expression SKB, LEN;
    typedef u8;
    identifier fn = { skb_put, __skb_put };
    @@
    - *(fn(SKB, LEN))
    + *(u8 *)fn(SKB, LEN)

    @@
    expression E, SKB, LEN;
    identifier fn = { skb_put, __skb_put };
    type T;
    @@
    - E = ((T *)(fn(SKB, LEN)))
    + E = fn(SKB, LEN)

    which actually doesn't cover pskb_put since there are only three
    users overall.

    A handful of stragglers were converted manually, notably a macro in
    drivers/isdn/i4l/isdn_bsdcomp.c and, oddly enough, one of the many
    instances in net/bluetooth/hci_sock.c. In the former file, I also
    had to fix one whitespace problem spatch introduced.

    Signed-off-by: Johannes Berg
    Signed-off-by: David S. Miller

    Johannes Berg
     
  • A common pattern with skb_put() is to just want to memcpy()
    some data into the new space, introduce skb_put_data() for
    this.

    An spatch similar to the one for skb_put_zero() converts many
    of the places using it:

    @@
    identifier p, p2;
    expression len, skb, data;
    type t, t2;
    @@
    (
    -p = skb_put(skb, len);
    +p = skb_put_data(skb, data, len);
    |
    -p = (t)skb_put(skb, len);
    +p = skb_put_data(skb, data, len);
    )
    (
    p2 = (t2)p;
    -memcpy(p2, data, len);
    |
    -memcpy(p, data, len);
    )

    @@
    type t, t2;
    identifier p, p2;
    expression skb, data;
    @@
    t *p;
    ...
    (
    -p = skb_put(skb, sizeof(t));
    +p = skb_put_data(skb, data, sizeof(t));
    |
    -p = (t *)skb_put(skb, sizeof(t));
    +p = skb_put_data(skb, data, sizeof(t));
    )
    (
    p2 = (t2)p;
    -memcpy(p2, data, sizeof(*p));
    |
    -memcpy(p, data, sizeof(*p));
    )

    @@
    expression skb, len, data;
    @@
    -memcpy(skb_put(skb, len), data, len);
    +skb_put_data(skb, data, len);

    (again, manually post-processed to retain some comments)

    Reviewed-by: Stephen Hemminger
    Signed-off-by: Johannes Berg
    Signed-off-by: David S. Miller

    Johannes Berg
     

13 Apr, 2017

2 commits