Skip to contentSkip to conversation

rds: tcp: fix uninit-value in __inet_bind

PATCH Applied Tabrez Ahmed 5 participants 5 messages Feb 17 – Feb 19

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

PATCH v2 1/1 rds: tcp: fix uninit-value in __inet_bind

KMSAN reported an uninit-value access in __inet_bind() when binding an RDS TCP socket.

The uninitialized memory originates from rds_tcp_conn_alloc(), which uses kmem_cache_alloc() to allocate the rds_tcp_connection structure.

Specifically, the field 't_client_port_group' is incremented in rds_tcp_conn_path_connect() without being initialized first:

    if (++tc->t_client_port_group >= port_groups)

Since kmem_cache_alloc() does not zero the memory, this field contains garbage, leading to the KMSAN report.

Fix this by using kmem_cache_zalloc() to ensure the structure is zero-initialized upon allocation.

Reported-by [email protected]
Fixes a20a6992558f ("net/rds: Encode cp_index in TCP source port")

---
v2:
- Updated Fixes tag to point to commit a20a6992558f as requested by Charalampos Mitrodimas and Allison Henderson.
- Explicitly mentioned 't_client_port_group' in the commit message.
- Fixed line wrapping to be under 75 characters.

 net/rds/tcp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/rds/tcp.c +1 -1
index 45484a93d75f..04f310255692 100644
@@ -373,7 +373,7 @@ static int rds_tcp_conn_alloc(struct rds_connection *conn, gfp_t gfp)
 	int ret = 0;
 
 	for (i = 0; i < RDS_MPATH_WORKERS; i++) {
-		tc = kmem_cache_alloc(rds_tcp_conn_slab, gfp);
+		tc = kmem_cache_zalloc(rds_tcp_conn_slab, gfp);
 		if (!tc) {
 			ret = -ENOMEM;
 			goto fail;
Signature · 1 line
2.43.0
Reviewed-by on v2 1/1
#1 lore raw
Quoted 17 lines · Tabrez Ahmed

KMSAN reported an uninit-value access in __inet_bind() when binding an RDS TCP socket.

The uninitialized memory originates from rds_tcp_conn_alloc(), which uses kmem_cache_alloc() to allocate the rds_tcp_connection structure.

Specifically, the field 't_client_port_group' is incremented in rds_tcp_conn_path_connect() without being initialized first:

    if (++tc->t_client_port_group >= port_groups)

Since kmem_cache_alloc() does not zero the memory, this field contains garbage, leading to the KMSAN report.

Fix this by using kmem_cache_zalloc() to ensure the structure is zero-initialized upon allocation.

Quoted 7 lines
Reported-by [email protected]
Fixes a20a6992558f ("net/rds: Encode cp_index in TCP source port")

---

Signature · 1 line
C. Mitrodimas
Reviewed-by on v2 1/1
#2 lore raw
In reply to Tabrez Ahmed
Quoted 17 lines · Tabrez Ahmed

KMSAN reported an uninit-value access in __inet_bind() when binding an RDS TCP socket.

The uninitialized memory originates from rds_tcp_conn_alloc(), which uses kmem_cache_alloc() to allocate the rds_tcp_connection structure.

Specifically, the field 't_client_port_group' is incremented in rds_tcp_conn_path_connect() without being initialized first:

    if (++tc->t_client_port_group >= port_groups)

Since kmem_cache_alloc() does not zero the memory, this field contains garbage, leading to the KMSAN report.

Fix this by using kmem_cache_zalloc() to ensure the structure is zero-initialized upon allocation.

Quoted 6 lines

This looks good to me. Thanks Tabrez.

Quoted 23 lines

---
v2:
- Updated Fixes tag to point to commit a20a6992558f as requested by Charalampos Mitrodimas and Allison Henderson.
- Explicitly mentioned 't_client_port_group' in the commit message.
- Fixed line wrapping to be under 75 characters.

 net/rds/tcp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/rds/tcp.c +1 -1
index 45484a93d75f..04f310255692 100644
@@ -373,7 +373,7 @@ static int rds_tcp_conn_alloc(struct rds_connection *conn, gfp_t gfp)
 	int ret = 0;
 
 	for (i = 0; i < RDS_MPATH_WORKERS; i++) {
-		tc = kmem_cache_alloc(rds_tcp_conn_slab, gfp);
+		tc = kmem_cache_zalloc(rds_tcp_conn_slab, gfp);
 		if (!tc) {
 			ret = -ENOMEM;
 			goto fail;
maintainer
#3 lore raw
In reply to Tabrez Ahmed
Quoted 14 lines · Tabrez Ahmed

KMSAN reported an uninit-value access in __inet_bind() when binding an RDS TCP socket.

The uninitialized memory originates from rds_tcp_conn_alloc(), which uses kmem_cache_alloc() to allocate the rds_tcp_connection structure.

Specifically, the field 't_client_port_group' is incremented in rds_tcp_conn_path_connect() without being initialized first:

    if (++tc->t_client_port_group >= port_groups)

Since kmem_cache_alloc() does not zero the memory, this field contains garbage, leading to the KMSAN report.

Quoted 8 lines

Fix this by using kmem_cache_zalloc() to ensure the structure is zero-initialized upon allocation.

Reported-by [email protected]
Fixes a20a6992558f ("net/rds: Encode cp_index in TCP source port")

I'll fix this while applying the patch but for next submissions please avoid any empty line in the tag area.

/P

#4 lore raw
In reply to Tabrez Ahmed
This patch was applied to netdev/net.git (main) by Paolo Abeni <[email protected]>:

Hello:

This patch was applied to netdev/net.git (main)
by Paolo Abeni <[email protected]>:

Quoted 10 lines · On Tue, 17 Feb 2026 19:23:49 +0530 you wrote:

KMSAN reported an uninit-value access in __inet_bind() when binding an RDS TCP socket.

The uninitialized memory originates from rds_tcp_conn_alloc(), which uses kmem_cache_alloc() to allocate the rds_tcp_connection structure.

Specifically, the field 't_client_port_group' is incremented in rds_tcp_conn_path_connect() without being initialized first:

[...]

Here is the summary with links:
- [net,v2] rds: tcp: fix uninit-value in __inet_bind

    https://git.kernel.org/netdev/net/c/7b821da55b3f

You are awesome, thank you!

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