mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Dean Jenkins <Dean_Jenkins@mentor.com>
To: Andre Naujoks <nautsch2@gmail.com>, linux-kernel@vger.kernel.org
Cc: Jiri Slaby <jslaby@suse.cz>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Subject: [PATCH 1/5] Bluetooth: Add RFCOMM TTY write return error codes
Date: Tue,  2 Jul 2013 16:31:30 +0100	[thread overview]
Message-ID: <1372779094-11730-2-git-send-email-Dean_Jenkins@mentor.com> (raw)
In-Reply-To: <1372779094-11730-1-git-send-email-Dean_Jenkins@mentor.com>

It appears that rfcomm_tty_write() does not check that the
passed in TTY device_data is not NULL and also does not check
that the RFCOMM DLC serial data link pointer is not NULL.

A kernel crash was observed whilst SLIP was bound to /dev/rfcomm0
but the /dev/rfcomm0 had subsequently disconnected. Unfortunately,
SLIP attempted to write to the now non-existant RFCOMM TTY device
which caused a NULL pointer dereference because the device_data
no longer existed.

Therefore, add NULL pointer checks for the dev and dlc pointers
and output kernel error debug to show that NULL had been detected.

Signed-off-by: Dean Jenkins <Dean_Jenkins@mentor.com>
---
 net/bluetooth/rfcomm/tty.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
index b6e44ad..56d28d1 100644
--- a/net/bluetooth/rfcomm/tty.c
+++ b/net/bluetooth/rfcomm/tty.c
@@ -761,12 +761,24 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
 static int rfcomm_tty_write(struct tty_struct *tty, const unsigned char *buf, int count)
 {
 	struct rfcomm_dev *dev = (struct rfcomm_dev *) tty->driver_data;
-	struct rfcomm_dlc *dlc = dev->dlc;
+	struct rfcomm_dlc *dlc;
 	struct sk_buff *skb;
 	int err = 0, sent = 0, size;
 
 	BT_DBG("tty %p count %d", tty, count);
 
+	if (!dev) {
+		BT_ERR("RFCOMM TTY device data structure does not exist");
+		return -ENODEV;
+	}
+
+	dlc = dev->dlc;
+
+	if (!dlc) {
+		BT_ERR("RFCOMM serial data link does not exist");
+		return -ENOLINK;
+	}
+
 	while (count) {
 		size = min_t(uint, count, dlc->mtu);
 
-- 
1.8.1.5


  reply	other threads:[~2013-07-02 15:42 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-02 15:31 [PATCH 0/5] SLIP SLIP-Improve robustness to crashing Dean Jenkins
2013-07-02 15:31 ` Dean Jenkins [this message]
2013-07-24 23:12   ` [PATCH 1/5] Bluetooth: Add RFCOMM TTY write return error codes Peter Hurley
2013-07-02 15:31 ` [PATCH 2/5] SLIP: Handle error codes from the TTY layer Dean Jenkins
2013-07-24 22:18   ` Greg Kroah-Hartman
2013-07-02 15:31 ` [PATCH 3/5] SLIP: Prevent recursion stack overflow and scheduler crash Dean Jenkins
2013-07-25  1:12   ` Peter Hurley
2013-07-02 15:31 ` [PATCH 4/5] SLIP: Add error message for xleft non-zero Dean Jenkins
2013-07-24 22:18   ` Greg Kroah-Hartman
2013-07-24 22:41     ` Paul Bolle
2013-07-02 15:31 ` [PATCH 5/5] SLIP: Fix transmission segmentation mechanism Dean Jenkins
2013-07-24 22:18   ` Greg Kroah-Hartman
2013-07-25  0:13   ` Peter Hurley

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=1372779094-11730-2-git-send-email-Dean_Jenkins@mentor.com \
    --to=dean_jenkins@mentor.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jslaby@suse.cz \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nautsch2@gmail.com \
    /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

all inboxes | Powered by JetHome®