From patchwork Fri Mar 29 22:20:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 784086 Delivered-To: patch@linaro.org Received: by 2002:a5d:4e01:0:b0:33e:7753:30bd with SMTP id p1csp3426548wrt; Fri, 29 Mar 2024 15:22:09 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCU+0WDZkoH3tY750oapD4NSeUs8NS8QJni9y+YxBDXK6YCL0sPFRgtMSwfJrFnM548hvsA5pmB/psM7oJwo4NFN X-Google-Smtp-Source: AGHT+IFrO7gKnAQVvS4WPqNArLrL2vlDqhgk8mhhv+4NMFohhiREZUNXhtcLw4x38bohECn6gJWB X-Received: by 2002:a05:6214:16a:b0:696:ad33:cc01 with SMTP id y10-20020a056214016a00b00696ad33cc01mr3603476qvs.22.1711750929396; Fri, 29 Mar 2024 15:22:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1711750929; cv=none; d=google.com; s=arc-20160816; b=V+q9Rp9xcvF24VmjJe/7006OBZZ3QHHQu8hibuthvFGj71oy/weuBxEtuUhTFqvWPr UwTLQB3alNvzN3iSN621M8Z/lMmWN4mbMHV4Ok5GH6l9yD3YE0voxhULwl7E3+N1I73I zqZacPCIK/yYUqOcWDIesdudz85GHw2WvxQ6mL1D7mc+QcKt7fgIrM6XGey57zU7p4y6 dhhc+FJgy9+Z6FMymgNcQ3+GI5+zRxjXW2axzSq5BuVzUMVh7YLHo8MP9j1eydwcTf4D 24OK/hPxDCqkK5YA/+0ClU5mXA78W87ruutJEsXQ3rxkbbuN0MxDAmNnRckSFFIfUQAy z4nA== 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=HtUHg09UOjxxYBJJEpdXT1anxY6jjxQxzEq5yXQbAXE=; fh=o2XzhdKG+B45MJCghEfnYoypmHvLX2hd4SL6yXeiyXI=; b=tA3ZsCaDYzu8YyTYtqVBOZ64Z9rCTeX6BYcfVNRdkeBYNZMxxVGZiOzelFM1bEfAc1 xsA1lRGJElS8t/0kjotsNnKsjn8r9aN1deDxOyUlxdB5T1xsipsRW/rDiRPOIo/KUSzE xGix7XigO52HbADGMyJMWnUtrY6QACe+OPirlmvxfW8fKKaxKa6K6AxvQPR59R6NZ9DG RH4tKCKgxYrPpnS54ABCfb7iEw4qBF3BtwTj5DWeeSXUDc62HJsvXCGwl1eljMLUFEKp LvgYbAC3KwYpuCMB4hlQsFy3UY78MBH4qWgaiJvPEDL6TB7vxLaAFIPFhv0bPqHEptEE p+rw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=yBJGaOdr; 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 jy19-20020a0562142b5300b00696b17e2c70si4524777qvb.218.2024.03.29.15.22.09 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 29 Mar 2024 15:22:09 -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=yBJGaOdr; 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 1rqKae-00055n-Ss; Fri, 29 Mar 2024 18:20:48 -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 1rqKad-00055U-PG for qemu-devel@nongnu.org; Fri, 29 Mar 2024 18:20:47 -0400 Received: from mail-pf1-x42c.google.com ([2607:f8b0:4864:20::42c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rqKac-0001p9-9T for qemu-devel@nongnu.org; Fri, 29 Mar 2024 18:20:47 -0400 Received: by mail-pf1-x42c.google.com with SMTP id d2e1a72fcca58-6e74bd85f26so2032981b3a.1 for ; Fri, 29 Mar 2024 15:20:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1711750845; x=1712355645; darn=nongnu.org; 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=HtUHg09UOjxxYBJJEpdXT1anxY6jjxQxzEq5yXQbAXE=; b=yBJGaOdrjxNQNBorSTQqmPpBX4T4sd3LXvM2cI1rJX+8fCHqOMYiRWupAHDFL1+lJB vYukkFzzMz/qP2Ht9Rn6HF0LD1zg29tyoNxlVmyk27bQgAbV7w116SyLpiCs4qICIkru a//h8CKsi+/oZRk/6JKFTw7LSrqnN2PvvFXRBGSG+ibN6YVr5yyqVpDDQ3Z9Km6i0Esr zsnvevkFBoRegLZV2qOFw16vgIsTBHhKajHR7AjrT4J9SWXhPitXDU6bmxc9fJ8pfxIF 2Ph2e/9RCeSBSaWIr9drZo06fv15xcXn6/F9N0pg8bTGXRxnp6lOvSQX22+QwtHWPWPF feyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711750845; x=1712355645; 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=HtUHg09UOjxxYBJJEpdXT1anxY6jjxQxzEq5yXQbAXE=; b=uy+aVsv8+5hMTe6B3KLjT5T1xAp7D4W8XNxY2E3sCf57xjTngGI9QUroVDv/lLIo3P smL7uxHtYh+ucJb1Qb9npY8vaWOp8ops/ImqaYz2THsdX+bGdMo1XNzHiPXspWGwhT+Q vmDiZ0G1uy0ecRx5IGTxzUQfBZy5TURWSHd+l5iQlRoqnxxfQn9azIuPNnuJSkHvjC6c TJ1/ZXgXEzcazpPENqL4/PBiGPKAbHpLlxnfuGznJ5+HCO+CbqkbLXqzyTQr88HBaYqb 5GnSPHcmfjlhIvdVPjelu4zZ7MT4hnB6YP3BdLMNGHCKzMOMktDAWfVblthkIWX9o9oB XLMA== X-Gm-Message-State: AOJu0YxAI7oilD/G6bru9aP7lD3sfvM0LdL3dClBVRBKr6lfVM7Amd5v PmTDnwRj7I0Bz/i3V+EbA+2uIqEtOMpM9qnJLp5TWOMXTnRTDnr8dYUOhRBvwoL2RHvEuIXI4co o X-Received: by 2002:a05:6a00:1910:b0:6ea:ca90:3459 with SMTP id y16-20020a056a00191000b006eaca903459mr3588812pfi.32.1711750844955; Fri, 29 Mar 2024 15:20:44 -0700 (PDT) Received: from stoup.. (098-147-007-212.res.spectrum.com. [98.147.7.212]) by smtp.gmail.com with ESMTPSA id lc24-20020a056a004f5800b006eaacc63435sm3579811pfb.173.2024.03.29.15.20.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Mar 2024 15:20:44 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Ilya Leoshkevich Subject: [PULL 3/7] linux-user: Fix shmat(NULL) for h != g Date: Fri, 29 Mar 2024 12:20:33 -1000 Message-Id: <20240329222037.1735350-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240329222037.1735350-1-richard.henderson@linaro.org> References: <20240329222037.1735350-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42c; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42c.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 From: Ilya Leoshkevich In the h != g && shmaddr == NULL && !reserved_va case, target_shmat() incorrectly mmap()s the initial anonymous range with MAP_FIXED_NOREPLACE, even though the earlier mmap_find_vma() has already reserved the respective address range. Fix by using MAP_FIXED when "mapped", which is set after mmap_find_vma(), is true. Fixes: 78bc8ed9a8f0 ("linux-user: Rewrite target_shmat") Reviewed-by: Richard Henderson Signed-off-by: Ilya Leoshkevich Message-Id: <20240325192436.561154-4-iii@linux.ibm.com> Signed-off-by: Richard Henderson --- linux-user/mmap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/linux-user/mmap.c b/linux-user/mmap.c index 4505fd7376..be3b9a68eb 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -1354,7 +1354,7 @@ abi_ulong target_shmat(CPUArchState *cpu_env, int shmid, if (h_len != t_len) { int mmap_p = PROT_READ | (shmflg & SHM_RDONLY ? 0 : PROT_WRITE); int mmap_f = MAP_PRIVATE | MAP_ANONYMOUS - | (reserved_va || (shmflg & SHM_REMAP) + | (reserved_va || mapped || (shmflg & SHM_REMAP) ? MAP_FIXED : MAP_FIXED_NOREPLACE); test = mmap(want, m_len, mmap_p, mmap_f, -1, 0);