From: Jiri Pirko <jiri@resnulli.us>
To: Jian-Hong Pan <starnight@g.ncu.edu.tw>
Cc: "Andreas Färber" <afaerber@suse.de>,
netdev@vger.kernel.org, linux-lpwan@lists.infradead.org,
"Ben Whitten" <ben.whitten@lairdtech.com>,
linux-kernel@vger.kernel.org
Subject: Re: [RFC PATCH 3/5] net; lorawan: Fix net device leakage
Date: Wed, 16 Jan 2019 15:34:31 +0100 [thread overview]
Message-ID: <20190116143431.GG5265@nanopsycho> (raw)
In-Reply-To: <20190116142458.19542-3-starnight@g.ncu.edu.tw>
Wed, Jan 16, 2019 at 03:24:58PM CET, starnight@g.ncu.edu.tw wrote:
>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 <starnight@g.ncu.edu.tw>
>---
> 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
next prev parent reply other threads:[~2019-01-16 14:43 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-01-16 14:20 [RFC PATCH 0/5] net: lorawan: Refine the lorawan protocol module Jian-Hong Pan
2019-01-16 14:24 ` [RFC PATCH 1/5] net: lorawan: Refine the coding style Jian-Hong Pan
2019-01-16 14:33 ` Jiri Pirko
2019-01-16 15:07 ` Andreas Färber
2019-01-16 16:06 ` Jian-Hong Pan
2019-01-16 14:24 ` [RFC PATCH 2/5] net: lorawan: Remove unused lrw_dev_hard_header function Jian-Hong Pan
2019-01-16 14:24 ` [RFC PATCH 3/5] net; lorawan: Fix net device leakage Jian-Hong Pan
2019-01-16 14:34 ` Jiri Pirko [this message]
2019-01-16 14:25 ` [RFC PATCH 4/5] net: lorawan: Fulfill the help text of Kconfig Jian-Hong Pan
2019-01-16 14:35 ` Jiri Pirko
2019-01-16 14:25 ` [RFC PATCH 5/5] net: lorawan: Split skb definitions into another header Jian-Hong Pan
2019-01-16 14:36 ` Jiri Pirko
2019-01-16 14:50 ` Andreas Färber
2019-01-16 16:35 ` Jian-Hong Pan
2019-01-16 14:25 ` Jian-Hong Pan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190116143431.GG5265@nanopsycho \
--to=jiri@resnulli.us \
--cc=afaerber@suse.de \
--cc=ben.whitten@lairdtech.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-lpwan@lists.infradead.org \
--cc=netdev@vger.kernel.org \
--cc=starnight@g.ncu.edu.tw \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.