* [PATCH-stable v2] Bluetooth: eir: Fix using strlen with hdev->{dev_name,short_name}
@ 2022-05-28 0:35 Luiz Augusto von Dentz
2022-05-28 2:47 ` [PATCH-stable,v2] " bluez.test.bot
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Luiz Augusto von Dentz @ 2022-05-28 0:35 UTC (permalink / raw)
To: linux-bluetooth
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
Both dev_name and short_name are not guaranteed to be NULL terminated so
this instead use strnlen and then attempt to determine if the resulting
string needs to be truncated or not.
Link: https://bugzilla.kernel.org/show_bug.cgi?id=216018
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
---
net/bluetooth/eir.c | 41 ++++++++++++++++++++++++++---------------
net/bluetooth/mgmt.c | 4 ++--
2 files changed, 28 insertions(+), 17 deletions(-)
diff --git a/net/bluetooth/eir.c b/net/bluetooth/eir.c
index 7d77fb00c2bf..776d27f7e18d 100644
--- a/net/bluetooth/eir.c
+++ b/net/bluetooth/eir.c
@@ -13,6 +13,20 @@
#define PNP_INFO_SVCLASS_ID 0x1200
+static u8 eir_append_name(u8 *eir, u16 eir_len, u8 type, u8 *data, u8 data_len)
+{
+ u8 name[HCI_MAX_SHORT_NAME_LENGTH + 1];
+
+ /* If data is already NULL terminated just pass it directly */
+ if (data[data_len - 1] == '\0')
+ return eir_append_data(eir, eir_len, type, data, data_len);
+
+ memcpy(name, data, HCI_MAX_SHORT_NAME_LENGTH);
+ name[HCI_MAX_SHORT_NAME_LENGTH] = '\0';
+
+ return eir_append_data(eir, eir_len, type, name, sizeof(name));
+}
+
u8 eir_append_local_name(struct hci_dev *hdev, u8 *ptr, u8 ad_len)
{
size_t short_len;
@@ -23,29 +37,26 @@ u8 eir_append_local_name(struct hci_dev *hdev, u8 *ptr, u8 ad_len)
return ad_len;
/* use complete name if present and fits */
- complete_len = strlen(hdev->dev_name);
+ complete_len = strnlen(hdev->dev_name, sizeof(hdev->dev_name));
if (complete_len && complete_len <= HCI_MAX_SHORT_NAME_LENGTH)
- return eir_append_data(ptr, ad_len, EIR_NAME_COMPLETE,
+ return eir_append_name(ptr, ad_len, EIR_NAME_COMPLETE,
hdev->dev_name, complete_len + 1);
/* use short name if present */
- short_len = strlen(hdev->short_name);
+ short_len = strnlen(hdev->short_name, sizeof(hdev->short_name));
if (short_len)
- return eir_append_data(ptr, ad_len, EIR_NAME_SHORT,
- hdev->short_name, short_len + 1);
+ return eir_append_name(ptr, ad_len, EIR_NAME_SHORT,
+ hdev->short_name,
+ short_len == HCI_MAX_SHORT_NAME_LENGTH ?
+ short_len : short_len + 1);
/* use shortened full name if present, we already know that name
* is longer then HCI_MAX_SHORT_NAME_LENGTH
*/
- if (complete_len) {
- u8 name[HCI_MAX_SHORT_NAME_LENGTH + 1];
-
- memcpy(name, hdev->dev_name, HCI_MAX_SHORT_NAME_LENGTH);
- name[HCI_MAX_SHORT_NAME_LENGTH] = '\0';
-
- return eir_append_data(ptr, ad_len, EIR_NAME_SHORT, name,
- sizeof(name));
- }
+ if (complete_len)
+ return eir_append_name(ptr, ad_len, EIR_NAME_SHORT,
+ hdev->dev_name,
+ HCI_MAX_SHORT_NAME_LENGTH);
return ad_len;
}
@@ -181,7 +192,7 @@ void eir_create(struct hci_dev *hdev, u8 *data)
u8 *ptr = data;
size_t name_len;
- name_len = strlen(hdev->dev_name);
+ name_len = strnlen(hdev->dev_name, sizeof(hdev->dev_name));
if (name_len > 0) {
/* EIR Data type */
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index cd1b300b9be7..82cc645193f2 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -1082,11 +1082,11 @@ static u16 append_eir_data_to_buf(struct hci_dev *hdev, u8 *eir)
eir_len = eir_append_le16(eir, eir_len, EIR_APPEARANCE,
hdev->appearance);
- name_len = strlen(hdev->dev_name);
+ name_len = strnlen(hdev->dev_name, sizeof(hdev->dev_name));
eir_len = eir_append_data(eir, eir_len, EIR_NAME_COMPLETE,
hdev->dev_name, name_len);
- name_len = strlen(hdev->short_name);
+ name_len = strnlen(hdev->short_name, sizeof(hdev->short_name));
eir_len = eir_append_data(eir, eir_len, EIR_NAME_SHORT,
hdev->short_name, name_len);
--
2.35.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* RE: [PATCH-stable,v2] Bluetooth: eir: Fix using strlen with hdev->{dev_name,short_name}
2022-05-28 0:35 [PATCH-stable v2] Bluetooth: eir: Fix using strlen with hdev->{dev_name,short_name} Luiz Augusto von Dentz
@ 2022-05-28 2:47 ` bluez.test.bot
2022-05-28 7:38 ` [PATCH-stable v2] " Paul Menzel
2022-06-21 19:10 ` patchwork-bot+bluetooth
2 siblings, 0 replies; 4+ messages in thread
From: bluez.test.bot @ 2022-05-28 2:47 UTC (permalink / raw)
To: linux-bluetooth, luiz.dentz
[-- Attachment #1: Type: text/plain, Size: 1421 bytes --]
This is automated email and please do not reply to this email!
Dear submitter,
Thank you for submitting the patches to the linux bluetooth mailing list.
This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=645709
---Test result---
Test Summary:
CheckPatch PASS 1.03 seconds
GitLint FAIL 0.44 seconds
SubjectPrefix PASS 0.32 seconds
BuildKernel PASS 37.48 seconds
BuildKernel32 PASS 34.03 seconds
Incremental Build with patchesPASS 43.64 seconds
TestRunner: Setup PASS 606.84 seconds
TestRunner: l2cap-tester PASS 20.58 seconds
TestRunner: bnep-tester PASS 7.39 seconds
TestRunner: mgmt-tester PASS 125.53 seconds
TestRunner: rfcomm-tester PASS 11.44 seconds
TestRunner: sco-tester PASS 10.94 seconds
TestRunner: smp-tester PASS 10.50 seconds
TestRunner: userchan-tester PASS 7.66 seconds
Details
##############################
Test: GitLint - FAIL - 0.44 seconds
Run gitlint with rule in .gitlint
[PATCH-stable,v2] Bluetooth: eir: Fix using strlen with hdev->{dev_name,short_name}
1: T1 Title exceeds max length (83>80): "[PATCH-stable,v2] Bluetooth: eir: Fix using strlen with hdev->{dev_name,short_name}"
---
Regards,
Linux Bluetooth
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH-stable v2] Bluetooth: eir: Fix using strlen with hdev->{dev_name,short_name}
2022-05-28 0:35 [PATCH-stable v2] Bluetooth: eir: Fix using strlen with hdev->{dev_name,short_name} Luiz Augusto von Dentz
2022-05-28 2:47 ` [PATCH-stable,v2] " bluez.test.bot
@ 2022-05-28 7:38 ` Paul Menzel
2022-06-21 19:10 ` patchwork-bot+bluetooth
2 siblings, 0 replies; 4+ messages in thread
From: Paul Menzel @ 2022-05-28 7:38 UTC (permalink / raw)
To: Luiz Augusto von Dentz; +Cc: linux-bluetooth
Dear Luiz,
Thank you for your patch.
Am 28.05.22 um 02:35 schrieb Luiz Augusto von Dentz:
> From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
>
> Both dev_name and short_name are not guaranteed to be NULL terminated so
> this instead use strnlen and then attempt to determine if the resulting
The *this* does not seem to belong into the sentence.
> string needs to be truncated or not.
>
> Link: https://bugzilla.kernel.org/show_bug.cgi?id=216018
> Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
Should this be tagged for the stable series?
Kind regards,
Paul
> ---
> net/bluetooth/eir.c | 41 ++++++++++++++++++++++++++---------------
> net/bluetooth/mgmt.c | 4 ++--
> 2 files changed, 28 insertions(+), 17 deletions(-)
>
> diff --git a/net/bluetooth/eir.c b/net/bluetooth/eir.c
> index 7d77fb00c2bf..776d27f7e18d 100644
> --- a/net/bluetooth/eir.c
> +++ b/net/bluetooth/eir.c
> @@ -13,6 +13,20 @@
>
> #define PNP_INFO_SVCLASS_ID 0x1200
>
> +static u8 eir_append_name(u8 *eir, u16 eir_len, u8 type, u8 *data, u8 data_len)
> +{
> + u8 name[HCI_MAX_SHORT_NAME_LENGTH + 1];
> +
> + /* If data is already NULL terminated just pass it directly */
> + if (data[data_len - 1] == '\0')
> + return eir_append_data(eir, eir_len, type, data, data_len);
> +
> + memcpy(name, data, HCI_MAX_SHORT_NAME_LENGTH);
> + name[HCI_MAX_SHORT_NAME_LENGTH] = '\0';
> +
> + return eir_append_data(eir, eir_len, type, name, sizeof(name));
> +}
> +
> u8 eir_append_local_name(struct hci_dev *hdev, u8 *ptr, u8 ad_len)
> {
> size_t short_len;
> @@ -23,29 +37,26 @@ u8 eir_append_local_name(struct hci_dev *hdev, u8 *ptr, u8 ad_len)
> return ad_len;
>
> /* use complete name if present and fits */
> - complete_len = strlen(hdev->dev_name);
> + complete_len = strnlen(hdev->dev_name, sizeof(hdev->dev_name));
> if (complete_len && complete_len <= HCI_MAX_SHORT_NAME_LENGTH)
> - return eir_append_data(ptr, ad_len, EIR_NAME_COMPLETE,
> + return eir_append_name(ptr, ad_len, EIR_NAME_COMPLETE,
> hdev->dev_name, complete_len + 1);
>
> /* use short name if present */
> - short_len = strlen(hdev->short_name);
> + short_len = strnlen(hdev->short_name, sizeof(hdev->short_name));
> if (short_len)
> - return eir_append_data(ptr, ad_len, EIR_NAME_SHORT,
> - hdev->short_name, short_len + 1);
> + return eir_append_name(ptr, ad_len, EIR_NAME_SHORT,
> + hdev->short_name,
> + short_len == HCI_MAX_SHORT_NAME_LENGTH ?
> + short_len : short_len + 1);
>
> /* use shortened full name if present, we already know that name
> * is longer then HCI_MAX_SHORT_NAME_LENGTH
> */
> - if (complete_len) {
> - u8 name[HCI_MAX_SHORT_NAME_LENGTH + 1];
> -
> - memcpy(name, hdev->dev_name, HCI_MAX_SHORT_NAME_LENGTH);
> - name[HCI_MAX_SHORT_NAME_LENGTH] = '\0';
> -
> - return eir_append_data(ptr, ad_len, EIR_NAME_SHORT, name,
> - sizeof(name));
> - }
> + if (complete_len)
> + return eir_append_name(ptr, ad_len, EIR_NAME_SHORT,
> + hdev->dev_name,
> + HCI_MAX_SHORT_NAME_LENGTH);
>
> return ad_len;
> }
> @@ -181,7 +192,7 @@ void eir_create(struct hci_dev *hdev, u8 *data)
> u8 *ptr = data;
> size_t name_len;
>
> - name_len = strlen(hdev->dev_name);
> + name_len = strnlen(hdev->dev_name, sizeof(hdev->dev_name));
>
> if (name_len > 0) {
> /* EIR Data type */
> diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
> index cd1b300b9be7..82cc645193f2 100644
> --- a/net/bluetooth/mgmt.c
> +++ b/net/bluetooth/mgmt.c
> @@ -1082,11 +1082,11 @@ static u16 append_eir_data_to_buf(struct hci_dev *hdev, u8 *eir)
> eir_len = eir_append_le16(eir, eir_len, EIR_APPEARANCE,
> hdev->appearance);
>
> - name_len = strlen(hdev->dev_name);
> + name_len = strnlen(hdev->dev_name, sizeof(hdev->dev_name));
> eir_len = eir_append_data(eir, eir_len, EIR_NAME_COMPLETE,
> hdev->dev_name, name_len);
>
> - name_len = strlen(hdev->short_name);
> + name_len = strnlen(hdev->short_name, sizeof(hdev->short_name));
> eir_len = eir_append_data(eir, eir_len, EIR_NAME_SHORT,
> hdev->short_name, name_len);
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH-stable v2] Bluetooth: eir: Fix using strlen with hdev->{dev_name,short_name}
2022-05-28 0:35 [PATCH-stable v2] Bluetooth: eir: Fix using strlen with hdev->{dev_name,short_name} Luiz Augusto von Dentz
2022-05-28 2:47 ` [PATCH-stable,v2] " bluez.test.bot
2022-05-28 7:38 ` [PATCH-stable v2] " Paul Menzel
@ 2022-06-21 19:10 ` patchwork-bot+bluetooth
2 siblings, 0 replies; 4+ messages in thread
From: patchwork-bot+bluetooth @ 2022-06-21 19:10 UTC (permalink / raw)
To: Luiz Augusto von Dentz; +Cc: linux-bluetooth
Hello:
This patch was applied to bluetooth/bluetooth-next.git (master)
by Luiz Augusto von Dentz <luiz.von.dentz@intel.com>:
On Fri, 27 May 2022 17:35:28 -0700 you wrote:
> From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
>
> Both dev_name and short_name are not guaranteed to be NULL terminated so
> this instead use strnlen and then attempt to determine if the resulting
> string needs to be truncated or not.
>
> Link: https://bugzilla.kernel.org/show_bug.cgi?id=216018
> Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
>
> [...]
Here is the summary with links:
- [PATCH-stable,v2] Bluetooth: eir: Fix using strlen with hdev->{dev_name,short_name}
https://git.kernel.org/bluetooth/bluetooth-next/c/c8490f375393
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-06-21 19:10 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-28 0:35 [PATCH-stable v2] Bluetooth: eir: Fix using strlen with hdev->{dev_name,short_name} Luiz Augusto von Dentz
2022-05-28 2:47 ` [PATCH-stable,v2] " bluez.test.bot
2022-05-28 7:38 ` [PATCH-stable v2] " Paul Menzel
2022-06-21 19:10 ` patchwork-bot+bluetooth
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).