From patchwork Sun Aug 6 03:37:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 710869 Delivered-To: patch@linaro.org Received: by 2002:a05:6359:d30:b0:129:c516:61db with SMTP id gp48csp826071rwb; Sat, 5 Aug 2023 20:38:45 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF3oWe1j2htxQ7tF7pNHnNPAzzCh9M1CgzIPpBLzi9kggXmFijDWhwONIg84m7vIZ9ymPPq X-Received: by 2002:a0d:d48f:0:b0:56d:2afa:5801 with SMTP id w137-20020a0dd48f000000b0056d2afa5801mr6996866ywd.46.1691293125733; Sat, 05 Aug 2023 20:38:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691293125; cv=none; d=google.com; s=arc-20160816; b=Af8nxlKPztvINn15N76MxRE3cZ0NVq8TNWDHGck4zFE4d7FeNQ4Mwz4iRFx4XWNOaA yRfNgxdOSDyRRsN8uFA/H8+Y/eEhJeri6Iekbl9VVehRC21cVNphkRcTPTLwDiHRIBxt lzcrS550OUFhzL5gHZP5CaDY3DVk3OOP26c1oBSGqZ9QJB9I2AupZNToGqO/8MHagBWE gipkN1gWv85pHLkfglVv33DPGBHIDJ3WxbMl53eF/Mxjo7DmpAfeMV1FDFQRTV2HV6mJ VUj3x+hKgMw5MYxjVwm5nbKvq05NHs0Fo+iwbP15xddC2lUvj6/VF8aDHInib3bvSKwf +/tw== 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=vomPozctrgsg6DE89BvELws4YVtdKeVJ1N1yWapXTaiuwfUAvZFqVulBE2IjKCveH4 zq0c6hH2fs9QviUH2o7orsr21dSugyi0e2gkuhPUc/Jp+2A+vuO4H7UkgcpLJmkUsE2U 4AQhrFIBveGdHQnh4J3ig+txO7Ju4Js16bLch69BY4x1M8L+ig3U4HZ0qO2F9JjB1IXJ 2EIv1FGhyNTTgqNWc7KBJYp2tGIoojbN1NvZuqbalMh27L0aLbdH/rPFvLA2Gd5hBPw0 zbZ+SACM4o4G+hftx1PdqgN0B1pluCHTECaIKndq1ZTcewIlaA4P8PZ46vECr8b72Yfj dPOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="Ca2j5s/B"; 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 m8-20020a05620a290800b00767dcd66284si3365734qkp.260.2023.08.05.20.38.45 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 05 Aug 2023 20:38:45 -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="Ca2j5s/B"; 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 1qSUaF-0003ii-S4; Sat, 05 Aug 2023 23:37:35 -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 1qSUaC-0003gV-CJ for qemu-devel@nongnu.org; Sat, 05 Aug 2023 23:37:32 -0400 Received: from mail-pg1-x52a.google.com ([2607:f8b0:4864:20::52a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qSUaA-0007Zf-UJ for qemu-devel@nongnu.org; Sat, 05 Aug 2023 23:37:32 -0400 Received: by mail-pg1-x52a.google.com with SMTP id 41be03b00d2f7-5645bbc82aaso2460846a12.2 for ; Sat, 05 Aug 2023 20:37:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691293049; x=1691897849; 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=Ca2j5s/BFtOLCUKfMdbZy1xHU1VLWsUnkcnOuRkHvZaJt10Ar/8c/CS7zIkznYQLUt wcvYKUbvv0fUXa/i144iNeKbhky3wX8vwoXl7D5oAdfh0MoGK7T9QMVkVHZUYapJOzlh TeP5TVAFjJ+bs1pihN4NyjOCmcB3+Os2VIbAABHuqntzP05B2YylYI4/qth57FO70yAR 9g3JQOtIdi/DTH3epXm4D3e/ptBlntamVnSdP8Z/l7gCmIVAzfC9LoIPXV9Mc8xCqUo0 GU4vpz61YxzYBKC8L3E1dAgCfQJnqUYHRLch292/gBcuAXX+uLykPzyHSunn8hAill3d mkVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691293049; x=1691897849; 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=LOjQO4iVkgSmfb4rqJHlHjMfMsa345OHhV85dj4VsSnGC4fJB9oZ2VsWjZ4CQ5EMEl wSE2t+hvUTxeVX/dIOkCnHnLBlO/VWkwX6QOR8lqPq4vAPP0excRrZkhsjw9GwxHQRpJ zh+n0PFVSdB2/2K26efcOycG3D/HYUcoGg8QvxbXp3VDbdg9BlxmZNyWGvQO4Hct6R5O 1m+/EZOO5AYFx/2kisMjW0+P7gkr0fAbxQThYTroaBOPoDe4u86ewsv92Febhumc2R1t Ex/QR9A3Bu9tuTm5kXFC2hVrB+qTzdAXwM1HGi6aH0b9hLmCx8sCeP6LnBS1k4QjvbWw v9oQ== X-Gm-Message-State: AOJu0YwQETV7+LUjPIvAtJFg3h7vKqUxBfnLnpZF/EpkWm6dxOgna2xY D3pyQZidPGm29HberEyE7DtohaF5Bc+3gFa+AAg= X-Received: by 2002:a17:90a:12cc:b0:267:7021:4e3c with SMTP id b12-20020a17090a12cc00b0026770214e3cmr6084202pjg.8.1691293049589; Sat, 05 Aug 2023 20:37:29 -0700 (PDT) Received: from stoup.. ([2602:47:d490:6901:9454:a46f:1c22:a7c6]) by smtp.gmail.com with ESMTPSA id a5-20020a17090a740500b00262e604724dsm6306451pjg.50.2023.08.05.20.37.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Aug 2023 20:37:29 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Helge Deller , Akihiko Odaki Subject: [PULL 16/24] linux-user: Use MAP_FIXED_NOREPLACE for initial image mmap Date: Sat, 5 Aug 2023 20:37:07 -0700 Message-Id: <20230806033715.244648-17-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230806033715.244648-1-richard.henderson@linaro.org> References: <20230806033715.244648-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::52a; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x52a.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;