linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] drivers/bluetooth: Remove all strcpy() uses
@ 2021-07-18 15:36 Len Baker
  2021-07-18 16:11 ` bluez.test.bot
  2021-07-18 16:12 ` [PATCH] " Adam Sampson
  0 siblings, 2 replies; 4+ messages in thread
From: Len Baker @ 2021-07-18 15:36 UTC (permalink / raw)
  To: Kees Cook, Marcel Holtmann, Johan Hedberg, Luiz Augusto von Dentz
  Cc: Len Baker, linux-bluetooth, linux-kernel, linux-hardening

strcpy() performs no bounds checking on the destination buffer. This
could result in linear overflows beyond the end of the buffer, leading
to all kinds of misbehaviors. The safe replacement is strscpy() but in
this case it is better to use the scnprintf to simplify the arithmetic.

This is a previous step in the path to remove the strcpy() function
entirely from the kernel.

Signed-off-by: Len Baker <len.baker@gmx.com>
---
 drivers/bluetooth/btmrvl_sdio.c | 27 +++++++++++++--------------
 1 file changed, 13 insertions(+), 14 deletions(-)

diff --git a/drivers/bluetooth/btmrvl_sdio.c b/drivers/bluetooth/btmrvl_sdio.c
index cddd350beba3..d6674b367e05 100644
--- a/drivers/bluetooth/btmrvl_sdio.c
+++ b/drivers/bluetooth/btmrvl_sdio.c
@@ -1350,6 +1350,7 @@ static void btmrvl_sdio_coredump(struct device *dev)
 	u8 *dbg_ptr, *end_ptr, *fw_dump_data, *fw_dump_ptr;
 	u8 dump_num = 0, idx, i, read_reg, doneflag = 0;
 	u32 memory_size, fw_dump_len = 0;
+	int size = 0;

 	card = sdio_get_drvdata(func);
 	priv = card->priv;
@@ -1493,20 +1494,18 @@ static void btmrvl_sdio_coredump(struct device *dev)
 		struct memory_type_mapping *entry = &mem_type_mapping_tbl[idx];

 		if (entry->mem_ptr) {
-			strcpy(fw_dump_ptr, "========Start dump ");
-			fw_dump_ptr += strlen("========Start dump ");
-
-			strcpy(fw_dump_ptr, entry->mem_name);
-			fw_dump_ptr += strlen(entry->mem_name);
-
-			strcpy(fw_dump_ptr, "========\n");
-			fw_dump_ptr += strlen("========\n");
-
-			memcpy(fw_dump_ptr, entry->mem_ptr, entry->mem_size);
-			fw_dump_ptr += entry->mem_size;
-
-			strcpy(fw_dump_ptr, "\n========End dump========\n");
-			fw_dump_ptr += strlen("\n========End dump========\n");
+			size += scnprintf(fw_dump_ptr + size,
+					  sizeof(fw_dump_ptr) - size,
+					  "========Start dump %s========\n",
+					  entry->mem_name);
+
+			memcpy(fw_dump_ptr + size, entry->mem_ptr,
+			       entry->mem_size);
+			size += entry->mem_size;
+
+			size += scnprintf(fw_dump_ptr + size,
+					  sizeof(fw_dump_ptr) - size,
+					  "\n========End dump========\n");

 			vfree(mem_type_mapping_tbl[idx].mem_ptr);
 			mem_type_mapping_tbl[idx].mem_ptr = NULL;
--
2.25.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: drivers/bluetooth: Remove all strcpy() uses
  2021-07-18 15:36 [PATCH] drivers/bluetooth: Remove all strcpy() uses Len Baker
@ 2021-07-18 16:11 ` bluez.test.bot
  2021-07-18 16:12 ` [PATCH] " Adam Sampson
  1 sibling, 0 replies; 4+ messages in thread
From: bluez.test.bot @ 2021-07-18 16:11 UTC (permalink / raw)
  To: linux-bluetooth, len.baker

[-- Attachment #1: Type: text/plain, Size: 2727 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=517237

---Test result---

Test Summary:
CheckPatch                    PASS      0.54 seconds
GitLint                       PASS      0.12 seconds
BuildKernel                   PASS      535.11 seconds
TestRunner: Setup             PASS      360.63 seconds
TestRunner: l2cap-tester      PASS      2.56 seconds
TestRunner: bnep-tester       PASS      1.98 seconds
TestRunner: mgmt-tester       PASS      31.32 seconds
TestRunner: rfcomm-tester     PASS      2.19 seconds
TestRunner: sco-tester        PASS      2.07 seconds
TestRunner: smp-tester        FAIL      2.16 seconds
TestRunner: userchan-tester   PASS      2.03 seconds

Details
##############################
Test: CheckPatch - PASS - 0.54 seconds
Run checkpatch.pl script with rule in .checkpatch.conf


##############################
Test: GitLint - PASS - 0.12 seconds
Run gitlint with rule in .gitlint


##############################
Test: BuildKernel - PASS - 535.11 seconds
Build Kernel with minimal configuration supports Bluetooth


##############################
Test: TestRunner: Setup - PASS - 360.63 seconds
Setup environment for running Test Runner


##############################
Test: TestRunner: l2cap-tester - PASS - 2.56 seconds
Run test-runner with l2cap-tester
Total: 40, Passed: 40 (100.0%), Failed: 0, Not Run: 0

##############################
Test: TestRunner: bnep-tester - PASS - 1.98 seconds
Run test-runner with bnep-tester
Total: 1, Passed: 1 (100.0%), Failed: 0, Not Run: 0

##############################
Test: TestRunner: mgmt-tester - PASS - 31.32 seconds
Run test-runner with mgmt-tester
Total: 446, Passed: 443 (99.3%), Failed: 0, Not Run: 3

##############################
Test: TestRunner: rfcomm-tester - PASS - 2.19 seconds
Run test-runner with rfcomm-tester
Total: 9, Passed: 9 (100.0%), Failed: 0, Not Run: 0

##############################
Test: TestRunner: sco-tester - PASS - 2.07 seconds
Run test-runner with sco-tester
Total: 8, Passed: 8 (100.0%), Failed: 0, Not Run: 0

##############################
Test: TestRunner: smp-tester - FAIL - 2.16 seconds
Run test-runner with smp-tester
Total: 8, Passed: 7 (87.5%), Failed: 1, Not Run: 0

Failed Test Cases
SMP Client - SC Request 2                            Failed       0.022 seconds

##############################
Test: TestRunner: userchan-tester - PASS - 2.03 seconds
Run test-runner with userchan-tester
Total: 3, Passed: 3 (100.0%), Failed: 0, Not Run: 0



---
Regards,
Linux Bluetooth


[-- Attachment #2: l2cap-tester.log --]
[-- Type: application/octet-stream, Size: 44350 bytes --]

[-- Attachment #3: bnep-tester.log --]
[-- Type: application/octet-stream, Size: 3557 bytes --]

[-- Attachment #4: mgmt-tester.log --]
[-- Type: application/octet-stream, Size: 614404 bytes --]

[-- Attachment #5: rfcomm-tester.log --]
[-- Type: application/octet-stream, Size: 11677 bytes --]

[-- Attachment #6: sco-tester.log --]
[-- Type: application/octet-stream, Size: 9912 bytes --]

[-- Attachment #7: smp-tester.log --]
[-- Type: application/octet-stream, Size: 11705 bytes --]

[-- Attachment #8: userchan-tester.log --]
[-- Type: application/octet-stream, Size: 5453 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] drivers/bluetooth: Remove all strcpy() uses
  2021-07-18 15:36 [PATCH] drivers/bluetooth: Remove all strcpy() uses Len Baker
  2021-07-18 16:11 ` bluez.test.bot
@ 2021-07-18 16:12 ` Adam Sampson
  2021-07-24 12:22   ` Len Baker
  1 sibling, 1 reply; 4+ messages in thread
From: Adam Sampson @ 2021-07-18 16:12 UTC (permalink / raw)
  To: Len Baker
  Cc: Kees Cook, Marcel Holtmann, Johan Hedberg,
	Luiz Augusto von Dentz, linux-bluetooth, linux-kernel,
	linux-hardening

Len Baker <len.baker@gmx.com> writes:

> strcpy() performs no bounds checking on the destination buffer. This
> could result in linear overflows beyond the end of the buffer, leading
> to all kinds of misbehaviors. The safe replacement is strscpy() but in
> this case it is better to use the scnprintf to simplify the arithmetic.
>
> This is a previous step in the path to remove the strcpy() function
> entirely from the kernel.
>
> Signed-off-by: Len Baker <len.baker@gmx.com>
> ---
>  drivers/bluetooth/btmrvl_sdio.c | 27 +++++++++++++--------------
>  1 file changed, 13 insertions(+), 14 deletions(-)
>
> diff --git a/drivers/bluetooth/btmrvl_sdio.c b/drivers/bluetooth/btmrvl_sdio.c
> index cddd350beba3..d6674b367e05 100644
> --- a/drivers/bluetooth/btmrvl_sdio.c
> +++ b/drivers/bluetooth/btmrvl_sdio.c
> @@ -1350,6 +1350,7 @@ static void btmrvl_sdio_coredump(struct device *dev)
>  	u8 *dbg_ptr, *end_ptr, *fw_dump_data, *fw_dump_ptr;
[...]
> +			size += scnprintf(fw_dump_ptr + size,
> +					  sizeof(fw_dump_ptr) - size,
[...]
> +			size += scnprintf(fw_dump_ptr + size,
> +					  sizeof(fw_dump_ptr) - size,

sizeof(fw_dump_ptr) there looks wrong -- you want the size of the buffer
it points to (fw_dump_len + 1)?

Thanks,

-- 
Adam Sampson <ats@offog.org>                         <http://offog.org/>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] drivers/bluetooth: Remove all strcpy() uses
  2021-07-18 16:12 ` [PATCH] " Adam Sampson
@ 2021-07-24 12:22   ` Len Baker
  0 siblings, 0 replies; 4+ messages in thread
From: Len Baker @ 2021-07-24 12:22 UTC (permalink / raw)
  To: Adam Sampson
  Cc: Len Baker, Kees Cook, Marcel Holtmann, Johan Hedberg,
	Luiz Augusto von Dentz, linux-bluetooth, linux-kernel,
	linux-hardening

Hi,

On Sun, Jul 18, 2021 at 05:12:55PM +0100, Adam Sampson wrote:
> Len Baker <len.baker@gmx.com> writes:
>
> > strcpy() performs no bounds checking on the destination buffer. This
> > could result in linear overflows beyond the end of the buffer, leading
> > to all kinds of misbehaviors. The safe replacement is strscpy() but in
> > this case it is better to use the scnprintf to simplify the arithmetic.
> >
> > This is a previous step in the path to remove the strcpy() function
> > entirely from the kernel.
> >
> > Signed-off-by: Len Baker <len.baker@gmx.com>
> > ---
> >  drivers/bluetooth/btmrvl_sdio.c | 27 +++++++++++++--------------
> >  1 file changed, 13 insertions(+), 14 deletions(-)
> >
> > diff --git a/drivers/bluetooth/btmrvl_sdio.c b/drivers/bluetooth/btmrvl_sdio.c
> > index cddd350beba3..d6674b367e05 100644
> > --- a/drivers/bluetooth/btmrvl_sdio.c
> > +++ b/drivers/bluetooth/btmrvl_sdio.c
> > @@ -1350,6 +1350,7 @@ static void btmrvl_sdio_coredump(struct device *dev)
> >  	u8 *dbg_ptr, *end_ptr, *fw_dump_data, *fw_dump_ptr;
> [...]
> > +			size += scnprintf(fw_dump_ptr + size,
> > +					  sizeof(fw_dump_ptr) - size,
> [...]
> > +			size += scnprintf(fw_dump_ptr + size,
> > +					  sizeof(fw_dump_ptr) - size,
>
> sizeof(fw_dump_ptr) there looks wrong -- you want the size of the buffer
> it points to (fw_dump_len + 1)?

Apologies. I will work on it and I will send a new version for review.
Thanks for the feedback.

>
> Thanks,
>
> --
> Adam Sampson <ats@offog.org>                         <http://offog.org/>

Regards,
Len

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-07-24 12:22 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-18 15:36 [PATCH] drivers/bluetooth: Remove all strcpy() uses Len Baker
2021-07-18 16:11 ` bluez.test.bot
2021-07-18 16:12 ` [PATCH] " Adam Sampson
2021-07-24 12:22   ` Len Baker

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).