From nobody Wed Nov 20 18:30:55 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1688131399; cv=none; d=zohomail.com; s=zohoarc; b=RQYPvcmnLgioiRjBeSHZYgxfr/G/OA2w+/zvtRsR6vckUsglVhTMQ/31SXmYWYLtoiQV9JclPqgo9tIeBbFin+kJQpx2rPh9K/nQMbfdH18chyUW1nri3LYrQ1lbeUAFXS4oOPIA7N2xqCka8R7HttPBI0eXRm85U3CNoi/MsZo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1688131399; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=OUAuwo10Yq9+V7BF7q6x9M7fE+x9XcbokQqcquvrZKI=; b=fUKyVFkk4ZUcrI7nqh2s/+43ySXpchMN2V+/7bJ1wsKo/YpdeyveMg7XLjg1dKaIrNyf3p/s3wtdy3XB1zp8RKPVX+nDO0RuMcVmUDMg8qlVBcCOx3O4dkEfsCAHDT6Eukc5OA15hW9kXCs3CzyH55V23PQxY/sS5Ut0QgRTUgA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1688131399338288.2040528600627; Fri, 30 Jun 2023 06:23:19 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qFE4k-0007gV-Lb; Fri, 30 Jun 2023 09:22:14 -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 1qFE4i-0007e3-N4 for qemu-devel@nongnu.org; Fri, 30 Jun 2023 09:22:12 -0400 Received: from mail-wm1-x331.google.com ([2a00:1450:4864:20::331]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qFE4g-0003QI-Lb for qemu-devel@nongnu.org; Fri, 30 Jun 2023 09:22:12 -0400 Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-3fb4146e8deso23133705e9.0 for ; Fri, 30 Jun 2023 06:22:10 -0700 (PDT) Received: from localhost.localdomain ([139.47.41.96]) by smtp.gmail.com with ESMTPSA id a16-20020adfdd10000000b00313ef2150dcsm14571092wrm.45.2023.06.30.06.22.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Jun 2023 06:22:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688131329; x=1690723329; 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=OUAuwo10Yq9+V7BF7q6x9M7fE+x9XcbokQqcquvrZKI=; b=eAC6/hdTA7Sv2mmgrlVtc6HyUyPZfJ5unK1MCQ6VAcuz8B7W6IQ3UuZvjCWtIh0GPB LyafnR4HqDn/cvNKrbsCRBw8b7QnDpmwbPLg9DtpRx0e7RV830nhx3cDKyYRlwa88Hau hXg+tV2vmNJS5GkVmJS4Axdwf707B8c5T0qp+5UxXobIwlnp2OA4OaA3a19DW+McRxm9 AbZA0RGCbLFKM3GDisBgeuI3UJAToDPesLg31cKn0s5Jnq/MOUMkIxF/l5LaMXj9yPRi ElVXBKxchgFimnrgcR59ShZt9CRMtxEKxZjveUvRzNt8lrvzok7OSCuto9P8+jhA0SCG 3OCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688131329; x=1690723329; 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=OUAuwo10Yq9+V7BF7q6x9M7fE+x9XcbokQqcquvrZKI=; b=gD2oAtiU2SfHiGGVl+36XmDMDAjWB3+Rcm23trnzbp10Tv4/DzT1JJ3KBBfKNnA9gg heVN0+6UEzmodaSKu6DlfFVWQKgxjKgzi2CT24OWvWqp9iJQ6e1Q9YYHlmueKqPklCsd LV9Enrp8aOOaJ2Z5qkB7A0L4gaKaAq1kMbPI049wlXsezRF5W6u3hRPatn8pXZK3moaZ x6Zek9m0thQKiisXIbD5vOXLbCVTuAnhtGCza4N+f3ZbFZgAJrhP6GBuByKo/OxjCkdb VJiIE6jGNgJFykVvE0WhyAcTqxmoRnzm1kFZ+Ak9lx1wpQ+BvGOO0ADh428Zth2f2vYY iysA== X-Gm-Message-State: ABy/qLZaYYD15orH+ou6lgfsDqfGca4VOEp1KXr6mtDuXbGx+tqeZ+6U fM8FIO10OY2D6FMaM5rMTFIo8P/Zx4FNmswGLVYmuQ== X-Google-Smtp-Source: APBJJlHaZSEdt+HtlnTFNQX7oj0n2aaJqxSeT559mxU5B9qVAbAXnZJhxFysnwbX8q3/T3g+xVYNoQ== X-Received: by 2002:a5d:4f08:0:b0:313:dfa3:4f7b with SMTP id c8-20020a5d4f08000000b00313dfa34f7bmr2714153wru.20.1688131329301; Fri, 30 Jun 2023 06:22:09 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: mjt@tls.msk.ru, laurent@vivier.eu Subject: [PATCH 11/24] linux-user: Widen target_mmap offset argument to off_t Date: Fri, 30 Jun 2023 15:21:46 +0200 Message-Id: <20230630132159.376995-12-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230630132159.376995-1-richard.henderson@linaro.org> References: <20230630132159.376995-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::331; envelope-from=richard.henderson@linaro.org; helo=mail-wm1-x331.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, T_SCC_BODY_TEXT_LINE=-0.01 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1688131400929100007 Content-Type: text/plain; charset="utf-8" We build with _FILE_OFFSET_BITS=3D64, so off_t =3D off64_t =3D uint64_t. With an extra cast, this fixes emulation of mmap2, which could overflow the computation of the full value of offset. Signed-off-by: Richard Henderson --- linux-user/user-mmap.h | 2 +- linux-user/mmap.c | 14 ++++++++------ linux-user/syscall.c | 2 +- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/linux-user/user-mmap.h b/linux-user/user-mmap.h index 480ce1c114..3fc986f92f 100644 --- a/linux-user/user-mmap.h +++ b/linux-user/user-mmap.h @@ -20,7 +20,7 @@ =20 int target_mprotect(abi_ulong start, abi_ulong len, int prot); abi_long target_mmap(abi_ulong start, abi_ulong len, int prot, - int flags, int fd, abi_ulong offset); + int flags, int fd, off_t offset); int target_munmap(abi_ulong start, abi_ulong len); abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size, abi_ulong new_size, unsigned long flags, diff --git a/linux-user/mmap.c b/linux-user/mmap.c index 26d409cb60..98be739b5b 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -195,7 +195,7 @@ error: /* map an incomplete host page */ static int mmap_frag(abi_ulong real_start, abi_ulong start, abi_ulong end, - int prot, int flags, int fd, abi_ulong offset) + int prot, int flags, int fd, off_t offset) { abi_ulong real_end, addr; void *host_start; @@ -456,11 +456,12 @@ abi_ulong mmap_find_vma(abi_ulong start, abi_ulong si= ze, abi_ulong align) =20 /* NOTE: all the constants are the HOST ones */ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot, - int flags, int fd, abi_ulong offset) + int flags, int fd, off_t offset) { - abi_ulong ret, end, real_start, real_end, retaddr, host_offset, host_l= en, + abi_ulong ret, end, real_start, real_end, retaddr, host_len, passthrough_start =3D -1, passthrough_end =3D -1; int page_flags; + off_t host_offset; =20 mmap_lock(); trace_target_mmap(start, len, target_prot, flags, fd, offset); @@ -552,7 +553,7 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, in= t target_prot, } =20 if (!(flags & (MAP_FIXED | MAP_FIXED_NOREPLACE))) { - unsigned long host_start; + uintptr_t host_start; int host_prot; void *p; =20 @@ -571,7 +572,7 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, in= t target_prot, goto fail; } /* update start so that it points to the file position at 'offset'= */ - host_start =3D (unsigned long)p; + host_start =3D (uintptr_t)p; if (!(flags & MAP_ANONYMOUS)) { p =3D mmap(g2h_untagged(start), len, host_prot, flags | MAP_FIXED, fd, host_offset); @@ -675,7 +676,8 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, in= t target_prot, /* map the middle (easier) */ if (real_start < real_end) { void *p; - unsigned long offset1; + off_t offset1; + if (flags & MAP_ANONYMOUS) { offset1 =3D 0; } else { diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 459a2d8bc7..94cb4ad8fb 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -10350,7 +10350,7 @@ static abi_long do_syscall1(CPUArchState *cpu_env, = int num, abi_long arg1, #endif ret =3D target_mmap(arg1, arg2, arg3, target_to_host_bitmask(arg4, mmap_flags_tbl), - arg5, arg6 << MMAP_SHIFT); + arg5, (off_t)(abi_ulong)arg6 << MMAP_SHIFT); return get_errno(ret); #endif case TARGET_NR_munmap: --=20 2.34.1