From: Oleksij Rempel <o.rempel@pengutronix.de>
To: Zhang Changzhong <zhangchangzhong@huawei.com>
Cc: robin@protonic.nl, linux@rempel-privat.de, kernel@pengutronix.de,
socketcan@hartkopp.net, mkl@pengutronix.de, davem@davemloft.net,
kuba@kernel.org, linux-can@vger.kernel.org,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH net] can: j1939: j1939_sk_bind(): return failure if netdev is down
Date: Fri, 11 Sep 2020 08:50:41 +0200 [thread overview]
Message-ID: <20200911065041.v4cetsbokqhdmbd4@pengutronix.de> (raw)
In-Reply-To: <1599460308-18770-1-git-send-email-zhangchangzhong@huawei.com>
On Mon, Sep 07, 2020 at 02:31:48PM +0800, Zhang Changzhong wrote:
> When a netdev down event occurs after a successful call to
> j1939_sk_bind(), j1939_netdev_notify() can handle it correctly.
>
> But if the netdev already in down state before calling j1939_sk_bind(),
> j1939_sk_release() will stay in wait_event_interruptible() blocked
> forever. Because in this case, j1939_netdev_notify() won't be called and
> j1939_tp_txtimer() won't call j1939_session_cancel() or other function
> to clear session for ENETDOWN error, this lead to mismatch of
> j1939_session_get/put() and jsk->skb_pending will never decrease to
> zero.
>
> To reproduce it use following commands:
> 1. ip link add dev vcan0 type vcan
> 2. j1939acd -r 100,80-120 1122334455667788 vcan0
> 3. presses ctrl-c and thread will be blocked forever
>
> This patch adds check for ndev->flags in j1939_sk_bind() to avoid this
> kind of situation and return with -ENETDOWN.
>
> Fixes: 9d71dd0c7009 ("can: add support of SAE J1939 protocol")
> Signed-off-by: Zhang Changzhong <zhangchangzhong@huawei.com>
Acked-by: Oleksij Rempel <o.rempel@pengutronix.de>
Thank you!
> ---
> net/can/j1939/socket.c | 6 ++++++
> 1 file changed, 6 insertions(+)
>
> diff --git a/net/can/j1939/socket.c b/net/can/j1939/socket.c
> index 1be4c89..f239665 100644
> --- a/net/can/j1939/socket.c
> +++ b/net/can/j1939/socket.c
> @@ -475,6 +475,12 @@ static int j1939_sk_bind(struct socket *sock, struct sockaddr *uaddr, int len)
> goto out_release_sock;
> }
>
> + if (!(ndev->flags & IFF_UP)) {
> + dev_put(ndev);
> + ret = -ENETDOWN;
> + goto out_release_sock;
> + }
> +
> priv = j1939_netdev_start(ndev);
> dev_put(ndev);
> if (IS_ERR(priv)) {
> --
> 2.9.5
>
>
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
prev parent reply other threads:[~2020-09-11 6:51 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-07 6:31 [PATCH net] can: j1939: j1939_sk_bind(): return failure if netdev is down Zhang Changzhong
2020-09-11 6:50 ` Oleksij Rempel [this message]
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=20200911065041.v4cetsbokqhdmbd4@pengutronix.de \
--to=o.rempel@pengutronix.de \
--cc=davem@davemloft.net \
--cc=kernel@pengutronix.de \
--cc=kuba@kernel.org \
--cc=linux-can@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@rempel-privat.de \
--cc=mkl@pengutronix.de \
--cc=netdev@vger.kernel.org \
--cc=robin@protonic.nl \
--cc=socketcan@hartkopp.net \
--cc=zhangchangzhong@huawei.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).