1. 15 2月, 2014 12 次提交
    • P
      Bluetooth: Refactor dlc disconnect logic in rfcomm_dlc_close() · f622357a
      Peter Hurley 提交于
      Prepare for directly closing dlc if the RFCOMM session has not
      yet been started; refactor the dlc disconnect logic into a separate
      local function, __rfcomm_dlc_disconn(). Retains functional
      equivalence.
      Signed-off-by: NPeter Hurley <peter@hurleysoftware.com>
      Tested-By: NAlexander Holler <holler@ahsoftware.de>
      Signed-off-by: NMarcel Holtmann <marcel@holtmann.org>
      f622357a
    • P
      Bluetooth: Refactor deferred setup test in rfcomm_dlc_close() · 5998e040
      Peter Hurley 提交于
      Prepare for directly closing dlc if the RFCOMM session has not
      yet been started; refactor the deferred setup test for only those
      dlc states to which the test applies. Retains functional
      equivalence.
      Signed-off-by: NPeter Hurley <peter@hurleysoftware.com>
      Tested-By: NAlexander Holler <holler@ahsoftware.de>
      Signed-off-by: NMarcel Holtmann <marcel@holtmann.org>
      5998e040
    • P
      Bluetooth: Simplify RFCOMM session state eval · 4339c25a
      Peter Hurley 提交于
      Merge conditional test for BT_LISTEN session state into following
      switch statement (which is functionally equivalent).
      Signed-off-by: NPeter Hurley <peter@hurleysoftware.com>
      Tested-By: NAlexander Holler <holler@ahsoftware.de>
      Signed-off-by: NMarcel Holtmann <marcel@holtmann.org>
      4339c25a
    • P
      Bluetooth: Verify dlci not in use before rfcomm_dev create · c10a848c
      Peter Hurley 提交于
      Only one session/channel combination may be in use at any one
      time. However, the failure does not occur until the tty is
      opened (in rfcomm_dlc_open()).
      
      Because these settings are actually bound at rfcomm device
      creation (via RFCOMMCREATEDEV ioctl), validate and fail before
      creating the rfcomm tty device.
      Signed-off-by: NPeter Hurley <peter@hurleysoftware.com>
      Tested-By: NAlexander Holler <holler@ahsoftware.de>
      Signed-off-by: NMarcel Holtmann <marcel@holtmann.org>
      c10a848c
    • P
      Bluetooth: Fix RFCOMM tty teardown race · c949c224
      Peter Hurley 提交于
      RFCOMM tty device teardown can race with new tty device registration
      for the same device id:
      
      CPU 0                           | CPU 1
      rfcomm_dev_add                  | rfcomm_dev_destruct
                                      |   spin_lock
                                      |   list_del   <== dev_id no longer used
                                      |   spin_unlock
        spin_lock                     |     .
        [search rfcomm_dev_list]      |     .
        [dev_id not in use]           |     .
        [initialize new rfcomm_dev]   |     .
        spin_unlock                   |     .
                                      |     .
        tty_port_register_device      |   tty_unregister_device
      
      Don't remove rfcomm_dev from the device list until after tty device
      unregistration has completed.
      Signed-off-by: NPeter Hurley <peter@hurleysoftware.com>
      Tested-By: NAlexander Holler <holler@ahsoftware.de>
      Signed-off-by: NMarcel Holtmann <marcel@holtmann.org>
      c949c224
    • P
      Bluetooth: Fix unreleased rfcomm_dev reference · 80ea7337
      Peter Hurley 提交于
      When RFCOMM_RELEASE_ONHUP is set, the rfcomm tty driver 'takes over'
      the initial rfcomm_dev reference created by the RFCOMMCREATEDEV ioctl.
      The assumption is that the rfcomm tty driver will release the
      rfcomm_dev reference when the tty is freed (in rfcomm_tty_cleanup()).
      However, if the tty is never opened, the 'take over' never occurs,
      so when RFCOMMRELEASEDEV ioctl is called, the reference is not
      released.
      
      Track the state of the reference 'take over' so that the release
      is guaranteed by either the RFCOMMRELEASEDEV ioctl or the rfcomm tty
      driver.
      
      Note that the synchronous hangup in rfcomm_release_dev() ensures
      that rfcomm_tty_install() cannot race with the RFCOMMRELEASEDEV ioctl.
      Signed-off-by: NPeter Hurley <peter@hurleysoftware.com>
      Tested-By: NAlexander Holler <holler@ahsoftware.de>
      Signed-off-by: NMarcel Holtmann <marcel@holtmann.org>
      80ea7337
    • P
      Bluetooth: Release rfcomm_dev only once · 1c64834e
      Peter Hurley 提交于
      No logic prevents an rfcomm_dev from being released multiple
      times. For example, if the rfcomm_dev ref count is large due
      to pending tx, then multiple RFCOMMRELEASEDEV ioctls may
      mistakenly release the rfcomm_dev too many times. Note that
      concurrent ioctls are not required to create this condition.
      
      Introduce RFCOMM_DEV_RELEASED status bit which guarantees the
      rfcomm_dev can only be released once.
      
      NB: Since the flags are exported to userspace, introduce the status
      field to track state for which userspace should not be aware.
      Signed-off-by: NPeter Hurley <peter@hurleysoftware.com>
      Tested-By: NAlexander Holler <holler@ahsoftware.de>
      Signed-off-by: NMarcel Holtmann <marcel@holtmann.org>
      1c64834e
    • P
      Bluetooth: Exclude released devices from RFCOMMGETDEVLIST ioctl · 960603a5
      Peter Hurley 提交于
      When enumerating RFCOMM devices in the rfcomm_dev_list, holding
      the rfcomm_dev_lock only guarantees the existence of the enumerated
      rfcomm_dev in memory, and not safe access to its state. Testing
      the device state (such as RFCOMM_TTY_RELEASED) does not guarantee
      the device will remain in that state for the subsequent access
      to the rfcomm_dev's fields, nor guarantee that teardown has not
      commenced.
      
      Obtain an rfcomm_dev reference for the duration of rfcomm_dev
      access.
      Signed-off-by: NPeter Hurley <peter@hurleysoftware.com>
      Tested-By: NAlexander Holler <holler@ahsoftware.de>
      Signed-off-by: NMarcel Holtmann <marcel@holtmann.org>
      960603a5
    • P
      Bluetooth: Fix racy acquire of rfcomm_dev reference · 082a1532
      Peter Hurley 提交于
      rfcomm_dev_get() can return a rfcomm_dev reference for a
      device for which destruction may be commencing. This can happen
      on tty destruction, which calls rfcomm_tty_cleanup(), the last
      port reference may have been released but RFCOMM_TTY_RELEASED
      was not set. The following race is also possible:
      
      CPU 0                            | CPU 1
                                       | rfcomm_release_dev
      rfcomm_dev_get                   |   .
        spin_lock                      |   .
          dev  = __rfcomm_dev_get      |   .
          if dev                       |   .
            if test_bit(TTY_RELEASED)  |   .
                                       |   !test_and_set_bit(TTY_RELEASED)
                                       |     tty_port_put   <<<< last reference
            else                       |
              tty_port_get             |
      
      The reference acquire is bogus because destruction will commence
      with the release of the last reference.
      
      Ignore the external state change of TTY_RELEASED and instead rely
      on the reference acquire itself to determine if the reference is
      valid.
      
      Cc: Jiri Slaby <jslaby@suse.cz>
      Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: NPeter Hurley <peter@hurleysoftware.com>
      Tested-By: NAlexander Holler <holler@ahsoftware.de>
      Signed-off-by: NMarcel Holtmann <marcel@holtmann.org>
      082a1532
    • P
      Revert "Bluetooth: Move rfcomm_get_device() before rfcomm_dev_activate()" · f87c24e7
      Peter Hurley 提交于
      This reverts commit e228b633.
      
      This is the third of a 3-patch revert, together with
      Revert "Bluetooth: Remove rfcomm_carrier_raised()" and
      Revert "Bluetooth: Always wait for a connection on RFCOMM open()".
      
      Commit 4a2fb3ec,
      "Bluetooth: Always wait for a connection on RFCOMM open()" open-codes
      blocking on tty open(), rather than using the default behavior
      implemented by the tty port.
      
      The reasons for reverting that patch are detailed in that changelog;
      this patch restores required functionality for that revert.
      Signed-off-by: NPeter Hurley <peter@hurleysoftware.com>
      Tested-By: NAlexander Holler <holler@ahsoftware.de>
      Signed-off-by: NMarcel Holtmann <marcel@holtmann.org>
      f87c24e7
    • P
      Revert "Bluetooth: Always wait for a connection on RFCOMM open()" · 136c373b
      Peter Hurley 提交于
      This reverts commit 4a2fb3ec.
      
      This is the second of a 3-patch revert, together with
      Revert "Bluetooth: Remove rfcomm_carrier_raised()" and
      Revert "Bluetooth: Move rfcomm_get_device() before rfcomm_dev_activate()".
      
      Before commit cad348a1,
        Bluetooth: Implement .activate, .shutdown and .carrier_raised methods,
      tty_port_block_til_ready() was open-coded in rfcomm_tty_install() as
      part of the RFCOMM tty open().
      
      Unfortunately, it did not implement non-blocking open nor CLOCAL open,
      but rather always blocked for carrier. This is not the expected or
      typical behavior for ttys, and prevents several common terminal
      programming idioms from working (eg., opening in non-blocking
      mode to initialize desired termios settings then re-opening for
      connection).
      
      Commit cad348a1,
        Bluetooth: Implement .activate, .shutdown and .carrier_raised methods,
      added the necessary tty_port methods to use the default tty_port_open().
      However, this triggered two important user-space regressions.
      
      The first regression involves the complicated mechanism for reparenting
      the rfcomm tty device to the ACL link device which represents an
      open link to a specific bluetooth host. This regression causes ModemManager
      to conclude the rfcomm tty device does not front a modem so it makes
      no attempt to initialize an attached modem. This regression is
      caused by the lack of a device_move() if the dlc is already open (and
      not specifically related to the open-coded block_til_ready()).
      
      A more appropriate solution is submitted in
      "Bluetooth: Fix unsafe RFCOMM device parenting" and
      "Bluetooth: Fix RFCOMM parent device for reused dlc"
      
      The second regression involves "rfcomm bind" and wvdial (a ppp dialer).
      rfcomm bind creates a device node for a /dev/rfcomm<n>. wvdial opens
      that device in non-blocking mode (because it expects the connection
      to have already been established). In addition, subsequent writes
      to the rfcomm tty device fail (because the link is not yet connected;
      rfcomm connection begins with the actual tty open()).
      
      However, restoring the original behavior (in the patch which
      this reverts) was undesirable.
      
      Firstly, the original reporter notes that a trivial userspace
      "workaround" already exists: rfcomm connect, which creates the
      device node and establishes the expected connection.
      
      Secondly, the failed writes occur because the rfcomm tty driver
      does not buffer writes to an unconnected device; this contrasts with
      the dozen of other tty drivers (in fact, all of them) that do just
      that. The submitted patch "Bluetooth: Don't fail RFCOMM tty writes"
      corrects this.
      
      Thirdly, it was a long-standing bug to block on non-blocking open,
      which is re-fixed by revert.
      Signed-off-by: NPeter Hurley <peter@hurleysoftware.com>
      Tested-By: NAlexander Holler <holler@ahsoftware.de>
      Signed-off-by: NMarcel Holtmann <marcel@holtmann.org>
      136c373b
    • P
      Revert "Bluetooth: Remove rfcomm_carrier_raised()" · 7f717b91
      Peter Hurley 提交于
      This reverts commit f86772af.
      
      This is the first of a 3-patch revert, together with
      Revert "Bluetooth: Always wait for a connection on RFCOMM open()" and
      Revert "Bluetooth: Move rfcomm_get_device() before rfcomm_dev_activate()".
      
      Commit 4a2fb3ec,
      "Bluetooth: Always wait for a connection on RFCOMM open()" open-codes
      blocking on tty open(), rather than using the default behavior
      implemented by the tty port.
      
      The reasons for reverting that patch are detailed in that changelog;
      this patch restores required functionality for that revert.
      Signed-off-by: NPeter Hurley <peter@hurleysoftware.com>
      Tested-By: NAlexander Holler <holler@ahsoftware.de>
      Signed-off-by: NMarcel Holtmann <marcel@holtmann.org>
      7f717b91
  2. 13 2月, 2014 2 次提交
  3. 07 1月, 2014 4 次提交
  4. 21 11月, 2013 1 次提交
    • H
      net: rework recvmsg handler msg_name and msg_namelen logic · f3d33426
      Hannes Frederic Sowa 提交于
      This patch now always passes msg->msg_namelen as 0. recvmsg handlers must
      set msg_namelen to the proper size <= sizeof(struct sockaddr_storage)
      to return msg_name to the user.
      
      This prevents numerous uninitialized memory leaks we had in the
      recvmsg handlers and makes it harder for new code to accidentally leak
      uninitialized memory.
      
      Optimize for the case recvfrom is called with NULL as address. We don't
      need to copy the address at all, so set it to NULL before invoking the
      recvmsg handler. We can do so, because all the recvmsg handlers must
      cope with the case a plain read() is called on them. read() also sets
      msg_name to NULL.
      
      Also document these changes in include/linux/net.h as suggested by David
      Miller.
      
      Changes since RFC:
      
      Set msg->msg_name = NULL if user specified a NULL in msg_name but had a
      non-null msg_namelen in verify_iovec/verify_compat_iovec. This doesn't
      affect sendto as it would bail out earlier while trying to copy-in the
      address. It also more naturally reflects the logic by the callers of
      verify_iovec.
      
      With this change in place I could remove "
      if (!uaddr || msg_sys->msg_namelen == 0)
      	msg->msg_name = NULL
      ".
      
      This change does not alter the user visible error logic as we ignore
      msg_namelen as long as msg_name is NULL.
      
      Also remove two unnecessary curly brackets in ___sys_recvmsg and change
      comments to netdev style.
      
      Cc: David Miller <davem@davemloft.net>
      Suggested-by: NEric Dumazet <eric.dumazet@gmail.com>
      Signed-off-by: NHannes Frederic Sowa <hannes@stressinduktion.org>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      f3d33426
  5. 13 11月, 2013 3 次提交
    • S
      Bluetooth: Fix to set proper bdaddr_type for RFCOMM connect · 8992da09
      Seung-Woo Kim 提交于
      L2CAP socket validates proper bdaddr_type for connect, so this
      patch fixes to set explictly bdaddr_type for RFCOMM connect.
      Signed-off-by: NSeung-Woo Kim <sw0312.kim@samsung.com>
      Signed-off-by: NMarcel Holtmann <marcel@holtmann.org>
      8992da09
    • S
      Bluetooth: Fix RFCOMM bind fail for L2CAP sock · c507f138
      Seung-Woo Kim 提交于
      L2CAP socket bind checks its bdaddr type but RFCOMM kernel thread
      does not assign proper bdaddr type for L2CAP sock. This can cause
      that RFCOMM failure.
      Signed-off-by: NSeung-Woo Kim <sw0312.kim@samsung.com>
      Signed-off-by: NMarcel Holtmann <marcel@holtmann.org>
      c507f138
    • M
      Bluetooth: Fix issue with RFCOMM getsockopt operation · 60c7a3c9
      Marcel Holtmann 提交于
      The commit 94a86df0 seem to have
      uncovered a long standing bug that did not trigger so far.
      
      BUG: unable to handle kernel paging request at 00000009dd503502
      IP: [<ffffffff815b1868>] rfcomm_sock_getsockopt+0x128/0x200
      PGD 0
      Oops: 0000 [#1] SMP
      Modules linked in: ath5k ath mac80211 cfg80211
      CPU: 2 PID: 1459 Comm: bluetoothd Not tainted 3.11.0-133163-gcebd830 #2
      Hardware name: System manufacturer System Product Name/P6T DELUXE V2, BIOS
      1202    12/22/2010
      task: ffff8803304106a0 ti: ffff88033046a000 task.ti: ffff88033046a000
      RIP: 0010:[<ffffffff815b1868>]  [<ffffffff815b1868>]
      rfcomm_sock_getsockopt+0x128/0x200
      RSP: 0018:ffff88033046bed8  EFLAGS: 00010246
      RAX: 00000009dd503502 RBX: 0000000000000003 RCX: 00007fffa2ed5548
      RDX: 0000000000000003 RSI: 0000000000000012 RDI: ffff88032fd37480
      RBP: ffff88033046bf28 R08: 00007fffa2ed554c R09: ffff88032f5707d8
      R10: 00007fffa2ed5548 R11: 0000000000000202 R12: ffff880330bbd000
      R13: 00007fffa2ed5548 R14: 0000000000000003 R15: 00007fffa2ed554c
      FS:  00007fc44cfac700(0000) GS:ffff88033fc80000(0000) knlGS:0000000000000000
      CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
      CR2: 00000009dd503502 CR3: 00000003304c2000 CR4: 00000000000007e0
      Stack:
      ffff88033046bf28 ffffffff815b0f2f ffff88033046bf18 0002ffff81105ef6
      0000000600000000 ffff88032fd37480 0000000000000012 00007fffa2ed5548
      0000000000000003 00007fffa2ed554c ffff88033046bf78 ffffffff814c0380
      Call Trace:
      [<ffffffff815b0f2f>] ? rfcomm_sock_setsockopt+0x5f/0x190
      [<ffffffff814c0380>] SyS_getsockopt+0x60/0xb0
      [<ffffffff815e0852>] system_call_fastpath+0x16/0x1b
      Code: 02 00 00 00 0f 47 d0 4c 89 ef e8 74 13 cd ff 83 f8 01 19 c9 f7 d1 83 e1
      f2 e9 4b ff ff ff 0f 1f 44 00 00 49 8b 84 24 70 02 00 00 <4c> 8b 30 4c 89 c0 e8
      2d 19 cd ff 85 c0 49 89 d7 b9 f2 ff ff ff
      RIP  [<ffffffff815b1868>] rfcomm_sock_getsockopt+0x128/0x200
      RSP <ffff88033046bed8>
      CR2: 00000009dd503502
      
      It triggers in the following segment of the code:
      
      0x1313 is in rfcomm_sock_getsockopt (net/bluetooth/rfcomm/sock.c:743).
      738
      739	static int rfcomm_sock_getsockopt_old(struct socket *sock, int optname, char __user *optval, int __user *optlen)
      740	{
      741		struct sock *sk = sock->sk;
      742		struct rfcomm_conninfo cinfo;
      743		struct l2cap_conn *conn = l2cap_pi(sk)->chan->conn;
      744		int len, err = 0;
      745		u32 opt;
      746
      747		BT_DBG("sk %p", sk);
      
      The l2cap_pi(sk) is wrong here since it should have been rfcomm_pi(sk),
      but that socket of course does not contain the low-level connection
      details requested here.
      
      Tracking down the actual offending commit, it seems that this has been
      introduced when doing some L2CAP refactoring:
      
      commit 8c1d787b
      Author: Gustavo F. Padovan <padovan@profusion.mobi>
      Date:   Wed Apr 13 20:23:55 2011 -0300
      
      @@ -743,6 +743,7 @@ static int rfcomm_sock_getsockopt_old(struct socket *sock, int optname, char __u
              struct sock *sk = sock->sk;
              struct sock *l2cap_sk;
              struct rfcomm_conninfo cinfo;
      +       struct l2cap_conn *conn = l2cap_pi(sk)->chan->conn;
              int len, err = 0;
              u32 opt;
      
      @@ -787,8 +788,8 @@ static int rfcomm_sock_getsockopt_old(struct socket *sock, int optname, char __u
      
                      l2cap_sk = rfcomm_pi(sk)->dlc->session->sock->sk;
      
      -               cinfo.hci_handle = l2cap_pi(l2cap_sk)->conn->hcon->handle;
      -               memcpy(cinfo.dev_class, l2cap_pi(l2cap_sk)->conn->hcon->dev_class, 3);
      +               cinfo.hci_handle = conn->hcon->handle;
      +               memcpy(cinfo.dev_class, conn->hcon->dev_class, 3);
      
      The l2cap_sk got accidentally mixed into the sk (which is RFCOMM) and
      now causing a problem within getsocketopt() system call. To fix this,
      just re-introduce l2cap_sk and make sure the right socket is used for
      the low-level connection details.
      Reported-by: NFabio Rossi <rossi.f@inwind.it>
      Reported-by: NJanusz Dziedzic <janusz.dziedzic@gmail.com>
      Tested-by: NJanusz Dziedzic <janusz.dziedzic@gmail.com>
      Signed-off-by: NMarcel Holtmann <marcel@holtmann.org>
      Signed-off-by: NJohan Hedberg <johan.hedberg@intel.com>
      60c7a3c9
  6. 18 10月, 2013 1 次提交
  7. 14 10月, 2013 2 次提交
  8. 21 9月, 2013 1 次提交
    • G
      Bluetooth: don't release the port in rfcomm_dev_state_change() · 29cd718b
      Gianluca Anzolin 提交于
      When the dlc is closed, rfcomm_dev_state_change() tries to release the
      port in the case it cannot get a reference to the tty. However this is
      racy and not even needed.
      
      Infact as Peter Hurley points out:
      
      1. Only consider dlcs that are 'stolen' from a connected socket, ie.
         reused. Allocated dlcs cannot have been closed prior to port
         activate and so for these dlcs a tty reference will always be avail
         in rfcomm_dev_state_change() -- except for the conditions covered by
         #2b below.
      2. If a tty was at some point previously created for this rfcomm, then
         either
         (a) the tty reference is still avail, so rfcomm_dev_state_change()
             will perform a hangup. So nothing to do, or,
         (b) the tty reference is no longer avail, and the tty_port will be
             destroyed by the last tty_port_put() in rfcomm_tty_cleanup.
             Again, no action required.
      3. Prior to obtaining the dlc lock in rfcomm_dev_add(),
         rfcomm_dev_state_change() will not 'see' a rfcomm_dev so nothing to
         do here.
      4. After releasing the dlc lock in rfcomm_dev_add(),
         rfcomm_dev_state_change() will 'see' an incomplete rfcomm_dev if a
         tty reference could not be obtained. Again, the best thing to do here
         is nothing. Any future attempted open() will block on
         rfcomm_dev_carrier_raised(). The unconnected device will exist until
         released by ioctl(RFCOMMRELEASEDEV).
      
      The patch removes the aforementioned code and uses the
      tty_port_tty_hangup() helper to hangup the tty.
      Signed-off-by: NGianluca Anzolin <gianluca@sottospazio.it>
      Reviewed-by: NPeter Hurley <peter@hurleysoftware.com>
      Signed-off-by: NGustavo Padovan <gustavo.padovan@collabora.co.uk>
      29cd718b
  9. 19 9月, 2013 1 次提交
  10. 21 8月, 2013 6 次提交
  11. 10 4月, 2013 1 次提交
  12. 08 4月, 2013 1 次提交
  13. 21 3月, 2013 1 次提交
  14. 08 3月, 2013 4 次提交
    • D
      Bluetooth: Remove redundant RFCOMM BT_CLOSED settings · 24fd642c
      Dean Jenkins 提交于
      rfcomm_session_close() sets the RFCOMM session state to BT_CLOSED.
      However, in multiple places immediately before the function is
      called, the RFCOMM session is set to BT_CLOSED. Therefore,
      remove these unnecessary state settings.
      Signed-off-by: NDean Jenkins <Dean_Jenkins@mentor.com>
      Acked-by: NMarcel Holtmann <marcel@holtmann.org>
      Signed-off-by: NGustavo Padovan <gustavo.padovan@collabora.co.uk>
      24fd642c
    • D
      Bluetooth: Remove redundant call to rfcomm_send_disc · 8e888f27
      Dean Jenkins 提交于
      In rfcomm_session_del() remove the redundant call to
      rfcomm_send_disc() because it is not possible for the
      session to be in BT_CONNECTED state during deletion
      of the session.
      Signed-off-by: NDean Jenkins <Dean_Jenkins@mentor.com>
      Acked-by: NMarcel Holtmann <marcel@holtmann.org>
      Signed-off-by: NGustavo Padovan <gustavo.padovan@collabora.co.uk>
      8e888f27
    • D
      Bluetooth: Remove RFCOMM session refcnt · 08c30aca
      Dean Jenkins 提交于
      Previous commits have improved the handling of the RFCOMM session
      timer and the RFCOMM session pointers such that freed RFCOMM
      session structures should no longer be erroneously accessed. The
      RFCOMM session refcnt now has no purpose and will be deleted by
      this commit.
      
      Note that the RFCOMM session is now deleted as soon as the
      RFCOMM control channel link is no longer required. This makes the
      lifetime of the RFCOMM session deterministic and absolute.
      Previously with the refcnt, there was uncertainty about when
      the session structure would be deleted because the relative
      refcnt prevented the session structure from being deleted at will.
      
      It was noted that the refcnt could malfunction under very heavy
      real-time processor loading in embedded SMP environments. This
      could cause premature RFCOMM session deletion or double session
      deletion that could result in kernel crashes. Removal of the
      refcnt prevents this issue.
      
      There are 4 connection / disconnection RFCOMM session scenarios:
      host initiated control link ---> host disconnected control link
      host initiated ctrl link ---> remote device disconnected ctrl link
      remote device initiated ctrl link ---> host disconnected ctrl link
      remote device initiated ctrl link ---> remote device disc'ed ctrl link
      
      The control channel connection procedures are independent of the
      disconnection procedures. Strangely, the RFCOMM session refcnt was
      applying special treatment so erroneously combining connection and
      disconnection events. This commit fixes this issue by removing
      some session code that used the "initiator" member of the session
      structure that was intended for use with the data channels.
      Signed-off-by: NDean Jenkins <Dean_Jenkins@mentor.com>
      Acked-by: NMarcel Holtmann <marcel@holtmann.org>
      Signed-off-by: NGustavo Padovan <gustavo.padovan@collabora.co.uk>
      08c30aca
    • D
      Bluetooth: Return RFCOMM session ptrs to avoid freed session · 8ff52f7d
      Dean Jenkins 提交于
      Unfortunately, the design retains local copies of the s RFCOMM
      session pointer in various code blocks and this invites the erroneous
      access to a freed RFCOMM session structure.
      
      Therefore, return the RFCOMM session pointer back up the call stack
      to avoid accessing a freed RFCOMM session structure. When the RFCOMM
      session is deleted, NULL is passed up the call stack.
      
      If active DLCs exist when the rfcomm session is terminating,
      avoid a memory leak of rfcomm_dlc structures by ensuring that
      rfcomm_session_close() is used instead of rfcomm_session_del().
      Signed-off-by: NDean Jenkins <Dean_Jenkins@mentor.com>
      Acked-by: NMarcel Holtmann <marcel@holtmann.org>
      Signed-off-by: NGustavo Padovan <gustavo.padovan@collabora.co.uk>
      8ff52f7d