Skip to contentSkip to conversation

bpf/xskmap: Return ERR_PTR for failure case instead of NULL.

PATCH Applied Jonathan Lemon 3 participants 3 messages Sep 24, 2019 – Sep 25, 2019

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

PATCH 1/1 bpf/xskmap: Return ERR_PTR for failure case instead of NULL.

When kzalloc() failed, NULL was returned to the caller, which tested the pointer with IS_ERR(), which didn't match, so the pointer was used later, resulting in a NULL dereference.

Return ERR_PTR(-ENOMEM) instead of NULL.

Reported-by [email protected]
Fixes 0402acd683c6 ("xsk: remove AF_XDP socket from map when the socket is released")
---
 kernel/bpf/xskmap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/bpf/xskmap.c +1 -1
index 942c662e2eed..82a1ffe15dfa 100644
@@ -37,7 +37,7 @@ static struct xsk_map_node *xsk_map_node_alloc(struct xsk_map *map,
 
 	node = kzalloc(sizeof(*node), GFP_ATOMIC | __GFP_NOWARN);
 	if (!node)
-		return NULL;
+		return ERR_PTR(-ENOMEM);
 
 	err = xsk_map_inc(map);
 	if (err) {
Signature · 1 line
2.17.1
Acked-by on v1 1/1
#1 lore raw
Quoted 9 lines · Jonathan Lemon

When kzalloc() failed, NULL was returned to the caller, which tested the pointer with IS_ERR(), which didn't match, so the pointer was used later, resulting in a NULL dereference.

Return ERR_PTR(-ENOMEM) instead of NULL.

Reported-by [email protected]
Fixes 0402acd683c6 ("xsk: remove AF_XDP socket from map when the socket is released")

Thanks Jonathan! You beat me to it! :-P

Quoted 18 lines
---
  kernel/bpf/xskmap.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
kernel/bpf/xskmap.c +1 -1
index 942c662e2eed..82a1ffe15dfa 100644
@@ -37,7 +37,7 @@ static struct xsk_map_node *xsk_map_node_alloc(struct xsk_map *map,
 
  	node = kzalloc(sizeof(*node), GFP_ATOMIC | __GFP_NOWARN);
  	if (!node)
-		return NULL;
+		return ERR_PTR(-ENOMEM);
 
  	err = xsk_map_inc(map);
  	if (err) {
maintainer Applied
#2 lore raw
Quoted 7 lines · Björn Töpel
Quoted 6 lines · Jonathan Lemon

When kzalloc() failed, NULL was returned to the caller, which tested the pointer with IS_ERR(), which didn't match, so the pointer was used later, resulting in a NULL dereference.

Return ERR_PTR(-ENOMEM) instead of NULL.

Quoted 7 lines
Quoted 3 lines
Reported-by [email protected]
Fixes 0402acd683c6 ("xsk: remove AF_XDP socket from map when the socket is released")

Thanks Jonathan! You beat me to it! :-P

Applied, thanks!