All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH BlueZ 0/6] [v4] Fix bugs found by SVACE static analisys tool
@ 2022-04-01 12:16 Ildar Kamaletdinov
  2022-04-01 12:16 ` [PATCH BlueZ 1/6] monitor: Fix out-of-bound read in print_le_states Ildar Kamaletdinov
                   ` (6 more replies)
  0 siblings, 7 replies; 11+ messages in thread
From: Ildar Kamaletdinov @ 2022-04-01 12:16 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Ildar Kamaletdinov

This patch set includes few fixes that was found by Linux Verification Center
(linuxtesting.org) with the SVACE static analysis tool.

I have manually filtered out non-relevant and false positive problems and only
procedeed with bugs that currently lead to some errors/vulnerabilities or may
lead to them in some specific conditions.

Changelog:
[v4] one patch was dropped due to overchecking, seems that it is not required
[v3] one fix wasn't staged, sorry, one more fix after CI checks
[v2] some minor style fixes after CI check.
[v1] initial version.

Ildar Kamaletdinov (6):
  monitor: Fix out-of-bound read in print_le_states
  tools: Fix buffer overflow in hciattach_tialt.c
  tools: Fix signed integer overflow in btsnoop.c
  tools: Limit width of fields in sscanf
  device: Limit width of fields in sscanf
  gatt: Fix double free and freed memory dereference

 monitor/packet.c        |  7 ++++---
 src/device.c            | 14 +++++++-------
 src/gatt-database.c     |  4 ++++
 tools/btmgmt.c          |  2 +-
 tools/btsnoop.c         |  2 +-
 tools/hciattach_tialt.c |  3 ++-
 tools/hex2hcd.c         |  2 +-
 7 files changed, 20 insertions(+), 14 deletions(-)

-- 
2.35.1


^ permalink raw reply	[flat|nested] 11+ messages in thread
* [PATCH BlueZ 1/7] monitor: Fix out-of-bound read in print_le_states
@ 2022-04-01 11:14 Ildar Kamaletdinov
  2022-04-01 12:46 ` Fix bugs found by SVACE static analisys tool bluez.test.bot
  0 siblings, 1 reply; 11+ messages in thread
From: Ildar Kamaletdinov @ 2022-04-01 11:14 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Ildar Kamaletdinov

Accessing le_states_desc_table array with value 15 can cause
out-of-bound read because current size of array is 14.

Currently this cannot lead to any problems becase we do no have such
state in le_states_comb_table but this could be changed in future and
raise described problem.

Found by Linux Verification Center (linuxtesting.org) with the SVACE
static analysis tool.
---
 monitor/packet.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/monitor/packet.c b/monitor/packet.c
index b7431b57d..1f04063d3 100644
--- a/monitor/packet.c
+++ b/monitor/packet.c
@@ -2816,7 +2816,8 @@ static const struct {
 static void print_le_states(const uint8_t *states_array)
 {
 	uint64_t mask, states = 0;
-	int i, n;
+	int i = 0;
+	size_t n = 0;
 
 	for (i = 0; i < 8; i++)
 		states |= ((uint64_t) states_array[i]) << (i * 8);
@@ -2828,12 +2829,12 @@ static void print_le_states(const uint8_t *states_array)
 	for (i = 0; le_states_comb_table[i].states; i++) {
 		uint64_t val = (((uint64_t) 1) << le_states_comb_table[i].bit);
 		const char *str[3] = { NULL, };
-		int num = 0;
+		size_t num = 0;
 
 		if (!(states & val))
 			continue;
 
-		for (n = 0; n < 16; n++) {
+		for (n = 0; n < ARRAY_SIZE(le_states_desc_table); n++) {
 			if (le_states_comb_table[i].states & (1 << n))
 				str[num++] = le_states_desc_table[n].str;
 		}
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread
* [PATCH BlueZ 1/7] monitor: Fix out-of-bound read in print_le_states
@ 2022-04-01  7:46 Ildar Kamaletdinov
  2022-04-01  8:45 ` Fix bugs found by SVACE static analisys tool bluez.test.bot
  0 siblings, 1 reply; 11+ messages in thread
From: Ildar Kamaletdinov @ 2022-04-01  7:46 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Ildar Kamaletdinov

Accessing le_states_desc_table array with value 15 can cause
out-of-bound read because current size of array is 14.

Currently this cannot lead to any problems becase we do no have such
state in le_states_comb_table but this could be changed in future and
raise described problem.

Found by Linux Verification Center (linuxtesting.org) with the SVACE
static analysis tool.
---
 monitor/packet.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/monitor/packet.c b/monitor/packet.c
index b7431b57d..c61d6bd4b 100644
--- a/monitor/packet.c
+++ b/monitor/packet.c
@@ -2833,7 +2833,7 @@ static void print_le_states(const uint8_t *states_array)
 		if (!(states & val))
 			continue;
 
-		for (n = 0; n < 16; n++) {
+		for (n = 0; n < ARRAY_SIZE(le_states_desc_table); n++) {
 			if (le_states_comb_table[i].states & (1 << n))
 				str[num++] = le_states_desc_table[n].str;
 		}
-- 
2.34.0


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

end of thread, other threads:[~2022-04-04 21:27 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-04-01 12:16 [PATCH BlueZ 0/6] [v4] Fix bugs found by SVACE static analisys tool Ildar Kamaletdinov
2022-04-01 12:16 ` [PATCH BlueZ 1/6] monitor: Fix out-of-bound read in print_le_states Ildar Kamaletdinov
2022-04-01 16:00   ` Fix bugs found by SVACE static analisys tool bluez.test.bot
2022-04-01 12:16 ` [PATCH BlueZ 2/6] tools: Fix buffer overflow in hciattach_tialt.c Ildar Kamaletdinov
2022-04-01 12:16 ` [PATCH BlueZ 3/6] tools: Fix signed integer overflow in btsnoop.c Ildar Kamaletdinov
2022-04-01 12:16 ` [PATCH BlueZ 4/6] tools: Limit width of fields in sscanf Ildar Kamaletdinov
2022-04-01 12:16 ` [PATCH BlueZ 5/6] device: " Ildar Kamaletdinov
2022-04-01 12:16 ` [PATCH BlueZ 6/6] gatt: Fix double free and freed memory dereference Ildar Kamaletdinov
2022-04-04 17:14 ` [PATCH BlueZ 0/6] [v4] Fix bugs found by SVACE static analisys tool patchwork-bot+bluetooth
  -- strict thread matches above, loose matches on Subject: below --
2022-04-01 11:14 [PATCH BlueZ 1/7] monitor: Fix out-of-bound read in print_le_states Ildar Kamaletdinov
2022-04-01 12:46 ` Fix bugs found by SVACE static analisys tool bluez.test.bot
2022-04-01  7:46 [PATCH BlueZ 1/7] monitor: Fix out-of-bound read in print_le_states Ildar Kamaletdinov
2022-04-01  8:45 ` Fix bugs found by SVACE static analisys tool bluez.test.bot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.