From nobody Tue Feb 10 23:36:06 2026 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1660682770; cv=none; d=zohomail.com; s=zohoarc; b=ZWYnAR6nNTljmfNip4hRr99SLo+lkRrGbNSD8tyySZyVJA289S8En5M6M4jWau/QfclUcOlM0Tpg5fEsaj7GwTLeHTaXV+lWiztepripOYRALBtygGWn2GD8nVoY1kQGoLF7SqjK714NXJr99VUGnbVc0cK0JvpcZNZy0KGSf9A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1660682770; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=WyS1AkJjXgcx++s5EL+CHkdS52eWUfbVT52gpN5EMKs=; b=UOvNIdNH/sWwITuAy7OgvwReEs+PhX1/vTo8bgdJeoF3N1+AWwmtGSe36CfLyo5lbZ3vBxT28E6MFaHq/gkQ4TQ+pn3ev4u/lRteFZw1DvBJbawWUCfkHrIV8JU3I7FTvbOksE1fgQ+z+p+rYN2n4Y3w9aJeBTvKCRQdbHc9CRg= 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+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1660682770499236.91514477258193; Tue, 16 Aug 2022 13:46:10 -0700 (PDT) Received: from localhost ([::1]:43094 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oO3Rx-0003Ex-Cy for importer2@patchew.org; Tue, 16 Aug 2022 16:46:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39456) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oO3GW-0004iv-3m for qemu-devel@nongnu.org; Tue, 16 Aug 2022 16:34:21 -0400 Received: from mail-oa1-x35.google.com ([2001:4860:4864:20::35]:45728) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oO3GS-0004UY-37 for qemu-devel@nongnu.org; Tue, 16 Aug 2022 16:34:19 -0400 Received: by mail-oa1-x35.google.com with SMTP id 586e51a60fabf-11ba6e79dd1so7806072fac.12 for ; Tue, 16 Aug 2022 13:34:15 -0700 (PDT) Received: from stoup.. ([2605:ef80:80f6:61fa:9bc2:5095:d612:5e22]) by smtp.gmail.com with ESMTPSA id y23-20020a056870b01700b0010ef8ccde67sm2285220oae.13.2022.08.16.13.34.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Aug 2022 13:34:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=WyS1AkJjXgcx++s5EL+CHkdS52eWUfbVT52gpN5EMKs=; b=Kqw28FrA0Ip0ok8/Z7eWT12WmrIOGLZ5XZmdEpFDDAOcAadGlugvqRahSfeIgGVMwk h34e2u0lkHX6DdBb/bYepYbsyxcSlYEgtQh7g/MC8q9OJsTnuD2QW0dkgvM0B6DO85Pp ziGgWUeWx/tldYbEKDgz9WjL7F+3IIRVOfP+k32GBsxeQ+9gRFkjE4pNOypVbieF6Etm oAM2XdGc4HLeRn2hJJO9DRRhNkTT347ZaG9sNebJjaGsn2cDKo0ms/CsOwnvrE3HEQ3Z tw7u/cQW5K6efJyoOv9abF+P1/6UjMRP0jf75RIhkMxixuILMhYfmElg2lc4sIFbW5bW +Ntw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=WyS1AkJjXgcx++s5EL+CHkdS52eWUfbVT52gpN5EMKs=; b=8A4x/alJb9nA0vRa4cKPwWOe+UY5RaLtkCBzOIAX18QFfWZTB/Jnj70uCIQL/muKOT yW05MA3ClAy8paRxEqDM+GAv+hMpm3b+bN99Lb5oT2yzvJoPbetv4sqB4OwRNT7IuygN y2LQc3eTfmAuAzN2zVK8KU0U7FRZWR5eGexpwaKrRh8/hDl/8Nn9drZN6sm+5ydmpz3z IYAj58zsLNrSZVr1nIsX6iBegZCThhQzPbi7JLm4gaNt0CumKt/KiC0NsE9fUpMNn7AY vXxs36swZVBSoYyC48XusjgVYFCJBvhOQ/Lh0rj05Yyw214y8wdH4l1Q/0AccAVMo+A1 yLNg== X-Gm-Message-State: ACgBeo2BDJAunr0E6+HvEgRgaeVgzwS+8lgwQiOYVx6KGX1RPgE0vjo4 vGFrkWFyjaSSmSCqnIlBVMN8zkXIUN/V7A== X-Google-Smtp-Source: AA6agR4hkNt+pCgF09LJ7PMSN3/gMZvx0A/Qd1eQrylUVbCZwohIr13taCR/x5PwX3yfn0Pgu1X8dQ== X-Received: by 2002:a05:6870:e2ca:b0:10e:6f87:baa with SMTP id w10-20020a056870e2ca00b0010e6f870baamr164238oad.58.1660682054340; Tue, 16 Aug 2022 13:34:14 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, alex.bennee@linaro.org, iii@linux.ibm.com Subject: [PATCH v2 04/33] linux-user: Honor PT_GNU_STACK Date: Tue, 16 Aug 2022 15:33:31 -0500 Message-Id: <20220816203400.161187-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220816203400.161187-1-richard.henderson@linaro.org> References: <20220816203400.161187-1-richard.henderson@linaro.org> 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2001:4860:4864:20::35; envelope-from=richard.henderson@linaro.org; helo=mail-oa1-x35.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, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1660682772061100001 Content-Type: text/plain; charset="utf-8" Map the stack executable if required by default or on demand. Signed-off-by: Richard Henderson --- include/elf.h | 1 + linux-user/qemu.h | 1 + linux-user/elfload.c | 19 ++++++++++++++++++- 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/include/elf.h b/include/elf.h index 3a4bcb646a..3d6b9062c0 100644 --- a/include/elf.h +++ b/include/elf.h @@ -31,6 +31,7 @@ typedef int64_t Elf64_Sxword; #define PT_LOPROC 0x70000000 #define PT_HIPROC 0x7fffffff =20 +#define PT_GNU_STACK (PT_LOOS + 0x474e551) #define PT_GNU_PROPERTY (PT_LOOS + 0x474e553) =20 #define PT_MIPS_REGINFO 0x70000000 diff --git a/linux-user/qemu.h b/linux-user/qemu.h index 7d90de1b15..e2e93fbd1d 100644 --- a/linux-user/qemu.h +++ b/linux-user/qemu.h @@ -48,6 +48,7 @@ struct image_info { uint32_t elf_flags; int personality; abi_ulong alignment; + bool exec_stack; =20 /* Generic semihosting knows about these pointers. */ abi_ulong arg_strings; /* strings for argv */ diff --git a/linux-user/elfload.c b/linux-user/elfload.c index d783240a36..050cd1fa08 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -233,6 +233,7 @@ static bool init_guest_commpage(void) #define ELF_ARCH EM_386 =20 #define ELF_PLATFORM get_elf_platform() +#define EXSTACK_DEFAULT true =20 static const char *get_elf_platform(void) { @@ -309,6 +310,7 @@ static void elf_core_copy_regs(target_elf_gregset_t *re= gs, const CPUX86State *en =20 #define ELF_ARCH EM_ARM #define ELF_CLASS ELFCLASS32 +#define EXSTACK_DEFAULT true =20 static inline void init_thread(struct target_pt_regs *regs, struct image_info *infop) @@ -777,6 +779,7 @@ static inline void init_thread(struct target_pt_regs *r= egs, #else =20 #define ELF_CLASS ELFCLASS32 +#define EXSTACK_DEFAULT true =20 #endif =20 @@ -974,6 +977,7 @@ static void elf_core_copy_regs(target_elf_gregset_t *re= gs, const CPUPPCState *en =20 #define ELF_CLASS ELFCLASS64 #define ELF_ARCH EM_LOONGARCH +#define EXSTACK_DEFAULT true =20 #define elf_check_arch(x) ((x) =3D=3D EM_LOONGARCH) =20 @@ -1069,6 +1073,7 @@ static uint32_t get_elf_hwcap(void) #define ELF_CLASS ELFCLASS32 #endif #define ELF_ARCH EM_MIPS +#define EXSTACK_DEFAULT true =20 #ifdef TARGET_ABI_MIPSN32 #define elf_check_abi(x) ((x) & EF_MIPS_ABI2) @@ -1807,6 +1812,10 @@ static inline void init_thread(struct target_pt_regs= *regs, #define bswaptls(ptr) bswap32s(ptr) #endif =20 +#ifndef EXSTACK_DEFAULT +#define EXSTACK_DEFAULT false +#endif + #include "elf.h" =20 /* We must delay the following stanzas until after "elf.h". */ @@ -2082,6 +2091,7 @@ static abi_ulong setup_arg_pages(struct linux_binprm = *bprm, struct image_info *info) { abi_ulong size, error, guard; + int prot; =20 size =3D guest_stack_size; if (size < STACK_LOWER_LIMIT) { @@ -2092,7 +2102,11 @@ static abi_ulong setup_arg_pages(struct linux_binprm= *bprm, guard =3D qemu_real_host_page_size(); } =20 - error =3D target_mmap(0, size + guard, PROT_READ | PROT_WRITE, + prot =3D PROT_READ | PROT_WRITE; + if (info->exec_stack) { + prot |=3D PROT_EXEC; + } + error =3D target_mmap(0, size + guard, prot, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); if (error =3D=3D -1) { perror("mmap stack"); @@ -2920,6 +2934,7 @@ static void load_elf_image(const char *image_name, in= t image_fd, */ loaddr =3D -1, hiaddr =3D 0; info->alignment =3D 0; + info->exec_stack =3D EXSTACK_DEFAULT; for (i =3D 0; i < ehdr->e_phnum; ++i) { struct elf_phdr *eppnt =3D phdr + i; if (eppnt->p_type =3D=3D PT_LOAD) { @@ -2962,6 +2977,8 @@ static void load_elf_image(const char *image_name, in= t image_fd, if (!parse_elf_properties(image_fd, info, eppnt, bprm_buf, &er= r)) { goto exit_errmsg; } + } else if (eppnt->p_type =3D=3D PT_GNU_STACK) { + info->exec_stack =3D eppnt->p_flags & PF_X; } } =20 --=20 2.34.1