Skip to contentSkip to conversation

can: isotp: convert struct tpcon::{idx,len} to unsigned int

RFC PATCH In review Marc Kleine-Budde 2 participants 2 messages Jan 5, 2022

Subsystems (2)
lore
Share & tools
lore

Marc Kleine-Budde

author maintainer
#0 lore raw

RFC PATCH 1/1 can: isotp: convert struct tpcon::{idx,len} to unsigned int

In isotp_rcv_ff() 32 bit of data received over the network is assigned to struct tpcon::len. Later in that function the length is checked for the maximal supported length against MAX_MSG_LENGTH.

As struct tpcon::len is an "int" this check does not work, if the provided length overflows the "int".

Later on struct tpcon::idx is compared against struct tpcon::len.

To fix this problem this patch converts both struct tpcon::{idx,len} to unsigned int.

Fixes e057dd3fc20f ("can: add ISO 15765-2:2016 transport protocol")

\# Cc: [email protected]

---
 net/can/isotp.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
net/can/isotp.c +2 -2
index df6968b28bf4..02cbcb2ecf0d 100644
@@ -119,8 +119,8 @@ enum {
 };
 
 struct tpcon {
-	int idx;
-	int len;
+	unsigned int idx;
+	unsigned int len;
 	u32 state;
 	u8 bs;
 	u8 sn;
Signature · 1 line
2.34.1
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 7 lines · Marc Kleine-Budde

In isotp_rcv_ff() 32 bit of data received over the network is assigned to struct tpcon::len. Later in that function the length is checked for the maximal supported length against MAX_MSG_LENGTH.

As struct tpcon::len is an "int" this check does not work, if the provided length overflows the "int".

Quoted 8 lines

Later on struct tpcon::idx is compared against struct tpcon::len.

To fix this problem this patch converts both struct tpcon::{idx,len} to unsigned int.

Fixes e057dd3fc20f ("can: add ISO 15765-2:2016 transport protocol")

\# Cc: [email protected]
Cc: Oliver Hartkopp <[email protected]>

Thanks Marc!

Quoted 22 lines
---
  net/can/isotp.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
net/can/isotp.c +2 -2
index df6968b28bf4..02cbcb2ecf0d 100644
@@ -119,8 +119,8 @@ enum {
  };
 
  struct tpcon {
-	int idx;
-	int len;
+	unsigned int idx;
+	unsigned int len;
  	u32 state;
  	u8 bs;
  	u8 sn;