Thread (4 messages) flat view 4 messages, 2 authors, 2018-09-04
STALE2932d

[PATCH] net: ipv6: route: Fix a sleep-in-atomic-context bug in ip6_convert_metrics()

From: Jia-Ju Bai <hidden>
Date: 2018-09-01 11:20:12
Also in: lkml
Subsystem: networking [general], networking [ipv4/ipv6], the rest · Maintainers: "David S. Miller", Eric Dumazet, Jakub Kicinski, Paolo Abeni, David Ahern, Ido Schimmel, Linus Torvalds

The kernel module may sleep with holding a spinlock.

The function call paths (from bottom to top) in Linux-4.16 are:

[FUNC] kzalloc(GFP_KERNEL)
net/ipv6/route.c, 2430: 
	kzalloc in ip6_convert_metrics
net/ipv6/route.c, 2890: 
	ip6_convert_metrics in ip6_route_add
net/ipv6/addrconf.c, 2322: 
	ip6_route_add in addrconf_prefix_route
net/ipv6/addrconf.c, 3331: 
	addrconf_prefix_route in fixup_permanent_addr
net/ipv6/addrconf.c, 3354: 
	fixup_permanent_addr in addrconf_permanent_addr
net/ipv6/addrconf.c, 3358: 
	_raw_write_lock_bh in addrconf_permanent_addr

To fix this bug, GFP_KERNEL is replaced with GFP_ATOMIC.

This bug is found by my static analysis tool DSAC.

Signed-off-by: Jia-Ju Bai <redacted>
---
 net/ipv6/route.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/ipv6/route.c b/net/ipv6/route.c
index ec18b3ce8b6d..d15e72def7c1 100644
--- a/net/ipv6/route.c
+++ b/net/ipv6/route.c
@@ -2742,7 +2742,7 @@ static int ip6_convert_metrics(struct net *net, struct fib6_info *rt,
 	if (!cfg->fc_mx)
 		return 0;
 
-	p = kzalloc(sizeof(*rt->fib6_metrics), GFP_KERNEL);
+	p = kzalloc(sizeof(*rt->fib6_metrics), GFP_ATOMIC);
 	if (unlikely(!p))
 		return -ENOMEM;
 
-- 
2.17.0
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help