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 E477DA0032; Fri, 29 Oct 2021 11:23:43 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id D35DA410E1; Fri, 29 Oct 2021 11:23:43 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mails.dpdk.org (Postfix) with ESMTP id 26752410E0 for ; Fri, 29 Oct 2021 11:23:42 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1635499421; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=dpfK6qHJRju6RruAxmOgBpSqLtP7ckn5b8BMXbMXnB0=; b=ZDxNOmpmDMNfuZq0qtwNFn5CM0+i7yPspjYI9ygW0Yq3nG65QE76ZR+SYYo2PEV1VFbxjb TVzglIRxRD0AR39wkZuRNqa0zsNul5H86SeYQe40GNMkCskimGhhoxN8+hWbgXkx3G3Rh2 vjZBG8yy2SGCg/t+Yxintv0Mmb27X2Y= Received: from mail-lf1-f70.google.com (mail-lf1-f70.google.com [209.85.167.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-19-cNmEPUDJMImQTuFJKZrLJQ-1; Fri, 29 Oct 2021 05:23:40 -0400 X-MC-Unique: cNmEPUDJMImQTuFJKZrLJQ-1 Received: by mail-lf1-f70.google.com with SMTP id i1-20020a056512340100b003fdd5b951e0so3901713lfr.22 for ; Fri, 29 Oct 2021 02:23:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=dpfK6qHJRju6RruAxmOgBpSqLtP7ckn5b8BMXbMXnB0=; b=MfzPhHWUva4kHtgI7/GfVguL5BCmc7P0wFuC/kfom1jmx5KlHz3TehCZo5/jKQH4sx hMtvSK5kiaoFuXUJ3tc1KF/tswAp+brAzXYgwN+FBIKN11+RBZHB6VUshbGIVE8PkZ8v 8sfw/+Te3SROylOgAEy40rpRKIRdmoKRJZ4WCO1TINg6Ixbh1c2qH3KaUobqFfi+cy8R kQqc52miC77t4WUNsDTWgZhOK19OQmkWOea6dtNMZwnm8Usrm+9QTGY/6sMSP7E4Fax6 dIahZsK1qdJadWXC0im8OYOuxwJcH2hfIu39xRZutP+NM0hkq0hdAs2SvXRPyTYLV0iK A8QA== X-Gm-Message-State: AOAM530Aip6t9iDkz2dh2eH5e5q97mY3Z6dhT1HC6p3B4Leuvby9qjbf eHenpZ14wlfPSSCfSym2Fa6TQt8oRkzbxT8TUfHm7ZV//IbLR3FVerFIintB/ooGxmoOrnrYyCX Qnaivd8fCLr2ELYk327w= X-Received: by 2002:ac2:44d5:: with SMTP id d21mr9416696lfm.484.1635499418559; Fri, 29 Oct 2021 02:23:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxgl15hW/vhjHYPuuYBnkkB9D75r9Ka+rdIOuImA05t/vHPCkxbaEDpvl/T90Lzynm0WXdHmk5JJazjG267EsM= X-Received: by 2002:ac2:44d5:: with SMTP id d21mr9416666lfm.484.1635499418290; Fri, 29 Oct 2021 02:23:38 -0700 (PDT) MIME-Version: 1.0 References: <20211019151524.2005442-4-zhihongx.peng@intel.com> <20211020074643.3004385-1-zhihongx.peng@intel.com> <20211020074643.3004385-2-zhihongx.peng@intel.com> In-Reply-To: <20211020074643.3004385-2-zhihongx.peng@intel.com> From: David Marchand Date: Fri, 29 Oct 2021 11:23:27 +0200 Message-ID: To: Zhihong Peng Cc: Thomas Monjalon , "Burakov, Anatoly" , "Ananyev, Konstantin" , Stephen Hemminger , Cristian Dumitrescu , "Mcnamara, John" , Bruce Richardson , dev , Xueqin Lin Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dmarchan@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" Subject: Re: [dpdk-dev] [PATCH v13 2/4] DPDK code adapts to ASan 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 Wed, Oct 20, 2021 at 9:47 AM wrote: > > From: Zhihong Peng > > DPDK ASan functionality is currently only supported on Linux x86_64. > If want to support on other platforms, need to define ASAN_SHADOW_OFFSET > value according to google ASan document, and configure meson file > (config/meson.build). > > Signed-off-by: Xueqin Lin > Signed-off-by: Zhihong Peng > Acked-by: Anatoly Burakov Suggests following title/commitlog: """ mem: instrument allocator for ASan This patch adds necessary hooks in the memory allocator for ASan. This feature is currently available in DPDK only on Linux x86_64. If other OS/architectures want to support it, ASAN_SHADOW_OFFSET must be defined and RTE_MALLOC_ASAN must be set accordingly in meson. """ > --- > v7: Split doc and code into two. > v8: No change. > v9: Modify the definition of RTE_MALLOC_ASAN. > v10:Modify the definition of RTE_MALLOC_ASAN. > v11:No change. > v12:No change. > v13:Modify the document. > --- > config/meson.build | 4 + > doc/guides/prog_guide/asan.rst | 58 +++++++++- > lib/eal/common/malloc_elem.c | 26 ++++- > lib/eal/common/malloc_elem.h | 194 ++++++++++++++++++++++++++++++++- > lib/eal/common/malloc_heap.c | 12 ++ > lib/eal/common/rte_malloc.c | 9 +- > 6 files changed, 296 insertions(+), 7 deletions(-) > > diff --git a/config/meson.build b/config/meson.build > index f02b0e9c6d..bf751583bd 100644 > --- a/config/meson.build > +++ b/config/meson.build > @@ -425,6 +425,10 @@ if get_option('b_sanitize') == 'address' or get_option('b_sanitize') == 'address > add_project_link_arguments('-lasan', language: 'c') > dpdk_extra_ldflags += '-lasan' > endif > + > + if is_linux and arch_subdir == 'x86' Missing a check on "and dpdk_conf.get('RTE_ARCH_64')" for i386 build. > + dpdk_conf.set10('RTE_MALLOC_ASAN', true) > + endif > endif > > if get_option('default_library') == 'both' > diff --git a/doc/guides/prog_guide/asan.rst b/doc/guides/prog_guide/asan.rst > index 6888fc9a87..02591ca68a 100644 > --- a/doc/guides/prog_guide/asan.rst > +++ b/doc/guides/prog_guide/asan.rst > @@ -13,6 +13,58 @@ printing out detailed debug information whenever an error is detected. > > AddressSanitizer is a part of LLVM (3.1+) and GCC (4.8+). I'll move the examples after the explanations on how to enable ASan. > > +DPDK ASan functionality is currently only supported on Linux x86_64. > +If want to support on other platforms, need to define ASAN_SHADOW_OFFSET > +value according to google ASan document, and configure meson file > +(config/meson.build). DPDK ASan functionnality is vague. Suggests rewording: """ ASan is aware of DPDK memory allocations, thanks to added instrumentation. This is only enabled on x86_64 at the moment. Other architectures may have to define ASAN_SHADOW_OFFSET. """ > + > +Example heap-buffer-overflow error > +---------------------------------- > + > +Add below unit test code in examples/helloworld/main.c:: > + > + Add code to helloworld: > + char *p = rte_zmalloc(NULL, 9, 0); > + if (!p) { > + printf("rte_zmalloc error."); > + return -1; > + } > + p[9] = 'a'; > + > +Above code will result in heap-buffer-overflow error if ASan is enabled, because apply 9 bytes of memory but access the tenth byte, detailed error log as below:: > + > + ==369953==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x7fb17f465809 at pc 0x5652e6707b84 bp 0x7ffea70eea20 sp 0x7ffea70eea10 WRITE of size 1 at 0x7fb17f465809 thread T0 > + #0 0x5652e6707b83 in main ../examples/helloworld/main.c:47 > + #1 0x7fb94953c0b2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x270b2) > + #2 0x5652e67079bd in _start (/home/pzh/asan_test/x86_64-native-linuxapp-gcc/examples/dpdk-helloworld+0x8329bd) > + > + Address 0x7fb17f465809 is a wild pointer. > + SUMMARY: AddressSanitizer: heap-buffer-overflow ../examples/helloworld/main.c:47 in main I'll move the note update here: """ Note:: - Some of the features of ASan (for example, 'Display memory application location, currently displayed as a wild pointer') are not currently supported with DPDK allocations. """ > + > +Example use-after-free error > +---------------------------- > + > +Add below unit test code in examples/helloworld/main.c:: > + > + Add code to helloworld: > + char *p = rte_zmalloc(NULL, 9, 0); > + if (!p) { > + printf("rte_zmalloc error."); > + return -1; > + } > + rte_free(p); > + *p = 'a'; > + > +Above code will result in use-after-free error if ASan is enabled, because apply 9 bytes of memory but access the first byte after release, detailed error log as below:: > + > + ==417048==ERROR: AddressSanitizer: heap-use-after-free on address 0x7fc83f465800 at pc 0x564308a39b89 bp 0x7ffc8c85bf50 sp 0x7ffc8c85bf40 WRITE of size 1 at 0x7fc83f465800 thread T0 > + #0 0x564308a39b88 in main ../examples/helloworld/main.c:48 > + #1 0x7fd0079c60b2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x270b2) > + #2 0x564308a399bd in _start (/home/pzh/asan_test/x86_64-native-linuxapp-gcc/examples/dpdk-helloworld+0x8329bd) > + > + Address 0x7fc83f465800 is a wild pointer. > + SUMMARY: AddressSanitizer: heap-use-after-free ../examples/helloworld/main.c:48 in main > + > Add following meson build commands to enable ASan in the meson build system: > > * gcc:: > @@ -25,6 +77,8 @@ Add following meson build commands to enable ASan in the meson build system: > > .. Note:: > > - a) If compile with gcc in centos, libasan needs to be installed separately. > - b) If the program is tested using cmdline, you may need to execute the > + a) Some of the features of ASan (for example, 'Display memory application location, currently > + displayed as a wild pointer') are not currently supported by DPDK's implementation. > + b) If compile with gcc in centos, libasan needs to be installed separately. > + c) If the program is tested using cmdline, you may need to execute the > "stty echo" command when an error occurs. -- David Marchand