netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH][next] ixgbe: fix potential u32 overflow on shift
@ 2019-06-06 13:10 Colin King
  2019-06-06 20:33 ` Keller, Jacob E
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Colin King @ 2019-06-06 13:10 UTC (permalink / raw)
  To: Jacob Keller, Jeff Kirsher, David S . Miller, intel-wired-lan, netdev
  Cc: kernel-janitors, linux-kernel

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.

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>
---
 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


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* RE: [PATCH][next] ixgbe: fix potential u32 overflow on shift
  2019-06-06 13:10 [PATCH][next] ixgbe: fix potential u32 overflow on shift Colin King
@ 2019-06-06 20:33 ` Keller, Jacob E
  2019-06-07 17:44 ` Keller, Jacob E
  2019-06-13 21:17 ` [Intel-wired-lan] " Bowers, AndrewX
  2 siblings, 0 replies; 4+ messages in thread
From: Keller, Jacob E @ 2019-06-06 20:33 UTC (permalink / raw)
  To: Colin King, Kirsher, Jeffrey T, David S . Miller,
	intel-wired-lan, netdev
  Cc: kernel-janitors, linux-kernel

> -----Original Message-----
> From: Colin King [mailto:colin.king@canonical.com]
> Sent: Thursday, June 06, 2019 6:11 AM
> To: Keller, Jacob E <jacob.e.keller@intel.com>; Kirsher, Jeffrey T
> <jeffrey.t.kirsher@intel.com>; David S . Miller <davem@davemloft.net>; 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
> 
> 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.
> 

Ah, yep. Thanks for the fix!

> 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>
> ---
>  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);
> 

This makes sense to me.

Regards,
Jake

> @@ -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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: [PATCH][next] ixgbe: fix potential u32 overflow on shift
  2019-06-06 13:10 [PATCH][next] ixgbe: fix potential u32 overflow on shift Colin King
  2019-06-06 20:33 ` Keller, Jacob E
@ 2019-06-07 17:44 ` Keller, Jacob E
  2019-06-13 21:17 ` [Intel-wired-lan] " Bowers, AndrewX
  2 siblings, 0 replies; 4+ messages in thread
From: Keller, Jacob E @ 2019-06-07 17:44 UTC (permalink / raw)
  To: Colin King, Kirsher, Jeffrey T, David S . Miller,
	intel-wired-lan, netdev
  Cc: kernel-janitors, linux-kernel

> -----Original Message-----
> From: Colin King [mailto:colin.king@canonical.com]
> Sent: Thursday, June 06, 2019 6:11 AM
> To: Keller, Jacob E <jacob.e.keller@intel.com>; Kirsher, Jeffrey T
> <jeffrey.t.kirsher@intel.com>; David S . Miller <davem@davemloft.net>; 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
> 
> 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.
> 
> 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>
> ---
>  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.
>  	 */

With this change, the comment above the div_u64 doesn't make much sense. I would also drop the part about the assuming it won't overflow 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.
>  	 */

Same here.

Thanks,
Jake

> -	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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: [Intel-wired-lan] [PATCH][next] ixgbe: fix potential u32 overflow on shift
  2019-06-06 13:10 [PATCH][next] ixgbe: fix potential u32 overflow on shift Colin King
  2019-06-06 20:33 ` Keller, Jacob E
  2019-06-07 17:44 ` Keller, Jacob E
@ 2019-06-13 21:17 ` Bowers, AndrewX
  2 siblings, 0 replies; 4+ messages in thread
From: Bowers, AndrewX @ 2019-06-13 21:17 UTC (permalink / raw)
  To: intel-wired-lan, netdev; +Cc: kernel-janitors, linux-kernel

> -----Original Message-----
> From: Intel-wired-lan [mailto:intel-wired-lan-bounces@osuosl.org] On
> Behalf Of Colin King
> Sent: Thursday, June 6, 2019 6:11 AM
> To: Keller, Jacob E <jacob.e.keller@intel.com>; Kirsher, Jeffrey T
> <jeffrey.t.kirsher@intel.com>; David S . Miller <davem@davemloft.net>;
> intel-wired-lan@lists.osuosl.org; netdev@vger.kernel.org
> Cc: kernel-janitors@vger.kernel.org; linux-kernel@vger.kernel.org
> Subject: [Intel-wired-lan] [PATCH][next] ixgbe: fix potential u32 overflow on
> shift
> 
> 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.
> 
> 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>
> ---
>  drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)

Tested-by: Andrew Bowers <andrewx.bowers@intel.com>


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-06-13 21:18 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-06 13:10 [PATCH][next] ixgbe: fix potential u32 overflow on shift Colin King
2019-06-06 20:33 ` Keller, Jacob E
2019-06-07 17:44 ` Keller, Jacob E
2019-06-13 21:17 ` [Intel-wired-lan] " Bowers, AndrewX

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).