From patchwork Sun Jun 25 23:17:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Bugaev X-Patchwork-Id: 1799587 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org 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=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=Q5mbNct1; dkim-atps=neutral Received: from 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 (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Qq6NG5rwrz20b7 for ; Mon, 26 Jun 2023 09:18:22 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CB3A63857720 for ; Sun, 25 Jun 2023 23:18:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CB3A63857720 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1687735099; bh=PhTZWH/Z1zQBT9/VMufWC+SklY+iUOjvbdzbh09F2Sk=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=Q5mbNct1ENBIsEnMVdBwLL7Bag+iVAvCWIEJZ0VyU7JyXzAFgwdH19WEfttnml/z3 PUNkxcwQ179SO9GJ1Mnn7d6Q08uh9qMcGA3ZImjzHn8vjCJNyS1IsrBQdeQ9j0lehT PYlHIL5z1LqQK7qQp6v5NuKSGJ+8pfjym/xGECIY= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-lj1-x22a.google.com (mail-lj1-x22a.google.com [IPv6:2a00:1450:4864:20::22a]) by sourceware.org (Postfix) with ESMTPS id D296F3858D33 for ; Sun, 25 Jun 2023 23:18:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D296F3858D33 Received: by mail-lj1-x22a.google.com with SMTP id 38308e7fff4ca-2b69a48368fso12135401fa.0 for ; Sun, 25 Jun 2023 16:18:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687735082; x=1690327082; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=PhTZWH/Z1zQBT9/VMufWC+SklY+iUOjvbdzbh09F2Sk=; b=BmPd+VDS+jCga+UtOuL1KqVIfkYpHcL0CmTyez41UgS1yGVyYiYRmwgQsdBrOBUwxI faeBUO/UzXGpS23f7F89CLUGuIkZhBqJv6ciRdTSH0hAaFdU4LQA1/X38UXo60UNqN1l l/Jq01ofqXcyC7ScFETlCC9lcCyNR8PWb20X4Z72CBWGXRTwiqLkMLD7Lc8nUGVk+hwG DpTIp6Z0dgLxveHNxLuI35+EVnoWSUijg0GsWeAYeqhqqI6fXe9MKybPNbqiWyE9KY3e 7HRUvOa9xWAJLFrwmPeLWOF49OjTiFVGbO2SO8ZiY/sI+KdjZK6Eu/wWGFaPewg5DZKR qdKw== X-Gm-Message-State: AC+VfDznFiRdnn/ioJ43ghfrChb9q9KeaHj8KClD0WrBrpNdtXj1crF4 TaDFX3JPq0WVzEjKHL/O1YnDehzC5yA= X-Google-Smtp-Source: ACHHUZ7Z5DsorQ41DEXczQtm5M572k3e1ng66m4Nq0eTVk9nFMkjJvzlBJB5+I0MsV1jmQqtr2iVnw== X-Received: by 2002:a05:6512:1584:b0:4f8:710c:e2c7 with SMTP id bp4-20020a056512158400b004f8710ce2c7mr9032004lfb.33.1687735081789; Sun, 25 Jun 2023 16:18:01 -0700 (PDT) Received: from localhost.localdomain ([2a02:2168:b344:a600:4435:f106:1598:d2b0]) by smtp.gmail.com with ESMTPSA id eq6-20020a056512488600b004f86d546458sm851547lfb.6.2023.06.25.16.18.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Jun 2023 16:18:01 -0700 (PDT) To: libc-alpha@sourceware.org, bug-hurd@gnu.org Subject: [PATCH 2/5] hurd: Map brk non-executable Date: Mon, 26 Jun 2023 02:17:48 +0300 Message-ID: <20230625231751.404120-2-bugaevc@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230625231751.404120-1-bugaevc@gmail.com> References: <20230625231751.404120-1-bugaevc@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Sergey Bugaev via Libc-alpha From: Sergey Bugaev Reply-To: Sergey Bugaev Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" The rest of the heap (backed by individual pages) is already mapped RW. Mapping these pages RWX presents a security hazard. Also, in another branch memory gets allocated using vm_allocate, which sets memory protection to VM_PROT_DEFAULT (which is RW). The mismatch between protections prevents Mach from coalescing the VM map entries. Signed-off-by: Sergey Bugaev --- sysdeps/mach/hurd/brk.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sysdeps/mach/hurd/brk.c b/sysdeps/mach/hurd/brk.c index f1349495..3a335194 100644 --- a/sysdeps/mach/hurd/brk.c +++ b/sysdeps/mach/hurd/brk.c @@ -106,7 +106,7 @@ _hurd_set_brk (vm_address_t addr) /* First finish allocation. */ err = __vm_protect (__mach_task_self (), pagebrk, alloc_start - pagebrk, 0, - VM_PROT_READ|VM_PROT_WRITE|VM_PROT_EXECUTE); + VM_PROT_READ|VM_PROT_WRITE); if (! err) _hurd_brk = alloc_start; @@ -120,7 +120,7 @@ _hurd_set_brk (vm_address_t addr) else /* Make the memory accessible. */ err = __vm_protect (__mach_task_self (), pagebrk, pagend - pagebrk, - 0, VM_PROT_READ|VM_PROT_WRITE|VM_PROT_EXECUTE); + 0, VM_PROT_READ|VM_PROT_WRITE); if (err) return __hurd_fail (err);