examples/vhost: fix potential overflow in args process
PATCH 1/1 examples/vhost: fix potential overflow in args process
Add args length check to fix potential overflow issue.
Coverity issue: 363741
--- examples/vhost/main.c | 5 +++++ 1 file changed, 5 insertions(+)
examples/vhost/main.c +5 -0
@@ -669,6 +669,11 @@ us_vhost_parse_args(int argc, char **argv)break ;case OPT_DMA_TYPE_NUM : +if (strlen (optarg) >=MAX_LONG_OPT_SZ ) { +RTE_LOG (INFO ,VHOST_CONFIG ,"Wrong DMA type\n" ); +us_vhost_usage (prgname); +return -1 ; + }strcpy (dma_type, optarg);break ;
Signature · 1 line
2.29.2
Quoted 6 lines · Cheng Jiang
Add args length check to fix potential overflow issue.
Coverity issue: 363741
Fixes 965b06f0358 ("examples/vhost: enhance getopt_long usage")
No need for Cc: stable since this issue only affects the current release.
Quoted 2 lines
Signed-off-by Cheng Jiang <[email protected]>
It should indeed fix the coverity report but this limit does not make sense. Could you make dma_type point at either optarg (it should be fine as we only read this string)?
Something like (untested):
examples/vhost/main.c +1 -4
@@ -55,9 +55,6 @@#define INVALID_PORT_ID 0xFF -/* Maximum long option length for option parsing. */ -#define MAX_LONG_OPT_SZ 64 -/* mask of enabled ports */ static uint32_t enabled_port_mask =0 ;
@@ -97,7 +94,7 @@ static int builtin_net_driver;static int async_vhost_driver; -static char dma_type[MAX_LONG_OPT_SZ ]; +static char *dma_type;/* Specify timeout (in useconds) between retries on RX. */ static uint32_t burst_rx_delay_time =BURST_RX_WAIT_US ;
@@ -201,7 +198,7 @@ struct vhost_bufftable *vhost_txbuff[RTE_MAX_LCORE
* MAX_VHOST_DEVICE];
static inline int
open_dma(const char *value)
{
- if (strncmp(dma_type, "ioat", 4) == 0)
+ if (dma_type != NULL && strncmp(dma_type, "ioat", 4) == 0)
return open_ioat(value);
return -1;
@@ -669,7 +666,7 @@ us_vhost_parse_args(int argc, char **argv)
break;
case OPT_DMA_TYPE_NUM:
- strcpy(dma_type, optarg);
+ dma_type = optarg;
break;
case OPT_DMAS_NUM:
@@ -1472,7 +1469,7 @@ new_device(int vid)
struct rte_vhost_async_features f;
struct rte_vhost_async_channel_ops channel_ops;- if (strncmp(dma_type, "ioat", 4) == 0) {
+ if (dma_type != NULL && strncmp(dma_type, "ioat", 4) == 0) {
channel_ops.transfer_data = ioat_transfer_data_cb;
channel_ops.check_completed_copies =
ioat_check_completed_copies_cb;Signature · 1 line
David Marchand
Hi,
Quoted 13 lines
-----Original Message-----
From: David Marchand <[email protected]>
Sent: Monday, April 26, 2021 4:25 PM
To: Jiang, Cheng1 <[email protected]>
Cc: Maxime Coquelin <[email protected]>; Xia, Chenbo <[email protected]>; dev <[email protected]>; dpdk stable <[email protected]>
Subject: Re: [dpdk-stable] [PATCH] examples/vhost: fix potential overflow in args processQuoted 1 line · Cheng Jiang
Quoted 7 lines
Quoted 5 lines
Add args length check to fix potential overflow issue.
Coverity issue: 363741
Fixes 965b06f0358 ("examples/vhost: enhance getopt_long usage")No need for Cc: stable since this issue only affects the current release.
Sure, sorry about that.
Quoted 66 lines
Quoted 3 lines
Signed-off-by Cheng Jiang <[email protected]>It should indeed fix the coverity report but this limit does not make sense. Could you make
dma_typepoint at either optarg (it should be fine as we only read this string)?Something like (untested):
examples/vhost/main.c +2
-5@@ -55,9 +55,6 @@#define INVALID_PORT_ID 0xFF -/* Maximum long option length for option parsing. */ -#define MAX_LONG_OPT_SZ 64 -/* mask of enabled ports */ static uint32_t enabled_port_mask =0 ;@@ -97,7 +94,7 @@ static int builtin_net_driver;static int async_vhost_driver; -static char dma_type[MAX_LONG_OPT_SZ ]; +static char *dma_type;/* Specify timeout (in useconds) between retries on RX. */ static uint32_t burst_rx_delay_time =BURST_RX_WAIT_US ;@@ -201,7 +198,7 @@ struct vhost_bufftable *vhost_txbuff[RTE_MAX_LCORE *MAX_VHOST_DEVICE ];static inline int open_dma (const char *value) { -if (strncmp (dma_type,"ioat" ,4 ) ==0 ) +if (dma_type !=NULL &&strncmp (dma_type,"ioat" ,4 ) ==0 )return open_ioat (value);return -1;examples/vhost/main.c +2
-3@@ -669,7 +666,7 @@ us_vhost_parse_args(int argc, char **argv)break ;case OPT_DMA_TYPE_NUM : -strcpy (dma_type, optarg); + dma_type = optarg;break ;case OPT_DMAS_NUM :@@ -1472,7 +1469,7 @@ new_device(int vid)struct rte_vhost_async_features f;struct rte_vhost_async_channel_ops channel_ops; -if (strncmp (dma_type,"ioat" ,4 ) ==0 ) { +if (dma_type !=NULL &&strncmp (dma_type,"ioat" ,4 ) ==0 ) { channel_ops.transfer_data = ioat_transfer_data_cb; channel_ops.check_completed_copies = ioat_check_completed_copies_cb; --
Quoted 1 line
David Marchand
I think that make sense. I'll send a new version according your comments.
Thanks.
Cheng
PATCH v2 1/1 examples/vhost: fix potential overflow in args process
In reply to Cheng JiangChange the way passing args to fix potential overflow in args process.
Coverity issue: 363741
---
v2:
* Change the way passing args
* Change git log
examples/vhost/main.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-)
examples/vhost/main.c +4 -7
@@ -55,9 +55,6 @@#define INVALID_PORT_ID 0xFF -/* Maximum long option length for option parsing. */ -#define MAX_LONG_OPT_SZ 64 -/* mask of enabled ports */ static uint32_t enabled_port_mask =0 ;
@@ -97,7 +94,7 @@ static int builtin_net_driver;static int async_vhost_driver; -static char dma_type[MAX_LONG_OPT_SZ ]; +static char *dma_type;/* Specify timeout (in useconds) between retries on RX. */ static uint32_t burst_rx_delay_time =BURST_RX_WAIT_US ;
@@ -201,7 +198,7 @@ struct vhost_bufftable *vhost_txbuff[RTE_MAX_LCORE * MAX_VHOST_DEVICE];static inline int open_dma (const char *value) { -if (strncmp (dma_type,"ioat" ,4 ) ==0 ) +if (dma_type !=NULL &&strncmp (dma_type,"ioat" ,4 ) ==0 )return open_ioat (value);return -1 ;
@@ -669,7 +666,7 @@ us_vhost_parse_args(int argc, char **argv)break ;case OPT_DMA_TYPE_NUM : -strcpy (dma_type, optarg); + dma_type = optarg;break ;case OPT_DMAS_NUM :
@@ -1472,7 +1469,7 @@ new_device(int vid)struct rte_vhost_async_features f;struct rte_vhost_async_channel_ops channel_ops; -if (strncmp (dma_type,"ioat" ,4 ) ==0 ) { +if (dma_type !=NULL &&strncmp (dma_type,"ioat" ,4 ) ==0 ) { channel_ops.transfer_data = ioat_transfer_data_cb; channel_ops.check_completed_copies = ioat_check_completed_copies_cb;
--
2.29.2
Quoted 5 lines · Cheng Jiang
Change the way passing args to fix potential overflow in args process.
Coverity issue: 363741
Fixes 965b06f0358 ("examples/vhost: enhance getopt_long usage")
Quoted 9 lines
Signed-off-by Cheng Jiang <[email protected]>---
v2:
* Change the way passing args
* Change git logexamples/vhost/main.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-)
Thanks,
Maxime
Maxime Coquelin
AppliedQuoted 5 lines · Cheng Jiang
Change the way passing args to fix potential overflow in args process.
Coverity issue: 363741
Fixes 965b06f0358 ("examples/vhost: enhance getopt_long usage")
Quoted 9 lines
Signed-off-by Cheng Jiang <[email protected]>---
v2:
* Change the way passing args
* Change git logexamples/vhost/main.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-)
Applied to dpdk-next-virtio/main.
Thanks,
Maxime