Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3872189pxb; Tue, 17 Nov 2020 05:54:49 -0800 (PST) X-Google-Smtp-Source: ABdhPJzx+xCIEr6fbIjlXfo96XlXC1uf3vxM4qPbO1StYsSF9W+9eh7KPnGNaHVU6zzyeL70M1t6 X-Received: by 2002:aa7:c716:: with SMTP id i22mr21216673edq.94.1605621289590; Tue, 17 Nov 2020 05:54:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605621289; cv=none; d=google.com; s=arc-20160816; b=NVvZn3FrhF7jlUW2AoyLPjeWsFVhnZe57juSVHMbfN0tFQlIli/BAPE633DBs3SIXd w5x40WuC5/wtUQzVFrn7zcaPw2kdlHP7Ej3Nq76mHOnlpUW+dAGvKOUAl458X4dIEEWn zVYfqZYeCAlKWvc9pT4oWnYtsDOBqSr4z2Te+kmi9QoXGspY6xF5eGMusoJvZJRRotEv 4gNRkOhuG94yOZqRJMMliubJGx0LBOBUTHIW7scYMtNN65awPn6Y7I3tUML6V/Tt+NSu wi7NfB4tBR4cZZvX4uLDBGU7h4yh9RauH0x3vHElQAvu7k5rTYUeY3mPxkCq9M/cH2+X L8wA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=nbYhQ1LYQjL6C+r1WPR90jUpN8v6fVeySvJr9C5zcOA=; b=D5j88i2jOnFdkibgZxEzLN+EvvZRKkUyaF6Gpq1yWvF82ICY9lP8ZBsPq5gCG569Om x3yY/1Ws6QWuguUgex9KmjI7OFs7Z2uZEl3iBt9oNWtDwya9nti9+0UAyf+mqgu03XW3 Dp2hbXlgTANtXY6T6ED+btu4+U+/Bi8te7ck82qZJd14wa3Wus/xIrFJ9FLjP59ODx9g wn1iwVf+fOHwpFy+QW0onFKyND8uNmTP+eTuRAyYqA4qnv6ynfO70GYS/H0voTS9X6eo K5T8qtG8USv2AVb9oiFQn6VlXmVOLKuNGwfTZjjMraDTPKDzynLVr1LyQ14ntWqGs8ET ylBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=fJQrohkb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y12si13193037ejf.670.2020.11.17.05.54.26; Tue, 17 Nov 2020 05:54:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=fJQrohkb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732282AbgKQNcZ (ORCPT + 99 others); Tue, 17 Nov 2020 08:32:25 -0500 Received: from mail.kernel.org ([198.145.29.99]:41488 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731540AbgKQNcG (ORCPT ); Tue, 17 Nov 2020 08:32:06 -0500 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E55B8207BC; Tue, 17 Nov 2020 13:32:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1605619926; bh=U5ILUUZszFVgPDcqDtYOt4f9Ux+iVgLzLZO2zPJ9aG0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fJQrohkb/BfVm0mJzUVwBUZEbSQxrDBCH7xcAoggHkHnYVksPR6t9eS7y9vGMRJv4 SG5YA8hLSn41qhOEHK19HHZahdjTWxUyNyO468AEZBlwIlpcPjoaSOXRR8nHXcZ+0r RKB/v/xqulIy4hbYlq9pr/NKO+JmUQeqzNPQxh6A= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Zhang Changzhong , Oleksij Rempel , Marc Kleine-Budde , Sasha Levin Subject: [PATCH 5.9 050/255] can: j1939: j1939_sk_bind(): return failure if netdev is down Date: Tue, 17 Nov 2020 14:03:10 +0100 Message-Id: <20201117122141.386940561@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201117122138.925150709@linuxfoundation.org> References: <20201117122138.925150709@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Zhang Changzhong [ Upstream commit 08c487d8d807535f509ed80c6a10ad90e6872139 ] 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 Link: https://lore.kernel.org/r/1599460308-18770-1-git-send-email-zhangchangzhong@huawei.com Acked-by: Oleksij Rempel Signed-off-by: Marc Kleine-Budde Signed-off-by: Sasha Levin --- 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 1be4c898b2fa8..f23966526a885 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.27.0