Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp8066691ybi; Thu, 6 Jun 2019 06:13:30 -0700 (PDT) X-Google-Smtp-Source: APXvYqzgIxlxQwrsnvFS7onJ7JWTRKQlW5zD2IpHk/aQmi1SJTuDg8X0wgpg3A6AqUIYhGYV45Au X-Received: by 2002:a17:90a:d58d:: with SMTP id v13mr16878368pju.1.1559826810262; Thu, 06 Jun 2019 06:13:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559826810; cv=none; d=google.com; s=arc-20160816; b=yBYcSBEA4W4kztIzp8RW9ttEIOWDJILUDHHF7Ay7D9mcv1lpyAgVkQ03pjq8LKVMAQ vGF60pQ7cnVOnVlpF3bx6xVONFcc51XGSZoDBGH0WEvQaoOaqJRWZORgPBImuP7yotq4 lU1e9eNakBzqp6+/m0oNd50AIVOs3YBocqtafES+WQaLXLAyDvZNzfmIc4Y09n9eYA00 YJxaJiXqf3iwTKs4ttLPwwOFFnHs6SLD6iv1DMQEXUmndtYi9vqPM2tr3vM+oskk9TMY TOHFYX1IxdYmfdC8jxuIjdNTP+2jGiZ6KRrxugKw+yD/F4aN+KhNV/kwHTGjQWatp/UW 2wKw== 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 :message-id:date:subject:cc:to:from; bh=ICeaY9MW1gejmLEwh1cK/dpXntm7dEBtBRDOzG1+vKo=; b=dKmu6vqBafbxqQtbUuEVxYzW62s0Nf7ts7OKLmOcAKDi5WndHovHNdcotM6YvTRUGf Zz/TsSwp9xa1KKBzYlTap9IRe9s62q9Pyr2yuS7Hph2chVdLaHbEjUSp5TNCYUqZhign Nt0a73V4nGLeT4BQJR46q0/O4oJMahMolJCCQjb4wMsrz2qZX+XZBCuKmlGB/L1ZtS0u 3NkSFGVSKESUZzM5ZrPUpqMKOyfHI3Z6z3fqDt5sgYWLybk7pGOCgAxn3YlhI2xJfS7h hAWvyuBcLv1L+KmiCR+WM8J1Tnv/338ArGmlmmo1btdmEX8btYcWC+PPTJE8Z2eiXM76 Idqw== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w125si1952243pfb.10.2019.06.06.06.13.12; Thu, 06 Jun 2019 06:13:30 -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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727354AbfFFNK7 (ORCPT + 99 others); Thu, 6 Jun 2019 09:10:59 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:51951 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725782AbfFFNK7 (ORCPT ); Thu, 6 Jun 2019 09:10:59 -0400 Received: from 1.general.cking.uk.vpn ([10.172.193.212] helo=localhost) by youngberry.canonical.com with esmtpsa (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.76) (envelope-from ) id 1hYsAP-0007iC-RR; Thu, 06 Jun 2019 13:10:53 +0000 From: Colin King To: Jacob Keller , Jeff Kirsher , "David S . Miller" , intel-wired-lan@lists.osuosl.org, netdev@vger.kernel.org Cc: kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH][next] ixgbe: fix potential u32 overflow on shift Date: Thu, 6 Jun 2019 14:10:53 +0100 Message-Id: <20190606131053.25103-1-colin.king@canonical.com> X-Mailer: git-send-email 2.20.1 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: Colin Ian King The u32 variable rem is being shifted using u32 arithmetic however it is being passed to div_u64 that expects the expression to be a u64. The 32 bit shift may potentially overflow, so cast rem to a u64 before shifting to avoid this. Addresses-Coverity: ("Unintentional integer overflow") Fixes: cd4583206990 ("ixgbe: implement support for SDP/PPS output on X550 hardware") Fixes: 68d9676fc04e ("ixgbe: fix PTP SDP pin setup on X540 hardware") Signed-off-by: Colin Ian King --- drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c index 2c4d327fcc2e..ff229d0e9146 100644 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c @@ -209,7 +209,7 @@ static void ixgbe_ptp_setup_sdp_X540(struct ixgbe_adapter *adapter) * assumes that the cycle counter shift is small enough to avoid * overflowing when shifting the remainder. */ - clock_edge += div_u64((rem << cc->shift), cc->mult); + clock_edge += div_u64(((u64)rem << cc->shift), cc->mult); trgttiml = (u32)clock_edge; trgttimh = (u32)(clock_edge >> 32); @@ -295,7 +295,7 @@ static void ixgbe_ptp_setup_sdp_X550(struct ixgbe_adapter *adapter) * assumes that the cycle counter shift is small enough to avoid * overflowing when shifting the remainder. */ - clock_edge += div_u64((rem << cc->shift), cc->mult); + clock_edge += div_u64(((u64)rem << cc->shift), cc->mult); /* X550 hardware stores the time in 32bits of 'billions of cycles' and * 32bits of 'cycles'. There's no guarantee that cycles represents -- 2.20.1