From patchwork Mon Aug 7 16:37:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 711144 Delivered-To: patch@linaro.org Received: by 2002:ab3:63c7:0:b0:238:c968:2573 with SMTP id m7csp2128182ltf; Mon, 7 Aug 2023 09:39:43 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGLq02Wh3JRlTyiwVtnxDNcB5XBOTJ8CDq9zl7uGq7Q12IRCjW31Bdz11AWI2HlpSdhhtWO X-Received: by 2002:a0c:e291:0:b0:63f:8212:bfd9 with SMTP id r17-20020a0ce291000000b0063f8212bfd9mr3079689qvl.59.1691426383361; Mon, 07 Aug 2023 09:39:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691426383; cv=none; d=google.com; s=arc-20160816; b=sx7kfZXvjEuFj2yDjUCvkzZfOrDdzYLBCedQOBAWlgdtA87Nds/VEHs86zd1o2ID3i ZMBEgGBp6uIG2ZO9FRfcTB3hRwBUgEvPNYkBJpedCxGjNVl+eK/W+L4GxhGmygAWgygD wr4505i8XnRjyo3EXy8Lrc2gyXDvy3pA4sfwmJv1u1a7zoq2zC2kLi5l1s+eaRq3iVx+ ojfA4DP7HpvpzhFYTXFvTQ/+Xwi3ViziA1G5SaG5+VgeKd9pu36p8JZi1lF4VWcuvxnO kEp3CNkwkgKQDNacoEtJVoCZKs/wevyw8iy3UMSwwyVuI+UKgHbsBu01ZSYtDehZaEoT MT8w== 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=37Oa1Q6Q3bF0gL9Um9Xifn0V/D4ohTtQq5asniTUIIY=; fh=nM8F09xKNAze8fdJGCDZoH2K0rjOXqNih6JoyRf4NS8=; b=FqZSn+PD1ooA+8xGhQZg5uboxp3JozPxbnks/oNHx9F9/EKzITqo1+Jbl9BeZfwuui pOnSDtiV27DIv5jRoiDq8Wl6nrYjjWyO/rXacIO57o6cDNrJCSS8faxpkGO0sIiWqrvh N2pi/VmBGQXFHiuc04V9wRj6KF4z3EqVJd36NSNt4YHedFtcecp23EytOMYY2KKLW7D5 r3LX/NF1uXRvYxbH2zSN36Yiespv3olm8TgGc2FQzSj6rzTZF8oaoyAheFF+OK2nMJ7J WHl7Bi268DlkwaCUTVNPNvU4LME2RceSm4D1qhFs8f5IzKLtG3/PdW9a2r6ZTXIDFUty 9/7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=GCKh8Cay; 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 m4-20020a0cac44000000b0063d15cbadb0si5085030qvb.613.2023.08.07.09.39.43 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 07 Aug 2023 09:39:43 -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=GCKh8Cay; 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 1qT3EZ-0007Yv-Mh; Mon, 07 Aug 2023 12:37:31 -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 1qT3EO-00076J-GD for qemu-devel@nongnu.org; Mon, 07 Aug 2023 12:37:22 -0400 Received: from mail-pl1-x632.google.com ([2607:f8b0:4864:20::632]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qT3EM-0002iJ-NP for qemu-devel@nongnu.org; Mon, 07 Aug 2023 12:37:20 -0400 Received: by mail-pl1-x632.google.com with SMTP id d9443c01a7336-1bbf8cb694aso40640755ad.3 for ; Mon, 07 Aug 2023 09:37:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691426237; x=1692031037; 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=37Oa1Q6Q3bF0gL9Um9Xifn0V/D4ohTtQq5asniTUIIY=; b=GCKh8Cay5DJtgXhZ5sxRPiapN3ly1+VFPoH4828ht5vYjyDxgaj7/svl6v958AtbtL xA4aHW7bQyqg6E76O6+n1d+qc9bYRZNcuplLnEFlxklqCpKYrMrbD49PjzvzCStSCU4f c7Tqpkphb3jvlKxUTveOxzpGw4LtAZ1bV/9Qa3bAA2sWAgrdNa71lgLpU/jfTHiESNMr +XqVUMbfcPKRqkDNCF3jkEyx9gTySEx91Xb5+jCpk+Gt42EqsnsWEJPos8dMX+OgDrve 1X3x0sMyqKpkYcOcwbCYJaX1wPl3k1RB2qsK9OJb9eJ+FbsZEK+8gA1fnEYKAgTC1Voa JwTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691426237; x=1692031037; 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=37Oa1Q6Q3bF0gL9Um9Xifn0V/D4ohTtQq5asniTUIIY=; b=DVq+3sHACpgPpfCs2Dj8pwTUenAvM6M/gKM/3fpHJnwuyF/a1bmQ9ECyp3q0LMhUVv YwsE5JtKKCRns2sjdt6syyBaGKbUtE1dzWdhN06n6EQDikS8S/P1r71Xm5STk91LMW1n CPEKFqF6P/GrpFkWwPY+pnYJL4EiVAdkt+HngIFGVh418doww9j2QUcJVEwHaBmo+5Ro zvsvo7F2Tz+G89Nen9v2IYTm+SAIfvHheohFvA+Xmxg9hdlm9y4Flfe4emnZv4zVWWcc Vj8J8YCtlz6gqNH3rF+JigR09mWW38E3a6rDlmCjApZko1icDNqSrtVsvWf3+E31/y/p 2jfQ== X-Gm-Message-State: AOJu0Yw0RU0gqNyHFvqGXy8uLzf3OA+jP9zCj22iyeNQbZeEN7SezLq8 nK7WEU2/KMRGWBRUxw3Q0/26HLL5J6zgGci2Lcc= X-Received: by 2002:a17:902:d3c5:b0:1aa:d971:4623 with SMTP id w5-20020a170902d3c500b001aad9714623mr9888148plb.38.1691426237352; Mon, 07 Aug 2023 09:37:17 -0700 (PDT) Received: from stoup.. ([2602:47:d490:6901:e306:567a:e0a1:341]) by smtp.gmail.com with ESMTPSA id l6-20020a170902d34600b001b9df8f14d7sm7119837plk.267.2023.08.07.09.37.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Aug 2023 09:37:16 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: pbonzini@redhat.com, philmd@linaro.org, laurent@vivier.eu, deller@gmx.de Subject: [PATCH for-8.1 v10 12/14] linux-user: Consolidate guest bounds check in probe_guest_base Date: Mon, 7 Aug 2023 09:37:03 -0700 Message-Id: <20230807163705.9848-13-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230807163705.9848-1-richard.henderson@linaro.org> References: <20230807163705.9848-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::632; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x632.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. Signed-off-by: Richard Henderson Reviewed-by: Alex Bennée --- 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 400af4a4c0..484ab7131a 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -2527,25 +2527,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. @@ -2696,13 +2677,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) { /* @@ -2768,13 +2742,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); @@ -2801,6 +2768,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) {