From patchwork Tue Aug 8 21:08:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 711577 Delivered-To: patch@linaro.org Received: by 2002:ab3:63c7:0:b0:238:c968:2573 with SMTP id m7csp2881918ltf; Tue, 8 Aug 2023 14:10:39 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGmh9RaSxzUJkuChlYD++i/ji7srllyEQ30uvcFBzYW3yXFwCoiKm260xIRQP+f+wf3zcYP X-Received: by 2002:ac8:5b41:0:b0:403:b4bd:8052 with SMTP id n1-20020ac85b41000000b00403b4bd8052mr15827500qtw.15.1691529038881; Tue, 08 Aug 2023 14:10:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691529038; cv=none; d=google.com; s=arc-20160816; b=t5BaNai7fEuGNbVlDKpUVu0Y/FephAxmudvKCT1unGkValPxZ4+/ZikOasgzKyO1VH brQgbHgWu6hNZLwnqKS2bSDYVhsRX083f0zm4Mm3hC8+lVvbddZuzfjOYCGwLWmnxHjn G7T3OsUweznWK9eetFX77BQNvsu/bbyVtuf45QqXzbea06IMrIjghCIENSRtbIUbrCzr 8x7DnJFAsSs4oKIMfoiXJHdB3ePMs/SFwvKfJbKFAEfJSm5pjoeNRfR7DPVJR3IIt+hJ gSS4ZM5p0qO0mUFHgsa5IKQ4EzvVPTcJQK2bzsGZ3nDOv47Nx1j8BfgeNDMVtzAXcy5Q jwGg== 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=1TQ+ng9YK2iHiUzqlLMSJnh2uowz6Q550xji3/gr0BY=; fh=ZuLSLtzpwbOj79Lm6HQkAzCl7AYBeBRT4Q/1zeFcrQg=; b=ex1i21ju+t7LIkyMbNTf0LbZjVObI9AqhUzYpg5vRYS1NM2Z3VYYuvQG43bxtkaK5b WFWlJ0XmndCVBXg5brFvjHGyCfpcBL7Kg6jINwjQk5Oj8UET+RzoOFvIpFZjH2dBkiiL maIBi1PQvGUKDxTwfPTKaPS00TkrVsPQ3Me1tXWs9ljcawV0Unk92PUve69IhKSIBIeL HAzocdcQhwWzuohX5nGstSftAoHUsLXAnqd9FTU/0LazScmcS4AjY99gFJWMQ4oQbycP GcYFcbqlQp2NJW5qAY8UXeO8wjDt59FE3X6gNSYHXHGsE/WcsKgtJYkXM214NdCw244G SUGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=eEWbJJCd; 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 19-20020ac85713000000b0040354027d63si6879190qtw.91.2023.08.08.14.10.38 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 08 Aug 2023 14:10:38 -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=eEWbJJCd; 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 1qTTx3-0007jw-DE; Tue, 08 Aug 2023 17:09:13 -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 1qTTx2-0007jN-8C for qemu-devel@nongnu.org; Tue, 08 Aug 2023 17:09:12 -0400 Received: from mail-pj1-x102f.google.com ([2607:f8b0:4864:20::102f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qTTx0-0005xU-9m for qemu-devel@nongnu.org; Tue, 08 Aug 2023 17:09:11 -0400 Received: by mail-pj1-x102f.google.com with SMTP id 98e67ed59e1d1-2681223aaacso212544a91.0 for ; Tue, 08 Aug 2023 14:09:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691528949; x=1692133749; 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=1TQ+ng9YK2iHiUzqlLMSJnh2uowz6Q550xji3/gr0BY=; b=eEWbJJCdoaCUkmRIhkYdrZjrWCm1uUf6acv38Rml9ApkhCqDcPWr2Sh0fDqO3HtC5F KLHz28TiSXtlcSY+/3ZZjZ/8gRx/DoFEaCnJh3tik4UXSAlSpYH9DNilITb9dCkn62wq COUAyIKGIWLWBuoSLN5QzIf21lkM63mht5v6Me6LSp9xd83gOxf3cXmLd4yktlOBSjIx UdvJo0FX35q1YdX0XzBr9ssbVyPgAsYbYFlRSGS4kriJHGxvcw0uq76S1Hb39KiteNBa PgaxZJgfKtguGylHId7CkgRwQwPfYt91AbtMxuePAhIgVK/3usVH1lUrPcHTIa25WXb6 cqDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691528949; x=1692133749; 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=1TQ+ng9YK2iHiUzqlLMSJnh2uowz6Q550xji3/gr0BY=; b=aBLu18lhNvCDqO79C9nzbFQYP9XnB5rns76Dgifh65Q1t7X0lh44nEQg+jlaxNWcEV QlR6KQox5EnoDyELUJwaYuPd0WUaaV+OQK3i1kRPpTLBcGSxgGoLNbCOf5FJ0sN+fR1c /W+SmSC0UU3b3rqRfkCZSFtt7Z0BWvjs+LZ87QzL47WmbLlNTQhf4D5NL314p6gmkvBJ 4HPwIHEsGtlt6vE+N0tPlcKyKjrMrnIWGCK3kkTJyIZvgJWOXg4uaYWA99pRE1WAsAf/ eH2zRc/lPzGyjHxk/tqFDvPULkIHmH+apWJv/61umhWxuUqTTSlqrZ2dnlMtqQt42fi7 3HfA== X-Gm-Message-State: AOJu0Yzu40I5eAR/A0uNpIfmLv2u/nChCU06xo5v5OfWZdu9lh+WG7bT TzTm1kEd7zr9Xw6QdNZpxTEk/ohzsvUprC34OKA= X-Received: by 2002:a17:90b:1990:b0:268:8ff2:5c0d with SMTP id mv16-20020a17090b199000b002688ff25c0dmr1110601pjb.17.1691528948854; Tue, 08 Aug 2023 14:09:08 -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.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Aug 2023 14:09:08 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Alex_Benn=C3=A9e?= Subject: [PULL 12/14] linux-user: Consolidate guest bounds check in probe_guest_base Date: Tue, 8 Aug 2023 14:08:54 -0700 Message-Id: <20230808210856.95568-13-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::102f; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102f.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 The three sets of checks are identical, logically. Reviewed-by: Alex Bennée Signed-off-by: Richard Henderson --- linux-user/elfload.c | 50 +++++++++++++++----------------------------- 1 file changed, 17 insertions(+), 33 deletions(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index c14139a5fc..06d81f83b1 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -2525,25 +2525,6 @@ static void pgb_have_guest_base(const char *image_name, abi_ulong guest_loaddr, exit(EXIT_FAILURE); } - /* Sanity check the guest binary. */ - if (reserved_va) { - if (guest_hiaddr > reserved_va) { - error_report("%s: requires more than reserved virtual " - "address space (0x%" PRIx64 " > 0x%lx)", - image_name, (uint64_t)guest_hiaddr, reserved_va); - exit(EXIT_FAILURE); - } - } else { -#if HOST_LONG_BITS < TARGET_ABI_BITS - if ((guest_hiaddr - guest_base) > ~(uintptr_t)0) { - error_report("%s: requires more virtual address space " - "than the host can provide (0x%" PRIx64 ")", - image_name, (uint64_t)guest_hiaddr + 1 - guest_base); - exit(EXIT_FAILURE); - } -#endif - } - /* * Expand the allocation to the entire reserved_va. * Exclude the mmap_min_addr hole. @@ -2694,13 +2675,6 @@ static void pgb_static(const char *image_name, abi_ulong orig_loaddr, uintptr_t offset = 0; uintptr_t addr; - if (hiaddr != orig_hiaddr) { - error_report("%s: requires virtual address space that the " - "host cannot provide (0x%" PRIx64 ")", - image_name, (uint64_t)orig_hiaddr + 1); - exit(EXIT_FAILURE); - } - loaddr &= -align; if (HI_COMMPAGE) { /* @@ -2766,13 +2740,6 @@ static void pgb_reserved_va(const char *image_name, abi_ulong guest_loaddr, int flags = MAP_ANONYMOUS | MAP_PRIVATE | MAP_NORESERVE; void *addr, *test; - if (guest_hiaddr > reserved_va) { - error_report("%s: requires more than reserved virtual " - "address space (0x%" PRIx64 " > 0x%lx)", - image_name, (uint64_t)guest_hiaddr, reserved_va); - exit(EXIT_FAILURE); - } - /* Widen the "image" to the entire reserved address space. */ pgb_static(image_name, 0, reserved_va, align); @@ -2799,6 +2766,23 @@ void probe_guest_base(const char *image_name, abi_ulong guest_loaddr, /* In order to use host shmat, we must be able to honor SHMLBA. */ uintptr_t align = MAX(SHMLBA, qemu_host_page_size); + /* Sanity check the guest binary. */ + if (reserved_va) { + if (guest_hiaddr > reserved_va) { + error_report("%s: requires more than reserved virtual " + "address space (0x%" PRIx64 " > 0x%lx)", + image_name, (uint64_t)guest_hiaddr, reserved_va); + exit(EXIT_FAILURE); + } + } else { + if (guest_hiaddr != (uintptr_t)guest_hiaddr) { + error_report("%s: requires more virtual address space " + "than the host can provide (0x%" PRIx64 ")", + image_name, (uint64_t)guest_hiaddr + 1); + exit(EXIT_FAILURE); + } + } + if (have_guest_base) { pgb_have_guest_base(image_name, guest_loaddr, guest_hiaddr, align); } else if (reserved_va) {