From nobody Tue Nov 26 08:35:10 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=1709151987; cv=none; d=zohomail.com; s=zohoarc; b=fXptHEPuVmkJJROqWcniwhdLcwKA9B6IYCcuMzNN24LBllQGDouPVkphx3npuDvZvQiIVCfRqfCHDCKZKNOkq1aYkss9KxyPqqCpO5n+xvaAw+PlP3WAgaScvkRJaqMquvwT+4h99XfKQ/atKasAV4n/AKgLH6GIQP5BLRdGjVA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709151987; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=p6tPGvcWUCgEHkg4WhhgoNhXXsmKMPZyhGixNdkwuIE=; b=ULdn8Xq3KG/53ahmxGrYKWz3SoLvUm04zd7RWSG9imKAECSkRPKwZLyACD+iJD3DxOnPOSBC5Gg20Woy7TxyIu3KSlTonb0aG/VJGAOziEyHwM6GlIuHkLA6don4A+weiGl/luu5MuuwSVwI9L0jtTT0Zh/D3OBKNm5fbh1/tY4= 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 1709151987891526.5803777923804; Wed, 28 Feb 2024 12:26:27 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rfQUw-00087k-2U; Wed, 28 Feb 2024 15:25:51 -0500 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 1rfQUs-00086E-Ov for qemu-devel@nongnu.org; Wed, 28 Feb 2024 15:25:47 -0500 Received: from mail-pg1-x52b.google.com ([2607:f8b0:4864:20::52b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rfQUd-0007Mv-2K for qemu-devel@nongnu.org; Wed, 28 Feb 2024 15:25:46 -0500 Received: by mail-pg1-x52b.google.com with SMTP id 41be03b00d2f7-5cfd95130c6so103368a12.1 for ; Wed, 28 Feb 2024 12:25:30 -0800 (PST) Received: from stoup.. (098-147-055-211.res.spectrum.com. [98.147.55.211]) by smtp.gmail.com with ESMTPSA id oh5-20020a17090b3a4500b0029ab712f648sm2118499pjb.38.2024.02.28.12.25.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 12:25:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709151929; x=1709756729; 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=p6tPGvcWUCgEHkg4WhhgoNhXXsmKMPZyhGixNdkwuIE=; b=T4axga2FbF4om3bn1Y4hsgNRtmpOjBaUc4/NxeH+EEP0dtdxzMa8leX1rLiOPCadJr UafXs7ZNmgYCsdYndtyMgB/fse1N2+IJYQuJUjg+i1vZoczWhkjIX9SlVYtE1kw2lF9h hYU7/P3jPuRUZFYTs4cP8CdH7wStrQeZrYymAVLPNL57ECFQhTYJeWfWLPFu1wo8Ju5X FGnrGzKe9az6norOL3u4I61oxn6+0+gIiiwt+D6FQG6DVj52WQ2tMvSLiJM0hAWqPtaM vEWC0RANXD7QMVu7mLadL2wW7spVzHuv7mR+R3YUljAtZ7hl2KkeINAEQ9ag3FjoBLOb 84Jw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709151929; x=1709756729; 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=p6tPGvcWUCgEHkg4WhhgoNhXXsmKMPZyhGixNdkwuIE=; b=gTqmFA+Yloe7TveitLaMb+x34FgLzOTXB4FhzWE8PTxZ2VRXylShRm3x84vqJD5/ZL zXi3Ldu8CrWbBgaieoiLRUckuOZ3aS2tE9evWWZbS+iEltTha6M/ReFr0aJnUXQaJdmp cXNQnq5ddhcVaClptl5GXOPkOrsMIqD1bvpL14ajDBf5PX6nziA9sFCcsT51forgo0BW lQQNWBJlNeWHOvXYr+hjfg1PmrlR38HqjPT1e5lo510UZCxC5/sJR2OY7e9/lROZohz1 QjXWAXJNcpYDg69xrza6y5M8pdMMfPw5SeSfSeotLkxrYV3IVFaYcVa5ojv5HO0An8bH kE3w== X-Gm-Message-State: AOJu0YxhB3ONJeCg9pXBayDmE1jCDzz1+OqD9VkZT5lhKjG4G7Xv/y8U 0OBpbSUc9/Plq2RtM7Cyulw54uDDeM1r9jo+H3EFt0zJts5pOO9BjWUkPLz1sqFn1W88/ca3L64 h X-Google-Smtp-Source: AGHT+IFpLKEaiu7JuvZ8j3W1ZjVyxMMXEWIJpJnC0TU19pabpd4XPWCuEh4EQADC6JBJztYQ7+DxkQ== X-Received: by 2002:a17:90a:4206:b0:299:df2:66b2 with SMTP id o6-20020a17090a420600b002990df266b2mr262073pjg.22.1709151929447; Wed, 28 Feb 2024 12:25:29 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: laurent@vivier.eu, richard.purdie@linuxfoundation.org, mjt@tls.msk.ru, iii@linux.ibm.com Subject: [PATCH v2 5/5] tests/tcg: Check that shmat() does not break /proc/self/maps Date: Wed, 28 Feb 2024 10:25:18 -1000 Message-Id: <20240228202518.33180-6-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240228202518.33180-1-richard.henderson@linaro.org> References: <20240228202518.33180-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=2607:f8b0:4864:20::52b; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x52b.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, 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: 1709151989867100003 Content-Type: text/plain; charset="utf-8" From: Ilya Leoshkevich Add a regression test for a recently fixed issue, where shmat() desynced the guest and the host view of the address space and caused open("/proc/self/maps") to SEGV. Signed-off-by: Ilya Leoshkevich Message-Id: Signed-off-by: Richard Henderson --- tests/tcg/multiarch/linux/linux-shmat-maps.c | 55 ++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 tests/tcg/multiarch/linux/linux-shmat-maps.c diff --git a/tests/tcg/multiarch/linux/linux-shmat-maps.c b/tests/tcg/multi= arch/linux/linux-shmat-maps.c new file mode 100644 index 0000000000..0ccf7a973a --- /dev/null +++ b/tests/tcg/multiarch/linux/linux-shmat-maps.c @@ -0,0 +1,55 @@ +/* + * Test that shmat() does not break /proc/self/maps. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ +#include +#include +#include +#include +#include +#include + +int main(void) +{ + char buf[128]; + int err, fd; + int shmid; + ssize_t n; + void *p; + + shmid =3D shmget(IPC_PRIVATE, 1, IPC_CREAT | 0600); + assert(shmid !=3D -1); + + /* + * The original bug required a non-NULL address, which skipped the + * mmap_find_vma step, which could result in a host mapping smaller + * than the target mapping. Choose an address at random. + */ + p =3D shmat(shmid, (void *)0x800000, SHM_RND); + if (p =3D=3D (void *)-1) { + /* + * Because we are now running the testcase for all guests for which + * we have a cross-compiler, the above random address might confli= ct + * with the guest executable in some way. Rather than stopping, + * continue with a system supplied address, which should never fai= l. + */ + p =3D shmat(shmid, NULL, 0); + assert(p !=3D (void *)-1); + } + + fd =3D open("/proc/self/maps", O_RDONLY); + assert(fd !=3D -1); + do { + n =3D read(fd, buf, sizeof(buf)); + assert(n >=3D 0); + } while (n !=3D 0); + close(fd); + + err =3D shmdt(p); + assert(err =3D=3D 0); + err =3D shmctl(shmid, IPC_RMID, NULL); + assert(err =3D=3D 0); + + return EXIT_SUCCESS; +} --=20 2.34.1