From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9527EC43219 for ; Mon, 21 Nov 2022 14:13:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229928AbiKUONl (ORCPT ); Mon, 21 Nov 2022 09:13:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51888 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229908AbiKUONP (ORCPT ); Mon, 21 Nov 2022 09:13:15 -0500 Received: from vps0.lunn.ch (vps0.lunn.ch [156.67.10.101]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BE6CA11C2C; Mon, 21 Nov 2022 06:11:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lunn.ch; s=20171124; h=In-Reply-To:Content-Disposition:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:From:Sender:Reply-To:Subject: Date:Message-ID:To:Cc:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Content-Disposition:In-Reply-To:References; bh=hmcYM8Hy3CsFIKQSfVLJ79ErmXZM58kJ44FUCnY1kW0=; b=vDBAOB6+F/VIwIT/223EtnfdKQ EBUd2uqXhjPbufQFAeM5C7ObvnVc9RAdFun7OGtqWmbp6JCmuKS04ptVf2EnzbuCNSI04UUh8qheA n9oqnNZgqMAdZhwnZg2N3hKxW1en1TtIE257rZI8Gq//KYk2XtfaezwCLXii9oggPUVQ=; Received: from andrew by vps0.lunn.ch with local (Exim 4.94.2) (envelope-from ) id 1ox7V4-0030yn-9U; Mon, 21 Nov 2022 15:10:18 +0100 Date: Mon, 21 Nov 2022 15:10:18 +0100 From: Andrew Lunn To: Maxim Korotkov Cc: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Guangbin Huang , Tom Rix , Marco Bonelli , Edward Cree , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, lvc-project@linuxtesting.org Subject: Re: [PATCH] ethtool: avoiding integer overflow in ethtool_phys_id() Message-ID: References: <20221121075618.15877-1-korotkov.maxim.s@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221121075618.15877-1-korotkov.maxim.s@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Nov 21, 2022 at 10:56:18AM +0300, Maxim Korotkov wrote: > The value of an arithmetic expression "n * id.data" is subject > to possible overflow due to a failure to cast operands to a larger data > type before performing arithmetic. Added cast of first operand to u64 > for avoiding overflow. > > Found by Linux Verification Center (linuxtesting.org) with SVACE. > > Fixes: 2adc6edcaec0 ("ethtool: fix error handling in ethtool_phys_id") > Signed-off-by: Maxim Korotkov > --- > net/ethtool/ioctl.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/net/ethtool/ioctl.c b/net/ethtool/ioctl.c > index 6a7308de192d..cf87e53c2e74 100644 > --- a/net/ethtool/ioctl.c > +++ b/net/ethtool/ioctl.c > @@ -2007,7 +2007,7 @@ static int ethtool_phys_id(struct net_device *dev, void __user *useraddr) > } else { > /* Driver expects to be called at twice the frequency in rc */ > int n = rc * 2, interval = HZ / n; > - u64 count = n * id.data, i = 0; > + u64 count = (u64)n * id.data, i = 0; How about moving the code around a bit, change n to a u64 and drop the cast? Does this look correct? int interval = HZ / rc / 2; u64 n = rc * 2; u64 count = n * id.data; i = 0; I just don't like casts, they suggest the underlying types are wrong, so should fix that, not add a cast. Andrew