fix coverity issues in packet capture framework
PATCH 2/3 pdump: fix string overflow
In reply to Reshma Pattanusing source length in strncpy can cause destination overflow if destination length is not big enough to handle the source string. Changes are made to use destination size instead of source length in strncpy.
Cverity issue 127350: string overflow
--- lib/librte_pdump/rte_pdump.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
lib/librte_pdump/rte_pdump.c +5 -4
@@ -460,8 +460,7 @@ pdump_get_socket_path(char *buffer, int bufsz, enum rte_pdump_socktype type) SOCKET_PATH_HOME, __func__, __LINE__);return -1 ; } - } -else + }else dir =SOCKET_PATH_VAR_RUN ; }
@@ -800,13 +799,15 @@ pdump_prepare_client_request(char *device, uint16_t queue, req.flags = flags; req.op = operation;if ((operation &ENABLE ) !=0 ) { -strncpy (req.data.en_v1.device, device,strlen (device)); +strncpy (req.data.en_v1.device, device, +sizeof (req.data.en_v1.device)-1 ); req.data.en_v1.queue = queue; req.data.en_v1.ring = ring; req.data.en_v1.mp = mp; req.data.en_v1.filter = filter; }else { -strncpy (req.data.dis_v1.device, device,strlen (device)); +strncpy (req.data.dis_v1.device, device, +sizeof (req.data.dis_v1.device)-1 ); req.data.dis_v1.queue = queue; req.data.dis_v1.ring =NULL ; req.data.dis_v1.mp =NULL ;
Signature · 1 line
2.5.0
PATCH 1/3 pdump: check getenv return value
In reply to Reshma Pattangetenv can return a NULL pointer if the match forSOCKET_PATH_HOME is not found in the environment.
NULL check is added to return immediately without
calling mkdir.
Coverity issue 127344: return value check Coverity issue 127347: null pointer dereference
--- lib/librte_pdump/rte_pdump.c | 46 ++++++++++++++++++++++++++++++++++++++------ 1 file changed, 40 insertions(+), 6 deletions(-)
lib/librte_pdump/rte_pdump.c +40 -6
@@ -441,7 +441,7 @@ set_pdump_rxtx_cbs(struct pdump_request *p) }/* get socket path (/var/run if root, $HOME otherwise) */ -static void +static int pdump_get_socket_path (char *buffer,int bufsz,enum rte_pdump_socktype type) {const char *dir =NULL ;
@@ -451,8 +451,16 @@ pdump_get_socket_path(char *buffer, int bufsz, enum rte_pdump_socktype type)else if (type ==RTE_PDUMP_SOCKET_CLIENT && client_socket_dir[0 ] !=0 ) dir = client_socket_dir;else { -if (getuid () !=0 ) +if (getuid () !=0 ) { dir =getenv (SOCKET_PATH_HOME ); +if (!dir) { +RTE_LOG (ERR ,PDUMP , +"Failed to get environment variable" +"value for %s, %s:%d\n" , +SOCKET_PATH_HOME , __func__, __LINE__); +return -1 ; + } + }else dir =SOCKET_PATH_VAR_RUN ; }
@@ -463,6 +471,8 @@ pdump_get_socket_path(char *buffer, int bufsz, enum rte_pdump_socktype type)else snprintf (buffer, bufsz,CLIENT_SOCKET , dir,getpid (),rte_sys_gettid ()); + +return 0 ; } static int
@@ -472,8 +482,14 @@ pdump_create_server_socket(void)struct sockaddr_un addr;socklen_t addr_len; -pdump_get_socket_path (addr.sun_path,sizeof (addr.sun_path), + ret =pdump_get_socket_path (addr.sun_path,sizeof (addr.sun_path),RTE_PDUMP_SOCKET_SERVER ); +if (ret !=0 ) { +RTE_LOG (ERR ,PDUMP , +"Failed to get server socket path: %s:%d\n" , + __func__, __LINE__); +return -1 ; + } addr.sun_family =AF_UNIX ;/* remove if file already exists */
@@ -604,8 +620,14 @@ rte_pdump_uninit(void)struct sockaddr_un addr; -pdump_get_socket_path (addr.sun_path,sizeof (addr.sun_path), + ret =pdump_get_socket_path (addr.sun_path,sizeof (addr.sun_path),RTE_PDUMP_SOCKET_SERVER ); +if (ret !=0 ) { +RTE_LOG (ERR ,PDUMP , +"Failed to get server socket path: %s:%d\n" , + __func__, __LINE__); +return -1 ; + } ret =unlink (addr.sun_path);if (ret !=0 ) { RTE_LOG(ERR, PDUMP,
@@ -639,8 +661,14 @@ pdump_create_client_socket(struct pdump_request *p)return ret; } -pdump_get_socket_path (addr.sun_path,sizeof (addr.sun_path), + ret =pdump_get_socket_path (addr.sun_path,sizeof (addr.sun_path),RTE_PDUMP_SOCKET_CLIENT ); +if (ret !=0 ) { +RTE_LOG (ERR ,PDUMP , +"Failed to get client socket path: %s:%d\n" , + __func__, __LINE__); +return -1 ; + } addr.sun_family =AF_UNIX ; addr_len =sizeof (struct sockaddr_un );
@@ -656,9 +684,15 @@ pdump_create_client_socket(struct pdump_request *p) serv_len =sizeof (struct sockaddr_un );memset (&serv_addr,0 ,sizeof (serv_addr)); -pdump_get_socket_path (serv_addr.sun_path, + ret =pdump_get_socket_path (serv_addr.sun_path,sizeof (serv_addr.sun_path),RTE_PDUMP_SOCKET_SERVER ); +if (ret !=0 ) { +RTE_LOG (ERR ,PDUMP , +"Failed to get server socket path: %s:%d\n" , + __func__, __LINE__); +break ; + } serv_addr.sun_family =AF_UNIX ; n = sendto(socket_fd, p, sizeof(struct pdump_request), 0,
Signature · 1 line
2.5.0
cover fix coverity issues in packet capture framework
This patchset fixes coverity issues in pdump library and pdump tool.
Reshma Pattan (3):
pdump: check getenv return value
pdump: fix string overflow
app/pdump: fix string overflow
app/pdump/main.c | 4 ++-- lib/librte_pdump/rte_pdump.c | 53 ++++++++++++++++++++++++++++++++++++-------- 2 files changed, 46 insertions(+), 11 deletions(-)
Signature · 1 line
2.5.0
PATCH 3/3 app/pdump: fix string overflow
using source length in strncpy can cause destination overflow if destination length is not big enough to handle the source string. Changes are made to use destination size instead of source length in strncpy.
Coverity issue 127351: string overflow
--- app/pdump/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
app/pdump/main.c +2 -2
@@ -217,12 +217,12 @@ parse_rxtxdev(const char *key, const char *value, void *extra_args)struct pdump_tuples *pt = extra_args;if (!strcmp (key,PDUMP_RX_DEV_ARG )) { -strncpy (pt->rx_dev, value,strlen (value)); +strncpy (pt->rx_dev, value,sizeof (pt->rx_dev)-1 );/* identify the tx stream type for pcap vdev */ if (if_nametoindex (pt->rx_dev)) pt->rx_vdev_stream_type =IFACE ; }else if (!strcmp (key,PDUMP_TX_DEV_ARG )) { -strncpy (pt->tx_dev, value,strlen (value)); +strncpy (pt->tx_dev, value,sizeof (pt->tx_dev)-1 );/* identify the tx stream type for pcap vdev */ if (if_nametoindex (pt->tx_dev)) pt->tx_vdev_stream_type =IFACE ;
Signature · 1 line
2.5.0
Re: [PATCH 1/3] pdump: check getenv return value
In reply to Reshma PattanQuoted 12 lines · Reshma Pattan
getenv can return a NULL pointer if the match for
SOCKET_PATH_HOMEis not found in the environment.
NULL check is added to return immediately without
calling mkdir.Coverity issue 127344: return value check Coverity issue 127347: null pointer dereferenceFixes 278f945402c5 ("pdump: add new library for packet capture")Fixes 278f945402c5 ("pdump: add new library for packet capture")Signed-off-by Reshma Pattan <[email protected]>
...
Quoted 9 lines
/* get socket path (
/var/runif root, $HOME otherwise) */lib/librte_pdump/rte_pdump.c +1
-1-static void +static int pdump_get_socket_path (char *buffer,int bufsz,enum rte_pdump_socktype type) {const char *dir =NULL ;@@ -451,8 +451,16 @@ pdump_get_socket_path(char *buffer, int bufsz, enum rte_pdump_socktype type)else if (type ==RTE_PDUMP_SOCKET_CLIENT && client_socket_dir[0 ] !=0 ) dir = client_socket_dir;
lib/librte_pdump/rte_pdump.c pdump_get_socket_path(char *buffer, int bufsz, enum rte_pdump_socktype type) · line 461
Quoted 10 lines
lib/librte_pdump/rte_pdump.c +7
-1else { -if (getuid () !=0 ) +if (getuid () !=0 ) { dir =getenv (SOCKET_PATH_HOME ); +if (!dir) { +RTE_LOG (ERR ,PDUMP , +"Failed to get environment variable" +"value for %s, %s:%d\n" , +SOCKET_PATH_HOME , __func__, __LINE__); +return -1 ;
Instead of failing, does it make sense to fallback to a default path? Is it possible that sometimes end user doesn't really care where socket created as long as it created and runs smoothly?
Re: [PATCH 2/3] pdump: fix string overflow
In reply to Reshma PattanQuoted 19 lines · Reshma Pattan
using source length in strncpy can cause destination overflow if destination length is not big enough to handle the source string. Changes are made to use destination size instead of source length in strncpy.
Cverity issue 127350: string overflow
Fixes 278f945402c5 ("pdump: add new library for packet capture")Signed-off-by Reshma Pattan <[email protected]>--- lib/librte_pdump/rte_pdump.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)lib/librte_pdump/rte_pdump.c +0
-0
lib/librte_pdump/rte_pdump.c pdump_get_socket_path(char *buffer, int bufsz, enum rte_pdump_socktype type) · line 463
Quoted 6 lines
lib/librte_pdump/rte_pdump.c +1
-2@@ -460,8 +460,7 @@ pdump_get_socket_path(char *buffer, int bufsz, enum rte_pdump_socktype type) SOCKET_PATH_HOME, __func__, __LINE__);return -1 ; } - } -else + }else
syntax fix may be not belong to this patch
lib/librte_pdump/rte_pdump.c pdump_prepare_client_request(char *device, uint16_t queue, · line 803
Quoted 10 lines
lib/librte_pdump/rte_pdump.c +2
-1dir =SOCKET_PATH_VAR_RUN ; }@@ -800,13 +799,15 @@ pdump_prepare_client_request(char *device, uint16_t queue, req.flags = flags; req.op = operation;if ((operation &ENABLE ) !=0 ) { -strncpy (req.data.en_v1.device, device,strlen (device)); +strncpy (req.data.en_v1.device, device, +sizeof (req.data.en_v1.device)-1 );
"-" missing spaces around
Re: [PATCH 3/3] app/pdump: fix string overflow
In reply to Reshma PattanQuoted 19 lines · Reshma Pattan
using source length in strncpy can cause destination overflow if destination length is not big enough to handle the source string. Changes are made to use destination size instead of source length in strncpy.
Coverity issue 127351: string overflow
Fixes caa7028276b8 ("app/pdump: add tool for packet capturing")Signed-off-by Reshma Pattan <[email protected]>--- app/pdump/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)app/pdump/main.c +0
-0
app/pdump/main.c parse_rxtxdev(const char *key, const char *value, void *extra_args) · line 220
Quoted 5 lines
app/pdump/main.c +1
-1@@ -217,12 +217,12 @@ parse_rxtxdev(const char *key, const char *value, void *extra_args)struct pdump_tuples *pt = extra_args;if (!strcmp (key,PDUMP_RX_DEV_ARG )) { -strncpy (pt->rx_dev, value,strlen (value)); +strncpy (pt->rx_dev, value,sizeof (pt->rx_dev)-1 );
I guess size-1 is to give room for terminating null byte, but for this case is it guarantied that pt->rx_dev last byte is NULL?
Re: [PATCH 3/3] app/pdump: fix string overflow
app/pdump/main.c parse_rxtxdev(const char *key, const char *value, void *extra_args) · line 220
Quoted 3 lines
if (!strcmp(key, PDUMP_RX_DEV_ARG)) {app/pdump/main.c +1
-1-strncpy (pt->rx_dev, value,strlen (value)); +strncpy (pt->rx_dev, value,sizeof (pt->rx_dev)-1 );
I guess size-1 is to give room for terminating null byte, but for this case is it guarantied that pt->rx_dev last byte is NULL?
why not just use a snprintf(...) here since it has better error behavior ? although compared to str*cpy it might be a bit slow, but hopefully that should be ok ?
--
thanks
anupam
Quoted 31 lines · Ferruh Yigit
app/pdump/main.c parse_rxtxdev(const char *key, const char *value,
Quoted 19 lines · Reshma Pattan
using source length in strncpy can cause destination overflow if destination length is not big enough to handle the source string. Changes are made to use destination size instead of source length in strncpy.
Coverity issue 127351: string overflow
Fixes caa7028276b8 ("app/pdump: add tool for packet capturing")Signed-off-by Reshma Pattan <[email protected]>--- app/pdump/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)app/pdump/main.c +0
-0@@ -217,12 +217,12 @@ parse_rxtxdev(const char *key, const char *value,void
*extra_args)app/pdump/main.c parse_rxtxdev(const char *key, const char *value, void *extra_args) · line 220
Quoted 5 lines
app/pdump/main.c +1
-1struct pdump_tuples *pt = extra_args;if (!strcmp (key,PDUMP_RX_DEV_ARG )) { -strncpy (pt->rx_dev, value,strlen (value)); +strncpy (pt->rx_dev, value,sizeof (pt->rx_dev)-1 );I guess size-1 is to give room for terminating null byte, but for this case is it guarantied that
pt->rx_devlast byte is NULL?
Signature · 2 lines
In the beginning was the lambda, and the lambda was with Emacs, and Emacs was the lambda.
Re: [PATCH 1/3] pdump: check getenv return value
In reply to Ferruh YigitHi Ferruh,
Quoted 18 lines
-----Original Message-----
From: Yigit, Ferruh
Sent: Tuesday, June 21, 2016 5:56 PM
To: Pattan, Reshma <[email protected]>; [email protected]
Subject: Re: [dpdk-dev] [PATCH 1/3] pdump: check getenv return valuelib/librte_pdump/rte_pdump.c pdump_get_socket_path(char *buffer, int bufsz, enum rte_pdump_socktype type)
Quoted 10 lines · Reshma Pattan
lib/librte_pdump/rte_pdump.c +6
-1dir = client_socket_dir; else { -if (getuid () !=0 ) +if (getuid () !=0 ) { dir =getenv (SOCKET_PATH_HOME ); +if (!dir) { + RTE_LOG(ERR, PDUMP, + "Failed to get environment variable" + "value for %s, %s:%d\n", + SOCKET_PATH_HOME, __func__,
__LINE__);
Quoted 6 lines
Review
Quoted 1 line
(quoted diff) +1
-0+ return -1;Instead of failing, does it make sense to fallback to a default path? Is it possible that sometimes end user doesn't really care where socket created as long as it created and runs smoothly?
This is for default path only.
Thanks,
Reshma
Re: [PATCH 3/3] app/pdump: fix string overflow
In reply to Anupam KapoorQuoted 11 lines · Anupam Kapoor
app/pdump/main.c parse_rxtxdev(const char *key, const char *value, void *extra_args) · line 220
Quoted 3 lines
if (!strcmp(key, PDUMP_RX_DEV_ARG)) {app/pdump/main.c +1
-1-strncpy (pt->rx_dev, value,strlen (value)); +strncpy (pt->rx_dev, value,sizeof (pt->rx_dev)-1 );I guess size-1 is to give room for terminating null byte, but for this case is it guarantied that
pt->rx_devlast byte is NULL?why not just use a snprintf(...) here since it has better error behavior ? although compared to str*cpy it might be a bit slow, but hopefully that should be ok ?
Definite +1. For safely copying strings I think snprintf is often the easiest API to use.
/Bruce
Quoted 44 lines
--
thanks
anupamQuoted 31 lines · Ferruh Yigit
app/pdump/main.c parse_rxtxdev(const char *key, const char *value,
Quoted 19 lines · Reshma Pattan
using source length in strncpy can cause destination overflow if destination length is not big enough to handle the source string. Changes are made to use destination size instead of source length in strncpy.
Coverity issue 127351: string overflow
Fixes caa7028276b8 ("app/pdump: add tool for packet capturing")Signed-off-by Reshma Pattan <[email protected]>--- app/pdump/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)app/pdump/main.c +0
-0@@ -217,12 +217,12 @@ parse_rxtxdev(const char *key, const char *value,void
*extra_args)app/pdump/main.c parse_rxtxdev(const char *key, const char *value, void *extra_args) · line 220
Quoted 5 lines
app/pdump/main.c +1
-1struct pdump_tuples *pt = extra_args;if (!strcmp (key,PDUMP_RX_DEV_ARG )) { -strncpy (pt->rx_dev, value,strlen (value)); +strncpy (pt->rx_dev, value,sizeof (pt->rx_dev)-1 );I guess size-1 is to give room for terminating null byte, but for this case is it guarantied that
pt->rx_devlast byte is NULL?Signature · 2 lines
In the beginning was the lambda, and the lambda was with Emacs, and Emacs was the lambda.
Re: [PATCH 3/3] app/pdump: fix string overflow
Hi,
Quoted 16 lines
-----Original Message-----
From: Richardson, Bruce
Sent: Wednesday, June 22, 2016 10:22 AM
To: Anupam Kapoor <[email protected]>
Cc: Yigit, Ferruh <[email protected]>; Pattan, Reshma <[email protected]>; [email protected]
Subject: Re: [dpdk-dev] [PATCH 3/3] app/pdump: fix string overflowQuoted 7 lines · Anupam Kapoor
app/pdump/main.c parse_rxtxdev(const char *key, const char *value, void *extra_args) · line 220
Quoted 3 lines
if (!strcmp(key, PDUMP_RX_DEV_ARG)) {app/pdump/main.c +1
-1-strncpy (pt->rx_dev, value,strlen (value)); +strncpy (pt->rx_dev, value,sizeof (pt->rx_dev)-1 );I guess size-1 is to give room for terminating null byte, but for this case is it guarantied that
pt->rx_devlast byte is NULL?
Quoted 8 lines
Quoted 4 lines
why not just use a snprintf(...) here since it has better error behavior ? although compared to str*cpy it might be a bit slow, but hopefully that should be ok ?
Definite +1. For safely copying strings I think snprintf is often the easiest API to use.
Ok, will make the changes.
Thanks,
Reshma
PATCH v2 1/3 pdump: check getenv return value
In reply to Reshma Pattaninside pdump_get_socket_path(), getenv can return a NULL pointer if the match for SOCKET_PATH_HOME is not found in the environment. NULL check is added to return -1 immediately without calling mkdir. Since pdump_get_socket_path() returns -1 now, wherever this function is called there the return value is checked and error message is logged.
Coverity issue 127344: return value check Coverity issue 127347: null pointer dereference
--- lib/librte_pdump/rte_pdump.c | 47 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 40 insertions(+), 7 deletions(-)
lib/librte_pdump/rte_pdump.c +40 -7
@@ -441,7 +441,7 @@ set_pdump_rxtx_cbs(struct pdump_request *p) }/* get socket path (/var/run if root, $HOME otherwise) */ -static void +static int pdump_get_socket_path (char *buffer,int bufsz,enum rte_pdump_socktype type) {const char *dir =NULL ;
@@ -451,9 +451,16 @@ pdump_get_socket_path(char *buffer, int bufsz, enum rte_pdump_socktype type)else if (type ==RTE_PDUMP_SOCKET_CLIENT && client_socket_dir[0 ] !=0 ) dir = client_socket_dir;else { -if (getuid () !=0 ) +if (getuid () !=0 ) { dir =getenv (SOCKET_PATH_HOME ); -else +if (!dir) { +RTE_LOG (ERR ,PDUMP , +"Failed to get environment variable" +" value for %s, %s:%d\n" , +SOCKET_PATH_HOME , __func__, __LINE__); +return -1 ; + } + }else dir =SOCKET_PATH_VAR_RUN ; }
@@ -463,6 +470,8 @@ pdump_get_socket_path(char *buffer, int bufsz, enum rte_pdump_socktype type)else snprintf (buffer, bufsz,CLIENT_SOCKET , dir,getpid (),rte_sys_gettid ()); + +return 0 ; } static int
@@ -472,8 +481,14 @@ pdump_create_server_socket(void)struct sockaddr_un addr;socklen_t addr_len; -pdump_get_socket_path (addr.sun_path,sizeof (addr.sun_path), + ret =pdump_get_socket_path (addr.sun_path,sizeof (addr.sun_path),RTE_PDUMP_SOCKET_SERVER ); +if (ret !=0 ) { +RTE_LOG (ERR ,PDUMP , +"Failed to get server socket path: %s:%d\n" , + __func__, __LINE__); +return -1 ; + } addr.sun_family =AF_UNIX ;/* remove if file already exists */
@@ -604,8 +619,14 @@ rte_pdump_uninit(void)struct sockaddr_un addr; -pdump_get_socket_path (addr.sun_path,sizeof (addr.sun_path), + ret =pdump_get_socket_path (addr.sun_path,sizeof (addr.sun_path),RTE_PDUMP_SOCKET_SERVER ); +if (ret !=0 ) { +RTE_LOG (ERR ,PDUMP , +"Failed to get server socket path: %s:%d\n" , + __func__, __LINE__); +return -1 ; + } ret =unlink (addr.sun_path);if (ret !=0 ) { RTE_LOG(ERR, PDUMP,
@@ -639,8 +660,14 @@ pdump_create_client_socket(struct pdump_request *p)return ret; } -pdump_get_socket_path (addr.sun_path,sizeof (addr.sun_path), + ret =pdump_get_socket_path (addr.sun_path,sizeof (addr.sun_path),RTE_PDUMP_SOCKET_CLIENT ); +if (ret !=0 ) { +RTE_LOG (ERR ,PDUMP , +"Failed to get client socket path: %s:%d\n" , + __func__, __LINE__); +return -1 ; + } addr.sun_family =AF_UNIX ; addr_len =sizeof (struct sockaddr_un );
@@ -656,9 +683,15 @@ pdump_create_client_socket(struct pdump_request *p) serv_len =sizeof (struct sockaddr_un );memset (&serv_addr,0 ,sizeof (serv_addr)); -pdump_get_socket_path (serv_addr.sun_path, + ret =pdump_get_socket_path (serv_addr.sun_path,sizeof (serv_addr.sun_path),RTE_PDUMP_SOCKET_SERVER ); +if (ret !=0 ) { +RTE_LOG (ERR ,PDUMP , +"Failed to get server socket path: %s:%d\n" , + __func__, __LINE__); +break ; + } serv_addr.sun_family =AF_UNIX ; n = sendto(socket_fd, p, sizeof(struct pdump_request), 0,
Signature · 1 line
2.5.0
v2 cover fix coverity issues in packet capture framework
In reply to Reshma PattanThis patchset fixes coverity issues in pdump library and pdump tool.
v2:
fixed code review comment to use snprintf instead of strncpy.
Reshma Pattan (3):
pdump: check getenv return value
pdump: fix string overflow
app/pdump: fix string overflow
app/pdump/main.c | 4 ++-- lib/librte_pdump/rte_pdump.c | 53 ++++++++++++++++++++++++++++++++++++-------- 2 files changed, 46 insertions(+), 11 deletions(-)
Signature · 1 line
2.5.0
PATCH v2 2/3 pdump: fix string overflow
replaced strncpy with snprintf for safely
copying the strings.
Cverity issue 127350: string overflow
--- lib/librte_pdump/rte_pdump.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
lib/librte_pdump/rte_pdump.c +4 -2
@@ -799,13 +799,15 @@ pdump_prepare_client_request(char *device, uint16_t queue, req.flags = flags; req.op = operation;if ((operation &ENABLE ) !=0 ) { -strncpy (req.data.en_v1.device, device,strlen (device)); +snprintf (req.data.en_v1.device,sizeof (req.data.en_v1.device), +"%s" , device); req.data.en_v1.queue = queue; req.data.en_v1.ring = ring; req.data.en_v1.mp = mp; req.data.en_v1.filter = filter; }else { -strncpy (req.data.dis_v1.device, device,strlen (device)); +snprintf (req.data.dis_v1.device,sizeof (req.data.dis_v1.device), +"%s" , device); req.data.dis_v1.queue = queue; req.data.dis_v1.ring =NULL ; req.data.dis_v1.mp =NULL ;
Signature · 1 line
2.5.0
PATCH v2 3/3 app/pdump: fix string overflow
In reply to Reshma Pattanreplaced strncpy with snprintf for safely
copying the strings.
Coverity issue 127351: string overflow
--- app/pdump/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
app/pdump/main.c +2 -2
@@ -217,12 +217,12 @@ parse_rxtxdev(const char *key, const char *value, void *extra_args)struct pdump_tuples *pt = extra_args;if (!strcmp (key,PDUMP_RX_DEV_ARG )) { -strncpy (pt->rx_dev, value,strlen (value)); +snprintf (pt->rx_dev,sizeof (pt->rx_dev),"%s" , value);/* identify the tx stream type for pcap vdev */ if (if_nametoindex (pt->rx_dev)) pt->rx_vdev_stream_type =IFACE ; }else if (!strcmp (key,PDUMP_TX_DEV_ARG )) { -strncpy (pt->tx_dev, value,strlen (value)); +snprintf (pt->tx_dev,sizeof (pt->tx_dev),"%s" , value);/* identify the tx stream type for pcap vdev */ if (if_nametoindex (pt->tx_dev)) pt->tx_vdev_stream_type =IFACE ;
Signature · 1 line
2.5.0
PATCH v3 3/4 pdump: fix string overflow
In reply to Reshma Pattanreplaced strncpy with snprintf for safely
copying the strings.
Cverity issue 127350: string overflow
--- lib/librte_pdump/rte_pdump.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
lib/librte_pdump/rte_pdump.c +4 -2
@@ -804,13 +804,15 @@ pdump_prepare_client_request(char *device, uint16_t queue, req.flags = flags; req.op = operation;if ((operation &ENABLE ) !=0 ) { -strncpy (req.data.en_v1.device, device,strlen (device)); +snprintf (req.data.en_v1.device,sizeof (req.data.en_v1.device), +"%s" , device); req.data.en_v1.queue = queue; req.data.en_v1.ring = ring; req.data.en_v1.mp = mp; req.data.en_v1.filter = filter; }else { -strncpy (req.data.dis_v1.device, device,strlen (device)); +snprintf (req.data.dis_v1.device,sizeof (req.data.dis_v1.device), +"%s" , device); req.data.dis_v1.queue = queue; req.data.dis_v1.ring =NULL ; req.data.dis_v1.mp =NULL ;
Signature · 1 line
2.5.0
v3 cover fix issues in packet capture framework
In reply to Reshma PattanThis patchset includes listed fixes
1)fix default socket path in pdump library.
2)fix coverity issues in pdump library.
3)fix coverity issues in pdump tool.
v3:
added new patch for fixing default socket paths "HOME" and "/var/run". reworked coverity fixes on top of the above change.
v2:
fixed code review comment to use snprintf instead of strncpy.
Reshma Pattan (4):
pdump: fix default socket path
pdump: check getenv return value
pdump: fix string overflow
app/pdump: fix string overflow
app/pdump/main.c | 4 +-- lib/librte_pdump/rte_pdump.c | 72 ++++++++++++++++++++++++++++++++++---------- 2 files changed, 58 insertions(+), 18 deletions(-)
Signature · 1 line
2.5.0
PATCH v3 4/4 app/pdump: fix string overflow
replaced strncpy with snprintf for safely
copying the strings.
Coverity issue 127351: string overflow
--- app/pdump/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
app/pdump/main.c +2 -2
@@ -217,12 +217,12 @@ parse_rxtxdev(const char *key, const char *value, void *extra_args)struct pdump_tuples *pt = extra_args;if (!strcmp (key,PDUMP_RX_DEV_ARG )) { -strncpy (pt->rx_dev, value,strlen (value)); +snprintf (pt->rx_dev,sizeof (pt->rx_dev),"%s" , value);/* identify the tx stream type for pcap vdev */ if (if_nametoindex (pt->rx_dev)) pt->rx_vdev_stream_type =IFACE ; }else if (!strcmp (key,PDUMP_TX_DEV_ARG )) { -strncpy (pt->tx_dev, value,strlen (value)); +snprintf (pt->tx_dev,sizeof (pt->tx_dev),"%s" , value);/* identify the tx stream type for pcap vdev */ if (if_nametoindex (pt->tx_dev)) pt->tx_vdev_stream_type =IFACE ;
Signature · 1 line
2.5.0
PATCH v3 1/4 pdump: fix default socket path
In reply to Reshma PattanSOCKET_PATH_HOME is to specify environment variable "HOME", so it should not contain "/pdump_sockets" in the macro. So remove "/pdump_sockets" from SOCKET_PATH_HOME and create new macro for "/pdump_sockets". Similary removed "/pdump_sockets" from SOCKET_PATH_VAR_RUN.
Changes are done in pdump_get_socket_path() to accommodate new socket path changes.
--- lib/librte_pdump/rte_pdump.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-)
lib/librte_pdump/rte_pdump.c +13 -9
@@ -50,8 +50,9 @@#include "rte_pdump.h" -#define SOCKET_PATH_VAR_RUN "/var/run/pdump_sockets" -#define SOCKET_PATH_HOME "HOME/pdump_sockets" +#define SOCKET_PATH_VAR_RUN "/var/run" +#define SOCKET_PATH_HOME "HOME" +#define SOCKET_DIR "/pdump_sockets"#define SERVER_SOCKET "%s/pdump_server_socket"#define CLIENT_SOCKET "%s/pdump_client_socket_%d_%u"#define DEVICE_ID_SIZE 64
@@ -444,17 +445,20 @@ set_pdump_rxtx_cbs(struct pdump_request *p)static void pdump_get_socket_path (char *buffer,int bufsz,enum rte_pdump_socktype type) { -const char *dir =NULL ; +char dir[PATH_MAX ] = {0 }; +char *dir_home =NULL ;if (type ==RTE_PDUMP_SOCKET_SERVER && server_socket_dir[0 ] !=0 ) - dir = server_socket_dir; +snprintf (dir,sizeof (dir),"%s" , server_socket_dir);else if (type ==RTE_PDUMP_SOCKET_CLIENT && client_socket_dir[0 ] !=0 ) - dir = client_socket_dir; +snprintf (dir,sizeof (dir),"%s" , client_socket_dir);else { -if (getuid () !=0 ) - dir =getenv (SOCKET_PATH_HOME ); -else - dir =SOCKET_PATH_VAR_RUN ; +if (getuid () !=0 ) { + dir_home =getenv (SOCKET_PATH_HOME ); +strcat (dir, dir_home); + }else +strcat (dir,SOCKET_PATH_VAR_RUN ); +strcat (dir,SOCKET_DIR ); }mkdir (dir,700 );
Signature · 1 line
2.5.0
PATCH v3 2/4 pdump: check getenv return value
In reply to Reshma Pattaninside pdump_get_socket_path(), getenv can return a NULL pointer if the match for SOCKET_PATH_HOME is not found in the environment. NULL check is added to return -1 immediately. Since pdump_get_socket_path() returns -1 now, wherever this function is called there the return value is checked and error message is logged.
Coverity issue 127344: return value check Coverity issue 127347: null pointer dereference
--- lib/librte_pdump/rte_pdump.c | 44 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 39 insertions(+), 5 deletions(-)
lib/librte_pdump/rte_pdump.c +39 -5
@@ -442,7 +442,7 @@ set_pdump_rxtx_cbs(struct pdump_request *p) }/* get socket path (/var/run if root, $HOME otherwise) */ -static void +static int pdump_get_socket_path (char *buffer,int bufsz,enum rte_pdump_socktype type) {char dir[PATH_MAX ] = {0 };
@@ -455,9 +455,17 @@ pdump_get_socket_path(char *buffer, int bufsz, enum rte_pdump_socktype type)else {if (getuid () !=0 ) { dir_home =getenv (SOCKET_PATH_HOME ); +if (!dir_home) { +RTE_LOG (ERR ,PDUMP , +"Failed to get environment variable" +" value for %s, %s:%d\n" , +SOCKET_PATH_HOME , __func__, __LINE__); +return -1 ; + }strcat (dir, dir_home); }else strcat (dir,SOCKET_PATH_VAR_RUN ); +strcat (dir,SOCKET_DIR ); }
@@ -467,6 +475,8 @@ pdump_get_socket_path(char *buffer, int bufsz, enum rte_pdump_socktype type)else snprintf (buffer, bufsz,CLIENT_SOCKET , dir,getpid (),rte_sys_gettid ()); + +return 0 ; } static int
@@ -476,8 +486,14 @@ pdump_create_server_socket(void)struct sockaddr_un addr;socklen_t addr_len; -pdump_get_socket_path (addr.sun_path,sizeof (addr.sun_path), + ret =pdump_get_socket_path (addr.sun_path,sizeof (addr.sun_path),RTE_PDUMP_SOCKET_SERVER ); +if (ret !=0 ) { +RTE_LOG (ERR ,PDUMP , +"Failed to get server socket path: %s:%d\n" , + __func__, __LINE__); +return -1 ; + } addr.sun_family =AF_UNIX ;/* remove if file already exists */
@@ -608,8 +624,14 @@ rte_pdump_uninit(void)struct sockaddr_un addr; -pdump_get_socket_path (addr.sun_path,sizeof (addr.sun_path), + ret =pdump_get_socket_path (addr.sun_path,sizeof (addr.sun_path),RTE_PDUMP_SOCKET_SERVER ); +if (ret !=0 ) { +RTE_LOG (ERR ,PDUMP , +"Failed to get server socket path: %s:%d\n" , + __func__, __LINE__); +return -1 ; + } ret =unlink (addr.sun_path);if (ret !=0 ) { RTE_LOG(ERR, PDUMP,
@@ -643,8 +665,14 @@ pdump_create_client_socket(struct pdump_request *p)return ret; } -pdump_get_socket_path (addr.sun_path,sizeof (addr.sun_path), + ret =pdump_get_socket_path (addr.sun_path,sizeof (addr.sun_path),RTE_PDUMP_SOCKET_CLIENT ); +if (ret !=0 ) { +RTE_LOG (ERR ,PDUMP , +"Failed to get client socket path: %s:%d\n" , + __func__, __LINE__); +return -1 ; + } addr.sun_family =AF_UNIX ; addr_len =sizeof (struct sockaddr_un );
@@ -660,9 +688,15 @@ pdump_create_client_socket(struct pdump_request *p) serv_len =sizeof (struct sockaddr_un );memset (&serv_addr,0 ,sizeof (serv_addr)); -pdump_get_socket_path (serv_addr.sun_path, + ret =pdump_get_socket_path (serv_addr.sun_path,sizeof (serv_addr.sun_path),RTE_PDUMP_SOCKET_SERVER ); +if (ret !=0 ) { +RTE_LOG (ERR ,PDUMP , +"Failed to get server socket path: %s:%d\n" , + __func__, __LINE__); +break ; + } serv_addr.sun_family =AF_UNIX ; n = sendto(socket_fd, p, sizeof(struct pdump_request), 0,
Signature · 1 line
2.5.0
v4 cover fix issues in packet capture framework
In reply to Reshma PattanThis patchset includes listed fixes
1)fix default socket path in pdump library.
2)fix coverity issues in pdump library.
3)fix coverity issues in pdump tool.
4)fix wrong typecast of ring size in pdump tool.
v4:
added new patch for fixing wrong typecast of ring size in pdump tool.
v3:
added new patch for fixing default socket paths "HOME" and "/var/run". reworked coverity fixes on top of the above change.
v2:
fixed code review comment to use snprintf instead of strncpy.
Reshma Pattan (5):
pdump: fix default socket path
pdump: check getenv return value
pdump: fix string overflow
app/pdump: fix string overflow
app/pdump: fix type casting of ring size
app/pdump/main.c | 6 ++-- lib/librte_pdump/rte_pdump.c | 72 ++++++++++++++++++++++++++++++++++---------- 2 files changed, 59 insertions(+), 19 deletions(-)
Signature · 1 line
2.5.0
PATCH v4 1/5 pdump: fix default socket path
SOCKET_PATH_HOME is to specify environment variable "HOME", so it should not contain "/pdump_sockets" in the macro. So remove "/pdump_sockets" from SOCKET_PATH_HOME and create new macro for "/pdump_sockets". Similary removed "/pdump_sockets" from SOCKET_PATH_VAR_RUN.
Changes are done in pdump_get_socket_path() to accommodate new socket path changes.
--- lib/librte_pdump/rte_pdump.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-)
lib/librte_pdump/rte_pdump.c +13 -9
@@ -50,8 +50,9 @@#include "rte_pdump.h" -#define SOCKET_PATH_VAR_RUN "/var/run/pdump_sockets" -#define SOCKET_PATH_HOME "HOME/pdump_sockets" +#define SOCKET_PATH_VAR_RUN "/var/run" +#define SOCKET_PATH_HOME "HOME" +#define SOCKET_DIR "/pdump_sockets"#define SERVER_SOCKET "%s/pdump_server_socket"#define CLIENT_SOCKET "%s/pdump_client_socket_%d_%u"#define DEVICE_ID_SIZE 64
@@ -444,17 +445,20 @@ set_pdump_rxtx_cbs(struct pdump_request *p)static void pdump_get_socket_path (char *buffer,int bufsz,enum rte_pdump_socktype type) { -const char *dir =NULL ; +char dir[PATH_MAX ] = {0 }; +char *dir_home =NULL ;if (type ==RTE_PDUMP_SOCKET_SERVER && server_socket_dir[0 ] !=0 ) - dir = server_socket_dir; +snprintf (dir,sizeof (dir),"%s" , server_socket_dir);else if (type ==RTE_PDUMP_SOCKET_CLIENT && client_socket_dir[0 ] !=0 ) - dir = client_socket_dir; +snprintf (dir,sizeof (dir),"%s" , client_socket_dir);else { -if (getuid () !=0 ) - dir =getenv (SOCKET_PATH_HOME ); -else - dir =SOCKET_PATH_VAR_RUN ; +if (getuid () !=0 ) { + dir_home =getenv (SOCKET_PATH_HOME ); +strcat (dir, dir_home); + }else +strcat (dir,SOCKET_PATH_VAR_RUN ); +strcat (dir,SOCKET_DIR ); }mkdir (dir,700 );
Signature · 1 line
2.5.0
PATCH v4 2/5 pdump: check getenv return value
In reply to Reshma Pattaninside pdump_get_socket_path(), getenv can return a NULL pointer if the match for SOCKET_PATH_HOME is not found in the environment. NULL check is added to return -1 immediately. Since pdump_get_socket_path() returns -1 now, wherever this function is called there the return value is checked and error message is logged.
Coverity issue 127344: return value check Coverity issue 127347: null pointer dereference
--- lib/librte_pdump/rte_pdump.c | 44 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 39 insertions(+), 5 deletions(-)
lib/librte_pdump/rte_pdump.c +39 -5
@@ -442,7 +442,7 @@ set_pdump_rxtx_cbs(struct pdump_request *p) }/* get socket path (/var/run if root, $HOME otherwise) */ -static void +static int pdump_get_socket_path (char *buffer,int bufsz,enum rte_pdump_socktype type) {char dir[PATH_MAX ] = {0 };
@@ -455,9 +455,17 @@ pdump_get_socket_path(char *buffer, int bufsz, enum rte_pdump_socktype type)else {if (getuid () !=0 ) { dir_home =getenv (SOCKET_PATH_HOME ); +if (!dir_home) { +RTE_LOG (ERR ,PDUMP , +"Failed to get environment variable" +" value for %s, %s:%d\n" , +SOCKET_PATH_HOME , __func__, __LINE__); +return -1 ; + }strcat (dir, dir_home); }else strcat (dir,SOCKET_PATH_VAR_RUN ); +strcat (dir,SOCKET_DIR ); }
@@ -467,6 +475,8 @@ pdump_get_socket_path(char *buffer, int bufsz, enum rte_pdump_socktype type)else snprintf (buffer, bufsz,CLIENT_SOCKET , dir,getpid (),rte_sys_gettid ()); + +return 0 ; } static int
@@ -476,8 +486,14 @@ pdump_create_server_socket(void)struct sockaddr_un addr;socklen_t addr_len; -pdump_get_socket_path (addr.sun_path,sizeof (addr.sun_path), + ret =pdump_get_socket_path (addr.sun_path,sizeof (addr.sun_path),RTE_PDUMP_SOCKET_SERVER ); +if (ret !=0 ) { +RTE_LOG (ERR ,PDUMP , +"Failed to get server socket path: %s:%d\n" , + __func__, __LINE__); +return -1 ; + } addr.sun_family =AF_UNIX ;/* remove if file already exists */
@@ -608,8 +624,14 @@ rte_pdump_uninit(void)struct sockaddr_un addr; -pdump_get_socket_path (addr.sun_path,sizeof (addr.sun_path), + ret =pdump_get_socket_path (addr.sun_path,sizeof (addr.sun_path),RTE_PDUMP_SOCKET_SERVER ); +if (ret !=0 ) { +RTE_LOG (ERR ,PDUMP , +"Failed to get server socket path: %s:%d\n" , + __func__, __LINE__); +return -1 ; + } ret =unlink (addr.sun_path);if (ret !=0 ) { RTE_LOG(ERR, PDUMP,
@@ -643,8 +665,14 @@ pdump_create_client_socket(struct pdump_request *p)return ret; } -pdump_get_socket_path (addr.sun_path,sizeof (addr.sun_path), + ret =pdump_get_socket_path (addr.sun_path,sizeof (addr.sun_path),RTE_PDUMP_SOCKET_CLIENT ); +if (ret !=0 ) { +RTE_LOG (ERR ,PDUMP , +"Failed to get client socket path: %s:%d\n" , + __func__, __LINE__); +return -1 ; + } addr.sun_family =AF_UNIX ; addr_len =sizeof (struct sockaddr_un );
@@ -660,9 +688,15 @@ pdump_create_client_socket(struct pdump_request *p) serv_len =sizeof (struct sockaddr_un );memset (&serv_addr,0 ,sizeof (serv_addr)); -pdump_get_socket_path (serv_addr.sun_path, + ret =pdump_get_socket_path (serv_addr.sun_path,sizeof (serv_addr.sun_path),RTE_PDUMP_SOCKET_SERVER ); +if (ret !=0 ) { +RTE_LOG (ERR ,PDUMP , +"Failed to get server socket path: %s:%d\n" , + __func__, __LINE__); +break ; + } serv_addr.sun_family =AF_UNIX ; n = sendto(socket_fd, p, sizeof(struct pdump_request), 0,
Signature · 1 line
2.5.0
PATCH v4 3/5 pdump: fix string overflow
In reply to Reshma Pattanreplaced strncpy with snprintf for safely
copying the strings.
Cverity issue 127350: string overflow
--- lib/librte_pdump/rte_pdump.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
lib/librte_pdump/rte_pdump.c +4 -2
@@ -804,13 +804,15 @@ pdump_prepare_client_request(char *device, uint16_t queue, req.flags = flags; req.op = operation;if ((operation &ENABLE ) !=0 ) { -strncpy (req.data.en_v1.device, device,strlen (device)); +snprintf (req.data.en_v1.device,sizeof (req.data.en_v1.device), +"%s" , device); req.data.en_v1.queue = queue; req.data.en_v1.ring = ring; req.data.en_v1.mp = mp; req.data.en_v1.filter = filter; }else { -strncpy (req.data.dis_v1.device, device,strlen (device)); +snprintf (req.data.dis_v1.device,sizeof (req.data.dis_v1.device), +"%s" , device); req.data.dis_v1.queue = queue; req.data.dis_v1.ring =NULL ; req.data.dis_v1.mp =NULL ;
Signature · 1 line
2.5.0
PATCH v4 4/5 app/pdump: fix string overflow
In reply to Reshma Pattanreplaced strncpy with snprintf for safely
copying the strings.
Coverity issue 127351: string overflow
--- app/pdump/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
app/pdump/main.c +2 -2
@@ -217,12 +217,12 @@ parse_rxtxdev(const char *key, const char *value, void *extra_args)struct pdump_tuples *pt = extra_args;if (!strcmp (key,PDUMP_RX_DEV_ARG )) { -strncpy (pt->rx_dev, value,strlen (value)); +snprintf (pt->rx_dev,sizeof (pt->rx_dev),"%s" , value);/* identify the tx stream type for pcap vdev */ if (if_nametoindex (pt->rx_dev)) pt->rx_vdev_stream_type =IFACE ; }else if (!strcmp (key,PDUMP_TX_DEV_ARG )) { -strncpy (pt->tx_dev, value,strlen (value)); +snprintf (pt->tx_dev,sizeof (pt->tx_dev),"%s" , value);/* identify the tx stream type for pcap vdev */ if (if_nametoindex (pt->tx_dev)) pt->tx_vdev_stream_type =IFACE ;
Signature · 1 line
2.5.0
PATCH v4 5/5 app/pdump: fix type casting of ring size
In reply to Reshma Pattanring_size value is wrongly type casted to uint16_t. It should be type casted to uint32_t, as maximum ring size is 28bit long. Wrong type cast wrapping around the ring size values bigger than 65535.
--- app/pdump/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
app/pdump/main.c +1 -1
@@ -362,7 +362,7 @@ parse_pdump(const char *optarg) &parse_uint_value, &v);if (ret <0 ) goto free_kvlist; - pt->ring_size = (uint16_t ) v.val; + pt->ring_size = (uint32_t ) v.val; }else pt->ring_size =RING_SIZE ;
Signature · 1 line
2.5.0
Re: [PATCH v4 1/5] pdump: fix default socket path
In reply to Reshma Pattan2016-06-24 14:54, Reshma Pattan:
Quoted 1 line
+#define
SOCKET_DIR"/pdump_sockets"
I think the default socket directory should contain dpdk as prefix. Like dpdk-pdump-sockets (I think dash is preferred for filenames). I wonder whether it should be a hidden directory:
~/.dpdk-pdump-sockets
And after all, why not simply
~/.dpdk/
It would allow other DPDK applications to put some files.
Re: [PATCH v4 1/5] pdump: fix default socket path
Quoted 10 lines
-----Original Message-----
From: Thomas Monjalon [mailto:[email protected]]
Sent: Friday, June 24, 2016 3:55 PM
To: Pattan, Reshma <[email protected]>
Cc: [email protected]
Subject: Re: [dpdk-dev] [PATCH v4 1/5] pdump: fix default socket path2016-06-24 14:54, Reshma Pattan:
Quoted 8 lines
Quoted 1 line
+#define
SOCKET_DIR"/pdump_sockets"I think the default socket directory should contain dpdk as prefix. Like dpdk-pdump-sockets (I think dash is preferred for filenames). I wonder whether it should be a hidden directory:
~/.dpdk-pdump-sockets
And after all, why not simply~/.dpdk/
Hmm I would keep the name dpdk-pdump-sockets as library creates this only for pdump sockets.
Hidden directory just gives the advantage of not cluttering the display. If your comment is for the same I can add a . in the directory name:-).
Quoted 1 line
It would allow other DPDK applications to put some files.
v5 cover fix issues in packet capture framework
In reply to Reshma PattanThis patchset includes listed fixes
1)fix default socket path in pdump library.
2)fix coverity issues in pdump library.
3)fix coverity issues in pdump tool.
4)fix wrong typecast of ring size in pdump tool.
v5:
changes are done to default socket paths
now default socket path will be /var/run/.dpdk/pdump_sockets for root users and HOME/.dpdk/pdump_sockets for nonroot users.
v4:
added new patch for fixing wrong typecast of ring size in pdump tool.
v3:
added new patch for fixing default socket paths "HOME" and "/var/run". reworked coverity fixes on top of the above change.
v2:
fixed code review comment to use snprintf instead of strncpy.
Reshma Pattan (5):
pdump: fix default socket path
pdump: check getenv return value
pdump: fix string overflow
app/pdump: fix string overflow
app/pdump: fix type casting of ring size
app/pdump/main.c | 6 ++-- lib/librte_pdump/rte_pdump.c | 78 +++++++++++++++++++++++++++++++++++--------- 2 files changed, 65 insertions(+), 19 deletions(-)
Signature · 1 line
2.5.0
PATCH v5 1/5 pdump: fix default socket path
SOCKET_PATH_HOME is to specify environment variable "HOME", so it should not contain "/pdump_sockets" in the macro. So removed "/pdump_sockets" from SOCKET_PATH_HOME and SOCKET_PATH_VAR_RUN. New changes will create pdump sockets under /var/run/.dpdk/pdump_sockets for root users and
under HOME/.dpdk/pdump_sockets for non root users. Changes are done in pdump_get_socket_path() to accommodate new socket path changes.
--- lib/librte_pdump/rte_pdump.c | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-)
lib/librte_pdump/rte_pdump.c +20 -9
@@ -50,8 +50,10 @@#include "rte_pdump.h" -#define SOCKET_PATH_VAR_RUN "/var/run/pdump_sockets" -#define SOCKET_PATH_HOME "HOME/pdump_sockets" +#define SOCKET_PATH_VAR_RUN "/var/run" +#define SOCKET_PATH_HOME "HOME" +#define DPDK_DIR "/.dpdk" +#define SOCKET_DIR "/pdump_sockets"#define SERVER_SOCKET "%s/pdump_server_socket"#define CLIENT_SOCKET "%s/pdump_client_socket_%d_%u"#define DEVICE_ID_SIZE 64
@@ -444,17 +446,26 @@ set_pdump_rxtx_cbs(struct pdump_request *p)static void pdump_get_socket_path (char *buffer,int bufsz,enum rte_pdump_socktype type) { -const char *dir =NULL ; +char dpdk_dir[PATH_MAX ] = {0 }; +char dir[PATH_MAX ] = {0 }; +char *dir_home =NULL ;if (type ==RTE_PDUMP_SOCKET_SERVER && server_socket_dir[0 ] !=0 ) - dir = server_socket_dir; +snprintf (dir,sizeof (dir),"%s" , server_socket_dir);else if (type ==RTE_PDUMP_SOCKET_CLIENT && client_socket_dir[0 ] !=0 ) - dir = client_socket_dir; +snprintf (dir,sizeof (dir),"%s" , client_socket_dir);else { -if (getuid () !=0 ) - dir =getenv (SOCKET_PATH_HOME ); -else - dir =SOCKET_PATH_VAR_RUN ; +if (getuid () !=0 ) { + dir_home =getenv (SOCKET_PATH_HOME ); +snprintf (dpdk_dir,sizeof (dpdk_dir),"%s%s" , + dir_home,DPDK_DIR ); + }else +snprintf (dpdk_dir,sizeof (dpdk_dir),"%s%s" , +SOCKET_PATH_VAR_RUN ,DPDK_DIR ); + +mkdir (dpdk_dir,700 ); +snprintf (dir,sizeof (dir),"%s%s" , + dpdk_dir,SOCKET_DIR ); }mkdir (dir,700 );
Signature · 1 line
2.5.0
PATCH v5 2/5 pdump: check getenv return value
In reply to Reshma Pattaninside pdump_get_socket_path(), getenv can return a NULL pointer if the match for SOCKET_PATH_HOME is not found in the environment. NULL check is added to return -1 immediately. Since pdump_get_socket_path() returns -1 now, wherever this function is called there the return value is checked and error message is logged.
Coverity issue 127344: return value check Coverity issue 127347: null pointer dereference
--- lib/librte_pdump/rte_pdump.c | 43 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 38 insertions(+), 5 deletions(-)
lib/librte_pdump/rte_pdump.c +38 -5
@@ -443,7 +443,7 @@ set_pdump_rxtx_cbs(struct pdump_request *p) }/* get socket path (/var/run if root, $HOME otherwise) */ -static void +static int pdump_get_socket_path (char *buffer,int bufsz,enum rte_pdump_socktype type) {char dpdk_dir[PATH_MAX ] = {0 };
@@ -457,6 +457,13 @@ pdump_get_socket_path(char *buffer, int bufsz, enum rte_pdump_socktype type)else {if (getuid () !=0 ) { dir_home =getenv (SOCKET_PATH_HOME ); +if (!dir_home) { +RTE_LOG (ERR ,PDUMP , +"Failed to get environment variable" +" value for %s, %s:%d\n" , +SOCKET_PATH_HOME , __func__, __LINE__); +return -1 ; + }snprintf (dpdk_dir,sizeof (dpdk_dir),"%s%s" , dir_home,DPDK_DIR ); }else
@@ -474,6 +481,8 @@ pdump_get_socket_path(char *buffer, int bufsz, enum rte_pdump_socktype type)else snprintf (buffer, bufsz,CLIENT_SOCKET , dir,getpid (),rte_sys_gettid ()); + +return 0 ; } static int
@@ -483,8 +492,14 @@ pdump_create_server_socket(void)struct sockaddr_un addr;socklen_t addr_len; -pdump_get_socket_path (addr.sun_path,sizeof (addr.sun_path), + ret =pdump_get_socket_path (addr.sun_path,sizeof (addr.sun_path),RTE_PDUMP_SOCKET_SERVER ); +if (ret !=0 ) { +RTE_LOG (ERR ,PDUMP , +"Failed to get server socket path: %s:%d\n" , + __func__, __LINE__); +return -1 ; + } addr.sun_family =AF_UNIX ;/* remove if file already exists */
@@ -615,8 +630,14 @@ rte_pdump_uninit(void)struct sockaddr_un addr; -pdump_get_socket_path (addr.sun_path,sizeof (addr.sun_path), + ret =pdump_get_socket_path (addr.sun_path,sizeof (addr.sun_path),RTE_PDUMP_SOCKET_SERVER ); +if (ret !=0 ) { +RTE_LOG (ERR ,PDUMP , +"Failed to get server socket path: %s:%d\n" , + __func__, __LINE__); +return -1 ; + } ret =unlink (addr.sun_path);if (ret !=0 ) { RTE_LOG(ERR, PDUMP,
@@ -650,8 +671,14 @@ pdump_create_client_socket(struct pdump_request *p)return ret; } -pdump_get_socket_path (addr.sun_path,sizeof (addr.sun_path), + ret =pdump_get_socket_path (addr.sun_path,sizeof (addr.sun_path),RTE_PDUMP_SOCKET_CLIENT ); +if (ret !=0 ) { +RTE_LOG (ERR ,PDUMP , +"Failed to get client socket path: %s:%d\n" , + __func__, __LINE__); +return -1 ; + } addr.sun_family =AF_UNIX ; addr_len =sizeof (struct sockaddr_un );
@@ -667,9 +694,15 @@ pdump_create_client_socket(struct pdump_request *p) serv_len =sizeof (struct sockaddr_un );memset (&serv_addr,0 ,sizeof (serv_addr)); -pdump_get_socket_path (serv_addr.sun_path, + ret =pdump_get_socket_path (serv_addr.sun_path,sizeof (serv_addr.sun_path),RTE_PDUMP_SOCKET_SERVER ); +if (ret !=0 ) { +RTE_LOG (ERR ,PDUMP , +"Failed to get server socket path: %s:%d\n" , + __func__, __LINE__); +break ; + } serv_addr.sun_family =AF_UNIX ; n = sendto(socket_fd, p, sizeof(struct pdump_request), 0,
Signature · 1 line
2.5.0
PATCH v5 5/5 app/pdump: fix type casting of ring size
In reply to Reshma Pattanring_size value is wrongly type casted to uint16_t. It should be type casted to uint32_t, as maximum ring size is 28bit long. Wrong type cast wrapping around the ring size values bigger than 65535.
--- app/pdump/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
app/pdump/main.c +1 -1
@@ -362,7 +362,7 @@ parse_pdump(const char *optarg) &parse_uint_value, &v);if (ret <0 ) goto free_kvlist; - pt->ring_size = (uint16_t ) v.val; + pt->ring_size = (uint32_t ) v.val; }else pt->ring_size =RING_SIZE ;
Signature · 1 line
2.5.0
PATCH v5 4/5 app/pdump: fix string overflow
In reply to Reshma Pattanreplaced strncpy with snprintf for safely
copying the strings.
Coverity issue 127351: string overflow
--- app/pdump/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
app/pdump/main.c +2 -2
@@ -217,12 +217,12 @@ parse_rxtxdev(const char *key, const char *value, void *extra_args)struct pdump_tuples *pt = extra_args;if (!strcmp (key,PDUMP_RX_DEV_ARG )) { -strncpy (pt->rx_dev, value,strlen (value)); +snprintf (pt->rx_dev,sizeof (pt->rx_dev),"%s" , value);/* identify the tx stream type for pcap vdev */ if (if_nametoindex (pt->rx_dev)) pt->rx_vdev_stream_type =IFACE ; }else if (!strcmp (key,PDUMP_TX_DEV_ARG )) { -strncpy (pt->tx_dev, value,strlen (value)); +snprintf (pt->tx_dev,sizeof (pt->tx_dev),"%s" , value);/* identify the tx stream type for pcap vdev */ if (if_nametoindex (pt->tx_dev)) pt->tx_vdev_stream_type =IFACE ;
Signature · 1 line
2.5.0
PATCH v5 3/5 pdump: fix string overflow
In reply to Reshma Pattanreplaced strncpy with snprintf for safely
copying the strings.
Cverity issue 127350: string overflow
--- lib/librte_pdump/rte_pdump.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
lib/librte_pdump/rte_pdump.c +4 -2
@@ -810,13 +810,15 @@ pdump_prepare_client_request(char *device, uint16_t queue, req.flags = flags; req.op = operation;if ((operation &ENABLE ) !=0 ) { -strncpy (req.data.en_v1.device, device,strlen (device)); +snprintf (req.data.en_v1.device,sizeof (req.data.en_v1.device), +"%s" , device); req.data.en_v1.queue = queue; req.data.en_v1.ring = ring; req.data.en_v1.mp = mp; req.data.en_v1.filter = filter; }else { -strncpy (req.data.dis_v1.device, device,strlen (device)); +snprintf (req.data.dis_v1.device,sizeof (req.data.dis_v1.device), +"%s" , device); req.data.dis_v1.queue = queue; req.data.dis_v1.ring =NULL ; req.data.dis_v1.mp =NULL ;
Signature · 1 line
2.5.0
Re: [PATCH v4 1/5] pdump: fix default socket path
In reply to Thomas MonjalonQuoted 10 lines
-----Original Message-----
From: Thomas Monjalon [mailto:[email protected]]
Sent: Friday, June 24, 2016 3:55 PM
To: Pattan, Reshma <[email protected]>
Cc: [email protected]
Subject: Re: [dpdk-dev] [PATCH v4 1/5] pdump: fix default socket path2016-06-24 14:54, Reshma Pattan:
Quoted 8 lines
Quoted 1 line
+#define
SOCKET_DIR"/pdump_sockets"I think the default socket directory should contain dpdk as prefix. Like dpdk-pdump-sockets (I think dash is preferred for filenames). I wonder whether it should be a hidden directory:
~/.dpdk-pdump-sockets
And after all, why not simply~/.dpdk/
patch v5 is sent with changes /.dpdk/pdump_sockets.
Quoted 1 line
It would allow other DPDK applications to put some files.
Re: [PATCH v5 1/5] pdump: fix default socket path
In reply to Reshma PattanQuoted 17 lines
-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Reshma Pattan
Sent: Friday, June 24, 2016 5:36 PM
To: [email protected]
Cc: Pattan, Reshma <[email protected]>
Subject: [dpdk-dev] [PATCH v5 1/5] pdump: fix default socket path
SOCKET_PATH_HOMEis to specify environment variable "HOME", so it should not contain "/pdump_sockets" in the macro.
So removed "/pdump_sockets" fromSOCKET_PATH_HOMEandSOCKET_PATH_VAR_RUN. New changes will create pdump sockets under/var/run/.dpdk/pdump_socketsfor root users and under HOME/.dpdk/pdump_sockets for non root users. Changes are done inpdump_get_socket_path()to accommodate new socket path changes.
Quoted 3 lines
Fixes 278f945402c5 ("pdump: add new library for packet capture")Signed-off-by Reshma Pattan <[email protected]>
Re: [PATCH v5 2/5] pdump: check getenv return value
In reply to Reshma PattanQuoted 13 lines
-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Reshma Pattan
Sent: Friday, June 24, 2016 5:36 PM
To: [email protected]
Cc: Pattan, Reshma <[email protected]>
Subject: [dpdk-dev] [PATCH v5 2/5] pdump: check getenv return valueinside
pdump_get_socket_path(), getenv can return a NULL pointer if the match forSOCKET_PATH_HOMEis not found in the environment. NULL check is added to return -1 immediately. Sincepdump_get_socket_path()returns -1 now, wherever this function is called there the return value is checked and error message is logged.
Quoted 6 lines
Coverity issue 127344: return value check Coverity issue 127347: null pointer dereference
Fixes 278f945402c5 ("pdump: add new library for packet capture")Signed-off-by Reshma Pattan <[email protected]>
Re: [PATCH v5 3/5] pdump: fix string overflow
In reply to Reshma PattanQuoted 7 lines
-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Reshma Pattan
Sent: Friday, June 24, 2016 5:36 PM
To: [email protected]
Cc: Pattan, Reshma <[email protected]>
Subject: [dpdk-dev] [PATCH v5 3/5] pdump: fix string overflow
Quoted 7 lines
replaced strncpy with snprintf for safely copying the strings.
Cverity issue 127350: string overflow
Fixes 278f945402c5 ("pdump: add new library for packet capture")Signed-off-by Reshma Pattan <[email protected]>
Re: [PATCH v5 4/5] app/pdump: fix string overflow
In reply to Reshma PattanQuoted 7 lines
-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Reshma Pattan
Sent: Friday, June 24, 2016 5:36 PM
To: [email protected]
Cc: Pattan, Reshma <[email protected]>
Subject: [dpdk-dev] [PATCH v5 4/5] app/pdump: fix string overflow
Quoted 7 lines
replaced strncpy with snprintf for safely copying the strings.
Coverity issue 127351: string overflow
Fixes caa7028276b8 ("app/pdump: add tool for packet capturing")Signed-off-by Reshma Pattan <[email protected]>
Re: [PATCH v5 5/5] app/pdump: fix type casting of ring size
In reply to Reshma PattanQuoted 8 lines
-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Reshma Pattan
Sent: Friday, June 24, 2016 5:36 PM
To: [email protected]
Cc: Pattan, Reshma <[email protected]>
Subject: [dpdk-dev] [PATCH v5 5/5] app/pdump: fix type casting of ring size
Quoted 7 lines
ring_sizevalue is wrongly type casted touint16_t.
It should be type casted touint32_t, as maximum ring size is 28bit long. Wrong type cast wrapping around the ring size values bigger than 65535.Fixes caa7028276b8 ("app/pdump: add tool for packet capturing")Signed-off-by Reshma Pattan <[email protected]>
Thomas Monjalon
AppliedRe: [PATCH v5 0/5] fix issues in packet capture framework
In reply to Reshma PattanQuoted 6 lines
Reshma Pattan (5):
pdump: fix default socket path
pdump: check getenv return value
pdump: fix string overflow
app/pdump: fix string overflow
app/pdump: fix type casting of ring size
Applied, thanks