From patchwork Sat Mar 23 17:32:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Bugaev X-Patchwork-Id: 1915211 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=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=IagYsARy; 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 4V25xT23vFz1yXr for ; Sun, 24 Mar 2024 04:37:33 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3A6703858D38 for ; Sat, 23 Mar 2024 17:37:31 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-lf1-x130.google.com (mail-lf1-x130.google.com [IPv6:2a00:1450:4864:20::130]) by sourceware.org (Postfix) with ESMTPS id 9E6803858289 for ; Sat, 23 Mar 2024 17:35:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9E6803858289 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 9E6803858289 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::130 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1711215323; cv=none; b=Fyd/J+WbxsN8t/3oygMhm3pkJLCfxzcB08s9vEwzI/GAQJYQmSKTva0pcTe1zs4GD9S+G0RrtXnlLlaKbZYmKZlfFUjFv6WAQJMVOkpOmlqMkDLtaFgrIrT2iJ/PXCWzZx5RDRQZvU/OjstXt3hIL5re21svfXMB0pflwvQvnkQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1711215323; c=relaxed/simple; bh=FiT30InLaDT/ATXnZMIILKf2/FCcTlz5mQl9B3WnOrI=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=SYQR2CL6vL6UbWDt+ZzLKppQF0aj9QWjJxguQxviMub0pfCDw8Y3BCLV11afmeayUuxAb//tNjHr9PQ302hq2SIllMGK2WFTH4BnWnUUUVRhNSkjyb9uAY8KtgNJw5s8uJrSjbsz7XKEsW0rmUJ201hCJXlAoMdYIm2UzC4CDy0= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lf1-x130.google.com with SMTP id 2adb3069b0e04-513d599dbabso4100294e87.1 for ; Sat, 23 Mar 2024 10:35:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711215317; x=1711820117; darn=sourceware.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; bh=vOFkdsdbPkJKKEh1bnap+Fybnsj+mN6iJAVwYHsCRUA=; b=IagYsARyEwjFP+AkqLJDPVXcF9DEGu/ePj/Qjaj39kdFGCYMJO01o4paEbNHBn7POz QmeSHIQGaTio0mym+aPHd+q8CUvpYOJVse9dARnfB6UEZolxYx4V+Q/HoeeTEt8l5BIx pAcDNXgHS3pM2sFu/48az2rNNdRUBhn8B3NRNeUHu08X2E2oSAO9kl8jRAC831XkF0f9 zi8VdzAU3g9upnOlLsSkoyud0YzpTtwFELcH0oalOQQFp3c1T52C30HTkHwFTXiEMjD0 ACHSzvvj58NaC4h0XDnoowBZXEfUwaqhiPARxxNT/qRhB51MKEj7LkWraDpV1HDG1WZ4 0yBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711215317; x=1711820117; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vOFkdsdbPkJKKEh1bnap+Fybnsj+mN6iJAVwYHsCRUA=; b=NyI2ZCc28TrtgyQABXv6om+pIJ2WzwHlAqPdVOfl08AcvB+5OUg/b1XSGxMQK+HGsM RWJEIBROPlmuwUOMxgwkZd0wlzCPJiTsc9m3Fcx5A6QD8Va/RzcTwb/IbmnDxOcTfS3w A25kCXSu0bbpEA094KFK04qigOftwVm2LC77QNce11zOAzLwNDXGEw0GD/hJfXrjDkvp 6tV1vJmo1o1Yf7GF8KCyjG5zJCTHzm/NYBs6fhIV9lNi1a/dvu1LMygGa0PkVJtY1sR/ w04KetuJCP1XTkr+Co8Y0/oMI+/dI+Z+9ke/KjjIxfl7vqde/bGsARzEkGFkcYR/bBCo o07A== X-Gm-Message-State: AOJu0YxV3Lwf/ksJftYYnt61x+RT4OMq2gV6+NbQenxoKbOkPJo3fTCg JSGq0Bgz6C3ypkmB546hSRgaBbDpjPhBDPDEW0oo54br5JZQuCG4dKQYmSxZ X-Google-Smtp-Source: AGHT+IFxFS5NYd9DwE6NYVNNoHoYvhwI56sOVoA2HIJBFcLD7B/nfrP6Y2oY07cYr2U6NtoxcEeYMA== X-Received: by 2002:a19:9108:0:b0:515:8550:58c9 with SMTP id t8-20020a199108000000b00515855058c9mr2114346lfd.63.1711215314907; Sat, 23 Mar 2024 10:35:14 -0700 (PDT) Received: from surface-pro-6.. (79-139-171-253.dynamic.spd-mgts.ru. [79.139.171.253]) by smtp.gmail.com with ESMTPSA id g20-20020ac25394000000b00513973dee6fsm361290lfh.150.2024.03.23.10.35.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Mar 2024 10:35:13 -0700 (PDT) From: Sergey Bugaev To: libc-alpha@sourceware.org, bug-hurd@gnu.org Cc: Maxim Kuvyrkov , Luca Subject: [PATCH v2 06/20] htl: Respect GL(dl_stack_flags) when allocating stacks Date: Sat, 23 Mar 2024 20:32:47 +0300 Message-ID: <20240323173301.151066-7-bugaevc@gmail.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240323173301.151066-1-bugaevc@gmail.com> References: <20240323173301.151066-1-bugaevc@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-9.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham 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 Previously, HTL would always allocate non-executable stacks. This has never been noticed, since GNU Mach on x86 ignores VM_PROT_EXECUTE and makes all pages implicitly executable. Since GNU Mach on AArch64 supports non-executable pages, HTL forgetting to pass VM_PROT_EXECUTE immediately breaks any code that (unfortunately, still) relies on executable stacks. Signed-off-by: Sergey Bugaev --- sysdeps/htl/Versions | 4 ++++ sysdeps/mach/htl/pt-stack-alloc.c | 9 +++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/sysdeps/htl/Versions b/sysdeps/htl/Versions index 3a3b1e8b..7b5450d2 100644 --- a/sysdeps/htl/Versions +++ b/sysdeps/htl/Versions @@ -12,4 +12,8 @@ libc { pthread_spin_destroy; pthread_spin_init; pthread_spin_lock; pthread_spin_trylock; pthread_spin_unlock; } + + GLIBC_PRIVATE { + __vm_map; + } } diff --git a/sysdeps/mach/htl/pt-stack-alloc.c b/sysdeps/mach/htl/pt-stack-alloc.c index 61974bd5..0597770b 100644 --- a/sysdeps/mach/htl/pt-stack-alloc.c +++ b/sysdeps/mach/htl/pt-stack-alloc.c @@ -31,9 +31,14 @@ int __pthread_stack_alloc (void **stackaddr, size_t stacksize) { error_t err; + vm_prot_t prot = VM_PROT_READ | VM_PROT_WRITE; - err = __vm_allocate (__mach_task_self (), (vm_offset_t *) stackaddr, - stacksize, TRUE); + if (GL(dl_stack_flags) & PF_X) + prot |= VM_PROT_EXECUTE; + + err = __vm_map (__mach_task_self (), (vm_offset_t *) stackaddr, + stacksize, 0, TRUE, MEMORY_OBJECT_NULL, 0, FALSE, + prot, VM_PROT_ALL, VM_INHERIT_COPY); if (err == KERN_NO_SPACE) err = EAGAIN;