[2/2,net-next] thunderbolt: Right shifting to zero bug in tbnet_handle_packet()
diff mbox series

Message ID 20171017123301.z6heqexdlo6lc52b@mwanda
State Accepted, archived
Delegated to: David Miller
Headers show
Series
  • [1/2,v2,net-next] thunderbolt: Fix a couple right shifting to zero bugs
Related show

Commit Message

Dan Carpenter Oct. 17, 2017, 12:33 p.m. UTC
There is a problem when we do:

	sequence = pkg->hdr.length_sn & TBIP_HDR_SN_MASK;
	sequence >>= TBIP_HDR_SN_SHIFT;

TBIP_HDR_SN_SHIFT is 27, and right shifting a u8 27 bits is always
going to result in zero.  The fix is to declare these variables as u32.

Fixes: e69b6c02b4c3 ("net: Add support for networking over Thunderbolt cable")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

Comments

Bernat, Yehezkel Oct. 17, 2017, 1:17 p.m. UTC | #1
On Tue, 2017-10-17 at 15:33 +0300, Dan Carpenter wrote:
> There is a problem when we do:

> 

> 	sequence = pkg->hdr.length_sn & TBIP_HDR_SN_MASK;

> 	sequence >>= TBIP_HDR_SN_SHIFT;

> 

> TBIP_HDR_SN_SHIFT is 27, and right shifting a u8 27 bits is always

> going to result in zero.  The fix is to declare these variables as

> u32.

> 

> Fixes: e69b6c02b4c3 ("net: Add support for networking over

> Thunderbolt cable")

> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

> 

> diff --git a/drivers/net/thunderbolt.c b/drivers/net/thunderbolt.c

> index 1a7bc0bf4598..435854688a7a 100644

> --- a/drivers/net/thunderbolt.c

> +++ b/drivers/net/thunderbolt.c

> @@ -394,7 +394,7 @@ static int tbnet_handle_packet(const void *buf,

> size_t size, void *data)

>  	struct tbnet *net = data;

>  	u32 command_id;

>  	int ret = 0;

> -	u8 sequence;

> +	u32 sequence;

>  	u64 route;

>  

>  	/* Make sure the packet is for us */


Acked-by: Yehezkel Bernat <yehezkel.bernat@intel.com>


Thanks!
David Miller Oct. 19, 2017, 12:05 p.m. UTC | #2
From: Dan Carpenter <dan.carpenter@oracle.com>
Date: Tue, 17 Oct 2017 15:33:01 +0300

> There is a problem when we do:
> 
> 	sequence = pkg->hdr.length_sn & TBIP_HDR_SN_MASK;
> 	sequence >>= TBIP_HDR_SN_SHIFT;
> 
> TBIP_HDR_SN_SHIFT is 27, and right shifting a u8 27 bits is always
> going to result in zero.  The fix is to declare these variables as u32.
> 
> Fixes: e69b6c02b4c3 ("net: Add support for networking over Thunderbolt cable")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

Applied.

Patch
diff mbox series

diff --git a/drivers/net/thunderbolt.c b/drivers/net/thunderbolt.c
index 1a7bc0bf4598..435854688a7a 100644
--- a/drivers/net/thunderbolt.c
+++ b/drivers/net/thunderbolt.c
@@ -394,7 +394,7 @@  static int tbnet_handle_packet(const void *buf, size_t size, void *data)
 	struct tbnet *net = data;
 	u32 command_id;
 	int ret = 0;
-	u8 sequence;
+	u32 sequence;
 	u64 route;
 
 	/* Make sure the packet is for us */