Thread (15 messages) 15 messages, 3 authors, 2019-01-16

Re: [RFC PATCH 3/5] net; lorawan: Fix net device leakage

flat view

From: Jiri Pirko <jiri@resnulli.us>
Date: 2019-01-16 14:43:06
Also in: lkml

Wed, Jan 16, 2019 at 03:24:58PM CET, starnight@g.ncu.edu.tw wrote:
quoted hunk ↗ jump to hunk
The net device may be missed to be put after error check.  This patch
fixes the issue to prevent the leakage.

Signed-off-by: Jian-Hong Pan <redacted>
---
net/lorawan/socket.c | 12 ++++--------
1 file changed, 4 insertions(+), 8 deletions(-)
diff --git a/net/lorawan/socket.c b/net/lorawan/socket.c
index 9c0722379e25..7139fab63159 100644
--- a/net/lorawan/socket.c
+++ b/net/lorawan/socket.c
@@ -51,8 +51,10 @@ lrw_get_dev_by_addr(struct net *net, u32 devaddr)
	rcu_read_lock();
	ndev = dev_getbyhwaddr_rcu(net, ARPHRD_LORAWAN, (char *)&be_addr);
-	if (ndev)
+	if (ndev && ndev->type == ARPHRD_LORAWAN)
		dev_hold(ndev);
+	else
+		ndev = NULL;
	rcu_read_unlock();

	return ndev;
@@ -99,11 +101,6 @@ dgram_bind(struct sock *sk, struct sockaddr *uaddr, int len)
	}
	netdev_dbg(ndev, "%s: get ndev\n", __func__);

-	if (ndev->type != ARPHRD_LORAWAN) {
-		ret = -ENODEV;
-		goto dgram_bind_end;
-	}
-
	ro->src_devaddr = addr->addr_in.devaddr;
	ro->bound = 1;
	ret = 0;
@@ -152,7 +149,7 @@ dgram_sendmsg(struct sock *sk, struct msghdr *msg, size_t size)
	if (size > ndev->mtu) {
		netdev_dbg(ndev, "size = %zu, mtu = %u\n", size, ndev->mtu);
		ret = -EMSGSIZE;
-		goto dgram_sendmsg_end;
+		goto dgram_sendmsg_no_skb;
	}

	netdev_dbg(ndev, "%s: create skb\n", __func__);
@@ -189,7 +186,6 @@ dgram_sendmsg(struct sock *sk, struct msghdr *msg, size_t size)
	kfree_skb(skb);
dgram_sendmsg_no_skb:
	dev_put(ndev);
-
Please avoid hunks like this one.

dgram_sendmsg_end:
	return ret;
}
-- 
2.20.1


_______________________________________________
linux-lpwan mailing list
linux-lpwan@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-lpwan
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help