event/octeontx: resolve possible integer overflow
PATCH 1/1 event/octeontx: resolve possible integer overflow
The last argument passed to ssovf_parsekv() is an unsigned char*, but it is accessed as an integer. This can lead to an integer overflow.
Hence, make ensure the argument is accessed as a char and for better error handling use strtol instead of atoi.
--- drivers/event/octeontx/ssovf_evdev.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
drivers/event/octeontx/ssovf_evdev.c +10 -2
@@ -719,8 +719,16 @@ ssovf_close(struct rte_eventdev *dev)static int ssovf_parsekv(const char *key __rte_unused, const char *value, void *opaque) { -int *flag = opaque; - *flag = !!atoi (value); +uint8_t *flag = (uint8_t *)opaque; +char *end; + + errno =0 ; + *flag = (uint8_t )strtol (value, &end,2 ); +if ((errno !=0 ) || (value == end)) { +ssovf_log_err ("fail to get key val ret:%d err:%d" , *flag, errno); +return -EINVAL ; + } +return 0 ; }
Signature · 1 line
2.25.1
Quoted 8 lines
The last argument passed to
ssovf_parsekv()is an unsigned char*, but it is accessed as an integer. This can lead to an integer overflow.Hence, make ensure the argument is accessed as a char and for better error handling use strtol instead of atoi.
Signed-off-by Hanumanth Pothula <[email protected]>
Quoted 31 lines
--- drivers/event/octeontx/ssovf_evdev.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)drivers/event/octeontx/ssovf_evdev.c +10
-3@@ -719,8 +719,16 @@ ssovf_close(struct rte_eventdev *dev)static int ssovf_parsekv(const char *key __rte_unused, const char *value, void *opaque) { -int *flag = opaque; - *flag = !!atoi (value); +uint8_t *flag = (uint8_t *)opaque; +char *end; + + errno =0 ; + *flag = (uint8_t )strtol (value, &end,2 ); +if ((errno !=0 ) || (value == end)) { +ssovf_log_err ("fail to get key val ret:%d err:%d" , *flag, errno); +return -EINVAL ; + } +return 0 ; } --2.25.1
Quoted 24 lines · On Fri, 18 Oct 2024 13:29:03 +0530 Hanumanth Pothula <[email protected]>…
The last argument passed to
ssovf_parsekv()is an unsigned char*, but it is accessed as an integer. This can lead to an integer overflow.Hence, make ensure the argument is accessed as a char and for better error handling use strtol instead of atoi.
Signed-off-by Hanumanth Pothula <[email protected]>--- drivers/event/octeontx/ssovf_evdev.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)drivers/event/octeontx/ssovf_evdev.c +2
-2@@ -719,8 +719,16 @@ ssovf_close(struct rte_eventdev *dev)static int ssovf_parsekv(const char *key __rte_unused, const char *value, void *opaque) { -int *flag = opaque; - *flag = !!atoi (value); +uint8_t *flag = (uint8_t *)opaque; +char *end;
drivers/event/octeontx/ssovf_evdev.c ssovf_close(struct rte_eventdev *dev) · line 733
Quoted 10 lines
drivers/event/octeontx/ssovf_evdev.c +8
-0+ + errno =0 ; + *flag = (uint8_t )strtol (value, &end,2 ); +if ((errno !=0 ) || (value == end)) { +ssovf_log_err ("fail to get key val ret:%d err:%d" , *flag, errno); +return -EINVAL ; + } +return 0 ; }
Cast of opaque is unnecessary in C.
Use strtoul to avoid allowing negative numbers.
Passing 2 as argument makes it assume binary so 101 is legal value and returns 5 and it is not helping.
Why not:
drivers/event/octeontx/ssovf_evdev.c +13 -3
@@ -717,10 +717,20 @@ ssovf_close(struct rte_eventdev *dev) }static int -ssovf_parsekv(const char *key __rte_unused, const char *value, void *opaque) +ssovf_parsekv (const char *key,const char *value,void *opaque) { -int *flag = opaque; - *flag = !!atoi (value); +uint8_t *flag = opaque; +unsigned long v; +char *end; + + errno =0 ; + v =strtoul (value, &end,0 ); +if (errno !=0 || end == value || *end !='\0' ) { +ssvf_log_err ("invalid %s value %s" , key, value); +return -EINVAL ; + } + + *flag = !!v;return 0 ; }
PATCH v2 1/1 event/octeontx: resolve possible integer overflow
In reply to Hanumanth PothulaThe last argument passed to ssovf_parsekv() is an unsigned char*, but it is accessed as an integer. This can lead to an integer overflow.
Hence, make ensure the argument is accessed as a char and for better error handling use strtol instead of atoi.
---
v2: use strtoul instead of strtol
--- drivers/event/octeontx/ssovf_evdev.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-)
drivers/event/octeontx/ssovf_evdev.c +13 -3
@@ -717,10 +717,20 @@ ssovf_close(struct rte_eventdev *dev) }static int -ssovf_parsekv(const char *key __rte_unused, const char *value, void *opaque) +ssovf_parsekv (const char *key,const char *value,void *opaque) { -int *flag = opaque; - *flag = !!atoi (value); +uint8_t *flag = opaque; +uint64_t v; +char *end; + + errno =0 ; + v = (uint8_t )strtoul (value, &end,0 ); +if ((errno !=0 ) || (value == end) || *end !='\0' ) { +ssovf_log_err ("invalid %s value %s" , key, value); +return -EINVAL ; + } + + *flag = !!v;return 0 ; }
Signature · 1 line
2.25.1
drivers/event/octeontx/ssovf_evdev.c ssovf_close(struct rte_eventdev *dev) · line 727
Quoted 12 lines · On Wed, 23 Oct 2024 12:45:46 +0530 Hanumanth Pothula <[email protected]>…
static int
drivers/event/octeontx/ssovf_evdev.c +7
-3-ssovf_parsekv(const char *key __rte_unused, const char *value, void *opaque) +ssovf_parsekv(const char *key, const char *value, void *opaque) { - int *flag = opaque; - *flag = !!atoi (value); + uint8_t *flag = opaque; +uint64_t v; +char *end; + + errno =0 ; + v = (uint8_t )strtoul (value, &end,0 );
Cast will cause truncation of large values.
Maybe:
v = strtoul(value, &end, 0);
if (errno != 0 || value == end || *end != '\0' || v > UINT8_MAX) {...
Quoted 8 lines
drivers/event/octeontx/ssovf_evdev.c +6
-0+if ((errno !=0 ) || (value == end) || *end !='\0' ) { +ssovf_log_err ("invalid %s value %s" , key, value); +return -EINVAL ; + } + + *flag = !!v;return 0 ; }
From: Stephen Hemminger <[email protected]>
Sent: Wednesday, October 23, 2024 9:46 PM
To: Hanumanth Reddy Pothula <[email protected]>
Cc: Jerin Jacob <[email protected]>; [email protected]; Harman Kalra <[email protected]>
Subject: [EXTERNAL] Re: [PATCH v2 1/1] event/octeontx: resolve possible integer overflow
On Wed, 23 Oct 2024 12: 45: 46 +0530 Hanumanth Pothula <hpothula@ marvell. com> wrote: > static int > -ssovf_parsekv(const char *key __rte_unused, const char *value, void *opaque) > +ssovf_parsekv(const char *key, const char *value,
On Wed, 23 Oct 2024 12:45:46 +0530
Quoted 13 lines · Hanumanth Pothula <[email protected]<mailto:[email protected]>> wrote:
static int
(quoted diff) +2
-3-ssovf_parsekv(const char *key __rte_unused, const char *value, void *opaque) +ssovf_parsekv(const char *key, const char *value, void *opaque) { - int *flag = opaque; - *flag = !!atoi(value); + uint8_t *flag = opaque;
Review
Quoted 10 lines
(quoted diff) +5
-0+ uint64_t v; + char *end; + + errno = 0; + v = (uint8_t)strtoul(value, &end, 0);
Cast will cause truncation of large values.
Maybe:
v = strtoul(value, &end, 0);
if (errno != 0 || value == end || *end != '\0' || v > UINT8_MAX) {...
Thanks for the review/comment.
Here, the value can only be ‘0’ or ‘1’, so truncation won’t be an issue.
Quoted 15 lines
(quoted diff) +6
-0+ if ((errno != 0) || (value == end) || *end != '\0') { + ssovf_log_err("invalid %s value %s", key, value); + return -EINVAL; + } + + *flag = !!v; return 0; }
PATCH v3 1/1 event/octeontx: resolve possible integer overflow
In reply to Hanumanth PothulaThe last argument passed to ssovf_parsekv() is an unsigned char*, but it is accessed as an integer. This can lead to an integer overflow.
Hence, make ensure the argument is accessed as a char and for better error handling use strtol instead of atoi.
---
v2: use strtoul instead of strtol
v3: Add value boundry check. Here, value can be either 0 or 1.
--- drivers/event/octeontx/ssovf_evdev.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-)
drivers/event/octeontx/ssovf_evdev.c +13 -3
@@ -717,10 +717,20 @@ ssovf_close(struct rte_eventdev *dev) }static int -ssovf_parsekv(const char *key __rte_unused, const char *value, void *opaque) +ssovf_parsekv (const char *key,const char *value,void *opaque) { -int *flag = opaque; - *flag = !!atoi (value); +uint8_t *flag = opaque; +uint64_t v; +char *end; + + errno =0 ; + v =strtoul (value, &end,0 ); +if ((errno !=0 ) || (value == end) || *end !='\0' || v >1 ) { +ssovf_log_err ("invalid %s value %s" , key, value); +return -EINVAL ; + } + + *flag = !!v;return 0 ; }
Signature · 1 line
2.25.1
Quoted 15 lines
-----Original Message-----
From: Hanumanth Pothula <[email protected]>
Sent: Thursday, October 24, 2024 6:55 AM
To: Jerin Jacob <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]
Subject: [PATCH v3 1/1] event/octeontx: resolve possible integer overflowThe last argument passed to
ssovf_parsekv()is an
unsigned char*, but it is accessed as an integer.
This can lead to an integer overflow.Hence, make ensure the argument is accessed as a char and for better error handling use strtol instead of atoi.
Quoted 6 lines
Signed-off-by Hanumanth Pothula <[email protected]>---
v2: use strtoul instead of strtol
v3: Add value boundry check. Here, value can be either 0 or 1.
---
Confirmed that it resolves https://bugs.dpdk.org/show_bug.cgi?id=1512.
Thanks,
Ali
Quoted 9 lines · Ali Alnubani
Quoted 9 lines
-----Original Message-----
From: Hanumanth Pothula <[email protected]>
Sent: Thursday, October 24, 2024 6:55 AM
To: Jerin Jacob <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]
Subject: [PATCH v3 1/1] event/octeontx: resolve possible integer overflow
Quoted 7 lines
Quoted 7 lines
The last argument passed to
ssovf_parsekv()is an
unsigned char*, but it is accessed as an integer.
This can lead to an integer overflow.Hence, make ensure the argument is accessed as a char and for better error handling use strtol instead of atoi.
Add
Bugzilla ID: 1512
And add Fixes: tag
please start the git commit subject with event/octeontx: fix ...
Good to merge next version
Quoted 16 lines
Quoted 6 lines
Signed-off-by Hanumanth Pothula <[email protected]>---
v2: use strtoul instead of strtol
v3: Add value boundry check. Here, value can be either 0 or 1.
---Confirmed that it resolves https://bugs.dpdk.org/show_bug.cgi?id=1512.
Tested-by Ali Alnubani <[email protected]>Thanks,
Ali
PATCH v4 1/1 event/octeontx: fix possible integer overflow
In reply to Hanumanth PothulaThe last argument passed to ssovf_parsekv() is an
unsigned char*, but it is accessed as an integer.
This can lead to an integer overflow.
Hence, make ensure the argument is accessed as a char and for better error handling use strtol instead of atoi.
Bugzilla ID: 1512
---
v2: Use strtoul instead of strtol
v3: Add value boundry check. Here, value can be either 0 or 1.
v4: Commit text update
--- drivers/event/octeontx/ssovf_evdev.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-)
drivers/event/octeontx/ssovf_evdev.c +13 -3
@@ -717,10 +717,20 @@ ssovf_close(struct rte_eventdev *dev) }static int -ssovf_parsekv(const char *key __rte_unused, const char *value, void *opaque) +ssovf_parsekv (const char *key,const char *value,void *opaque) { -int *flag = opaque; - *flag = !!atoi (value); +uint8_t *flag = opaque; +uint64_t v; +char *end; + + errno =0 ; + v =strtoul (value, &end,0 ); +if ((errno !=0 ) || (value == end) || *end !='\0' || v >1 ) { +ssovf_log_err ("invalid %s value %s" , key, value); +return -EINVAL ; + } + + *flag = !!v;return 0 ; }
Signature · 1 line
2.25.1
Re: [PATCH v4 1/1] event/octeontx: fix possible integer overflow
Quoted 5 lines · Hanumanth Pothula
The last argument passed to
ssovf_parsekv()is an
unsigned char*, but it is accessed as an integer.
This can lead to an integer overflow.
Quoted 7 lines
Hence, make ensure the argument is accessed as a char and for better error handling use strtol instead of atoi.
Bugzilla ID: 1512
Fixes 3516327e00fd ("event/octeontx: add selftest to device arguments")Signed-off-by Hanumanth Pothula <[email protected]>
Missed following tag
Applied to dpdk-next-net-mrvl/for-main. Thanks
Quoted 40 lines
---
v2: Use strtoul instead of strtol
v3: Add value boundry check. Here, value can be either 0 or 1.
v4: Commit text update--- drivers/event/octeontx/ssovf_evdev.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-)drivers/event/octeontx/ssovf_evdev.c +13
-4@@ -717,10 +717,20 @@ ssovf_close(struct rte_eventdev *dev) }static int -ssovf_parsekv(const char *key __rte_unused, const char *value, void *opaque) +ssovf_parsekv (const char *key,const char *value,void *opaque) { -int *flag = opaque; - *flag = !!atoi (value); +uint8_t *flag = opaque; +uint64_t v; +char *end; + + errno =0 ; + v =strtoul (value, &end,0 ); +if ((errno !=0 ) || (value == end) || *end !='\0' || v >1 ) { +ssovf_log_err ("invalid %s value %s" , key, value); +return -EINVAL ; + } + + *flag = !!v;return 0 ; } --2.25.1