From patchwork Fri Aug 4 22:00:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 710260 Delivered-To: patch@linaro.org Received: by 2002:a05:6359:d30:b0:129:c516:61db with SMTP id gp48csp230192rwb; Fri, 4 Aug 2023 15:03:52 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFlF7zF0EMYSaHJEEjYt1lDmqq22iEaOiEa3ylouj/JjPw9kKD2ezB4JfrmlnB/uPap3scT X-Received: by 2002:ac8:5896:0:b0:406:8bc2:6ba8 with SMTP id t22-20020ac85896000000b004068bc26ba8mr4479705qta.2.1691186632014; Fri, 04 Aug 2023 15:03:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691186632; cv=none; d=google.com; s=arc-20160816; b=OcjwLXtI6j+173d764KT6MuFTxATBj1UvxAvv+70fGIsx3gM0ssMKRAX+J/znPlDTo 7Oez6abfkTjA64RAfJUIzoL4G622LlVaSo5iuoMpZGhd92FQMaSTW4+1jlUrGBGolyMt 3XKXwdG6pksr0E6JDHwgySdU5gyqGe9Nbq8UuWeEjD/4UWlzpAzeQY3kMQTvlq30Olz8 V35YFZJYLfGhFUl9vbMriAOds5iM92IV52N48ISexH0jlZo5M+EN/Aiw6eIG4/bkP89p ibz+ugtngvtNG9p9qFVR3tdK+tfHBXdLPy0b54Yz2422cfxHz96mrldrDjojVio9fYKL gZmg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=LDzaMFTSuoNmnLh18AUGiF2g+chM/kwaFDD4OLCcPrg=; fh=e1NRMjxVMtV0F5wYJj2s+gr60lsrqkDmE/ulJ4pjdtQ=; b=Iq0H4obk66+b2RiWl2+H5O1qxSNfBADAWiG575qEOrWvEvwbvO3xB2iWDZ6bTBMAIK CPiSPDMSTE9LB95Eb7BiqXpynnonFBMTniZOb/n59uLFET3bpX4UAkXoRg2Tshvbgksx 0N9YOYX0TaHV9yXnq39Xf3Ssr4V4yW8h4lJ6PG6Odv+yhr19mfErkjGzQzELbnlsmVwB pfQE2nXbSGIrJ5YneUJSBZuFT2omU0n7Tkjz91FuVTWxRYWjmeBYCRSMfZ0PSPPd3RXl ygTWKzA3DCpR6STCgTEgtTDJl9fJaGCkuqsT01x//DLMooqubMQMv1wuACj4PtGrG82+ xodQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=pK3wQkDQ; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id b22-20020ac85bd6000000b0040fdfccdd48si1877667qtb.759.2023.08.04.15.03.51 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 04 Aug 2023 15:03:52 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=pK3wQkDQ; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qS2rI-0004tf-2m; Fri, 04 Aug 2023 18:01:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qS2qo-0004jA-OL for qemu-devel@nongnu.org; Fri, 04 Aug 2023 18:00:52 -0400 Received: from mail-pl1-x62e.google.com ([2607:f8b0:4864:20::62e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qS2qm-0001u8-KD for qemu-devel@nongnu.org; Fri, 04 Aug 2023 18:00:50 -0400 Received: by mail-pl1-x62e.google.com with SMTP id d9443c01a7336-1bba48b0bd2so18545125ad.3 for ; Fri, 04 Aug 2023 15:00:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691186447; x=1691791247; 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=LDzaMFTSuoNmnLh18AUGiF2g+chM/kwaFDD4OLCcPrg=; b=pK3wQkDQgtPhaZj82WmJ4r4+65CGKOEob0gPr/U2/ymvNB3pVdAJsoWfsZpPV3kTsr Na/1M8SCL3mE8Hl1hZRpD4Zt2f8YRnbWcZwPC1WyhUanPox4UzDqRs5JLbrZNC6mNIP0 GZR5XFPT4iAqUHdqd+YCF79Zkm9jef4fvcxxCS4MCyZCJkdWMtdMeYey1d/ChoHYBNF6 N5/raIA1fCLYIM/kFhqFn/uSosT7n8wkWqGh8Fp20w9g5iworApac+upaaYNGMFY72R+ W85d3MBmJcI0hoc9a2FlYKNn8MuULKkoGy8Te9nyeLE+0Ry/I+I21nqUICE2dMRo6zUX Jqkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691186447; x=1691791247; 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=LDzaMFTSuoNmnLh18AUGiF2g+chM/kwaFDD4OLCcPrg=; b=BZxHjYl4fk2D+wuCRqQw99aVIkh++txeUDKcRg7VXHDwbherCyGLxpweFvHc+ZgBnW DOIgDIJ58iqz3XW8I4jSH20CBZwaoZ4RHHRz8TguoQNJW3OtBUMrDlRWyoAWdFT1Mz6Q tF4WzU39qVx81hqzFOpjgmr6XgDpG6+246dROEmkybkMTpylm7KvKmogxRFC5Go+LBV9 6LMZwOJ0J4Yn6CG7fg2HKL6FM1Ze+Fxxu+LhUch42MwUyC/FVgqUJDqvjjbORoWJdU4u mYuUi13UvJoWrYxoPSvani7ZOGF1s4k7dIaUqn5fX1RwyMqDgKB3hmQDrT72aBdQWJDe Jlfg== X-Gm-Message-State: AOJu0YyZuk/dMhR1db0XSPuVgr2eK+QC7g3Osm7pdlqZ50dDXCnALhnj iZdaiIbQYhv4Tdpq54sOMikWVLZfZ35KjKKhUmc= X-Received: by 2002:a17:902:c409:b0:1bc:56c1:a394 with SMTP id k9-20020a170902c40900b001bc56c1a394mr1346207plk.11.1691186447340; Fri, 04 Aug 2023 15:00:47 -0700 (PDT) Received: from stoup.. ([2602:47:d490:6901:1eed:f77f:f320:8b14]) by smtp.gmail.com with ESMTPSA id u1-20020a17090282c100b001bbf7fd354csm2185568plz.213.2023.08.04.15.00.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Aug 2023 15:00:46 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Helge Deller , Akihiko Odaki Subject: [PATCH v9 16/24] linux-user: Use MAP_FIXED_NOREPLACE for initial image mmap Date: Fri, 4 Aug 2023 15:00:24 -0700 Message-Id: <20230804220032.295411-17-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230804220032.295411-1-richard.henderson@linaro.org> References: <20230804220032.295411-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62e; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62e.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 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Use this as extra protection for the guest mapping over any qemu host mappings. Tested-by: Helge Deller Reviewed-by: Helge Deller Reviewed-by: Akihiko Odaki Signed-off-by: Richard Henderson --- linux-user/elfload.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 2aee2298ec..0c64aad8a5 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -3146,8 +3146,11 @@ static void load_elf_image(const char *image_name, int image_fd, /* * Reserve address space for all of this. * - * In the case of ET_EXEC, we supply MAP_FIXED so that we get - * exactly the address range that is required. + * In the case of ET_EXEC, we supply MAP_FIXED_NOREPLACE so that we get + * exactly the address range that is required. Without reserved_va, + * the guest address space is not isolated. We have attempted to avoid + * conflict with the host program itself via probe_guest_base, but using + * MAP_FIXED_NOREPLACE instead of MAP_FIXED provides an extra check. * * Otherwise this is ET_DYN, and we are searching for a location * that can hold the memory space required. If the image is @@ -3159,7 +3162,7 @@ static void load_elf_image(const char *image_name, int image_fd, */ load_addr = target_mmap(loaddr, (size_t)hiaddr - loaddr + 1, PROT_NONE, MAP_PRIVATE | MAP_ANON | MAP_NORESERVE | - (ehdr->e_type == ET_EXEC ? MAP_FIXED : 0), + (ehdr->e_type == ET_EXEC ? MAP_FIXED_NOREPLACE : 0), -1, 0); if (load_addr == -1) { goto exit_mmap;