diff mbox series

packet: Do not leak dev refcounts on error exit

Message ID 20190108232658.GA1911@ziepe.ca
State Accepted
Delegated to: David Miller
Headers show
Series packet: Do not leak dev refcounts on error exit | expand

Commit Message

Jason Gunthorpe Jan. 8, 2019, 11:27 p.m. UTC
'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")
Reported-by: Leon Romanovsky <leonro@mellanox.com>
Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
---
 net/packet/af_packet.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

This patch should go to -rc please. Thanks

Comments

Willem de Bruijn Jan. 8, 2019, 11:48 p.m. UTC | #1
On Tue, Jan 8, 2019 at 6:41 PM Jason Gunthorpe <jgg@mellanox.com> wrote:
>
> '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")
> Reported-by: Leon Romanovsky <leonro@mellanox.com>
> Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>

Acked-by: Willem de Bruijn <willemb@google.com>

Argh, indeed. Thanks for the fix.
David Miller Jan. 9, 2019, 2:59 a.m. UTC | #2
From: Jason Gunthorpe <jgg@mellanox.com>
Date: Tue, 8 Jan 2019 23:27:06 +0000

> '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")
> Reported-by: Leon Romanovsky <leonro@mellanox.com>
> Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>

Applied and queued up for -stable, thanks.
diff mbox series

Patch

diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
index eedacdebcd4c61..d0945253f43b3e 100644
--- a/net/packet/af_packet.c
+++ b/net/packet/af_packet.c
@@ -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;