Skip to contentSkip to conversation

bridge: fix potential snprintf overflow

PATCH Applied Stephen Hemminger 2 participants 3 messages Sep 18, 2023 – Sep 20, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 bridge: fix potential snprintf overflow

There is a theoretical snprintf overflow in bridge slave bitmask print code found by CodeQL scan.

---
 ip/iplink_bridge_slave.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
ip/iplink_bridge_slave.c +9 -2
index dc73c86574da..3821923b5da5 100644
@@ -100,13 +100,20 @@ static void _bitmask2str(__u16 bitmask, char *dst, size_t dst_size,
 	int len, i;
 
 	for (i = 0, len = 0; bitmask; i++, bitmask >>= 1) {
+		int n;
+
 		if (bitmask & 0x1) {
 			if (tbl[i])
-				len += snprintf(dst + len, dst_size - len, "%s,",
+				n = snprintf(dst + len, dst_size - len, "%s,",
 						tbl[i]);
 			else
-				len += snprintf(dst + len, dst_size - len, "0x%x,",
+				n = snprintf(dst + len, dst_size - len, "0x%x,",
 						(1 << i));
+
+			if (n < 0 || n >= dst_size - len)
+				break;
+
+			len += n;
 		}
 	}
 
Signature · 1 line
2.39.2
#1 lore raw

PATCH 2/2 ila: fix potential snprintf buffer overflow

The code to print 64 bit address has a theoretical overflow of snprintf buffer found by CodeQL scan.
Address by checking result.

---
 ip/ipila.c | 2 ++
 1 file changed, 2 insertions(+)
ip/ipila.c +2 -0
index 4f6d578f24ae..23b19a108862 100644
@@ -60,6 +60,8 @@ static void print_addr64(__u64 addr, char *buff, size_t len)
 			sep = "";
 
 		ret = snprintf(&buff[written], len - written, "%x%s", v, sep);
+		if (ret < 0 || ret >= len - written)
+			break;
 		written += ret;
 	}
 }
Signature · 1 line
2.39.2
#2 lore raw
In reply to Stephen Hemminger
This series was applied to iproute2/iproute2.git (main) by Stephen Hemminger <[email protected]>:

Hello:

This series was applied to iproute2/iproute2.git (main) by Stephen Hemminger <[email protected]>:

Quoted 7 lines · On Mon, 18 Sep 2023 11:46:30 -0700 you wrote:

There is a theoretical snprintf overflow in bridge slave bitmask print code found by CodeQL scan.

---
 ip/iplink_bridge_slave.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

Here is the summary with links:
- [iproute2,1/2] bridge: fix potential snprintf overflow

    https://git.kernel.org/pub/scm/network/iproute2/iproute2.git/commit/?id=4d80122ae82a
  - [iproute2,2/2] ila: fix potential snprintf buffer overflow
    https://git.kernel.org/pub/scm/network/iproute2/iproute2.git/commit/?id=e8a3fca81cd4

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html