From patchwork Sat Oct 28 19:55:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 1856597 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=w2+jc6cH; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4SHqzX0PSMz1yQM for ; Sun, 29 Oct 2023 06:56:23 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id F16FA38618D9 for ; Sat, 28 Oct 2023 19:56:21 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-oi1-x233.google.com (mail-oi1-x233.google.com [IPv6:2607:f8b0:4864:20::233]) by sourceware.org (Postfix) with ESMTPS id 0BE70385C6FC for ; Sat, 28 Oct 2023 19:56:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0BE70385C6FC Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 0BE70385C6FC Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::233 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698522972; cv=none; b=cUWXescc2OAtMiteDkJj/BIao2XXxC5ZgpkBPzVe7GWuRPlzSyE7KdFIozeDQuTnKOOEI9J50kLpdkWIVG4YliuV1haAOWQzAX9dIWj2ALr6GYnTFo8wj2RPWdObLDwPl7qdHvv5rtHz2+l1thNwPfEY1k1/0QLmas9ydxiWcZQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698522972; c=relaxed/simple; bh=jS0vInlhvN2Bbp4jIbjzLCz6bGxRw18NmTqqAKrrrIE=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=QifhUAQtR8YVhbh/mGZ/jUMha9pWHMoAdQwPkVdF3FMEzrLD1HV8rhvmbgXmusJuej2EojWNsb1p813mhJUhH+cYi6FxCh5F6ZWx3iGQ87z2Jidokh5l7xpuK8840GAbAzGx02ZHlNQjRoel/hk6DPDp0w2r4DdXA+Ifavj+KG8= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-oi1-x233.google.com with SMTP id 5614622812f47-3b2b1ae4c21so2210941b6e.0 for ; Sat, 28 Oct 2023 12:56:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1698522968; x=1699127768; darn=sourceware.org; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=au1POA+jNmhJ5f/3XKgaVrQLncRhtVb4FvarCSDhYYk=; b=w2+jc6cHE31CpGQWa3p4bykVPI1+KQD88BZJetT3CnGtT+ODd1+YLwX2BLK4N+lVKR tLlsvm361u3VzlSjAYC3xZr3uriVwkbCzQXriF0uuudNeefqrSXvlynFpggY9WBRzdO+ HwHV+mSdo6KnY1p5VbIjrWKdRcIylr/3YbZsigXtmCj9VB4e4oInb7j00tf7ABfQwkbg /krh3ZwcIsjKB7XG4osXM5ak8bMqn6gsSQnVOZE6+sIYcx7wooeFDUWyUdI8tI0f53eK K1W1AltaW8TxyJWc8YQ1kcB8ksgmVzHPvr9ZjUNr5nOn9KY6lAYZtllQN7/dScwSzckm t+Cw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698522968; x=1699127768; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=au1POA+jNmhJ5f/3XKgaVrQLncRhtVb4FvarCSDhYYk=; b=Pwrb51svNVojv8z7/4nGfSWpkUJ3NTK90pQKMMrqU+z5bydms23hJqZQNanGpIlUen t+6Hmcpfu+vhnR4RKY89kA7FjLTKFbvBuRKjNhteSJH/MCPrNlDrVR5H8jZae0C0J7oz +g1MXCkixBGfFjNuZwzzutUYpAsK1Q6V+z/WGvyWCILRzvJtct/Y+w7sv6frbOB2tAsy bzmBb6Y8DUbYktItr5wvy+KrkQNLPgvauht2p1y7xIEmpUA2SxF4fgCW4o+sAdp0tvZO YifbBRblMxXPPsGBzDBTbanvKl/L+27KM3GpC/LoUDkS5OOUYvw0eKEqBkLXqhZLs7jL v9Yw== X-Gm-Message-State: AOJu0YzfbuZil4d3EGZ78hxRC74hoKH6v2DTWMG7DKhRyJysLeXYIJ32 U2/R35WLyFxao/xyQaeZHokdcB4iN7rXgQWc/no= X-Google-Smtp-Source: AGHT+IETl7nUGwFTiSVL8VDDNc/BZk349nbFjQC1tNSlOM7IP+5oCtLisZVVzGfcl+RbjpPCNDiLJA== X-Received: by 2002:a05:6808:1986:b0:3ab:84f0:b49d with SMTP id bj6-20020a056808198600b003ab84f0b49dmr7627608oib.3.1698522968508; Sat, 28 Oct 2023 12:56:08 -0700 (PDT) Received: from localhost.localdomain ([139.178.84.207]) by smtp.gmail.com with ESMTPSA id w20-20020a056830411400b006b8c87551e8sm763181ott.35.2023.10.28.12.56.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Oct 2023 12:56:07 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org, Ian Rogers , Francesco Nigro , Carlos O'Donell , Siddhesh Poyarekar Subject: [PATCH v2 0/7] Add a tunable to decorate anonymous memory maps Date: Sat, 28 Oct 2023 19:55:52 +0000 Message-Id: <20231028195559.390407-1-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-6.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, URIBL_BLACK 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: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Linux 4.5 removed thread stack annotations due to the complexity of computing them, and Linux 5.17 added support to naming anonymous virtual memory areas through the prctl syscall [1]. Android and other projects like sanitizers uses this feature to improve debugability and a way to user understand better what kind of memory runtime allocates. The patchset adds annotations for the pthread stack, on both glibc created and user-provided, on loader minimal malloc and on malloc arenas and default allocation. For instance, on x86_64 the resulting mapping of the newly tst-decorate-maps shows: 5649d25bd000-5649d25bf000 r--p 00000000 103:05 40141614 /elf/tst-decorate-maps 5649d25bf000-5649d25c3000 r-xp 00002000 103:05 40141614 /elf/tst-decorate-maps 5649d25c3000-5649d25c5000 r--p 00006000 103:05 40141614 /elf/tst-decorate-maps 5649d25c5000-5649d25c6000 r--p 00007000 103:05 40141614 /elf/tst-decorate-maps 5649d25c6000-5649d25c7000 rw-p 00008000 103:05 40141614 /elf/tst-decorate-maps 5649d36c4000-5649d36e5000 rw-p 00000000 00:00 0 [heap] 7fc76c000000-7fc76c021000 rw-p 00000000 00:00 0 [anon: glibc: malloc arena] 7fc76c021000-7fc770000000 ---p 00000000 00:00 0 7fc774000000-7fc774021000 rw-p 00000000 00:00 0 [anon: glibc: malloc arena] 7fc774021000-7fc778000000 ---p 00000000 00:00 0 7fc77c000000-7fc77c021000 rw-p 00000000 00:00 0 [anon: glibc: malloc arena] 7fc77c021000-7fc780000000 ---p 00000000 00:00 0 7fc784000000-7fc784021000 rw-p 00000000 00:00 0 [anon: glibc: malloc arena] 7fc784021000-7fc788000000 ---p 00000000 00:00 0 7fc788000000-7fc788021000 rw-p 00000000 00:00 0 [anon: glibc: malloc arena] 7fc788021000-7fc78c000000 ---p 00000000 00:00 0 7fc78c000000-7fc78c021000 rw-p 00000000 00:00 0 [anon: glibc: malloc arena] 7fc78c021000-7fc790000000 ---p 00000000 00:00 0 7fc790000000-7fc790021000 rw-p 00000000 00:00 0 [anon: glibc: malloc arena] 7fc790021000-7fc794000000 ---p 00000000 00:00 0 7fc796800000-7fc797000000 rw-p 00000000 00:00 0 [anon: glibc: pthread stack: 2188506] 7fc797000000-7fc797800000 rw-p 00000000 00:00 0 [anon: glibc: pthread stack: 2188505] 7fc797800000-7fc798000000 rw-p 00000000 00:00 0 [anon: glibc: pthread stack: 2188504] 7fc798000000-7fc798800000 rw-p 00000000 00:00 0 [anon: glibc: pthread stack: 2188503] 7fc798800000-7fc799000000 rw-p 00000000 00:00 0 [anon: glibc: pthread stack: 2188502] 7fc799000000-7fc799800000 rw-p 00000000 00:00 0 [anon: glibc: pthread stack: 2188501] 7fc799800000-7fc79a000000 rw-p 00000000 00:00 0 [anon: glibc: pthread stack: 2188500] 7fc79a000000-7fc79a800000 rw-p 00000000 00:00 0 [anon: glibc: pthread stack: 2188499] 7fc79a800000-7fc79a826000 r--p 00000000 103:05 38343761 /libc.so 7fc79a826000-7fc79a99a000 r-xp 00026000 103:05 38343761 /libc.so 7fc79a99a000-7fc79a9f1000 r--p 0019a000 103:05 38343761 /libc.so 7fc79a9f1000-7fc79a9f5000 r--p 001f0000 103:05 38343761 /libc.so 7fc79a9f5000-7fc79a9f7000 rw-p 001f4000 103:05 38343761 /libc.so 7fc79a9f7000-7fc79aa04000 rw-p 00000000 00:00 0 7fc79aabb000-7fc79aafb000 rw-p 00000000 00:00 0 [anon: glibc: pthread user stack: 2188508] 7fc79aafb000-7fc79ab3b000 rw-p 00000000 00:00 0 [anon: glibc: pthread user stack: 2188507] 7fc79ab3b000-7fc79ab7c000 rw-p 00000000 00:00 0 [anon: glibc: malloc] 7fc79ab7c000-7fc79ab7d000 rw-s 00000000 00:01 19458 /dev/zero (deleted) 7fc79ab7d000-7fc79ab82000 rw-p 00000000 00:00 0 [anon: glibc: loader malloc] 7fc79ab82000-7fc79ab83000 r--p 00000000 103:05 40141609 /elf/ld.so 7fc79ab83000-7fc79aba9000 r-xp 00001000 103:05 40141609 /elf/ld.so 7fc79aba9000-7fc79abb3000 r--p 00027000 103:05 40141609 /elf/ld.so 7fc79abb3000-7fc79abb5000 r--p 00031000 103:05 40141609 /elf/ld.so 7fc79abb5000-7fc79abb7000 rw-p 00033000 103:05 40141609 /elf/ld.so 7ffdb2f1d000-7ffdb2f3f000 rw-p 00000000 00:00 0 [stack] 7ffdb2f7a000-7ffdb2f7e000 r--p 00000000 00:00 0 [vvar] 7ffdb2f7e000-7ffdb2f80000 r-xp 00000000 00:00 0 [vdso] ffffffffff600000-ffffffffff601000 --xp 00000000 00:00 0 [vsyscall] The PR_SET_VMA_ANON_NAME support is currently only enabled through a configurable kernel switch, mainly because assigning a name to a anonymous virtual memory area might prevent that area from being merged with adjacent virtual memory areas. There is also a potential scalability issue, where the prctl requires take the mmap global lock and it still not fully fixed in Linux [1] (for pthread stacks and arenas, it is mitigated by the stack cached and the arena reuse). So the decoration is only enable through a new tunable, glibc.mem.decorate_maps. [1] https://github.com/torvalds/linux/commit/65376df582174ffcec9e6471bf5b0dd79ba05e4a [1] https://github.com/torvalds/linux/commit/9a10064f5625d5572c3626c1516e0bebc6c9fe9b Changes from v1: * Fixed arm thumb build. * Added decoration on assert and __libc_fatal. Adhemerval Zanella (7): linux: Add PR_SET_VMA_ANON_NAME support support: Add support_set_vma_name nptl: Decorate thread stack on pthread_create malloc: Decorate malloc maps assert: Decorate error message buffer linux: Decorate __libc_fatal error buffer elf: Add glibc.mem.decorate_maps tunable NEWS | 5 + assert/assert.c | 2 + elf/Makefile | 7 + elf/dl-minimal-malloc.c | 2 + elf/dl-tunables.list | 5 + elf/tst-decorate-maps.c | 197 +++++++++++++++++++++++++++ include/sys/prctl.h | 5 + malloc/arena.c | 4 + malloc/malloc.c | 5 + manual/tunables.texi | 12 ++ nptl/Makefile | 4 + nptl/allocatestack.c | 40 ++++++ nptl/pthread_create.c | 6 + support/Makefile | 1 + support/support.h | 4 + support/support_set_vma_name.c | 49 +++++++ sysdeps/generic/setvmaname.h | 27 ++++ sysdeps/posix/libc_fatal.c | 3 + sysdeps/unix/sysv/linux/Makefile | 1 + sysdeps/unix/sysv/linux/setvmaname.c | 48 +++++++ sysdeps/unix/sysv/linux/setvmaname.h | 36 +++++ 21 files changed, 463 insertions(+) create mode 100644 elf/tst-decorate-maps.c create mode 100644 support/support_set_vma_name.c create mode 100644 sysdeps/generic/setvmaname.h create mode 100644 sysdeps/unix/sysv/linux/setvmaname.c create mode 100644 sysdeps/unix/sysv/linux/setvmaname.h