netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
To: davem@davemloft.net
Cc: Colin Ian King <colin.king@canonical.com>,
	netdev@vger.kernel.org, nhorman@redhat.com, sassmann@redhat.com,
	Jacob Keller <jacob.e.keller@intel.com>,
	Andrew Bowers <andrewx.bowers@intel.com>,
	Jeff Kirsher <jeffrey.t.kirsher@intel.com>
Subject: [net-next 04/15] ixgbe: fix potential u32 overflow on shift
Date: Fri, 28 Jun 2019 15:49:21 -0700	[thread overview]
Message-ID: <20190628224932.3389-5-jeffrey.t.kirsher@intel.com> (raw)
In-Reply-To: <20190628224932.3389-1-jeffrey.t.kirsher@intel.com>

From: Colin Ian King <colin.king@canonical.com>

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.  Also remove comment about overflow.

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 <colin.king@canonical.com>
Acked-by: Jacob Keller <jacob.e.keller@intel.com>
Tested-by: Andrew Bowers <andrewx.bowers@intel.com>
Signed-off-by: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
---
 drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)

diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
index 2c4d327fcc2e..0be13a90ff79 100644
--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
@@ -205,11 +205,8 @@ static void ixgbe_ptp_setup_sdp_X540(struct ixgbe_adapter *adapter)
 	 */
 	rem = (NS_PER_SEC - rem);
 
-	/* Adjust the clock edge to align with the next full second. This
-	 * 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);
+	/* Adjust the clock edge to align with the next full second. */
+	clock_edge += div_u64(((u64)rem << cc->shift), cc->mult);
 	trgttiml = (u32)clock_edge;
 	trgttimh = (u32)(clock_edge >> 32);
 
@@ -291,11 +288,8 @@ static void ixgbe_ptp_setup_sdp_X550(struct ixgbe_adapter *adapter)
 	 */
 	rem = (NS_PER_SEC - rem);
 
-	/* Adjust the clock edge to align with the next full second. This
-	 * 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);
+	/* Adjust the clock edge to align with the next full second. */
+	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.21.0


  parent reply	other threads:[~2019-06-28 22:49 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-28 22:49 [net-next 00/15][pull request] Intel Wired LAN Driver Updates 2019-06-28 Jeff Kirsher
2019-06-28 22:49 ` [net-next 01/15] ice: Use struct_size() helper Jeff Kirsher
2019-06-28 22:49 ` [net-next 02/15] e1000e: Increase pause and refresh time Jeff Kirsher
2019-06-28 22:49 ` [net-next 03/15] ixgbe: Avoid NULL pointer dereference with VF on non-IPsec hw Jeff Kirsher
2019-06-28 22:55   ` Shannon Nelson
2019-06-28 22:49 ` Jeff Kirsher [this message]
2019-06-28 22:49 ` [net-next 05/15] e1000: Use dma_wmb() instead of wmb() before doorbell writes Jeff Kirsher
2019-06-28 22:49 ` [net-next 06/15] iavf: use struct_size() helper Jeff Kirsher
2019-06-28 22:49 ` [net-next 07/15] e1000e: Reduce boot time by tightening sleep ranges Jeff Kirsher
2019-06-28 22:49 ` [net-next 08/15] iavf: Fix up debug print macro Jeff Kirsher
2019-06-29 20:42   ` Joe Perches
2019-07-01 17:27     ` Jeff Kirsher
2019-06-28 22:49 ` [net-next 09/15] igb: minor ethool regdump amendment Jeff Kirsher
2019-06-28 22:49 ` [net-next 10/15] igb: add RR2DCDELAY to ethtool registers dump Jeff Kirsher
2019-06-28 22:49 ` [net-next 11/15] iavf: fix dereference of null rx_buffer pointer Jeff Kirsher
2019-06-28 22:49 ` [net-next 12/15] ixgbevf: Use cached link state instead of re-reading the value for ethtool Jeff Kirsher
2019-06-28 22:49 ` [net-next 13/15] i40e: Add macvlan support on i40e Jeff Kirsher
2019-06-28 22:49 ` [net-next 14/15] e1000e: Make watchdog use delayed work Jeff Kirsher
2019-06-28 22:49 ` [net-next 15/15] e1000e: PCIm function state support Jeff Kirsher
2019-06-30 23:05 ` [net-next 00/15][pull request] Intel Wired LAN Driver Updates 2019-06-28 David Miller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190628224932.3389-5-jeffrey.t.kirsher@intel.com \
    --to=jeffrey.t.kirsher@intel.com \
    --cc=andrewx.bowers@intel.com \
    --cc=colin.king@canonical.com \
    --cc=davem@davemloft.net \
    --cc=jacob.e.keller@intel.com \
    --cc=netdev@vger.kernel.org \
    --cc=nhorman@redhat.com \
    --cc=sassmann@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).