ipv4: fib: Fix fib_info_hash_alloc() allocation type
Subsystems (3)
PATCH 1/1 ipv4: fib: Fix fib_info_hash_alloc() allocation type
In preparation for making the kmalloc family of allocators type aware, we need to make sure that the returned type from the allocation matches the type of the variable being assigned. (Before, the allocator would always return "void *", which can be implicitly cast to any pointer type.)
This was allocating many sizeof(struct hlist_head *) when it actually wanted sizeof(struct hlist_head). Luckily these are the same size. Adjust the allocation type to match the assignment.
---
Cc: "David S. Miller" <[email protected]>
Cc: David Ahern <[email protected]>
Cc: Eric Dumazet <[email protected]>
Cc: Jakub Kicinski <[email protected]>
Cc: Paolo Abeni <[email protected]>
Cc: Simon Horman <[email protected]>
Cc: <[email protected]>
--- net/ipv4/fib_semantics.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv4/fib_semantics.c +1 -1
@@ -365,7 +365,7 @@ static struct hlist_head *fib_info_laddrhash_bucket(const struct net *net,static struct hlist_head *fib_info_hash_alloc (unsigned int hash_bits) {/* The second half is used for prefsrc */ -return kvcalloc ((1 << hash_bits) *2 ,sizeof (struct hlist_head *), +return kvcalloc ((1 << hash_bits) *2 ,sizeof (struct hlist_head ),GFP_KERNEL ); }
Signature · 1 line
2.34.1
Quoted 10 lines · Kees Cook
In preparation for making the kmalloc family of allocators type aware, we need to make sure that the returned type from the allocation matches the type of the variable being assigned. (Before, the allocator would always return "void *", which can be implicitly cast to any pointer type.)
This was allocating many
sizeof(struct hlist_head *)when it actually wantedsizeof(struct hlist_head). Luckily these are the same size. Adjust the allocation type to match the assignment.Signed-off-by Kees Cook <[email protected]>
Thanks, your analysis matches my understanding of the code.
Quoted 27 lines · Kees Cook
In preparation for making the kmalloc family of allocators type aware, we need to make sure that the returned type from the allocation matches the type of the variable being assigned. (Before, the allocator would always return "void *", which can be implicitly cast to any pointer type.)
This was allocating many
sizeof(struct hlist_head *)when it actually wantedsizeof(struct hlist_head). Luckily these are the same size. Adjust the allocation type to match the assignment.Signed-off-by Kees Cook <[email protected]>---
Cc: "David S. Miller" <[email protected]>
Cc: David Ahern <[email protected]>
Cc: Eric Dumazet <[email protected]>
Cc: Jakub Kicinski <[email protected]>
Cc: Paolo Abeni <[email protected]>
Cc: Simon Horman <[email protected]>
Cc: <[email protected]>--- net/ipv4/fib_semantics.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)net/ipv4/fib_semantics.c +0
-0
net/ipv4/fib_semantics.c static struct hlist_head *fib_info_laddrhash_bucket(const struct net *net, · line 371
Quoted 8 lines
net/ipv4/fib_semantics.c +1
-1@@ -365,7 +365,7 @@ static struct hlist_head *fib_info_laddrhash_bucket(const struct net *net,static struct hlist_head *fib_info_hash_alloc (unsigned int hash_bits) {/* The second half is used for prefsrc */ -return kvcalloc ((1 << hash_bits) *2 ,sizeof (struct hlist_head *), +return kvcalloc ((1 << hash_bits) *2 ,sizeof (struct hlist_head ),GFP_KERNEL ); }
fib_info_laddrhash[] by kvcalloc().)
Kuniyuki Iwashima
Reviewed-byThanks for CC me, David.
From: David Ahern <[email protected]>
Date: Mon, 28 Apr 2025 16:50:53 -0600
Quoted 39 lines · Kees Cook
Quoted 27 lines
In preparation for making the kmalloc family of allocators type aware, we need to make sure that the returned type from the allocation matches the type of the variable being assigned. (Before, the allocator would always return "void *", which can be implicitly cast to any pointer type.)
This was allocating many
sizeof(struct hlist_head *)when it actually wantedsizeof(struct hlist_head). Luckily these are the same size. Adjust the allocation type to match the assignment.Signed-off-by Kees Cook <[email protected]>---
Cc: "David S. Miller" <[email protected]>
Cc: David Ahern <[email protected]>
Cc: Eric Dumazet <[email protected]>
Cc: Jakub Kicinski <[email protected]>
Cc: Paolo Abeni <[email protected]>
Cc: Simon Horman <[email protected]>
Cc: <[email protected]>--- net/ipv4/fib_semantics.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)net/ipv4/fib_semantics.c +0
-0net/ipv4/fib_semantics.c static struct hlist_head *fib_info_laddrhash_bucket(const struct net *net, · line 371
Quoted 8 lines
net/ipv4/fib_semantics.c +1
-1@@ -365,7 +365,7 @@ static struct hlist_head *fib_info_laddrhash_bucket(const struct net *net,static struct hlist_head *fib_info_hash_alloc (unsigned int hash_bits) {/* The second half is used for prefsrc */ -return kvcalloc ((1 << hash_bits) *2 ,sizeof (struct hlist_head *), +return kvcalloc ((1 << hash_bits) *2 ,sizeof (struct hlist_head ),GFP_KERNEL ); }Reviewed-by David Ahern <[email protected]>
Quoted 2 lines
Fixes fa336adc100e ("ipv4: fib: Allocate fib_info_hash[] andfib_info_laddrhash[] by
kvcalloc().)
I agree this should target net.git as the last statement will be false with LOCKDEP.
Thanks!
Quoted 43 lines · Kuniyuki Iwashima
Thanks for CC me, David.
From: David Ahern <[email protected]>
Date: Mon, 28 Apr 2025 16:50:53 -0600Quoted 39 lines · Kees Cook
Quoted 27 lines
In preparation for making the kmalloc family of allocators type aware, we need to make sure that the returned type from the allocation matches the type of the variable being assigned. (Before, the allocator would always return "void *", which can be implicitly cast to any pointer type.)
This was allocating many
sizeof(struct hlist_head *)when it actually wantedsizeof(struct hlist_head). Luckily these are the same size. Adjust the allocation type to match the assignment.Signed-off-by Kees Cook <[email protected]>---
Cc: "David S. Miller" <[email protected]>
Cc: David Ahern <[email protected]>
Cc: Eric Dumazet <[email protected]>
Cc: Jakub Kicinski <[email protected]>
Cc: Paolo Abeni <[email protected]>
Cc: Simon Horman <[email protected]>
Cc: <[email protected]>--- net/ipv4/fib_semantics.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)net/ipv4/fib_semantics.c +0
-0net/ipv4/fib_semantics.c static struct hlist_head *fib_info_laddrhash_bucket(const struct net *net, · line 371
Quoted 8 lines
net/ipv4/fib_semantics.c +1
-1@@ -365,7 +365,7 @@ static struct hlist_head *fib_info_laddrhash_bucket(const struct net *net,static struct hlist_head *fib_info_hash_alloc (unsigned int hash_bits) {/* The second half is used for prefsrc */ -return kvcalloc ((1 << hash_bits) *2 ,sizeof (struct hlist_head *), +return kvcalloc ((1 << hash_bits) *2 ,sizeof (struct hlist_head ),GFP_KERNEL ); }Reviewed-by David Ahern <[email protected]>
Quoted 5 lines
Quoted 2 lines
Fixes fa336adc100e ("ipv4: fib: Allocate fib_info_hash[] andfib_info_laddrhash[] by
kvcalloc().)I agree this should target net.git as the last statement will be false with LOCKDEP.
Which will be false with lockdep? Unless I'm missing it, I think hlist_head is always pointer sized:
struct hlist_head {
struct hlist_node *first;
};Quoted 2 lines
Reviewed-by Kuniyuki Iwashima <[email protected]>
Thanks!
Signature · 1 line
Kees Cook
From: Kees Cook <[email protected]>
Date: Mon, 28 Apr 2025 20:52:59 -0700
Quoted 44 lines · Kuniyuki Iwashima
Quoted 43 lines
Thanks for CC me, David.
From: David Ahern <[email protected]>
Date: Mon, 28 Apr 2025 16:50:53 -0600Quoted 39 lines · Kees Cook
Quoted 27 lines
In preparation for making the kmalloc family of allocators type aware, we need to make sure that the returned type from the allocation matches the type of the variable being assigned. (Before, the allocator would always return "void *", which can be implicitly cast to any pointer type.)
This was allocating many
sizeof(struct hlist_head *)when it actually wantedsizeof(struct hlist_head). Luckily these are the same size. Adjust the allocation type to match the assignment.Signed-off-by Kees Cook <[email protected]>---
Cc: "David S. Miller" <[email protected]>
Cc: David Ahern <[email protected]>
Cc: Eric Dumazet <[email protected]>
Cc: Jakub Kicinski <[email protected]>
Cc: Paolo Abeni <[email protected]>
Cc: Simon Horman <[email protected]>
Cc: <[email protected]>--- net/ipv4/fib_semantics.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)net/ipv4/fib_semantics.c +0
-0net/ipv4/fib_semantics.c static struct hlist_head *fib_info_laddrhash_bucket(const struct net *net, · line 371
Quoted 8 lines
net/ipv4/fib_semantics.c +1
-1@@ -365,7 +365,7 @@ static struct hlist_head *fib_info_laddrhash_bucket(const struct net *net,static struct hlist_head *fib_info_hash_alloc (unsigned int hash_bits) {/* The second half is used for prefsrc */ -return kvcalloc ((1 << hash_bits) *2 ,sizeof (struct hlist_head *), +return kvcalloc ((1 << hash_bits) *2 ,sizeof (struct hlist_head ),GFP_KERNEL ); }Reviewed-by David Ahern <[email protected]>
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
Fixes fa336adc100e ("ipv4: fib: Allocate fib_info_hash[] andfib_info_laddrhash[] by
kvcalloc().)I agree this should target net.git as the last statement will be false with LOCKDEP.
Which will be false with lockdep? Unless I'm missing it, I think
hlist_headis always pointer sized:
Oh sorry, now I'm not sure why I mentioned lockdep... maybe confused with other code :/
Quoted 4 lines
struct hlist_head {
struct hlist_node *first;
};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 10 lines · On Fri, 25 Apr 2025 23:05:30 -0700 you wrote:
In preparation for making the kmalloc family of allocators type aware, we need to make sure that the returned type from the allocation matches the type of the variable being assigned. (Before, the allocator would always return "void *", which can be implicitly cast to any pointer type.)
This was allocating many
sizeof(struct hlist_head *)when it actually wantedsizeof(struct hlist_head). Luckily these are the same size. Adjust the allocation type to match the assignment.[...]
Here is the summary with links:
- ipv4: fib: Fix fib_info_hash_alloc() allocation type
https://git.kernel.org/netdev/net-next/c/fca6170f5a03
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html