From: Matt Johnston <matt@codeconstruct.com.au>
To: unlisted-recipients:; (no To-header on input)
Cc: Jeremy Kerr <jk@codeconstruct.com.au>,
Jakub Kicinski <kuba@kernel.org>,
"David S. Miller" <davem@davemloft.net>,
netdev@vger.kernel.org
Subject: [PATCH net v2] mctp: Fix incorrect netdev unref for extended addr
Date: Fri, 18 Feb 2022 14:29:08 +0800 [thread overview]
Message-ID: <20220218062908.1994506-1-matt@codeconstruct.com.au> (raw)
In the extended addressing local route output codepath
dev_get_by_index_rcu() doesn't take a dev_hold() so we shouldn't
dev_put(). Instead we need to hold/put the mctp_dev.
Fixes: 99ce45d5e7db ("mctp: Implement extended addressing")
Signed-off-by: Matt Johnston <matt@codeconstruct.com.au>
---
v2: Fix incorrect "Fixes:" ID
---
net/mctp/route.c | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/net/mctp/route.c b/net/mctp/route.c
index e52cef750500..6ef79ab4a076 100644
--- a/net/mctp/route.c
+++ b/net/mctp/route.c
@@ -786,9 +786,8 @@ int mctp_local_output(struct sock *sk, struct mctp_route *rt,
{
struct mctp_sock *msk = container_of(sk, struct mctp_sock, sk);
struct mctp_skb_cb *cb = mctp_cb(skb);
- struct mctp_route tmp_rt;
+ struct mctp_route tmp_rt = {0};
struct mctp_sk_key *key;
- struct net_device *dev;
struct mctp_hdr *hdr;
unsigned long flags;
unsigned int mtu;
@@ -801,12 +800,12 @@ int mctp_local_output(struct sock *sk, struct mctp_route *rt,
if (rt) {
ext_rt = false;
- dev = NULL;
-
if (WARN_ON(!rt->dev))
goto out_release;
} else if (cb->ifindex) {
+ struct net_device *dev;
+
ext_rt = true;
rt = &tmp_rt;
@@ -816,8 +815,9 @@ int mctp_local_output(struct sock *sk, struct mctp_route *rt,
rcu_read_unlock();
return rc;
}
-
rt->dev = __mctp_dev_get(dev);
+ if (rt->dev)
+ mctp_dev_hold(rt->dev);
rcu_read_unlock();
if (!rt->dev)
@@ -891,10 +891,10 @@ int mctp_local_output(struct sock *sk, struct mctp_route *rt,
if (!ext_rt)
mctp_route_release(rt);
- dev_put(dev);
+ if (tmp_rt.dev)
+ mctp_dev_put(tmp_rt.dev);
return rc;
-
}
/* route management */
--
2.32.0
next reply other threads:[~2022-02-18 6:29 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-18 6:29 Matt Johnston [this message]
2022-02-19 5:42 ` [PATCH net v2] mctp: Fix incorrect netdev unref for extended addr Jakub Kicinski
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=20220218062908.1994506-1-matt@codeconstruct.com.au \
--to=matt@codeconstruct.com.au \
--cc=davem@davemloft.net \
--cc=jk@codeconstruct.com.au \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
/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.