mbuf:using sanity checks do not panic on null mbuf
PATCH 1/1 mbuf:using sanity checks do not panic on null mbuf
The rte_pktmbuf_free() allows for NULL mbuf pointer, but when sanity check is enabled it will panic with null pointer.
--- lib/librte_mbuf/rte_mbuf.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
lib/librte_mbuf/rte_mbuf.c +8 -2
@@ -205,8 +205,9 @@ rte_mbuf_sanity_check(const struct rte_mbuf *m, int is_header)const struct rte_mbuf *m_seg;unsigned int nb_segs; -if (m ==NULL ) -rte_panic ("mbuf is NULL\n" ); +/* Calling with NULL is valid in the API */ +if (!m) +return ;/* generic checks */ if (m->pool ==NULL )
@@ -243,6 +244,11 @@ rte_pktmbuf_dump(FILE *f, const struct rte_mbuf *m, unsigned dump_len)__rte_mbuf_sanity_check (m,1 ); +if (!m || !f) { +fprintf (stderr,"MBUF and/or FILE pointer is NULL\n" ); +return ; + } +fprintf (f,"dump mbuf at %p, iova=%" PRIx64", buf_len=%u\n" , m, (uint64_t )m->buf_iova, (unsigned )m->buf_len); fprintf(f, " pkt_len=%"PRIu32", ol_flags=%"PRIx64", nb_segs=%u, "
Signature · 1 line
2.14.1
lib/librte_mbuf/rte_mbuf.c rte_pktmbuf_dump(FILE *f, const struct rte_mbuf *m, unsigned dump_len) · line 250
Quoted 4 lines · On Mon, 8 Jan 2018 09:34:23 -0600 Keith Wiles <[email protected]> wrote:
lib/librte_mbuf/rte_mbuf.c +4
-0+if (!m || !f) { +fprintf (stderr,"MBUF and/or FILE pointer is NULL\n" ); +return ; + }
Calling with f of NULL is user error, let it still die in fprintf.
Quoted 7 lines · Stephen Hemminger
On Mon, 8 Jan 2018 09:34:23 -0600
Keith Wiles <[email protected]> wrote:
Quoted 6 lines
lib/librte_mbuf/rte_mbuf.c rte_pktmbuf_dump(FILE *f, const struct rte_mbuf *m, unsigned dump_len) · line 250
Quoted 4 lines
lib/librte_mbuf/rte_mbuf.c +4
-0+if (!m || !f) { +fprintf (stderr,"MBUF and/or FILE pointer is NULL\n" ); +return ; + }Calling with f of NULL is user error, let it still die in fprintf.
I thought about that too, but this routine is a debug routine does it really matter?
Regards,
Keith
-----Original Message-----
Quoted 11 lines
Date: Mon, 8 Jan 2018 09:34:23 -0600
From: Keith Wiles <[email protected]>
To: [email protected]
Subject: [dpdk-dev] [PATCH] mbuf:using sanity checks do not panic on null
mbuf
X-Mailer: git-send-email 2.10.1The
rte_pktmbuf_free()allows for NULL mbuf pointer, but when sanity check is enabled it will panic with null pointer.Signed-off-by Keith Wiles <[email protected]>
mbuf autotest is failing with this change.
# echo "mbuf_autotest" | sudo ./build/app/test
<snip>
Checking rte_mbuf_sanity_check for failure conditions Checking good mbuf initially
Now checking for error conditions
Error with NULL mbuf test test_failing_mbuf_sanity_check() failed
Test Failed
PATCH v2 1/1 mbuf:using sanity checks do not panic on null mbuf
In reply to Keith WilesThe rte_pktmbuf_free() allows for NULL mbuf pointer, but when sanity check is enabled it will panic with null pointer.
--- lib/librte_mbuf/rte_mbuf.c | 10 ++++++++-- test/test/test_mbuf.c | 4 +--- 2 files changed, 9 insertions(+), 5 deletions(-)
lib/librte_mbuf/rte_mbuf.c +8 -2
@@ -205,8 +205,9 @@ rte_mbuf_sanity_check(const struct rte_mbuf *m, int is_header)const struct rte_mbuf *m_seg;unsigned int nb_segs; -if (m ==NULL ) -rte_panic ("mbuf is NULL\n" ); +/* Calling with NULL is valid in the API */ +if (!m) +return ;/* generic checks */ if (m->pool ==NULL )
@@ -243,6 +244,11 @@ rte_pktmbuf_dump(FILE *f, const struct rte_mbuf *m, unsigned dump_len)__rte_mbuf_sanity_check (m,1 ); +if (!m) { +fprintf (stderr,"MBUF pointer is NULL\n" ); +return ; + } +fprintf (f,"dump mbuf at %p, iova=%" PRIx64", buf_len=%u\n" , m, (uint64_t )m->buf_iova, (unsigned )m->buf_len); fprintf(f, " pkt_len=%"PRIu32", ol_flags=%"PRIx64", nb_segs=%u, "
test/test/test_mbuf.c +1 -3
@@ -864,10 +864,8 @@ test_failing_mbuf_sanity_check(struct rte_mempool *pktmbuf_pool)printf ("Now checking for error conditions\n" ); -if (verify_mbuf_check_panics (NULL )) { -printf ("Error with NULL mbuf test\n" ); +if (verify_mbuf_check_panics (NULL ) !=-1 )return -1 ; - } badbuf = *buf; badbuf.pool =NULL ;
Signature · 1 line
2.14.1
Quoted 56 lines · Keith Wiles
The
rte_pktmbuf_free()allows for NULL mbuf pointer, but when sanity check is enabled it will panic with null pointer.Signed-off-by Keith Wiles <[email protected]>--- lib/librte_mbuf/rte_mbuf.c | 10 ++++++++-- test/test/test_mbuf.c | 4 +--- 2 files changed, 9 insertions(+), 5 deletions(-)lib/librte_mbuf/rte_mbuf.c +8
-2@@ -205,8 +205,9 @@ rte_mbuf_sanity_check(const struct rte_mbuf *m, int is_header)const struct rte_mbuf *m_seg;unsigned int nb_segs; -if (m ==NULL ) -rte_panic ("mbuf is NULL\n" ); +/* Calling with NULL is valid in the API */ +if (!m) +return ;/* generic checks */ if (m->pool ==NULL )@@ -243,6 +244,11 @@ rte_pktmbuf_dump(FILE *f, const struct rte_mbuf *m, unsigned dump_len)__rte_mbuf_sanity_check (m,1 ); +if (!m) { +fprintf (stderr,"MBUF pointer is NULL\n" ); +return ; + } +fprintf (f,"dump mbuf at %p, iova=%" PRIx64", buf_len=%u\n" , m, (uint64_t )m->buf_iova, (unsigned )m->buf_len); fprintf(f, " pkt_len=%"PRIu32", ol_flags=%"PRIx64", nb_segs=%u, "test/test/test_mbuf.c +1
-3@@ -864,10 +864,8 @@ test_failing_mbuf_sanity_check(struct rte_mempool *pktmbuf_pool)printf ("Now checking for error conditions\n" ); -if (verify_mbuf_check_panics (NULL )) { -printf ("Error with NULL mbuf test\n" ); +if (verify_mbuf_check_panics (NULL ) !=-1 )return -1 ; - } badbuf = *buf; badbuf.pool =NULL ;Signature · 1 line
2.14.1
The problem is a panic when rte_pktmbuf_free(NULL) when mbuf debug is enabled, right?
A NULL mbuf is only valid in case of a free because it is convenient, but for most (all ?) other mbuf functions, the mbuf must not be NULL.
What about this patch instead:
--- a/lib/librte_mbuf/rte_mbuf.h
+++ b/lib/librte_mbuf/rte_mbuf.h
@@ -1413,13 +1413,14 @@ rte_pktmbuf_free_seg(struct rte_mbuf *m)
* segment is added back into its original mempool. *
* @param m
- * The packet mbuf to be freed.
+ * The packet mbuf to be freed. If NULL, the function does nothing.
*/
static inline void rte_pktmbuf_free(struct rte_mbuf *m)
{
struct rte_mbuf *m_next; - __rte_mbuf_sanity_check(m, 1);
+ if (m != NULL)
+ __rte_mbuf_sanity_check(m, 1);
while (m != NULL) {
m_next = m->next;Quoted 83 lines · Olivier Matz
Quoted 56 lines · Keith Wiles
The
rte_pktmbuf_free()allows for NULL mbuf pointer, but when sanity check is enabled it will panic with null pointer.Signed-off-by Keith Wiles <[email protected]>---
lib/librte_mbuf/rte_mbuf.c| 10 ++++++++--test/test/test_mbuf.c| 4 +---2 files changed, 9 insertions(+), 5 deletions(-)lib/librte_mbuf/rte_mbuf.c +8
-2@@ -205,8 +205,9 @@ rte_mbuf_sanity_check(const struct rte_mbuf *m, int is_header)const struct rte_mbuf *m_seg;unsigned int nb_segs; -if (m ==NULL ) -rte_panic ("mbuf is NULL\n" ); +/* Calling with NULL is valid in the API */ +if (!m) +return ;/* generic checks */ if (m->pool ==NULL )@@ -243,6 +244,11 @@ rte_pktmbuf_dump(FILE *f, const struct rte_mbuf *m, unsigned dump_len)__rte_mbuf_sanity_check (m,1 ); +if (!m) { +fprintf (stderr,"MBUF pointer is NULL\n" ); +return ; + } +fprintf (f,"dump mbuf at %p, iova=%" PRIx64", buf_len=%u\n" , m, (uint64_t )m->buf_iova, (unsigned )m->buf_len); fprintf(f, " pkt_len=%"PRIu32", ol_flags=%"PRIx64", nb_segs=%u, "test/test/test_mbuf.c +1
-3@@ -864,10 +864,8 @@ test_failing_mbuf_sanity_check(struct rte_mempool *pktmbuf_pool)printf ("Now checking for error conditions\n" ); -if (verify_mbuf_check_panics (NULL )) { -printf ("Error with NULL mbuf test\n" ); +if (verify_mbuf_check_panics (NULL ) !=-1 )return -1 ; - } badbuf = *buf; badbuf.pool =NULL ;Signature · 1 line
2.14.1The problem is a panic when
rte_pktmbuf_free(NULL)when mbuf debug is enabled, right?A NULL mbuf is only valid in case of a free because it is convenient, but for most (all ?) other mbuf functions, the mbuf must not be NULL.
What about this patch instead:
---
a/lib/librte_mbuf/rte_mbuf.h
+++b/lib/librte_mbuf/rte_mbuf.h
@@ -1413,13 +1413,14 @@rte_pktmbuf_free_seg(struct rte_mbuf *m)
* segment is added back into its original mempool.
*
* @param m
- * The packet mbuf to be freed.
+ * The packet mbuf to be freed. If NULL, the function does nothing.
*/
static inline voidrte_pktmbuf_free(struct rte_mbuf *m){ struct rte_mbuf *m_next;
Quoted 6 lines
-
__rte_mbuf_sanity_check(m, 1);
+ if (m != NULL)
+__rte_mbuf_sanity_check(m, 1);while (m != NULL) { m_next = m->next;
Looks good to me I would ack that one. :-)
Quoted 1 line
Regards,
Keith
PATCH v3 1/1 mbuf: fix freeing of NULL mbuf when debug enabled
In reply to Keith WilesDo not panic when calling rte_pktmbuf_free(NULL) with mbuf debug enabled, it is a valid operation.
--- lib/librte_mbuf/rte_mbuf.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
lib/librte_mbuf/rte_mbuf.h +3 -2
@@ -1439,13 +1439,14 @@ rte_pktmbuf_free_seg(struct rte_mbuf *m)* segment is added back into its original mempool. * * @param m -* The packet mbuf to be freed. +* The packet mbuf to be freed. If NULL, the function does nothing. */ static inline void rte_pktmbuf_free (struct rte_mbuf *m) {struct rte_mbuf *m_next; -__rte_mbuf_sanity_check (m,1 ); +if (m !=NULL ) +__rte_mbuf_sanity_check (m,1 );while (m !=NULL ) { m_next = m->next;
Signature · 1 line
2.11.0
Thomas Monjalon
AppliedRe: [PATCH v3] mbuf: fix freeing of NULL mbuf when debug enabled
29/01/2018 10:39, Olivier Matz:
Quoted 8 lines
Do not panic when calling
rte_pktmbuf_free(NULL)with mbuf debug enabled, it is a valid operation.Fixes af75078fece3 ("first public release")Reported-by Keith Wiles <[email protected]>Signed-off-by Olivier Matz <[email protected]>
Applied, thanks