Skip to contentSkip to conversation

sock: Correct error checking condition for (assign|release)_proto_idx()

PATCH Applied Zijun Hu 4 participants 5 messages Apr 10, 2025 – Apr 11, 2025

Subsystems (3)
lore
Share & tools
lore

Zijun Hu

author
#0 lore raw

PATCH v2 1/1 sock: Correct error checking condition for (assign|release)_proto_idx()

From: Zijun Hu <[email protected]>

(assign|release)_proto_idx() wrongly check find_first_zero_bit() failure by condition '(prot->inuse_idx == PROTO_INUSE_NR - 1)' obviously.

Fix by correcting the condition to '(prot->inuse_idx == PROTO_INUSE_NR)'

Fixes 13ff3d6fa4e6 ("[SOCK]: Enumerate struct proto-s to facilitate percpu inuse accounting (v2).")

---
Changes in v2:
- Remove @prot->inuse_idx checks in fastpath
- Correct tile and commit message
- Link to v1: https://lore.kernel.org/r/[email protected]

---
 net/core/sock.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
net/core/sock.c +2 -2
index 323892066def8ba517ff59f98f2e4ab47edd4e63..e2c3c4bd9cd915706678137d98a15ca8c1a35cb8 100644
@@ -3999,7 +3999,7 @@ static int assign_proto_idx(struct proto *prot)
 {
 	prot->inuse_idx = find_first_zero_bit(proto_inuse_idx, PROTO_INUSE_NR);
 
-	if (unlikely(prot->inuse_idx == PROTO_INUSE_NR - 1)) {
+	if (unlikely(prot->inuse_idx == PROTO_INUSE_NR)) {
 		pr_err("PROTO_INUSE_NR exhausted\n");
 		return -ENOSPC;
 	}
@@ -4010,7 +4010,7 @@ static int assign_proto_idx(struct proto *prot)
 
 static void release_proto_idx(struct proto *prot)
 {
-	if (prot->inuse_idx != PROTO_INUSE_NR - 1)
+	if (prot->inuse_idx != PROTO_INUSE_NR)
 		clear_bit(prot->inuse_idx, proto_inuse_idx);
 }
 #else

---
base-commit: 34a07c5b257453b5fcadc2408719c7b075844014
change-id: 20250405-fix_net-3e8364d302ff

Best regards,

Signature · 1 line
Zijun Hu <[email protected]>
Reviewed-by on v2 1/1
#1 lore raw
Quoted 1 line

[PATCH net-next v2] sock: Correct error checking condition for (assign|release)_proto_idx()

Maybe net instead of net-next ?

From: Zijun Hu <[email protected]>
Date: Thu, 10 Apr 2025 09:01:27 +0800

Quoted 9 lines

From: Zijun Hu <[email protected]>

(assign|release)_proto_idx() wrongly check find_first_zero_bit() failure by condition '(prot->inuse_idx == PROTO_INUSE_NR - 1)' obviously.

Fix by correcting the condition to '(prot->inuse_idx == PROTO_INUSE_NR)'

Fixes 13ff3d6fa4e6 ("[SOCK]: Enumerate struct proto-s to facilitate percpu inuse accounting (v2).")
#2 lore raw
Quoted 5 lines · Kuniyuki Iwashima
Quoted 2 lines

[PATCH net-next v2] sock: Correct error checking condition for (assign|release)_proto_idx()

Maybe net instead of net-next ?

I think this is a minor change, I would not add a Fixes: tag and risk another CVE for such a case that is never reached.

We do not have 63 protocols, getting to 64 limit is moot.

As a matter of fact, release_proto_idx(struct proto *prot) should never hit the condition.

author
#3 lore raw
In reply to Kuniyuki Iwashima
Quoted 3 lines · Kuniyuki Iwashima
Quoted 1 line

[PATCH net-next v2] sock: Correct error checking condition for (assign|release)_proto_idx()

Maybe net instead of net-next ?

Either net or net-next is okay.

Quoted 13 lines

From: Zijun Hu <[email protected]>
Date: Thu, 10 Apr 2025 09:01:27 +0800

Quoted 9 lines

From: Zijun Hu <[email protected]>

(assign|release)_proto_idx() wrongly check find_first_zero_bit() failure by condition '(prot->inuse_idx == PROTO_INUSE_NR - 1)' obviously.

Fix by correcting the condition to '(prot->inuse_idx == PROTO_INUSE_NR)'

Fixes 13ff3d6fa4e6 ("[SOCK]: Enumerate struct proto-s to facilitate percpu inuse accounting (v2).")
#4 lore raw
In reply to Zijun Hu
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Quoted 8 lines · On Thu, 10 Apr 2025 09:01:27 +0800 you wrote:

From: Zijun Hu <[email protected]>

(assign|release)_proto_idx() wrongly check find_first_zero_bit() failure by condition '(prot->inuse_idx == PROTO_INUSE_NR - 1)' obviously.

Fix by correcting the condition to '(prot->inuse_idx == PROTO_INUSE_NR)'

[...]

Here is the summary with links:
- [net-next,v2] sock: Correct error checking condition for (assign|release)_proto_idx()

    https://git.kernel.org/netdev/net-next/c/faeefc173be4

You are awesome, thank you!

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