From patchwork Sat Jul 15 13:53:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 703222 Delivered-To: patch@linaro.org Received: by 2002:a5d:4e4d:0:b0:314:25da:8dc4 with SMTP id r13csp157272wrt; Sat, 15 Jul 2023 06:55:51 -0700 (PDT) X-Google-Smtp-Source: APBJJlGSdcfBeLKLGiSZ+Sxxs8ZQCuLu1iFZK5X6i2uF4yl+1g16ngEWML0+KVta0WktmzH2ydbA X-Received: by 2002:ac8:5cce:0:b0:403:691f:5403 with SMTP id s14-20020ac85cce000000b00403691f5403mr9792426qta.67.1689429351436; Sat, 15 Jul 2023 06:55:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689429351; cv=none; d=google.com; s=arc-20160816; b=dJHhJPzeyOIXIGKFhTrBFT4z4cMNQOcmTk56mCq7VTCkzNf9TSPxnHHd98aBemG1Eb vOfIF/J5rn/KGp6uhxGg9vuWAZjuNtwi+57Vr1FB8PntxoR67i0mQv3Ghk02PTLQvvBD tPc+sbmq8Ke/RWBf8tDGnc0Gq5PmPnAx7z+exI2auH1Jhg9/1SRPcS6qQ6OX3bEA9k1H pUgrJ+8Gc/zcB5+Yy1YNGpPgT+0TJdVGUr0XR0oOqHZcPyd9vl6/yGYgrfkFJMkSpPGh YxJ3MyTeyMeSHL5DGzfxOie2SwlBPi+vng3RmU6umAGDn1f57zp/euhKY1nwEhTWEl3U OcGw== 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=Fokkd6so43K12JUZOnDmBsniw0YcAJ7z1i5mex4l2TY=; fh=ZuLSLtzpwbOj79Lm6HQkAzCl7AYBeBRT4Q/1zeFcrQg=; b=1GxUMHV/ExRflXfLUZ0aOUBJTwouk353mlp995dZgMmsDxVX/7hshYKCSZqPSHLDzy 3KW6XJLCcyFBrc/Bo53pK9PPE3R0s3xHbUbSmXL49je77IX7216gqqZkBjGhdnhz/BH0 GOlMIgdOVJkMRczOlubV6JMxfqsNaZMcupMdda5oFjrbM5DrPXMQZruvaSAQkAd4IxXZ q4rQuIBii9pLuuSZdxXGaQNeBotxd3W+dUFNrMEi7Kakq4eHV1QU0O6r/YJYyiIMzbbh vRP7qHXj9kvRtgjckFOYlAnr63uWk8fVkj2ZPxM807N1DJunFkQl2BXeMgc021l0TPjH IkTQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="QaR3sF//"; 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 c7-20020ac85a87000000b0040357383472si5788315qtc.256.2023.07.15.06.55.50 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 15 Jul 2023 06:55:51 -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="QaR3sF//"; 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 1qKfj3-0004ZN-BU; Sat, 15 Jul 2023 09:54:21 -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 1qKfia-00048Y-22 for qemu-devel@nongnu.org; Sat, 15 Jul 2023 09:53:59 -0400 Received: from mail-wr1-x42e.google.com ([2a00:1450:4864:20::42e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qKfiS-0001Jh-FR for qemu-devel@nongnu.org; Sat, 15 Jul 2023 09:53:49 -0400 Received: by mail-wr1-x42e.google.com with SMTP id ffacd0b85a97d-3159da54e95so2755272f8f.3 for ; Sat, 15 Jul 2023 06:53:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1689429223; x=1692021223; 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=Fokkd6so43K12JUZOnDmBsniw0YcAJ7z1i5mex4l2TY=; b=QaR3sF//XkO8mVzAb1z/ZvnUn8vHEcew6h/biywu1IdsIghKWcWvqmC7cDr61WF83W Vq9A9L6w2gK3F8iSiXq/zG0MOvRDwKo6j7uskk+cp3pDx7G5NN5hmjcTF50PtGCfVy0f obrlLbS/TaN1Q7rV3j8JCnyxOepzAvT0Nnc8xBo7s7Euwuun6j6h0r5fHoaay+HZ72Rg C8ggAVYf6coZHsRVQ0zW5dYGNQp2nXHpN222xFxcAJLdWs1Hzvjz1vjrST5vAOO+fP2q WjXuOsjBqC2/b32xGinHsOCGFG3fF2BEx+ZDGQUV+eWdYDXEUFApVQQouZIbM6SFnVGj 8JDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689429223; x=1692021223; 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=Fokkd6so43K12JUZOnDmBsniw0YcAJ7z1i5mex4l2TY=; b=HvKkk9hoQkLjiTp4RSZfy6j493ulPwnSccVUmb+IsjCJIU44GvICQ2gkWXBLtOEIYi 9H/aW2CkSunRtl5lG+zSPsQCobdBhyziwkwiVKKk/q5I2GsRhAO5dIRku67+/g1l7WTz 2bkFezE04Zevim5J7kexqXQpkYI5yYl0gHLwG6AvYWFLT4TRs19zNwiiR0UBJ5c5BNOD S163kHkBgvIDR3cHwdLh/nW945pkU008RG8k/OTbpkqYd8dUSdy3eTZNZN1QiT9w4dM1 v0zDrNxkqNyRx+y+Quxv1vxSz1C3st67vPyj42NCK/KeATskT4diYKd5MDXx4MuG6y+E 8aqQ== X-Gm-Message-State: ABy/qLbGRo2pOVo+8XBEnKPDHQ6MxlC7uFcdJN2pG9j/+6jp0Dg2GRn0 lbOjUIz+OavBuKyNoCSLNLo7unchGmy0ZzZc1dPffQ== X-Received: by 2002:a5d:570d:0:b0:315:ad1a:5abc with SMTP id a13-20020a5d570d000000b00315ad1a5abcmr6869984wrv.5.1689429223284; Sat, 15 Jul 2023 06:53:43 -0700 (PDT) Received: from stoup.lan ([51.219.12.49]) by smtp.gmail.com with ESMTPSA id k10-20020a5d66ca000000b00313f9085119sm13838014wrw.113.2023.07.15.06.53.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 15 Jul 2023 06:53:42 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Alex_Benn=C3=A9e?= Subject: [PULL 30/47] linux-user: Widen target_mmap offset argument to off_t Date: Sat, 15 Jul 2023 14:53:00 +0100 Message-Id: <20230715135317.7219-31-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230715135317.7219-1-richard.henderson@linaro.org> References: <20230715135317.7219-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42e; envelope-from=richard.henderson@linaro.org; helo=mail-wr1-x42e.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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org We build with _FILE_OFFSET_BITS=64, so off_t = off64_t = uint64_t. With an extra cast, this fixes emulation of mmap2, which could overflow the computation of the full value of offset. Reviewed-by: Alex Bennée Signed-off-by: Richard Henderson Message-Id: <20230707204054.8792-14-richard.henderson@linaro.org> --- 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 @@ 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 12b1308a83..b2c2d85857 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -196,7 +196,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; @@ -463,11 +463,12 @@ abi_ulong mmap_find_vma(abi_ulong start, abi_ulong size, abi_ulong align) /* 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_len, + abi_ulong ret, end, real_start, real_end, retaddr, host_len, passthrough_start = -1, passthrough_end = -1; int page_flags; + off_t host_offset; mmap_lock(); trace_target_mmap(start, len, target_prot, flags, fd, offset); @@ -559,7 +560,7 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot, } if (!(flags & (MAP_FIXED | MAP_FIXED_NOREPLACE))) { - unsigned long host_start; + uintptr_t host_start; int host_prot; void *p; @@ -578,7 +579,7 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot, goto fail; } /* update start so that it points to the file position at 'offset' */ - host_start = (unsigned long)p; + host_start = (uintptr_t)p; if (!(flags & MAP_ANONYMOUS)) { p = mmap(g2h_untagged(start), len, host_prot, flags | MAP_FIXED, fd, host_offset); @@ -681,7 +682,8 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot, /* map the middle (easier) */ if (real_start < real_end) { void *p; - unsigned long offset1; + off_t offset1; + if (flags & MAP_ANONYMOUS) { offset1 = 0; } else { diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 3a89f6b408..a80d33ecf2 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -10591,7 +10591,7 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1, #endif ret = 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: