<feed xmlns='http://www.w3.org/2005/Atom'>
<title>kernel.git/net/bluetooth/rfcomm/tty.c, branch linux-2.6.25.y</title>
<subtitle>Hosts the 0x221E linux distro kernel.
</subtitle>
<id>https://git.0xinfinity.dev/distro/kernel.git/atom?h=linux-2.6.25.y</id>
<link rel='self' href='https://git.0xinfinity.dev/distro/kernel.git/atom?h=linux-2.6.25.y'/>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/'/>
<updated>2008-06-16T20:19:54Z</updated>
<entry>
<title>bluetooth: rfcomm_dev_state_change deadlock fix</title>
<updated>2008-06-16T20:19:54Z</updated>
<author>
<name>Dave Young</name>
</author>
<published>2008-06-02T06:50:52Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=0f624e67aa7cf66cf8477bb8b0d61750f4f94f4d'/>
<id>urn:sha1:0f624e67aa7cf66cf8477bb8b0d61750f4f94f4d</id>
<content type='text'>
commit 537d59af73d894750cff14f90fe2b6d77fbab15b in mainline

There's logic in __rfcomm_dlc_close:
	rfcomm_dlc_lock(d);
	d-&gt;state = BT_CLOSED;
	d-&gt;state_changed(d, err);
	rfcomm_dlc_unlock(d);

In rfcomm_dev_state_change, it's possible that rfcomm_dev_put try to
take the dlc lock, then we will deadlock.

Here fixed it by unlock dlc before rfcomm_dev_get in
rfcomm_dev_state_change.

why not unlock just before rfcomm_dev_put? it's because there's
another problem.  rfcomm_dev_get/rfcomm_dev_del will take
rfcomm_dev_lock, but in rfcomm_dev_add the lock order is :
rfcomm_dev_lock --&gt; dlc lock

so I unlock dlc before the taken of rfcomm_dev_lock.

Actually it's a regression caused by commit
1905f6c736cb618e07eca0c96e60e3c024023428 ("bluetooth :
__rfcomm_dlc_close lock fix"), the dlc state_change could be two
callbacks : rfcomm_sk_state_change and rfcomm_dev_state_change. I
missed the rfcomm_sk_state_change that time.

Thanks Arjan van de Ven &lt;arjan@linux.intel.com&gt; for the effort in
commit 4c8411f8c115def968820a4df6658ccfd55d7f1a ("bluetooth: fix
locking bug in the rfcomm socket cleanup handling") but he missed the
rfcomm_dev_state_change lock issue.

Signed-off-by: Dave Young &lt;hidave.darkstar@gmail.com&gt;
Acked-by: Marcel Holtmann &lt;marcel@holtmann.org&gt;
Signed-off-by: David S. Miller &lt;davem@davemloft.net&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@suse.de&gt;

</content>
</entry>
<entry>
<title>bluetooth : __rfcomm_dlc_close lock fix</title>
<updated>2008-04-02T06:59:06Z</updated>
<author>
<name>Dave Young</name>
</author>
<published>2008-04-02T06:59:06Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=1905f6c736cb618e07eca0c96e60e3c024023428'/>
<id>urn:sha1:1905f6c736cb618e07eca0c96e60e3c024023428</id>
<content type='text'>
Lockdep warning will be trigged while rfcomm connection closing.

The locks taken in rfcomm_dev_add:
rfcomm_dev_lock --&gt; d-&gt;lock

In __rfcomm_dlc_close:
d-&gt;lock --&gt; rfcomm_dev_lock (in rfcomm_dev_state_change)

There's two way to fix it, one is in rfcomm_dev_add we first locking
d-&gt;lock then the rfcomm_dev_lock

The other (in this patch), remove the locking of d-&gt;lock for
rfcomm_dev_state_change because just locking "d-&gt;state = BT_CLOSED;"
is enough.

[  295.002046] =======================================================
[  295.002046] [ INFO: possible circular locking dependency detected ]
[  295.002046] 2.6.25-rc7 #1
[  295.002046] -------------------------------------------------------
[  295.002046] krfcommd/2705 is trying to acquire lock:
[  295.002046]  (rfcomm_dev_lock){-.--}, at: [&lt;f89a090a&gt;] rfcomm_dev_state_change+0x6a/0xd0 [rfcomm]
[  295.002046] 
[  295.002046] but task is already holding lock:
[  295.002046]  (&amp;d-&gt;lock){--..}, at: [&lt;f899c533&gt;] __rfcomm_dlc_close+0x43/0xd0 [rfcomm]
[  295.002046] 
[  295.002046] which lock already depends on the new lock.
[  295.002046] 
[  295.002046] 
[  295.002046] the existing dependency chain (in reverse order) is:
[  295.002046] 
[  295.002046] -&gt; #1 (&amp;d-&gt;lock){--..}:
[  295.002046]        [&lt;c0149b23&gt;] check_prev_add+0xd3/0x200
[  295.002046]        [&lt;c0149ce5&gt;] check_prevs_add+0x95/0xe0
[  295.002046]        [&lt;c0149f6f&gt;] validate_chain+0x23f/0x320
[  295.002046]        [&lt;c014b7b1&gt;] __lock_acquire+0x1c1/0x760
[  295.002046]        [&lt;c014c349&gt;] lock_acquire+0x79/0xb0
[  295.002046]        [&lt;c03d6b99&gt;] _spin_lock+0x39/0x80
[  295.002046]        [&lt;f89a01c0&gt;] rfcomm_dev_add+0x240/0x360 [rfcomm]
[  295.002046]        [&lt;f89a047e&gt;] rfcomm_create_dev+0x6e/0xe0 [rfcomm]
[  295.002046]        [&lt;f89a0823&gt;] rfcomm_dev_ioctl+0x33/0x60 [rfcomm]
[  295.002046]        [&lt;f899facc&gt;] rfcomm_sock_ioctl+0x2c/0x50 [rfcomm]
[  295.002046]        [&lt;c0363d38&gt;] sock_ioctl+0x118/0x240
[  295.002046]        [&lt;c0194196&gt;] vfs_ioctl+0x76/0x90
[  295.002046]        [&lt;c0194446&gt;] do_vfs_ioctl+0x56/0x140
[  295.002046]        [&lt;c0194569&gt;] sys_ioctl+0x39/0x60
[  295.002046]        [&lt;c0104faa&gt;] syscall_call+0x7/0xb
[  295.002046]        [&lt;ffffffff&gt;] 0xffffffff
[  295.002046] 
[  295.002046] -&gt; #0 (rfcomm_dev_lock){-.--}:
[  295.002046]        [&lt;c0149a84&gt;] check_prev_add+0x34/0x200
[  295.002046]        [&lt;c0149ce5&gt;] check_prevs_add+0x95/0xe0
[  295.002046]        [&lt;c0149f6f&gt;] validate_chain+0x23f/0x320
[  295.002046]        [&lt;c014b7b1&gt;] __lock_acquire+0x1c1/0x760
[  295.002046]        [&lt;c014c349&gt;] lock_acquire+0x79/0xb0
[  295.002046]        [&lt;c03d6639&gt;] _read_lock+0x39/0x80
[  295.002046]        [&lt;f89a090a&gt;] rfcomm_dev_state_change+0x6a/0xd0 [rfcomm]
[  295.002046]        [&lt;f899c548&gt;] __rfcomm_dlc_close+0x58/0xd0 [rfcomm]
[  295.002046]        [&lt;f899d44f&gt;] rfcomm_recv_ua+0x6f/0x120 [rfcomm]
[  295.002046]        [&lt;f899e061&gt;] rfcomm_recv_frame+0x171/0x1e0 [rfcomm]
[  295.002046]        [&lt;f899e357&gt;] rfcomm_run+0xe7/0x550 [rfcomm]
[  295.002046]        [&lt;c013c18c&gt;] kthread+0x5c/0xa0
[  295.002046]        [&lt;c0105c07&gt;] kernel_thread_helper+0x7/0x10
[  295.002046]        [&lt;ffffffff&gt;] 0xffffffff
[  295.002046] 
[  295.002046] other info that might help us debug this:
[  295.002046] 
[  295.002046] 2 locks held by krfcommd/2705:
[  295.002046]  #0:  (rfcomm_mutex){--..}, at: [&lt;f899e2eb&gt;] rfcomm_run+0x7b/0x550 [rfcomm]
[  295.002046]  #1:  (&amp;d-&gt;lock){--..}, at: [&lt;f899c533&gt;] __rfcomm_dlc_close+0x43/0xd0 [rfcomm]
[  295.002046] 
[  295.002046] stack backtrace:
[  295.002046] Pid: 2705, comm: krfcommd Not tainted 2.6.25-rc7 #1
[  295.002046]  [&lt;c0128a38&gt;] ? printk+0x18/0x20
[  295.002046]  [&lt;c014927f&gt;] print_circular_bug_tail+0x6f/0x80
[  295.002046]  [&lt;c0149a84&gt;] check_prev_add+0x34/0x200
[  295.002046]  [&lt;c0149ce5&gt;] check_prevs_add+0x95/0xe0
[  295.002046]  [&lt;c0149f6f&gt;] validate_chain+0x23f/0x320
[  295.002046]  [&lt;c014b7b1&gt;] __lock_acquire+0x1c1/0x760
[  295.002046]  [&lt;c014c349&gt;] lock_acquire+0x79/0xb0
[  295.002046]  [&lt;f89a090a&gt;] ? rfcomm_dev_state_change+0x6a/0xd0 [rfcomm]
[  295.002046]  [&lt;c03d6639&gt;] _read_lock+0x39/0x80
[  295.002046]  [&lt;f89a090a&gt;] ? rfcomm_dev_state_change+0x6a/0xd0 [rfcomm]
[  295.002046]  [&lt;f89a090a&gt;] rfcomm_dev_state_change+0x6a/0xd0 [rfcomm]
[  295.002046]  [&lt;f899c548&gt;] __rfcomm_dlc_close+0x58/0xd0 [rfcomm]
[  295.002046]  [&lt;f899d44f&gt;] rfcomm_recv_ua+0x6f/0x120 [rfcomm]
[  295.002046]  [&lt;f899e061&gt;] rfcomm_recv_frame+0x171/0x1e0 [rfcomm]
[  295.002046]  [&lt;c014abd9&gt;] ? trace_hardirqs_on+0xb9/0x130
[  295.002046]  [&lt;c03d6e89&gt;] ? _spin_unlock_irqrestore+0x39/0x70
[  295.002046]  [&lt;f899e357&gt;] rfcomm_run+0xe7/0x550 [rfcomm]
[  295.002046]  [&lt;c03d4559&gt;] ? __sched_text_start+0x229/0x4c0
[  295.002046]  [&lt;c0120000&gt;] ? cpu_avg_load_per_task+0x20/0x30
[  295.002046]  [&lt;f899e270&gt;] ? rfcomm_run+0x0/0x550 [rfcomm]
[  295.002046]  [&lt;c013c18c&gt;] kthread+0x5c/0xa0
[  295.002046]  [&lt;c013c130&gt;] ? kthread+0x0/0xa0
[  295.002046]  [&lt;c0105c07&gt;] kernel_thread_helper+0x7/0x10
[  295.002046]  =======================

Signed-off-by: Dave Young &lt;hidave.darkstar@gmail.com&gt;
Signed-off-by: David S. Miller &lt;davem@davemloft.net&gt;
</content>
</entry>
<entry>
<title>bluetooth rfcomm tty: destroy before tty_close()</title>
<updated>2008-02-05T11:12:06Z</updated>
<author>
<name>Dave Young</name>
</author>
<published>2008-02-05T11:12:06Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=93d807401ced2320d0d1e56bf9de099bba5c0424'/>
<id>urn:sha1:93d807401ced2320d0d1e56bf9de099bba5c0424</id>
<content type='text'>
rfcomm dev could be deleted in tty_hangup, so we must not call
rfcomm_dev_del again to prevent from destroying rfcomm dev before tty
close.

Signed-off-by: Dave Young &lt;hidave.darkstar@gmail.com&gt;
Signed-off-by: Andrew Morton &lt;akpm@linux-foundation.org&gt;
Signed-off-by: David S. Miller &lt;davem@davemloft.net&gt;
</content>
</entry>
<entry>
<title>[BLUETOOTH]: Move children of connection device to NULL before connection down.</title>
<updated>2008-01-23T11:11:39Z</updated>
<author>
<name>Dave Young</name>
</author>
<published>2008-01-22T06:35:21Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=acea6852f32b8805e166d885ed7e9f0c7cd10d41'/>
<id>urn:sha1:acea6852f32b8805e166d885ed7e9f0c7cd10d41</id>
<content type='text'>
The rfcomm tty device will possibly retain even when conn is down, and
sysfs doesn't support zombie device moving, so this patch move the tty
device before conn device is destroyed.

For the bug refered please see :
http://lkml.org/lkml/2007/12/28/87

Signed-off-by: Dave Young &lt;hidave.darkstar@gmail.com&gt;
Signed-off-by: David S. Miller &lt;davem@davemloft.net&gt;
</content>
</entry>
<entry>
<title>[BLUETOOTH]: rfcomm tty BUG_ON() code fix</title>
<updated>2008-01-11T06:22:52Z</updated>
<author>
<name>Dave Young</name>
</author>
<published>2008-01-11T06:22:52Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=f951375d470c1a20d92c34377991197e6bf17990'/>
<id>urn:sha1:f951375d470c1a20d92c34377991197e6bf17990</id>
<content type='text'>
1) In tty.c the BUG_ON at line 115 will never be called, because the the
   before list_del_init in this same function.
	115          BUG_ON(!list_empty(&amp;dev-&gt;list));
   So move the list_del_init to rfcomm_dev_del 

2) The rfcomm_dev_del could be called from diffrent path
   (rfcomm_tty_hangup/rfcomm_dev_state_change/rfcomm_release_dev),

   So add another BUG_ON when the rfcomm_dev_del is called more than
   one time.

Signed-off-by: Dave Young &lt;hidave.darkstar@gmail.com&gt;
Signed-off-by: David S. Miller &lt;davem@davemloft.net&gt;
</content>
</entry>
<entry>
<title>[Bluetooth] Add address and channel attribute to RFCOMM TTY device</title>
<updated>2007-10-22T09:59:47Z</updated>
<author>
<name>Marcel Holtmann</name>
</author>
<published>2007-10-20T12:52:38Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=dae6a0f6636d05bcb28ece1f3630b23ed2d66e18'/>
<id>urn:sha1:dae6a0f6636d05bcb28ece1f3630b23ed2d66e18</id>
<content type='text'>
Export the remote device address and channel of RFCOMM TTY device
via sysfs attributes. This allows udev to create better naming rules
for configured RFCOMM devices.

Signed-off-by: Marcel Holtmann &lt;marcel@holtmann.org&gt;
</content>
</entry>
<entry>
<title>[IRDA]: Fix rfcomm use-after-free</title>
<updated>2007-07-31T09:28:05Z</updated>
<author>
<name>Marcel Holtmann</name>
</author>
<published>2007-07-26T07:12:25Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=09c7d8293a2d1317d16ef4ddb9f6dd2553d0694e'/>
<id>urn:sha1:09c7d8293a2d1317d16ef4ddb9f6dd2553d0694e</id>
<content type='text'>
Adrian Bunk wrote:
&gt; Commit 8de0a15483b357d0f0b821330ec84d1660cadc4e added the following
&gt; use-after-free in net/bluetooth/rfcomm/tty.c:
&gt;
&gt; &lt;--  snip  --&gt;
&gt;
&gt; ...
&gt; static int rfcomm_dev_add(struct rfcomm_dev_req *req, struct rfcomm_dlc *dlc)
&gt; {
&gt; ...
&gt;         if (IS_ERR(dev-&gt;tty_dev)) {
&gt;                 list_del(&amp;dev-&gt;list);
&gt;                 kfree(dev);
&gt;                 return PTR_ERR(dev-&gt;tty_dev);
&gt;         }
&gt; ...
&gt;
&gt; &lt;--  snip  --&gt;
&gt;
&gt; Spotted by the Coverity checker.

really good catch. I fully overlooked that one. The attached patch
should fix it.

Signed-off-by: Marcel Holtmann &lt;marcel@holtmann.org&gt;
Signed-off-by: David S. Miller &lt;davem@davemloft.net&gt;
</content>
</entry>
<entry>
<title>[Bluetooth] Keep rfcomm_dev on the list until it is freed</title>
<updated>2007-07-11T05:06:51Z</updated>
<author>
<name>Ville Tervo</name>
</author>
<published>2007-07-11T07:23:41Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=8de0a15483b357d0f0b821330ec84d1660cadc4e'/>
<id>urn:sha1:8de0a15483b357d0f0b821330ec84d1660cadc4e</id>
<content type='text'>
This patch changes the RFCOMM TTY release process so that the TTY is kept
on the list until it is really freed. A new device flag is used to keep
track of released TTYs.

Signed-off-by: Ville Tervo &lt;ville.tervo@nokia.com&gt;
Signed-off-by: Marcel Holtmann &lt;marcel@holtmann.org&gt;
</content>
</entry>
<entry>
<title>[Bluetooth] Hangup TTY before releasing rfcomm_dev</title>
<updated>2007-07-11T05:01:26Z</updated>
<author>
<name>Mikko Rapeli</name>
</author>
<published>2007-07-11T07:18:15Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=84950cf0ba02fd6a5defe2511bc41f9aa2237632'/>
<id>urn:sha1:84950cf0ba02fd6a5defe2511bc41f9aa2237632</id>
<content type='text'>
The core problem is that RFCOMM socket layer ioctl can release
rfcomm_dev struct while RFCOMM TTY layer is still actively using
it. Calling tty_vhangup() is needed for a synchronous hangup before
rfcomm_dev is freed.

Addresses the oops at http://bugzilla.kernel.org/show_bug.cgi?id=7509

Acked-by: Alan Cox &lt;alan@lxorguk.ukuu.org.uk&gt;
Signed-off-by: Marcel Holtmann &lt;marcel@holtmann.org&gt;
</content>
</entry>
<entry>
<title>[Bluetooth] Check that device is in rfcomm_dev_list before deleting</title>
<updated>2007-05-04T22:36:10Z</updated>
<author>
<name>Marcel Holtmann</name>
</author>
<published>2007-05-04T22:36:10Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=77f2a45fa1ba33147fd6cc8ae546188504a822cd'/>
<id>urn:sha1:77f2a45fa1ba33147fd6cc8ae546188504a822cd</id>
<content type='text'>
If RFCOMM_RELEASE_ONHUP flag is on and rfcomm_release_dev is called
before connection is closed, rfcomm_dev is deleted twice from the
rfcomm_dev_list and refcount is messed up. This patch adds a check
before deleting device that the device actually is listed.

Signed-off-by: Ville Tervo &lt;ville.tervo@nokia.com&gt;
Signed-off-by: Marcel Holtmann &lt;marcel@holtmann.org&gt;
</content>
</entry>
</feed>
