public inbox for linux-bluetooth@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH BlueZ 1/2] tools/smp-tester: don't write array out of bounds
@ 2026-04-06 12:06 Pauli Virtanen
  2026-04-06 12:06 ` [PATCH BlueZ 2/2] tools/ioctl-tester: don't read " Pauli Virtanen
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Pauli Virtanen @ 2026-04-06 12:06 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Pauli Virtanen

Fix accessing pdu data out of bounds in SMP Server - Invalid Request.
---
 tools/smp-tester.c | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/tools/smp-tester.c b/tools/smp-tester.c
index 6c3de6451..04b7ee088 100644
--- a/tools/smp-tester.c
+++ b/tools/smp-tester.c
@@ -536,19 +536,25 @@ static void pair_device_complete(uint8_t status, uint16_t length,
 	tester_print("Pairing succeedded");
 }
 
-static const void *get_pdu(const uint8_t *pdu)
+static const void *get_pdu(const uint8_t *pdu, size_t len)
 {
 	struct test_data *data = tester_get_data();
 	const struct smp_data *smp = data->test_data;
 	uint8_t opcode = pdu[0];
 	static uint8_t buf[65];
 
+	g_assert(len > 0);
+
 	switch (opcode) {
 	case 0x01: /* Pairing Request */
-		memcpy(data->preq, pdu, sizeof(data->preq));
+		g_assert(len <= sizeof(data->preq));
+		memset(data->preq, 0, sizeof(data->preq));
+		memcpy(data->preq, pdu, len);
 		break;
 	case 0x02: /* Pairing Response */
-		memcpy(data->prsp, pdu, sizeof(data->prsp));
+		g_assert(len <= sizeof(data->prsp));
+		memset(data->prsp, 0, sizeof(data->prsp));
+		memcpy(data->prsp, pdu, len);
 		break;
 	case 0x03: /* Pairing Confirm */
 		buf[0] = pdu[0];
@@ -686,7 +692,7 @@ next:
 
 		req = &smp->req[test_data->counter];
 
-		pdu = get_pdu(req->send);
+		pdu = get_pdu(req->send, req->send_len);
 		bthost_send_cid(bthost, test_data->handle, SMP_CID, pdu,
 								req->send_len);
 		if (req->expect)
@@ -756,7 +762,7 @@ static void smp_new_conn(uint16_t handle, void *user_data)
 
 	tester_print("Sending SMP PDU");
 
-	pdu = get_pdu(req->send);
+	pdu = get_pdu(req->send, req->send_len);
 	bthost_send_cid(bthost, handle, SMP_CID, pdu, req->send_len);
 
 	if (!req->expect)
-- 
2.53.0


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

end of thread, other threads:[~2026-04-06 17:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-06 12:06 [PATCH BlueZ 1/2] tools/smp-tester: don't write array out of bounds Pauli Virtanen
2026-04-06 12:06 ` [PATCH BlueZ 2/2] tools/ioctl-tester: don't read " Pauli Virtanen
2026-04-06 13:37 ` [BlueZ,1/2] tools/smp-tester: don't write " bluez.test.bot
2026-04-06 17:00 ` [PATCH BlueZ 1/2] " 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