From nobody Sun Dec 6 20:46:09 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1796219749; cv=none; d=zohomail.com; s=zohoarc; b=nVmDfrw4yeB4y+fYdcphYoHDWY2a9YytQu6ChlSZa2l70JCS8/b2wqXEdJRgYN0Q0Jx1OzmMfhc0W9oXrc1V+328W2ub3FTharZgAo6BKGG9NAlgnO1CWtIkM8UXMDtVmlgOT80YqX0+E9zPQAgj861I1tYRc37gyQwzLUbNrLU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1796219749; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=D/+eDieVFTBtB++pEKrTf+qwjtcWt/pol8zMAtFq3WI=; b=NfXxfQEAsovJMK5uMHKC/h2jIKnF4vMkMxeWpaRta2kKR7GMjgzlJUtuPwdNxZysIxbRnWPSEuSfvi7vaNFlleTFhyPeuGMkOFs0O7WOhwrW6skV1RAD75xGLT91infdJZ/AX64ORPKVQH9uobFm7YTCZg4t1NDu+GpYNbIVlgc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 179621974979267.2889632171507; Wed, 2 Dec 2026 05:55:49 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xYknm-0006Ow-Ad; Wed, 02 Dec 2026 08:55:18 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xYkng-0006KF-OI for qemu-devel@nongnu.org; Wed, 02 Dec 2026 08:55:14 -0500 Received: from mail-ej1-x636.google.com ([2a00:1450:4864:20::636]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xYknc-00017f-NE for qemu-devel@nongnu.org; Wed, 02 Dec 2026 08:55:12 -0500 Received: by mail-ej1-x636.google.com with SMTP id a640c23a62f3a-c523e545e45so79780166b.2 for ; Wed, 02 Dec 2026 05:55:02 -0800 (PST) Received: from qblck ([163.245.50.18]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-c513afc42easm1340479566b.60.2026.12.02.05.54.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Dec 2026 05:55:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796219701; x=1796824501; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=D/+eDieVFTBtB++pEKrTf+qwjtcWt/pol8zMAtFq3WI=; b=T9Xy46QkeObh8+NvjCJZs3lneErvVv/2Dd9kfYd2pOtVnuw3KOOx0akeJv7++7GI0Y VwyEJ7N/cMEhGBjtEBZQuXEuIrHn220gQ34YZp7YbxyMKMc8IJEl/SSpp3csKbLrsShO L9QnQPPl7NaL/8gEnlcZo1qzg2y7/LgqO70okV7jBngbxVp4b8JOu8bb3vdiPJZPR2Ze 34XVmPmSKj5J4246diD0+R9W7NQsMM0g0MslxmguwZMI7y6ESvW66U4ZExhEzLqainNo upPjnu5VZfDjSxwFzaIjqVuXNM6KWsxAdGKyc6Mc2goUgSyWDaY9ayDS21xCFAxf6pos 2xlA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796219701; x=1796824501; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=D/+eDieVFTBtB++pEKrTf+qwjtcWt/pol8zMAtFq3WI=; b=kWA9SjzgZNw95g/uOiBKPJJk+ZlUQ4uk2V9hlmgWITS5uNf+kl/URAfKdXHKpa/SIK BszhM4AweweKnxKA9cbQnjJvSagYo2uI1Fly6FTkvb93Ygu43uCCkVwznwavY4kg7Zmt oBv3x/XF7HM6YMs2WnlrHyijivWM6s8nCIHcQqWOxtrahddnkx9yvlyzyC4uL+WU0+d2 DjbUN1fSSnrRBB2RFSsvnOuT6AwcbyDP4rm7/6DIiJquZOWPs0PbIJAVBd5D6fmud3pi JKQ31dGxwyB6Jjk80EjEgGSOac2vN5lizteWFdJO6AujMc236rWXTyPjGwF7LUhxGQFp Jwfg== X-Gm-Message-State: APuU4Z+ak5j8HKezrAsirGaDfQwaa3Utxb8v1mP885ossyScQr1jhOcD e58PxboxMk/Mf9x4grYtTvJqtVYJrCXvtCujQntDsM+ad6pV+UW5HTuPdTnTCg== X-Gm-Gg: AZFdTZfrfeZxzTrKuMCwbTiSzvrIjTyuBnXzz3tiWfqoBZeXI3WrCynq8nL7SmVf36+ 56a1o50Jbk0v7CcZHI73GJbiY0CTkF+ywqjInujwCym+5JPLCGJsKGgjVh+KrjyYir2iAw9M5h1 rgg5yELnlkmSXZIdNuxEXmXCxPoZv6MSKgpRMINyssez5R8wf3QsppP1WWPWUWXFRse2632Q1sw kesQ7F7xAS5wFks8kVhLfA3rQc1v+PsHGafMJOumHEHSFqFb/RpvgZFs6vVZxRa6/SBAC6/kae5 /p1VpSmCghCVLiCq4R9ziDPdOb8cjQ/FT++pi0cCM+4QRroDCRZkBkmDJr6M5WqdIwAVO0TuOY0 7YaAT0HkejB/+gjS3B3JMn4Wj2QUn/hizzs8A/C0Nc81l5/grD6F2DIwKhNOMgWtuhKvLLMeR3y T1ixe5KMiCLoBEliQGdzTS99UGeTvrd7FOVdWZ/f8RvHCVYKnErq9tVrbA0ikpEqPMMi6J7cOvI ux+Lg2RKW0TdO6b6TrOEZdI6PjUA+Ic9rCRYfSAb6++yyfIIExDshAXBsZsQxVdrAoiqMPSMjyg 770c1iosyhdAe/bH2whK2iqzFxE/GhQ6hqTWIeHxsOUVfa6deEwOkIG2lzGwjMODLfHeJx3uXgK MPuFBtuHsal11cmnk X-Received: by 2002:a17:907:584:b0:c46:c3ad:e1ca with SMTP id a640c23a62f3a-c513a84dcf9mr2539130366b.9.1796219701063; Wed, 02 Dec 2026 05:55:01 -0800 (PST) From: Artemii Mashanov To: qemu-devel@nongnu.org Cc: Artemii Mashanov , qemu-arm@nongnu.org, laurent@vivier.eu, deller@gmx.de, pierrick.bouvier@oss.qualcomm.com, peter.maydell@linaro.org, alex.bennee@linaro.org Subject: [PATCH v3] linux-user: retry ignored ELF load hints for PIE executables Date: Wed, 2 Dec 2026 16:54:44 +0300 Message-ID: <20261202135444.34994-1-ralerrdirsardx@gmail.com> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261130225027.115785-1-ralerrdirsardx@gmail.com> References: <20261130225027.115785-1-ralerrdirsardx@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::636; envelope-from=ralerrdirsardx@gmail.com; helo=mail-ej1-x636.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1796219752168158500 Content-Type: text/plain; charset="utf-8" On x86_64 hosts that cannot map the preferred AArch64 ET_DYN base, mmap() may place the main image near QEMU's host mappings, causing subsequent brk growth to fail. Retry with lower page-aligned hints for main ET_DYN images without reserved guest address space. Add an AArch64 static PIE regression for heap growth, memory access and restoration of the original break. Allow individual TCG tests to select static PIE linking. Resolves: https://gitlab.com/qemu-project/qemu/-/issues/4645 Signed-off-by: Artemii Mashanov Reviewed-by: Pierrick Bouvier Tested-by: Pierrick Bouvier --- linux-user/elfload.c | 24 +++++++++++++++++------- tests/tcg/aarch64/brk-pie.c | 28 ++++++++++++++++++++++++++++ tests/tcg/aarch64/meson.build | 1 + tests/tcg/meson.build | 8 +++++--- 4 files changed, 51 insertions(+), 10 deletions(-) create mode 100644 tests/tcg/aarch64/brk-pie.c diff --git a/linux-user/elfload.c b/linux-user/elfload.c index c188fa0..f45326a 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -934,7 +934,7 @@ static void load_elf_image(const char *image_name, cons= t ImageSource *src, { g_autofree struct elf_phdr *phdr =3D NULL; PGBRange range =3D { -1, 0 }; - abi_ulong load_addr, load_bias, error, align; + abi_ulong load_addr, load_bias, error, align, mmap_hint; size_t reserve_size, align_size; int i, prot_exec; Error *err =3D NULL; @@ -1073,12 +1073,22 @@ static void load_elf_image(const char *image_name, = const ImageSource *src, align_size +=3D align - 1; } =20 - load_addr =3D target_mmap(load_addr, align_size, PROT_NONE, - MAP_PRIVATE | MAP_ANON | MAP_NORESERVE | - (ehdr->e_type =3D=3D ET_EXEC ? MAP_FIXED_NOREP= LACE : 0), - -1, 0); - if (load_addr =3D=3D -1) { - goto exit_mmap; + mmap_hint =3D load_addr; + for (;;) { + load_addr =3D target_mmap(mmap_hint, align_size, PROT_NONE, + MAP_PRIVATE | MAP_ANON | MAP_NORESERVE | + (ehdr->e_type =3D=3D ET_EXEC + ? MAP_FIXED_NOREPLACE : 0), + -1, 0); + if (load_addr =3D=3D -1) { + goto exit_mmap; + } + if (ehdr->e_type !=3D ET_DYN || pinterp_name =3D=3D NULL || reserv= ed_va || + load_addr =3D=3D mmap_hint || mmap_hint =3D=3D 0) { + break; + } + target_munmap(load_addr, align_size); + mmap_hint =3D (mmap_hint / 2) & TARGET_PAGE_MASK; } =20 if (align_size !=3D reserve_size) { diff --git a/tests/tcg/aarch64/brk-pie.c b/tests/tcg/aarch64/brk-pie.c new file mode 100644 index 0000000..a3736ad --- /dev/null +++ b/tests/tcg/aarch64/brk-pie.c @@ -0,0 +1,28 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +#define _DEFAULT_SOURCE +#include +#include + +int main(void) +{ + enum { SIZE =3D 64 * 1024 }; + void *initial =3D sbrk(0); + /* Keep heap accesses observable to the compiler. */ + volatile unsigned char *heap =3D initial; + + assert(initial !=3D (void *)-1); + assert(sbrk(SIZE) =3D=3D initial); + assert(sbrk(0) =3D=3D (char *)initial + SIZE); + + for (unsigned int i =3D 0; i < SIZE; i++) { + heap[i] =3D i; + } + for (unsigned int i =3D 0; i < SIZE; i++) { + assert(heap[i] =3D=3D (unsigned char)i); + } + + assert(sbrk(-SIZE) =3D=3D (char *)initial + SIZE); + assert(sbrk(0) =3D=3D initial); + return 0; +} diff --git a/tests/tcg/aarch64/meson.build b/tests/tcg/aarch64/meson.build index 2033356..a9a21c5 100644 --- a/tests/tcg/aarch64/meson.build +++ b/tests/tcg/aarch64/meson.build @@ -8,6 +8,7 @@ tests +=3D tcg_tests['multiarch-linux-user']['tests'] # Base architecture tests tests +=3D { '../arm/fcvt.c': {'cflags': '-lm', 'expected_output': 'fcvt.ref'}, + 'brk-pie.c': {'pie': true}, 'pcalign-a64.c': {}, 'lse2-fault.c': {}, 'test-2248.c': {}, diff --git a/tests/tcg/meson.build b/tests/tcg/meson.build index 01c0aaf..32e09a1 100644 --- a/tests/tcg/meson.build +++ b/tests/tcg/meson.build @@ -35,6 +35,7 @@ tcg_tests =3D {} # 'exe_name': ['provide an alternative binary name'], # 'test_name': ['provide an alternative test name'], # 'cflags': ['additional cflags to compile test', ...], +# 'pie': bool, # compile executable as PIE, default to false # 'depends': [meson_dependency, ...], # 'cc_feat': 'feature name, must be present in cc_feat_cflags', # 'qemu_args': ['qemu command line flags', ...], @@ -324,8 +325,8 @@ foreach target, plan: tcg_tests # return a clear error if user misspell a setup entry foreach key, _ : setup allowed =3D ['exe_name', 'env_var', 'expected_output', 'cc_feat', = 'cflags', - 'depends', 'gdb_feat', 'gdb_test', 'plugin_test', 'prot= ocol', - 'qemu_args', 'test_name', 'wrapper'] + 'depends', 'gdb_feat', 'gdb_test', 'pie', 'plugin_test', + 'protocol', 'qemu_args', 'test_name', 'wrapper'] if key not in allowed error('unknown tcg setup entry \'' + key + '\' for test ' + src + ' (possible: [' + ', '.join(allowed) + '])') @@ -438,10 +439,11 @@ foreach target, plan: tcg_tests =20 # build executable if needed if exe_name not in built_tests + static_flag =3D setup.get('pie', false) ? '-static-pie' : '-static' exe =3D custom_target(exe_name + '.test', input: file, command: [cc, '@INPUT@', - '-o', '@OUTPUT@', '-static', + '-o', '@OUTPUT@', static_flag, '-MMD', '-MF', '@DEPFILE@', '-Wall', '-Werror', '-O0', '-g', '-fno-strict-aliasing', Interdiff against v2: diff --git a/tests/tcg/multiarch/linux/brk-pie.c b/tests/tcg/aarch64/brk-= pie.c similarity index 100% rename from tests/tcg/multiarch/linux/brk-pie.c rename to tests/tcg/aarch64/brk-pie.c diff --git a/tests/tcg/aarch64/meson.build b/tests/tcg/aarch64/meson.build index e3aeb81..a9a21c5 100644 --- a/tests/tcg/aarch64/meson.build +++ b/tests/tcg/aarch64/meson.build @@ -8,7 +8,7 @@ tests +=3D tcg_tests['multiarch-linux-user']['tests'] # Base architecture tests tests +=3D { '../arm/fcvt.c': {'cflags': '-lm', 'expected_output': 'fcvt.ref'}, - '../multiarch/linux/brk-pie.c': {'pie': true}, + 'brk-pie.c': {'pie': true}, 'pcalign-a64.c': {}, 'lse2-fault.c': {}, 'test-2248.c': {}, --=20 2.56.1