Message ID | 20230206222513.1773039-1-iii@linux.ibm.com |
---|---|
Headers |
Return-Path: <elfutils-devel-bounces+patchwork=sourceware.org@sourceware.org> X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D428A3858D35 for <patchwork@sourceware.org>; Mon, 6 Feb 2023 22:25:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D428A3858D35 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1675722337; bh=voxzxLHtzjU5Eknqy/fpzd9LqUvzYaBtTWZfYO8Duek=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Help:List-Subscribe:From:Reply-To:From; b=DrIcShgy3TXF6SRBpHRcM8K6PINMBaviPgihFyLHmggtv0Mw5BYwBQ6AI56aWmSyD hR1omGSY7918dz6d/BN5bypTZCXzJE9t2DcPUpmv9nUrlADVJROgUITnrofw7tsRm5 r4mlSbOvx77S4vXi8eN/KCyg6Pb/C25plgMwQISg= X-Original-To: elfutils-devel@sourceware.org Delivered-To: elfutils-devel@sourceware.org Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by sourceware.org (Postfix) with ESMTPS id 339493858D1E for <elfutils-devel@sourceware.org>; Mon, 6 Feb 2023 22:25:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 339493858D1E Received: from pps.filterd (m0098396.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 316Ljjji018797 for <elfutils-devel@sourceware.org>; Mon, 6 Feb 2023 22:25:25 GMT Received: from ppma06ams.nl.ibm.com (66.31.33a9.ip4.static.sl-reverse.com [169.51.49.102]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3nk9rhrw8g-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for <elfutils-devel@sourceware.org>; Mon, 06 Feb 2023 22:25:24 +0000 Received: from pps.filterd (ppma06ams.nl.ibm.com [127.0.0.1]) by ppma06ams.nl.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 316GSWc2020984 for <elfutils-devel@sourceware.org>; Mon, 6 Feb 2023 22:25:22 GMT Received: from smtprelay06.fra02v.mail.ibm.com ([9.218.2.230]) by ppma06ams.nl.ibm.com (PPS) with ESMTPS id 3nhemfjv64-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for <elfutils-devel@sourceware.org>; Mon, 06 Feb 2023 22:25:22 +0000 Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay06.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 316MPJRH25297416 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 6 Feb 2023 22:25:19 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E722A20075; Mon, 6 Feb 2023 22:25:18 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9EE0520074; Mon, 6 Feb 2023 22:25:18 +0000 (GMT) Received: from heavy.lan (unknown [9.179.9.231]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP; Mon, 6 Feb 2023 22:25:18 +0000 (GMT) To: elfutils-devel@sourceware.org Cc: Ilya Leoshkevich <iii@linux.ibm.com> Subject: [PATCH RFC 00/11] Add Memory Sanitizer support Date: Mon, 6 Feb 2023 23:25:02 +0100 Message-Id: <20230206222513.1773039-1-iii@linux.ibm.com> X-Mailer: git-send-email 2.39.1 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: v_pQTeUtcSBwccdfXA7aERtFimryy6AY X-Proofpoint-ORIG-GUID: v_pQTeUtcSBwccdfXA7aERtFimryy6AY Content-Transfer-Encoding: 8bit X-Proofpoint-UnRewURL: 0 URL was un-rewritten MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.930,Hydra:6.0.562,FMLib:17.11.122.1 definitions=2023-02-06_07,2023-02-06_03,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 priorityscore=1501 lowpriorityscore=0 suspectscore=0 bulkscore=0 adultscore=0 spamscore=0 mlxscore=0 phishscore=0 malwarescore=0 clxscore=1011 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2302060191 X-Spam-Status: No, score=-4.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, KAM_ASCII_DIVIDERS, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: elfutils-devel@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Elfutils-devel mailing list <elfutils-devel.sourceware.org> List-Unsubscribe: <https://sourceware.org/mailman/options/elfutils-devel>, <mailto:elfutils-devel-request@sourceware.org?subject=unsubscribe> List-Archive: <https://sourceware.org/pipermail/elfutils-devel/> List-Help: <mailto:elfutils-devel-request@sourceware.org?subject=help> List-Subscribe: <https://sourceware.org/mailman/listinfo/elfutils-devel>, <mailto:elfutils-devel-request@sourceware.org?subject=subscribe> From: Ilya Leoshkevich via Elfutils-devel <elfutils-devel@sourceware.org> Reply-To: Ilya Leoshkevich <iii@linux.ibm.com> Errors-To: elfutils-devel-bounces+patchwork=sourceware.org@sourceware.org Sender: "Elfutils-devel" <elfutils-devel-bounces+patchwork=sourceware.org@sourceware.org> |
Series |
Add Memory Sanitizer support
|
|
Message
Ilya Leoshkevich
Feb. 6, 2023, 10:25 p.m. UTC
Hi, This series adds minimalistic support for Memory Sanitizer (MSan) [1]. MSan is compiler instrumentation for detecting accesses to uninitialized memory. The motivation behind this is to be able to link elfutils into projects instrumented with MSan, since it essentially requires all the code running in a process to be instrumented. The goal is to provide a setup where elfutils is linked only with zlib and most tests pass. Here is the description of the setup that I'm using: - LLVM with argp_parse() instrumentation [2]. - zlib-ng instrumented with MSan: git clone git@github.com:zlib-ng/zlib-ng.git cmake -DWITH_SANITIZER=Memory -DZLIB_COMPAT=ON -DWITH_GTEST=OFF \ -DCMAKE_C_COMPILER=clang -DCMAKE_INSTALL_PREFIX=/tmp/zlib-ng make install export CPATH=/tmp/zlib-ng/include export LIBRARY_PATH=/tmp/zlib-ng/lib - Hack: zlib is used by a lot of system utilities, so adding MSan-instrumented zlib to LD_LIBRARY_PATH causes a lot of grief. Let elfutils test infrastructure add it there only for running tests: ln -s /tmp/zlib-ng/lib/libz.so.1 libelf/ - elfutils uses printf("%n"), so tweak MSan to unpoison the respective arguments. Also disable fast unwinding to get better backtraces: export MSAN_OPTIONS=check_printf=1,fast_unwind_on_malloc=0 - Minimal configuration of elfutils instrumented with MSan: autoreconf -i CC=clang ./configure --enable-maintainer-mode \ --enable-sanitize-memory --without-bzlib \ --without-lzma --without-zstd \ --disable-debuginfod --disable-libdebuginfod \ --disable-demangler Results: ============================================================================ Testsuite summary for elfutils 0.188 ============================================================================ # TOTAL: 235 # PASS: 221 # SKIP: 14 # XFAIL: 0 # FAIL: 0 # XPASS: 0 # ERROR: 0 ============================================================================ The patches take care of the following: - Fixing clang build. - Adding small tweaks to get rid of false positives (no real issues were found, most likely because elfutils is already tested with valgrind). - Dealing with "-self" tests, which now see MSan runtime compiled into elfutils binaries. - MSan enablement itself. [1] https://clang.llvm.org/docs/MemorySanitizer.html [2] https://reviews.llvm.org/D143330 Best regards, Ilya Ilya Leoshkevich (11): libdwfl: Fix debuginfod_client redefinition libasm: Fix xdefault_pattern initialization printversion: Fix unused variable readelf: Fix set but not used parameter readelf: Fix set but not used variable Initialize reglocs for VMCOREINFO addr2line: Do not test demangling in run-addr2line-i-test.sh x86_64_return_value_location: Support lvalue and rvalue references configure: Use -fno-addrsig if possible configure: Add --disable-demangle configure: Add --enable-sanitize-memory backends/linux-core-note.c | 1 + backends/x86_64_retval.c | 2 ++ configure.ac | 40 ++++++++++++++++++++++++++++++++++- debuginfod/Makefile.am | 3 ++- lib/printversion.h | 3 ++- libasm/Makefile.am | 3 ++- libasm/asm_newscn.c | 5 ++--- libdw/Makefile.am | 3 ++- libdwfl/debuginfod-client.c | 2 +- libdwfl/libdwfl.h | 5 +---- libdwfl/libdwflP.h | 4 ++-- libelf/Makefile.am | 3 ++- src/readelf.c | 3 +-- tests/Makefile.am | 10 ++++++++- tests/run-addr2line-i-test.sh | 14 ++++++------ tests/run-readelf-self.sh | 5 +++++ tests/run-strip-reloc.sh | 5 +++++ tests/run-varlocs-self.sh | 5 +++++ 18 files changed, 90 insertions(+), 26 deletions(-)
Comments
Hi Ilya, On Mon, Feb 06, 2023 at 11:25:02PM +0100, Ilya Leoshkevich via Elfutils-devel wrote: > This series adds minimalistic support for Memory Sanitizer (MSan) [1]. > MSan is compiler instrumentation for detecting accesses to > uninitialized memory. > > The motivation behind this is to be able to link elfutils into projects > instrumented with MSan, since it essentially requires all the code > running in a process to be instrumented. Interesting. For regular CI testing we do use ubsan, valgrind and/or asan. So msan might not find many new issues in the elfutils code itself. But being able to link the elfutils libraries instrumented with msan against other projects build with msan might be very useful. > The goal is to provide a setup where elfutils is linked only with zlib > and most tests pass. Here is the description of the setup that I'm > using: > > - LLVM with argp_parse() instrumentation [2]. > > - zlib-ng instrumented with MSan: > > git clone git@github.com:zlib-ng/zlib-ng.git > cmake -DWITH_SANITIZER=Memory -DZLIB_COMPAT=ON -DWITH_GTEST=OFF \ > -DCMAKE_C_COMPILER=clang -DCMAKE_INSTALL_PREFIX=/tmp/zlib-ng > make install > export CPATH=/tmp/zlib-ng/include > export LIBRARY_PATH=/tmp/zlib-ng/lib > > - Hack: zlib is used by a lot of system utilities, so adding > MSan-instrumented zlib to LD_LIBRARY_PATH causes a lot of grief. > Let elfutils test infrastructure add it there only for running > tests: > > ln -s /tmp/zlib-ng/lib/libz.so.1 libelf/ > > - elfutils uses printf("%n"), so tweak MSan to unpoison the respective > arguments. Also disable fast unwinding to get better backtraces: > > export MSAN_OPTIONS=check_printf=1,fast_unwind_on_malloc=0 > > - Minimal configuration of elfutils instrumented with MSan: > > autoreconf -i > CC=clang ./configure --enable-maintainer-mode \ > --enable-sanitize-memory --without-bzlib \ > --without-lzma --without-zstd \ > --disable-debuginfod --disable-libdebuginfod \ > --disable-demangler Aren't there instrumented versions of bzip2, lzma/xz and/or zstd? Can't debuginfod and libdebuginfod be instrumented? Is the demangler disabled because you don't link against (an instrumented) libstdc++? > Results: > > ============================================================================ > Testsuite summary for elfutils 0.188 > ============================================================================ > # TOTAL: 235 > # PASS: 221 > # SKIP: 14 > # XFAIL: 0 > # FAIL: 0 > # XPASS: 0 > # ERROR: 0 > ============================================================================ Very good. > The patches take care of the following: > > - Fixing clang build. Yeah, it is a pity msan hasn't been integrated with gcc, we often find issues with clang. > - Adding small tweaks to get rid of false positives (no real issues > were found, most likely because elfutils is already tested with > valgrind). > - Dealing with "-self" tests, which now see MSan runtime compiled > into elfutils binaries. > - MSan enablement itself. > > Ilya Leoshkevich (11): > libdwfl: Fix debuginfod_client redefinition > libasm: Fix xdefault_pattern initialization > printversion: Fix unused variable > readelf: Fix set but not used parameter > readelf: Fix set but not used variable > Initialize reglocs for VMCOREINFO > addr2line: Do not test demangling in run-addr2line-i-test.sh > x86_64_return_value_location: Support lvalue and rvalue references > configure: Use -fno-addrsig if possible > configure: Add --disable-demangle > configure: Add --enable-sanitize-memory Thanks for splitting things out so nicely in separate patches. Cheers, Mark
On Tue, 2023-02-07 at 20:05 +0100, Mark Wielaard wrote: > Hi Ilya, > > On Mon, Feb 06, 2023 at 11:25:02PM +0100, Ilya Leoshkevich via > Elfutils-devel wrote: > > This series adds minimalistic support for Memory Sanitizer (MSan) > > [1]. > > MSan is compiler instrumentation for detecting accesses to > > uninitialized memory. [...] > > - Minimal configuration of elfutils instrumented with MSan: > > > > autoreconf -i > > CC=clang ./configure --enable-maintainer-mode \ > > --enable-sanitize-memory --without-bzlib \ > > --without-lzma --without-zstd \ > > --disable-debuginfod --disable-libdebuginfod > > \ > > --disable-demangler > > Aren't there instrumented versions of bzip2, lzma/xz and/or zstd? > > Can't debuginfod and libdebuginfod be instrumented? > > Is the demangler disabled because you don't link against (an > instrumented) libstdc++? I think with some effort instrumenting the dependencies is possible. bzlib and lzma are not particularly large, and zstd should support this out of the box. Regarding C++, an instrumented LLVM's libc++ should also just work. With all this, it should be possible to test elfutils with MSan without disabling the extra functionality. But since you already test with valgrind, I figured it would be highly unlikely that I find new bugs, and decided to limit the scope here. For my current purposes - linking elfutils into libbpf - this proved to be enough. [...] Best regards, Ilya