* [PATCH 1/2 v2 net-next] thunderbolt: Fix a couple right shifting to zero bugs
[not found] <20171013112959.sc2pwazrpk7fxbtw@mwanda>
@ 2017-10-17 12:32 ` Dan Carpenter
2017-10-19 12:04 ` David Miller
2017-10-17 12:33 ` [PATCH 2/2 net-next] thunderbolt: Right shifting to zero bug in tbnet_handle_packet() Dan Carpenter
1 sibling, 1 reply; 5+ messages in thread
From: Dan Carpenter @ 2017-10-17 12:32 UTC (permalink / raw)
To: Andreas Noever
Cc: Michael Jamet, Mika Westerberg, Yehezkel Bernat, netdev,
kernel-janitors
The problematic code looks like this:
res_seq = res_hdr->xd_hdr.length_sn & TB_XDOMAIN_SN_MASK;
res_seq >>= TB_XDOMAIN_SN_SHIFT;
TB_XDOMAIN_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: d1ff70241a27 ("thunderbolt: Add support for XDomain discovery protocol")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
v2: I accidentally sent this through the wrong list, so I'm resending to
netdev. Also Mika asked me to split it up because the Fixes tags
are different for these patches.
diff --git a/drivers/thunderbolt/xdomain.c b/drivers/thunderbolt/xdomain.c
index 138027537d29..ff8d91189e99 100644
--- a/drivers/thunderbolt/xdomain.c
+++ b/drivers/thunderbolt/xdomain.c
@@ -56,7 +56,7 @@ static bool tb_xdomain_match(const struct tb_cfg_request *req,
case TB_CFG_PKG_XDOMAIN_RESP: {
const struct tb_xdp_header *res_hdr = pkg->buffer;
const struct tb_xdp_header *req_hdr = req->request;
- u8 req_seq, res_seq;
+ u32 req_seq, res_seq;
if (pkg->frame.size < req->response_size / 4)
return false;
@@ -476,7 +476,7 @@ static void tb_xdp_handle_request(struct work_struct *work)
struct tb_ctl *ctl = tb->ctl;
const uuid_t *uuid;
int ret = 0;
- u8 sequence;
+ u32 sequence;
u64 route;
route = ((u64)xhdr->route_hi << 32 | xhdr->route_lo) & ~BIT_ULL(63);
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/2 net-next] thunderbolt: Right shifting to zero bug in tbnet_handle_packet()
[not found] <20171013112959.sc2pwazrpk7fxbtw@mwanda>
2017-10-17 12:32 ` [PATCH 1/2 v2 net-next] thunderbolt: Fix a couple right shifting to zero bugs Dan Carpenter
@ 2017-10-17 12:33 ` Dan Carpenter
2017-10-17 13:17 ` Bernat, Yehezkel
2017-10-19 12:05 ` David Miller
1 sibling, 2 replies; 5+ messages in thread
From: Dan Carpenter @ 2017-10-17 12:33 UTC (permalink / raw)
To: Michael Jamet, Amir Levy
Cc: Mika Westerberg, Yehezkel Bernat, netdev, kernel-janitors
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 */
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 2/2 net-next] thunderbolt: Right shifting to zero bug in tbnet_handle_packet()
2017-10-17 12:33 ` [PATCH 2/2 net-next] thunderbolt: Right shifting to zero bug in tbnet_handle_packet() Dan Carpenter
@ 2017-10-17 13:17 ` Bernat, Yehezkel
2017-10-19 12:05 ` David Miller
1 sibling, 0 replies; 5+ messages in thread
From: Bernat, Yehezkel @ 2017-10-17 13:17 UTC (permalink / raw)
To: dan.carpenter@oracle.com, Jamet, Michael, Levy, Amir (Jer)
Cc: mika.westerberg@linux.intel.com, netdev@vger.kernel.org,
davem@davemloft.net, kernel-janitors@vger.kernel.org
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!
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 1/2 v2 net-next] thunderbolt: Fix a couple right shifting to zero bugs
2017-10-17 12:32 ` [PATCH 1/2 v2 net-next] thunderbolt: Fix a couple right shifting to zero bugs Dan Carpenter
@ 2017-10-19 12:04 ` David Miller
0 siblings, 0 replies; 5+ messages in thread
From: David Miller @ 2017-10-19 12:04 UTC (permalink / raw)
To: dan.carpenter
Cc: andreas.noever, michael.jamet, mika.westerberg, yehezkel.bernat,
netdev, kernel-janitors
From: Dan Carpenter <dan.carpenter@oracle.com>
Date: Tue, 17 Oct 2017 15:32:17 +0300
> The problematic code looks like this:
>
> res_seq = res_hdr->xd_hdr.length_sn & TB_XDOMAIN_SN_MASK;
> res_seq >>= TB_XDOMAIN_SN_SHIFT;
>
> TB_XDOMAIN_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: d1ff70241a27 ("thunderbolt: Add support for XDomain discovery protocol")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Applied.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 2/2 net-next] thunderbolt: Right shifting to zero bug in tbnet_handle_packet()
2017-10-17 12:33 ` [PATCH 2/2 net-next] thunderbolt: Right shifting to zero bug in tbnet_handle_packet() Dan Carpenter
2017-10-17 13:17 ` Bernat, Yehezkel
@ 2017-10-19 12:05 ` David Miller
1 sibling, 0 replies; 5+ messages in thread
From: David Miller @ 2017-10-19 12:05 UTC (permalink / raw)
To: dan.carpenter
Cc: michael.jamet, amir.jer.levy, mika.westerberg, yehezkel.bernat,
netdev, kernel-janitors
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.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2017-10-19 12:05 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20171013112959.sc2pwazrpk7fxbtw@mwanda>
2017-10-17 12:32 ` [PATCH 1/2 v2 net-next] thunderbolt: Fix a couple right shifting to zero bugs Dan Carpenter
2017-10-19 12:04 ` David Miller
2017-10-17 12:33 ` [PATCH 2/2 net-next] thunderbolt: Right shifting to zero bug in tbnet_handle_packet() Dan Carpenter
2017-10-17 13:17 ` Bernat, Yehezkel
2017-10-19 12:05 ` David Miller
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).