Skip to contentSkip to conversation

common: fix potential NULL dereference in print_rss_hkey()

PATCH Applied [email protected] 3 participants 3 messages May 18, 2025 – Jun 10, 2025

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

PATCH 1/1 common: fix potential NULL dereference in print_rss_hkey()

From: AntonMoryakov <[email protected]>

Static analyzer (Svace) reported a possible null pointer dereference in print_rss_hkey(). Specifically, when the 'hkey' pointer is NULL, the function continues execution after printing an error message, leading to dereferencing hkey[i].

This patch adds an early return after the NULL check to prevent execution from continuing in such cases.

This resolves:
DEREF_AFTER_NULL: common.c:209

Found by Svace static analysis tool.

---
 common.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
common.c +3 -1
index 1ba27e7..35ec36d 100644
@@ -233,8 +233,10 @@ void print_rss_hkey(u8 *hkey, u32 hkey_size)
 	u32 i;
 
 	printf("RSS hash key:\n");
-	if (!hkey_size || !hkey)
+	if (!hkey_size || !hkey) {
 		printf("Operation not supported\n");
+		return;
+	}
 
 	for (i = 0; i < hkey_size; i++) {
 		if (i == (hkey_size - 1))
Signature · 1 line
2.34.1
#1 lore raw

Dne Sun, May 18, 2025 at 04:08:28PM GMT, [email protected] napsal:

Quoted 11 lines

From: AntonMoryakov <[email protected]>

Static analyzer (Svace) reported a possible null pointer dereference in print_rss_hkey(). Specifically, when the 'hkey' pointer is NULL, the function continues execution after printing an error message, leading to dereferencing hkey[i].

This patch adds an early return after the NULL check to prevent execution from continuing in such cases.

Quoted 8 lines

This resolves:
DEREF_AFTER_NULL: common.c:209

Found by Svace static analysis tool.

---

For the record, I believe the null pointer dereference is not actually possible with current ethtool code. As far as I can see, in the ioctl path hkey always points inside a block returned by calloc() so that it cannot actually be null (we bail out immediately if that calloc() call fails). In the netlink path hkey can only be null if ETHTOOL_A_RSS_HKEY attribute is not present in the message in which case hkey_size will be zero and the for cycle body is not executed at all.

That being said, I'll accept the patch as a safety precaution in case the calling code changes later. But I wanted to point this out for future reference as this kind of commits tends to come back later and haunt us in the form of CVEs.

Michal

Quoted 22 lines
 common.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
common.c +3 -1
index 1ba27e7..35ec36d 100644
@@ -233,8 +233,10 @@ void print_rss_hkey(u8 *hkey, u32 hkey_size)
 	u32 i;
 
 	printf("RSS hash key:\n");
-	if (!hkey_size || !hkey)
+	if (!hkey_size || !hkey) {
 		printf("Operation not supported\n");
+		return;
+	}
 
 	for (i = 0; i < hkey_size; i++) {
 		if (i == (hkey_size - 1))
Signature · 1 line
2.34.1
#2 lore raw
In reply to [email protected]
This patch was applied to ethtool/ethtool.git (master) by Michal Kubecek <[email protected]>:

Hello:

This patch was applied to ethtool/ethtool.git (master) by Michal Kubecek <[email protected]>:

Quoted 9 lines · On Sun, 18 May 2025 16:08:28 +0300 you wrote:

From: AntonMoryakov <[email protected]>

Static analyzer (Svace) reported a possible null pointer dereference in print_rss_hkey(). Specifically, when the 'hkey' pointer is NULL, the function continues execution after printing an error message, leading to dereferencing hkey[i].

[...]

Here is the summary with links:
- common: fix potential NULL dereference in print_rss_hkey()

    https://git.kernel.org/pub/scm/network/ethtool/ethtool.git/commit/?id=f111e854d99e

You are awesome, thank you!

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