Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp4457558rwb; Mon, 21 Nov 2022 07:50:26 -0800 (PST) X-Google-Smtp-Source: AA0mqf6t2R3pVOLbMDuNJEPLGZcSx19PFdVsOrdP1SXSvAi8HTiyKwuKrAesjHljh1islnClPVMc X-Received: by 2002:a17:906:504:b0:7b5:2d9f:4019 with SMTP id j4-20020a170906050400b007b52d9f4019mr6783990eja.536.1669045826409; Mon, 21 Nov 2022 07:50:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669045826; cv=none; d=google.com; s=arc-20160816; b=kgquWCA4BfTJBuPfRqy5zIjA4J0lm1TJAT4X1TSSs5hnzVrjdUcniri5jmVA4w57jw n80x5eKg4A6johibh8HNpn1YWafPkxysVIDx+E8684fN3f/jqwzPhazlaC9UvSwin9cu n65IF9tB8XQK/MSZf/TcmP+7P7FsK2k6QuLEcz+P9F37gx2NawRSo4kWw9OaScciDreX d6vJfDw58xNBcz7ozn9ANMTntXEQ/3dGcdpnqNGXbwKpP4uDMh8zXQJOEiqqWjzLYiBV ruzckXWqIxFYxwanA/ri1dOz2VUkk+XlfJaD61bVTeuxWBtoT3gxiHHuBcLmSFEjPE/B KxuA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=hmcYM8Hy3CsFIKQSfVLJ79ErmXZM58kJ44FUCnY1kW0=; b=pZ73o9X78ndwpscuA9e9oxBaLNo7+jzhj/Yo5TAzHMyMbVDUk/DnQJL38UIjZIec7J 07CpBvQiX+U78j8EWZvSyiD4TQRUm6KQzolY98MXvpMmgHhGkrjU0CXxXE9yw9VjiY2R YVKNdHKNsODd3PQ2iJVek/B7jncKBbLWquQWeU4ny74YFhLOCEVKnCv78z+JRMO+F+DA yrK63vo3fBI/xPaH/4bCubA44NT9n2aVxHAPsdGbzA7JX2xNrIDTpDsKdb0/HEG9vhWp xtk7rBuavM2WfsaZ2Br5twTdKncLg2i+Cqe9MRfp8LPi+EI5Yot0bPw4PJEA3kGfKXmK iljA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lunn.ch header.s=20171124 header.b=vDBAOB6+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=lunn.ch Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w13-20020a170906130d00b007ae664aa7dbsi8429229ejb.877.2022.11.21.07.49.53; Mon, 21 Nov 2022 07:50:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@lunn.ch header.s=20171124 header.b=vDBAOB6+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=lunn.ch Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229934AbiKUONj (ORCPT + 91 others); Mon, 21 Nov 2022 09:13:39 -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> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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