From patchwork Tue Aug 8 21:08:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 711572 Delivered-To: patch@linaro.org Received: by 2002:ab3:63c7:0:b0:238:c968:2573 with SMTP id m7csp2881466ltf; Tue, 8 Aug 2023 14:09:45 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHcbGMegOUZHNXV/p2Zxc3BcyrIx2C8mUdDoncjgQDnZMjDFTy8wak7iFrAtFJigNC5NUNj X-Received: by 2002:a05:620a:a83:b0:767:154b:2f91 with SMTP id v3-20020a05620a0a8300b00767154b2f91mr893820qkg.24.1691528985008; Tue, 08 Aug 2023 14:09:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691528984; cv=none; d=google.com; s=arc-20160816; b=sqGNOS/n/W6WgRQbY6v1tX2hdL2IPwDbmCKv+3yDdqFdYQtG89cukQpXyp0DBZc1+j E9mH7aVxnrDk+Ro29oXh3+gNbki+NcoHfTpQvoVIvxznBbM5eVMdxaYXdIyUo2UpgqAe hCLSPooTWDBogPGw6HMTya7PB/uS3h69k4+pOJf6PxDUKHt1umEEEgiVlXne7C8s58Fm 5G43GbNoWsoN7cUFq2VfvJhp4+yy1DtKUZWf6DfxVkIqqzSnGrUirZCbcre1fmkrMJ5C 30ZSFyiI5uQeMhKKavActH0KF8ql6nyXVUPJSuDyXtQUxgNVzQ7Z3n9E4DsEiG+nY/QU wx/g== 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=SJUFfIS4Wr1y8fuwf4as7ebNw3oHaTbxYse/4v8c7ug=; fh=e1NRMjxVMtV0F5wYJj2s+gr60lsrqkDmE/ulJ4pjdtQ=; b=nluAY4/z+W6BJZeNE4eKBIHvJvu97+3s8mMI/K25RHP+RTQDy4nHBrRnbrv4K2DlDF yKpsRgjqEAZNPV6gvU+U8U0GjziCqZlze2AAilMPV+941yucV/i11jWu4gHZh8w8BnEh VjS3wshPjRYMv/DDvxnPaATdJey9GSnmk7JhOcNoZUFHkiV+CMARdZM0w/IFjq7aRMgq EPzr6vZm4uk1lHkSM5gVX/GUpF+ZrUuRtpFbbTEgG5M+ix0ycwWB7NHFzQWfVEZSjsEx FGswYV5bFFiT1qh6GHQhWlC/JvDJkLV/0m6IGX0629vfKnVv0uVlZ+BBYkMKCzQzKUMo MWKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=c3odcsCm; 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 x18-20020a05620a259200b00767b7c58ac4si6850560qko.605.2023.08.08.14.09.44 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 08 Aug 2023 14:09:44 -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=c3odcsCm; 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 1qTTww-0007gV-Mw; Tue, 08 Aug 2023 17:09:06 -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 1qTTwu-0007fM-Q3 for qemu-devel@nongnu.org; Tue, 08 Aug 2023 17:09:04 -0400 Received: from mail-pg1-x536.google.com ([2607:f8b0:4864:20::536]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qTTwt-0005vx-3Q for qemu-devel@nongnu.org; Tue, 08 Aug 2023 17:09:04 -0400 Received: by mail-pg1-x536.google.com with SMTP id 41be03b00d2f7-56433b1b12dso3652336a12.1 for ; Tue, 08 Aug 2023 14:09:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691528942; x=1692133742; 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=SJUFfIS4Wr1y8fuwf4as7ebNw3oHaTbxYse/4v8c7ug=; b=c3odcsCmTbi6SjqtVD0sLtX7A5t+73vs2CspyQ4GUvPyU5DCV6Ipb7uTYNQH0jzXhN Q5WBls7nlioIAEk1aVJ85Y3jLYOLdcBJRomyjaU4QbQyHYCulJ34NvJfOhoEDCWLfGEv eS9zrkpUpCGi+SMJ2TJL5MMVbkzkcwuu22P9nvYmn86ZxaaNn9nrBoudSNmnVdax8V0K v95GinP1JDJQQ7ZWQFwnrK1eJXI0ulirLLjHKTijBv7aS+A9jRm3k/tu1UP7IyrGYFe4 ixPQCI1068f5NOknzSKbTnnYzPP8wuxiY6jugSH1A+3eML4oeZBc06If8Irgu5VsVZsi t46g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691528942; x=1692133742; 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=SJUFfIS4Wr1y8fuwf4as7ebNw3oHaTbxYse/4v8c7ug=; b=DE89nli0ZFT4FTVhRGQhTkQYk09/R1Dcg86nKlzGOYjhrE4yewUUkv+4LGX4P1T40e FOCLi36oOD3B93ckstizDfQ14iQVwUfRIDLpp6krUCT716qQ1k41CxY+EumwcpsyNkcj 2NnFBmYu/oqr5uoyQg5JkEG3bG3O2ynnUhQEfvG4tgt0g/+b3te9sQXhjLXswNIdzQqH +CZ7hI1ZWcqlXYfNDSHIBGiExe5cA1YJqdzO8njgrGtkA1euv/noW+MGgpwIw6es4NUu HfPp1n9demPkz/s89voDPmOPh+8G+h3a9AZl97YjlHJHvMEmlKAJV5nmU3teMf0kJpP9 ofsQ== X-Gm-Message-State: AOJu0YwR5372LLch/ATRw4Zxey2d4fF9u66Ul22Kc2onLQXNVjOzZLyw QsjYEP7eukAk9biSCaGtC8DpUverVhE1849hTzY= X-Received: by 2002:a17:90a:6c05:b0:268:c5c7:f7ed with SMTP id x5-20020a17090a6c0500b00268c5c7f7edmr642605pjj.30.1691528941789; Tue, 08 Aug 2023 14:09:01 -0700 (PDT) Received: from stoup.. ([2602:47:d490:6901:63dc:2a47:f4bc:4a95]) by smtp.gmail.com with ESMTPSA id k11-20020a170902694b00b001b3fb2f0296sm9437533plt.120.2023.08.08.14.09.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Aug 2023 14:09:01 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Helge Deller , Akihiko Odaki Subject: [PULL 04/14] linux-user: Use MAP_FIXED_NOREPLACE for initial image mmap Date: Tue, 8 Aug 2023 14:08:46 -0700 Message-Id: <20230808210856.95568-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230808210856.95568-1-richard.henderson@linaro.org> References: <20230808210856.95568-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::536; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x536.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 36e4026f05..1b4bb2d5af 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -3147,8 +3147,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 @@ -3160,7 +3163,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;