Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp3390351ybp; Sun, 6 Oct 2019 10:53:16 -0700 (PDT) X-Google-Smtp-Source: APXvYqwYlGIuhxZ4yPmL6EucObaSBfbKX+UCfurWHcd5Qy2SekUtlxo9/fK5O1a38QB7dCxHMGwP X-Received: by 2002:a50:886d:: with SMTP id c42mr25502097edc.24.1570384396150; Sun, 06 Oct 2019 10:53:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570384396; cv=none; d=google.com; s=arc-20160816; b=wpUospn4w2FUsX6s1MRd42QOYrSljttE3mpTP0ve1yXIQ/qN0q5yUUd+aghNwfe7Nv S5hfSYeqK5mW6vqm2zuZNYRXfMPDWNv0bjkzL45O1yiTrFZSIMLkCkp6EaFnompmtpiO 6NYOn1FBdPAlDub19pJ8wMkGwTnCFLt+aK583RglA/xK5/caUtlxxvGGRTjoL+7JzLrj D2dCGYgLjpiXIfO5N4bJxs9ZkrcIpvNNijgT4biz7pHV3ZzQ8lWDVvrPiRkei8bn1zwi RHb1UxwoZrWr6ekxjSyVt+WN+r41urfLS4ZNKWIlw+/ejaagxo4NLb4RZsJqdctgxAnZ Am9g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=B56/APx9jTSDKw11uLAN+psA5WSTRa5k0SjybOzdZow=; b=DY2oz4vZNUJ/0v8+M2Fz69XWkZeZALOuLFJjDnWm0m3s4weLaYKSSoSEX4toFdY+wD nSDqX/RWgjjSixVLxBiQ5fdi8WId7J0FtaOpVD3Dgl+UaA2uw4mm3Od2I/lqBDy6KzzN DrgBhnI2vH52ckWtTLuCOHaP8eDcPjTxAKRmK8S2gyNEVx+na1Un6kG7QMJrC0EU236+ rrb0g8BErfE8/M7dZAilwGAux2+HylpaFVHTujeHiBl0Oqd9G6rC78qDlf2hRMqOyjiq rInSf+2TGOLe7OzqePugBaIwSNNXsPK8Z828DvJexFs52WJzngpJ6zbid3IQ378L9v6R RLOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=oDkgbv5r; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d32si7765513eda.266.2019.10.06.10.52.52; Sun, 06 Oct 2019 10:53:16 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=oDkgbv5r; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730350AbfJFRvn (ORCPT + 99 others); Sun, 6 Oct 2019 13:51:43 -0400 Received: from mail.kernel.org ([198.145.29.99]:49022 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727964AbfJFRu5 (ORCPT ); Sun, 6 Oct 2019 13:50:57 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 6072920673; Sun, 6 Oct 2019 17:45:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570383954; bh=OebFyXabA0ERn/b/gsHcJyDaNDFID5j4xLypGKyKfnU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oDkgbv5rTvCw5JMfAg+WwMmXG4ASCYtZE+9U+zq81Oo6AzX1wuqeiEERYfGKOnf3O cRBpOJVK6lJmtHxBANqqjxU8DSm7o9Kg/pFY+XWVDAC50FD8AtG+JYPf+UyFW8VtiV AM5X2nuuUVxuGRJZDk654W4aHVZz5LXbmiGbZItI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Vladimir Oltean , Vinicius Costa Gomes , "David S. Miller" Subject: [PATCH 5.3 157/166] net: sched: taprio: Avoid division by zero on invalid link speed Date: Sun, 6 Oct 2019 19:22:03 +0200 Message-Id: <20191006171226.096259249@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191006171212.850660298@linuxfoundation.org> References: <20191006171212.850660298@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Vladimir Oltean [ Upstream commit 9a9251a3534745d08a92abfeca0ca467b912b5f6 ] The check in taprio_set_picos_per_byte is currently not robust enough and will trigger this division by zero, due to e.g. PHYLINK not setting kset->base.speed when there is no PHY connected: [ 27.109992] Division by zero in kernel. [ 27.113842] CPU: 1 PID: 198 Comm: tc Not tainted 5.3.0-rc5-01246-gc4006b8c2637-dirty #212 [ 27.121974] Hardware name: Freescale LS1021A [ 27.126234] [] (unwind_backtrace) from [] (show_stack+0x10/0x14) [ 27.133938] [] (show_stack) from [] (dump_stack+0xb0/0xc4) [ 27.141124] [] (dump_stack) from [] (Ldiv0_64+0x8/0x18) [ 27.148052] [] (Ldiv0_64) from [] (div64_u64+0xcc/0xf0) [ 27.154978] [] (div64_u64) from [] (div64_s64+0x4c/0x68) [ 27.161993] [] (div64_s64) from [] (taprio_set_picos_per_byte+0xe8/0xf4) [ 27.170388] [] (taprio_set_picos_per_byte) from [] (taprio_change+0x668/0xcec) [ 27.179302] [] (taprio_change) from [] (qdisc_create+0x1fc/0x4f4) [ 27.187091] [] (qdisc_create) from [] (tc_modify_qdisc+0x1ac/0x6f8) [ 27.195055] [] (tc_modify_qdisc) from [] (rtnetlink_rcv_msg+0x268/0x2dc) [ 27.203449] [] (rtnetlink_rcv_msg) from [] (netlink_rcv_skb+0xe0/0x114) [ 27.211756] [] (netlink_rcv_skb) from [] (netlink_unicast+0x1b4/0x22c) [ 27.219977] [] (netlink_unicast) from [] (netlink_sendmsg+0x284/0x340) [ 27.228198] [] (netlink_sendmsg) from [] (sock_sendmsg+0x14/0x24) [ 27.235988] [] (sock_sendmsg) from [] (___sys_sendmsg+0x214/0x228) [ 27.243863] [] (___sys_sendmsg) from [] (__sys_sendmsg+0x50/0x8c) [ 27.251652] [] (__sys_sendmsg) from [] (ret_fast_syscall+0x0/0x54) [ 27.259524] Exception stack(0xe8045fa8 to 0xe8045ff0) [ 27.264546] 5fa0: b6f608c8 000000f8 00000003 bed7e2f0 00000000 00000000 [ 27.272681] 5fc0: b6f608c8 000000f8 004ce54c 00000128 5d3ce8c7 00000000 00000026 00505c9c [ 27.280812] 5fe0: 00000070 bed7e298 004ddd64 b6dd1e64 Russell King points out that the ethtool API says zero is a valid return value of __ethtool_get_link_ksettings: * If it is enabled then they are read-only; if the link * is up they represent the negotiated link mode; if the link is down, * the speed is 0, %SPEED_UNKNOWN or the highest enabled speed and * @duplex is %DUPLEX_UNKNOWN or the best enabled duplex mode. So, it seems that taprio is not following the API... I'd suggest either fixing taprio, or getting agreement to change the ethtool API. The chosen path was to fix taprio. Fixes: 7b9eba7ba0c1 ("net/sched: taprio: fix picos_per_byte miscalculation") Signed-off-by: Vladimir Oltean Acked-by: Vinicius Costa Gomes Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/sched/sch_taprio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/net/sched/sch_taprio.c +++ b/net/sched/sch_taprio.c @@ -961,7 +961,7 @@ static void taprio_set_picos_per_byte(st if (err < 0) goto skip; - if (ecmd.base.speed != SPEED_UNKNOWN) + if (ecmd.base.speed && ecmd.base.speed != SPEED_UNKNOWN) speed = ecmd.base.speed; skip: