From patchwork Mon Jun 29 21:07:13 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 138088 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 03D484BA7990 for ; Mon, 29 Jun 2026 21:08:11 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTP id 9093F4BA23F9 for ; Mon, 29 Jun 2026 21:07:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9093F4BA23F9 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 9093F4BA23F9 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1782767246; cv=none; b=CjvYDHZsUQ1jMf3PgJDlFE8frZwpxf64TYj3CniGQb3joCrt58ghGnSCkhlvajbZZbmxPBwHD/vq/gEJfvDgClwmz8QITuXp84nVvAbG8AmNmX/bMld38xqYkMAFJAnPbD/KLxUU9I22bc6+a4hayQZt/+kRpDBqzsEMTLLyxug= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1782767246; c=relaxed/simple; bh=HxUZgw0PPi0azOypzof5DQm1EaedpFjNRLAtQ4IUn8k=; h=DKIM-Signature:From:To:Subject:Message-ID:Date:MIME-Version; b=tSAIrGUI9c2nhaoDg3x8bh4lc3WEh1f12pHinAF2zDBg61SJ9QBu7KVzq4090KHGn08tRWjx1hycUtlkfzHe8Shlrj3D2Xy9Jv9B7ywADV/yoHIIUbIr9eBD1i6DWQVlshkMnZxqvG1y0VtY2jETPs/m/qXqSxH/CwYnA8hewXw= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=HUQqVZlU DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9093F4BA23F9 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=HUQqVZlU DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1782767246; 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=pn3r87rzQQylVA6VzavitwFS2ZJ0knNUWtkU4xlpPYU=; b=HUQqVZlUg7Ot9iHv6XfdIYYla0kympAXMJmAx9mjer6n/5RYQdADfu5LKck2sUXvE31dYR 3+UAMfb7FoYtjBI7nzPB6NIYZOuvWKZAWq4IXl/0wLa8bcUdV4XJyS0KiNm7iuHUi1l+Ig eqT7xXV9FkOZN9KZITUA4YSq1b0n7Ao= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-479-YEmaH3FSPFq6agv8CplaXg-1; Mon, 29 Jun 2026 17:07:22 -0400 X-MC-Unique: YEmaH3FSPFq6agv8CplaXg-1 X-Mimecast-MFC-AGG-ID: YEmaH3FSPFq6agv8CplaXg_1782767241 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 5C719182FA46; Mon, 29 Jun 2026 21:07:20 +0000 (UTC) Received: from fweimer-oldenburg.csb.redhat.com (unknown [10.44.48.121]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id DDD601800347; Mon, 29 Jun 2026 21:07:16 +0000 (UTC) From: Florian Weimer To: libc-alpha@sourceware.org Cc: Simon Marchi , Andrew Burgess , Wilco Dijkstra , Yury Khrustalev , Thiago Jung Bauermann , Adhemerval Zanella Netto , Carlos O'Donell , Muhammad Kamran Subject: [PATCH 2/2] aarch64: Add workaround for GDB bug handling string literals In-Reply-To: Message-ID: <5fde182125e1e9d8a4c428a81b71aa78342a9836.1782766548.git.fweimer@redhat.com> References: X-From-Line: 5fde182125e1e9d8a4c428a81b71aa78342a9836 Mon Sep 17 00:00:00 2001 Date: Mon, 29 Jun 2026 23:07:13 +0200 User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: hQO_ce8BF34T-Vb5FzdwR2Z-cJkKYWqLwgc5hqKAuhs_1782767241 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-10.9 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_PASS, SPF_NONE, TXREP shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on 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~patchwork=sourceware.org@sourceware.org When GDB evaluates an expression in the inferior, it first creates a copy of the string using malloc. For this malloc call, GDB was not tracking properly if the malloc symbol is actually an IFUNC resolver. This means that the IFUNC resolver gets called like the real malloc function. This change adds a kludge to detect this, which prevents GDB from overwriting the __libc_malloc code with the user-supplied string literal. --- sysdeps/aarch64/multiarch/malloc-ifuncs.c | 60 +++++++++++++++++------ 1 file changed, 46 insertions(+), 14 deletions(-) diff --git a/sysdeps/aarch64/multiarch/malloc-ifuncs.c b/sysdeps/aarch64/multiarch/malloc-ifuncs.c index 648fb617de..3552168ecd 100644 --- a/sysdeps/aarch64/multiarch/malloc-ifuncs.c +++ b/sysdeps/aarch64/multiarch/malloc-ifuncs.c @@ -19,55 +19,87 @@ #if IS_IN (libc) #include +#include #include #include - -libc_ifunc_hidden (__libc_malloc, __libc_malloc_redirect, - __libc_malloc) +#include +#include +#include + +/* Return true if the resolver function has been called through GDB. + This used below to determine if GDB incorrectly calls the malloc + IFUNC resolver instead of the resolver result. The trampoline + address is either on the stack, or the kernel-provided entry point, + depending on architecture. + + A fixed GDB will get the malloc address from the GOT. Calling + malloc before relocation processing is complete should use the + ld.so malloc, which does not involve an IFUNC. */ +static inline bool +called_from_gdb (uintptr_t return_address, uintptr_t stack_frame) +{ +#ifdef SHARED + /* Assume that the stack grows downwards. */ + if (stack_frame <= return_address && return_address <= stack_frame + 128) + return true; + + /* GDB uses the kernel-provided entry point on some architectures + for the trampoline. */ + if (return_address == GLRO(dl_entry)) + return true; +#endif + return false; +} + +__ifunc_hidden (__libc_malloc, __libc_malloc_redirect, + called_from_gdb ((uintptr_t) __builtin_return_address (0), + (uintptr_t) __builtin_frame_address (0)) + ? __libc_malloc (size) : (void *) __libc_malloc, + size_t size, INIT_ARCH) strong_alias (__libc_malloc_redirect, malloc) libc_ifunc_hidden (__libc_calloc, __libc_calloc_redirect, - __libc_calloc) + __libc_calloc) weak_alias (__libc_calloc_redirect, calloc) libc_ifunc_hidden (__libc_memalign, __libc_memalign_redirect, - __libc_memalign) + __libc_memalign) weak_alias (__libc_memalign_redirect, memalign) libc_ifunc_hidden (__libc_valloc, __libc_valloc_redirect, - __libc_valloc) + __libc_valloc) weak_alias (__libc_valloc_redirect, valloc) libc_ifunc_hidden (__libc_pvalloc, __libc_pvalloc_redirect, - __libc_pvalloc) + __libc_pvalloc) weak_alias (__libc_pvalloc_redirect, pvalloc) libc_ifunc_hidden (__libc_realloc, __libc_realloc_redirect, - __libc_realloc) + __libc_realloc) strong_alias (__libc_realloc_redirect, realloc) libc_ifunc_hidden (__libc_free, __libc_free_redirect, - __libc_free) + __libc_free) strong_alias (__libc_free_redirect, free) libc_ifunc_hidden (__malloc_usable_size, __malloc_usable_size_redirect, - __malloc_usable_size) + __malloc_usable_size) weak_alias (__malloc_usable_size_redirect, malloc_usable_size) libc_ifunc_hidden (__posix_memalign, __posix_memalign_redirect, - __posix_memalign) + __posix_memalign) weak_alias (__posix_memalign_redirect, posix_memalign) libc_ifunc_hidden (__aligned_alloc, __aligned_alloc_redirect, - __aligned_alloc) + __aligned_alloc) weak_alias (__aligned_alloc_redirect, aligned_alloc) libc_ifunc_hidden (__free_sized, __free_sized_redirect, - __free_sized) + __free_sized) weak_alias (__free_sized_redirect, free_sized) libc_ifunc_hidden (__free_aligned_sized, __free_aligned_sized_redirect, - __free_aligned_sized) + __free_aligned_sized) weak_alias (__free_aligned_sized_redirect, free_aligned_sized) #endif /* IS_IN (libc) */