linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Michał Narajowski" <michal.narajowski@codecoup.pl>
To: linux-bluetooth@vger.kernel.org
Cc: "Michał Narajowski" <michal.narajowski@codecoup.pl>
Subject: [PATCH 2/3] Bluetooth: Fix local name validation
Date: Thu, 22 Sep 2016 16:01:38 +0200	[thread overview]
Message-ID: <1474552899-3837-2-git-send-email-michal.narajowski@codecoup.pl> (raw)
In-Reply-To: <1474552899-3837-1-git-send-email-michal.narajowski@codecoup.pl>

Short name should be shorter than complete name
and it should be a prefix of complete name.

Signed-off-by: Michał Narajowski <michal.narajowski@codecoup.pl>
---
 net/bluetooth/mgmt.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index 7b2bac4..5709377 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -3099,6 +3099,24 @@ unlock:
 	hci_dev_unlock(hdev);
 }
 
+static bool name_is_valid(u8 *complete_name, u8 *short_name)
+{
+	size_t complete_len = strlen(complete_name);
+	size_t short_len = strlen(short_name);
+
+	if (complete_len <= short_len)
+		return false;
+
+	/* Core Specification Supplement, A, 1.2.1:
+	 * A shortened name shall only contain contiguous characters from
+	 * the beginning of the full name.
+	 */
+	if (strncmp(short_name, complete_name, short_len) != 0)
+		return false;
+
+	return true;
+}
+
 static int set_local_name(struct sock *sk, struct hci_dev *hdev, void *data,
 			  u16 len)
 {
@@ -3122,6 +3140,12 @@ static int set_local_name(struct sock *sk, struct hci_dev *hdev, void *data,
 		goto failed;
 	}
 
+	if (!name_is_valid(cp->name, cp->short_name)) {
+		err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_LOCAL_NAME,
+				      MGMT_STATUS_INVALID_PARAMS);
+		goto failed;
+	}
+
 	memcpy(hdev->short_name, cp->short_name, sizeof(hdev->short_name));
 
 	if (!hdev_is_powered(hdev)) {
-- 
2.7.4


  reply	other threads:[~2016-09-22 14:01 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-22 14:01 [PATCH 1/3] Bluetooth: Fix local name in scan rsp Michał Narajowski
2016-09-22 14:01 ` Michał Narajowski [this message]
2016-09-22 15:50   ` [PATCH 2/3] Bluetooth: Fix local name validation Marcel Holtmann
2016-09-22 14:01 ` [PATCH 3/3] Bluetooth: Fix not updating scan rsp when adv off Michał Narajowski
2016-09-22 15:48   ` Marcel Holtmann
2016-09-22 15:47 ` [PATCH 1/3] Bluetooth: Fix local name in scan rsp Marcel Holtmann
2016-09-22 19:07   ` Szymon Janc
2016-09-22 19:56     ` Marcel Holtmann

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=1474552899-3837-2-git-send-email-michal.narajowski@codecoup.pl \
    --to=michal.narajowski@codecoup.pl \
    --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).