Skip to contentSkip to conversation

packet: Do not leak dev refcounts on error exit

PATCH In review Jason Gunthorpe 3 participants 3 messages Jan 8, 2019 – Jan 9, 2019

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

PATCH 1/1 packet: Do not leak dev refcounts on error exit

'dev' is non NULL when the addr_len check triggers so it must goto a label that does the dev_put otherwise dev will have a leaked refcount.

This bug causes the ib_ipoib module to become unloadable when using systemd-network as it triggers this check on InfiniBand links.

Fixes 99137b7888f4 ("packet: validate address length")
---
 net/packet/af_packet.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

This patch should go to -rc please. Thanks

net/packet/af_packet.c +2 -2
index eedacdebcd4c61..d0945253f43b3e 100644
@@ -2628,7 +2628,7 @@ static int tpacket_snd(struct packet_sock *po, struct msghdr *msg)
 		addr	= saddr->sll_halen ? saddr->sll_addr : NULL;
 		dev = dev_get_by_index(sock_net(&po->sk), saddr->sll_ifindex);
 		if (addr && dev && saddr->sll_halen < dev->addr_len)
-			goto out;
+			goto out_put;
 	}
 
 	err = -ENXIO;
@@ -2828,7 +2828,7 @@ static int packet_snd(struct socket *sock, struct msghdr *msg, size_t len)
 		addr	= saddr->sll_halen ? saddr->sll_addr : NULL;
 		dev = dev_get_by_index(sock_net(sk), saddr->sll_ifindex);
 		if (addr && dev && saddr->sll_halen < dev->addr_len)
-			goto out;
+			goto out_unlock;
 	}
 
 	err = -ENXIO;
Signature · 1 line
2.20.1
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 10 lines · Jason Gunthorpe

'dev' is non NULL when the addr_len check triggers so it must goto a label that does the dev_put otherwise dev will have a leaked refcount.

This bug causes the ib_ipoib module to become unloadable when using systemd-network as it triggers this check on InfiniBand links.

Fixes 99137b7888f4 ("packet: validate address length")

Argh, indeed. Thanks for the fix.

maintainer
#2 lore raw
In reply to Jason Gunthorpe

From: Jason Gunthorpe <[email protected]>
Date: Tue, 8 Jan 2019 23:27:06 +0000

Quoted 9 lines

'dev' is non NULL when the addr_len check triggers so it must goto a label that does the dev_put otherwise dev will have a leaked refcount.

This bug causes the ib_ipoib module to become unloadable when using systemd-network as it triggers this check on InfiniBand links.

Fixes 99137b7888f4 ("packet: validate address length")

Applied and queued up for -stable, thanks.