> -----Original Message----- > From: Stephen Hemminger <step...@networkplumber.org> > Sent: Friday, June 11, 2021 4:03 AM > To: Peng, ZhihongX <zhihongx.p...@intel.com> > Cc: Burakov, Anatoly <anatoly.bura...@intel.com>; dev@dpdk.org; Lin, > Xueqin <xueqin....@intel.com> > Subject: Re: [RFC] porting AddressSanitizer feature to DPDK > > On Thu, 10 Jun 2021 13:13:52 +0800 > zhihongx.p...@intel.com wrote: > > > From: Zhihong Peng <zhihongx.p...@intel.com> > > > > AddressSanitizer (ASan) is a google memory error detect standard tool. > > It could help to detect use-after-free and {heap,stack,global}-buffer > > overflow bugs in C/C++ programs, print detailed error information when > > error happens, large improve debug efficiency. > > > > By referring to its implementation algorithm > > (https://github.com/google/sanitizers/wiki/AddressSanitizerAlgorithm), > > ported heap-buffer-overflow and use-after-freefunctions to dpdk. > > > > Here is an example of heap-buffer-overflow bug: > > ...... > > char *p = rte_zmalloc(NULL, 7, 0); > > p[7] = 'a'; > > ...... > > > > Here is an example of use-after-free bug: > > ...... > > char *p = rte_zmalloc(NULL, 7, 0); > > rte_free(p); > > *p = 'a'; > > ...... > > > > If you want to use this feature, > > you need to use the following compilation options: > > -Dc_args='-DRTE_MALLOC_ASAN' > > -Db_lundef=false -Db_sanitize=address > > > > Signed-off-by: Xueqin Lin <xueqin....@intel.com> > > Signed-off-by: Zhihong Peng <zhihongx.p...@intel.com> > > --- > > lib/eal/common/malloc_elem.c | 33 +++++++- > > lib/eal/common/malloc_elem.h | 141 > ++++++++++++++++++++++++++++++++++- > > lib/eal/common/malloc_heap.c | 19 +++++ > > lib/eal/common/rte_malloc.c | 6 ++ > > 4 files changed, 197 insertions(+), 2 deletions(-) > > > > diff --git a/lib/eal/common/malloc_elem.c > > b/lib/eal/common/malloc_elem.c index c2c9461f1..4a146b1b9 100644 > > --- a/lib/eal/common/malloc_elem.c > > +++ b/lib/eal/common/malloc_elem.c > > @@ -446,6 +446,9 @@ malloc_elem_alloc(struct malloc_elem *elem, > size_t size, unsigned align, > > struct malloc_elem *new_free_elem = > > RTE_PTR_ADD(new_elem, size + > MALLOC_ELEM_OVERHEAD); > > > > +#ifdef RTE_MALLOC_ASAN > > + asan_clear_split_alloczone(new_free_elem); > > +#endif > > > Two things: > ASAN should be detected using standard compiler flags, not a DPDK option. > GCC uses __SANITIZE_ADDRESS__ and Clang uses feature macro.
Thanks Stephen for your review and suggestion, we will improve this part. Only use Asan standard compiler flags, remove DPDK option for the tool detect. > > Rather than littering DPDK code with ifdefs' a better method is to do define > stub inline (or macros if you insist) in the header file. Good capture, we will improve it in V2. >