From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id D753AA0C4D; Thu, 10 Jun 2021 22:03:25 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 7D3A44067C; Thu, 10 Jun 2021 22:03:25 +0200 (CEST) Received: from mail-pf1-f171.google.com (mail-pf1-f171.google.com [209.85.210.171]) by mails.dpdk.org (Postfix) with ESMTP id E60484003C for ; Thu, 10 Jun 2021 22:03:24 +0200 (CEST) Received: by mail-pf1-f171.google.com with SMTP id d16so2508897pfn.12 for ; Thu, 10 Jun 2021 13:03:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=f0O0R65zUe1oue4lHzT+oN0jCLcvv+LEv/hDfUNxm+M=; b=EHg+IlllFmqSHJzf76pbCPUVGwaIEl9Sbrf2QARLkBJhB2W8MgN8Q2KJmhlw6syljE +Suuf+AXUEHVQdu8dc8wEOaqZIBQ4fkXKrTvH9m67M5Bjd88h3VArFTfbhuLtunqQX0q Coe7tmWmcNnF114f/l7z6+lC/6M6QcySF0qsCo9+Etv1FgmpyFna7uyn/UpTLrA8o245 oPTsXtR0Hg1I2FeD166PvLDTaWlU/5lOwXxmdRefi85Xjc3nsTfzFnbaMNw/Kh9e4zXK udxB4hHEjJmt9CirWKr0RwmJ+L/FhgkPwOaOasI+lsXz46QtVdGwSxtrHAsWa7jyNwQb zBgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=f0O0R65zUe1oue4lHzT+oN0jCLcvv+LEv/hDfUNxm+M=; b=bOiBLTO/qnKlubiA41MaC8jgGiwDKYWkyVsFKPsuc4BLlY6Zte9q7WobzlwSmkzJBX a3lzEJw4gLBs0cfKbU5gouT7sKV6zzJGJOi4Z8t0K18GL0w1G04nloY6WnJFEXvqYavq xA5pN2natiCp//c6bqKE2FMMXrGelmfJeT8vRQu2kAHpjY8t6jKhb7zL5sMQ14pY8jQu rH7EfILBl8iD9flcn3jEgHqt9bSyuBMYq5wGP/1UzlEfdVAsIbgxXSZ0g+OashVddoQy HSenz/3EhomRqB/ErzQrbQSgvo0kzoDfsqdMpQ+iqbCknR4B9gwkrad+WuL3LXyw2Eok EzxA== X-Gm-Message-State: AOAM531GOzw/FBuoFqs/61dyYf7waKTKtjWD2kZQOyTwznEjh4WoESju dnT7hPxxSauOqRD5SsrWh7Sqcg== X-Google-Smtp-Source: ABdhPJyRe6LX4axR3yzhrids/jsfpUpxL/1xL9XssIrEEvwjyFZSvpUM/6FQ+CKX1OzTPCf9ovMR2w== X-Received: by 2002:aa7:93d2:0:b029:2ea:5909:ebfc with SMTP id y18-20020aa793d20000b02902ea5909ebfcmr4599430pff.40.1623355403826; Thu, 10 Jun 2021 13:03:23 -0700 (PDT) Received: from hermes.local (76-14-218-44.or.wavecable.com. [76.14.218.44]) by smtp.gmail.com with ESMTPSA id z18sm2998237pfn.37.2021.06.10.13.03.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Jun 2021 13:03:17 -0700 (PDT) Date: Thu, 10 Jun 2021 13:03:11 -0700 From: Stephen Hemminger To: zhihongx.peng@intel.com Cc: anatoly.burakov@intel.com, dev@dpdk.org, xueqin.lin@intel.com Message-ID: <20210610130311.57f5dbfb@hermes.local> In-Reply-To: <20210610051352.48493-1-zhihongx.peng@intel.com> References: <20210610051352.48493-1-zhihongx.peng@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Subject: Re: [dpdk-dev] [RFC] porting AddressSanitizer feature to DPDK X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" On Thu, 10 Jun 2021 13:13:52 +0800 zhihongx.peng@intel.com wrote: > From: Zhihong Peng > > 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 > Signed-off-by: Zhihong Peng > --- > 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. 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.