[v4,1/1] event/octeontx: fix possible integer overflow

Message ID 20241025105802.1099531-1-hpothula@marvell.com (mailing list archive)
State Accepted, archived
Delegated to: Jerin Jacob
Headers
Series [v4,1/1] event/octeontx: fix possible integer overflow |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/loongarch-compilation success Compilation OK
ci/loongarch-unit-testing success Unit Testing PASS
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/github-robot: build success github build: passed
ci/intel-Functional success Functional PASS
ci/iol-marvell-Functional success Functional Testing PASS
ci/iol-unit-arm64-testing success Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-compile-arm64-testing success Testing PASS
ci/iol-sample-apps-testing success Testing PASS
ci/iol-compile-amd64-testing success Testing PASS

Commit Message

Hanumanth Pothula Oct. 25, 2024, 10:58 a.m. UTC
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.

Bugzilla ID: 1512
Fixes: 3516327e00fd ("event/octeontx: add selftest to device arguments")

Signed-off-by: Hanumanth Pothula <hpothula@marvell.com>
---

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

Comments

Jerin Jacob Oct. 28, 2024, 3:31 p.m. UTC | #1
On Fri, Oct 25, 2024 at 4:28 PM Hanumanth Pothula <hpothula@marvell.com> wrote:
>
> 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.
>
> Bugzilla ID: 1512
> Fixes: 3516327e00fd ("event/octeontx: add selftest to device arguments")
>
> Signed-off-by: Hanumanth Pothula <hpothula@marvell.com>

Missed following tag
Tested-by: Ali Alnubani <alialnu@nvidia.com>

Applied to dpdk-next-net-mrvl/for-main. Thanks


> ---
>
> 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(-)
>
> diff --git a/drivers/event/octeontx/ssovf_evdev.c b/drivers/event/octeontx/ssovf_evdev.c
> index 3a933b1db7..957fcab04e 100644
> --- a/drivers/event/octeontx/ssovf_evdev.c
> +++ b/drivers/event/octeontx/ssovf_evdev.c
> @@ -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
>
  

Patch

diff --git a/drivers/event/octeontx/ssovf_evdev.c b/drivers/event/octeontx/ssovf_evdev.c
index 3a933b1db7..957fcab04e 100644
--- a/drivers/event/octeontx/ssovf_evdev.c
+++ b/drivers/event/octeontx/ssovf_evdev.c
@@ -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;
 }