common: fix potential NULL dereference in print_rss_hkey()
Subsystems (2)
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
@@ -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
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:209Found by Svace static analysis tool.
Signed-off-by Anton Moryakov <[email protected]>---
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@@ -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
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