public inbox for stable@vger.kernel.org
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	stable@vger.kernel.org, Itay Iellin <ieitayie@gmail.com>,
	Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
Subject: [PATCH 5.17 01/12] Bluetooth: Fix the creation of hdev->name
Date: Fri, 13 May 2022 16:24:01 +0200	[thread overview]
Message-ID: <20220513142228.696497916@linuxfoundation.org> (raw)
In-Reply-To: <20220513142228.651822943@linuxfoundation.org>

From: Itay Iellin <ieitayie@gmail.com>

commit 103a2f3255a95991252f8f13375c3a96a75011cd upstream.

Set a size limit of 8 bytes of the written buffer to "hdev->name"
including the terminating null byte, as the size of "hdev->name" is 8
bytes. If an id value which is greater than 9999 is allocated,
then the "snprintf(hdev->name, sizeof(hdev->name), "hci%d", id)"
function call would lead to a truncation of the id value in decimal
notation.

Set an explicit maximum id parameter in the id allocation function call.
The id allocation function defines the maximum allocated id value as the
maximum id parameter value minus one. Therefore, HCI_MAX_ID is defined
as 10000.

Signed-off-by: Itay Iellin <ieitayie@gmail.com>
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 include/net/bluetooth/hci_core.h |    3 +++
 net/bluetooth/hci_core.c         |    6 +++---
 2 files changed, 6 insertions(+), 3 deletions(-)

--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -36,6 +36,9 @@
 /* HCI priority */
 #define HCI_PRIO_MAX	7
 
+/* HCI maximum id value */
+#define HCI_MAX_ID 10000
+
 /* HCI Core structures */
 struct inquiry_data {
 	bdaddr_t	bdaddr;
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -2554,10 +2554,10 @@ int hci_register_dev(struct hci_dev *hde
 	 */
 	switch (hdev->dev_type) {
 	case HCI_PRIMARY:
-		id = ida_simple_get(&hci_index_ida, 0, 0, GFP_KERNEL);
+		id = ida_simple_get(&hci_index_ida, 0, HCI_MAX_ID, GFP_KERNEL);
 		break;
 	case HCI_AMP:
-		id = ida_simple_get(&hci_index_ida, 1, 0, GFP_KERNEL);
+		id = ida_simple_get(&hci_index_ida, 1, HCI_MAX_ID, GFP_KERNEL);
 		break;
 	default:
 		return -EINVAL;
@@ -2566,7 +2566,7 @@ int hci_register_dev(struct hci_dev *hde
 	if (id < 0)
 		return id;
 
-	sprintf(hdev->name, "hci%d", id);
+	snprintf(hdev->name, sizeof(hdev->name), "hci%d", id);
 	hdev->id = id;
 
 	BT_DBG("%p name %s bus %d", hdev, hdev->name, hdev->bus);



  reply	other threads:[~2022-05-13 14:34 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-13 14:24 [PATCH 5.17 00/12] 5.17.8-rc1 review Greg Kroah-Hartman
2022-05-13 14:24 ` Greg Kroah-Hartman [this message]
2022-05-13 14:24 ` [PATCH 5.17 02/12] rfkill: uapi: fix RFKILL_IOCTL_MAX_SIZE ioctl request definition Greg Kroah-Hartman
2022-05-13 14:24 ` [PATCH 5.17 03/12] udf: Avoid using stale lengthOfImpUse Greg Kroah-Hartman
2022-05-13 14:24 ` [PATCH 5.17 04/12] mm: fix missing cache flush for all tail pages of compound page Greg Kroah-Hartman
2022-05-13 14:24 ` [PATCH 5.17 05/12] mm: hugetlb: fix missing cache flush in copy_huge_page_from_user() Greg Kroah-Hartman
2022-05-13 14:24 ` [PATCH 5.17 06/12] mm: hugetlb: fix missing cache flush in hugetlb_mcopy_atomic_pte() Greg Kroah-Hartman
2022-05-13 14:24 ` [PATCH 5.17 07/12] mm: shmem: fix missing cache flush in shmem_mfill_atomic_pte() Greg Kroah-Hartman
2022-05-13 14:24 ` [PATCH 5.17 08/12] mm: userfaultfd: fix missing cache flush in mcopy_atomic_pte() and __mcopy_atomic() Greg Kroah-Hartman
2022-05-13 14:24 ` [PATCH 5.17 09/12] mm/hwpoison: fix error page recovered but reported "not recovered" Greg Kroah-Hartman
2022-05-13 14:24 ` [PATCH 5.17 10/12] mm/mlock: fix potential imbalanced rlimit ucounts adjustment Greg Kroah-Hartman
2022-05-13 14:24 ` [PATCH 5.17 11/12] mm,migrate: fix establishing demotion target Greg Kroah-Hartman
2022-05-13 14:24 ` [PATCH 5.17 12/12] mm: fix invalid page pointer returned with FOLL_PIN gups Greg Kroah-Hartman
2022-05-13 16:40 ` [PATCH 5.17 00/12] 5.17.8-rc1 review Jon Hunter
2022-05-13 20:35 ` Shuah Khan
2022-05-14  3:14 ` Ron Economos
2022-05-14  3:38 ` Florian Fainelli
2022-05-14  3:46 ` Naresh Kamboju
2022-05-14  6:12 ` Fenil Jain
2022-05-14  7:51 ` Fox Chen
2022-05-14 14:57 ` Guenter Roeck

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=20220513142228.696497916@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=ieitayie@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luiz.von.dentz@intel.com \
    --cc=stable@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