linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Karl Relton <karllinuxtest.relton@ntlworld.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH hidp] Fix Kernel OOPS in hidp_session caused by orphaned sock structures
Date: Tue, 08 Jan 2013 14:21:57 +0000	[thread overview]
Message-ID: <1357654917.5641.7.camel@dellpc> (raw)

This is a proposed fix to the kernel OOPS reported in

https://bugzilla.kernel.org/show_bug.cgi?id=50541

hidp_session() is crashing the kernel typically on a resume from
suspend. My analysis concluded that the sock structure pointed to by
ctrl_sk was being orphaned at some point parallel to the execution of
hidp_session (sometimes even while hidp_session is still in its main
loop). This mean that calls to sk_sleep(ctrl_sk) would return NULL,
leading to ..._wait() or ..._wakeup() calls crashing.

The proposed fix is to store the waitqueue_head structure needed for the
waiting/waking in a local variable. rcu_dereference_raw() [normally
called via sk_sleep()] is still used and required to protect access, but
we ensure we have the proper handle onto the structure rather than
losing it by the sock being orphaned.

Signed-off-by: Karl Relton <karllinuxtest.relton@ntlworld.com>

--- linux-3.7.0.orig/net/bluetooth/hidp/core.c	2013-01-08 13:04:35.945237334 +0000
+++ linux-3.7.0/net/bluetooth/hidp/core.c	2013-01-08 13:06:11.313240959 +0000
@@ -680,16 +680,19 @@ static int hidp_session(void *arg)
 	struct sock *intr_sk = session->intr_sock->sk;
 	struct sk_buff *skb;
 	wait_queue_t ctrl_wait, intr_wait;
+	struct socket_wq *ctrl_wq, *intr_wq;
 
 	BT_DBG("session %p", session);
 
 	__module_get(THIS_MODULE);
 	set_user_nice(current, -15);
 
+	ctrl_wq = ctrl_sk->sk_wq;
+	intr_wq = intr_sk->sk_wq;
 	init_waitqueue_entry(&ctrl_wait, current);
 	init_waitqueue_entry(&intr_wait, current);
-	add_wait_queue(sk_sleep(ctrl_sk), &ctrl_wait);
-	add_wait_queue(sk_sleep(intr_sk), &intr_wait);
+	add_wait_queue(&rcu_dereference_raw(ctrl_wq)->wait, &ctrl_wait);
+	add_wait_queue(&rcu_dereference_raw(intr_wq)->wait, &intr_wait);
 	session->waiting_for_startup = 0;
 	wake_up_interruptible(&session->startup_queue);
 	set_current_state(TASK_INTERRUPTIBLE);
@@ -722,8 +725,8 @@ static int hidp_session(void *arg)
 		set_current_state(TASK_INTERRUPTIBLE);
 	}
 	set_current_state(TASK_RUNNING);
-	remove_wait_queue(sk_sleep(intr_sk), &intr_wait);
-	remove_wait_queue(sk_sleep(ctrl_sk), &ctrl_wait);
+	remove_wait_queue(&rcu_dereference_raw(intr_wq)->wait, &intr_wait);
+	remove_wait_queue(&rcu_dereference_raw(ctrl_wq)->wait, &ctrl_wait);
 
 	clear_bit(HIDP_WAITING_FOR_SEND_ACK, &session->flags);
 	clear_bit(HIDP_WAITING_FOR_RETURN, &session->flags);
@@ -747,12 +750,15 @@ static int hidp_session(void *arg)
 	session->intr_sock->sk->sk_err = EUNATCH;
 	session->ctrl_sock->sk->sk_err = EUNATCH;
 
-	hidp_schedule(session);
+	wake_up_interruptible(&rcu_dereference_raw(ctrl_wq)->wait);
+	wake_up_interruptible(&rcu_dereference_raw(intr_wq)->wait);
 
 	fput(session->intr_sock->file);
 
-	wait_event_timeout(*(sk_sleep(ctrl_sk)),
-		(ctrl_sk->sk_state == BT_CLOSED), msecs_to_jiffies(500));
+	/* By now ctrl_sk might have been orphaned already */
+	if (ctrl_wq == ctrl_sk->sk_wq)
+		wait_event_timeout(rcu_dereference_raw(ctrl_wq)->wait,
+			(ctrl_sk->sk_state == BT_CLOSED), msecs_to_jiffies(500));
 
 	fput(session->ctrl_sock->file);
 



                 reply	other threads:[~2013-01-08 14:21 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1357654917.5641.7.camel@dellpc \
    --to=karllinuxtest.relton@ntlworld.com \
    --cc=linux-bluetooth@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).