From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id C1BCCC52D7C for ; Wed, 21 Aug 2024 16:20:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 609756B012A; Wed, 21 Aug 2024 12:20:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5B9526B012B; Wed, 21 Aug 2024 12:20:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4A7AA6B012E; Wed, 21 Aug 2024 12:20:20 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 2C5096B012A for ; Wed, 21 Aug 2024 12:20:20 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 86A72A0D87 for ; Wed, 21 Aug 2024 16:20:19 +0000 (UTC) X-FDA: 82476764958.09.FF6C066 Received: from mail-oo1-f46.google.com (mail-oo1-f46.google.com [209.85.161.46]) by imf11.hostedemail.com (Postfix) with ESMTP id 862FF40021 for ; Wed, 21 Aug 2024 16:20:17 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=GBqFeBpz; spf=pass (imf11.hostedemail.com: domain of pedro.falcato@gmail.com designates 209.85.161.46 as permitted sender) smtp.mailfrom=pedro.falcato@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724257154; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=vhsRhHHgA460KmlvgmMOROdQkEYqdVaGy9dpXTwKETQ=; b=GClixkyJHe6LJADfGW5YLbV1ZQhpI2ys1iJSLp3+v7oX4dwgCicszSIbrS0+bWYruDAeGV maHqwUHXKgZnMVFKHbnA8tR34Af5YgOrJ/Ur3v4n2YVt0k/4idgytU9xB4SpyhW8bJ9TB6 pQkKXVhMg8PG/25gKoShbL/mKip7dgY= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=GBqFeBpz; spf=pass (imf11.hostedemail.com: domain of pedro.falcato@gmail.com designates 209.85.161.46 as permitted sender) smtp.mailfrom=pedro.falcato@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724257154; a=rsa-sha256; cv=none; b=QBLNwecMrLnIJgzqfS6C6Cpd/sjgap6TFCWm10dfUeJAoVzToAmL1zrDe8Q3sBOLBy81vP wu4K2MlmyMFw4qKeHWLMngthPw3UHTMWoJizRqE8XmONqcJC+MCoSjRCzWV+eWsvlpm2mr TtUESb+3S95He+066tLD/RtfWpMcOcg= Received: by mail-oo1-f46.google.com with SMTP id 006d021491bc7-5dcad9845b4so231030eaf.2 for ; Wed, 21 Aug 2024 09:20:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724257216; x=1724862016; darn=kvack.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=vhsRhHHgA460KmlvgmMOROdQkEYqdVaGy9dpXTwKETQ=; b=GBqFeBpzh2SE34dP0VAq5CrmsizKAR7DY+wD1M17cmS5K9bu/kTHit11LjUpD8Nf7y wAmeispUBsDADpqJtogoWNsKBJMv12CvgpyzfhbhEwYEx/h0LIOTfoJeyiDGuz5Y6ymP 7yRcdSe+ReLCRaXgfBKAxR86lgTwutK/hcXzLjDBZaPKWus9lbT8G0tdwYoaLOh9lPcx QEyKQs5gOBdTT+FBZbP/NY8Zp5oXq37j1YMpCU4mE7mmJxkY9hZ04DFnwCm/xULTVOvp RPEc3ZyiZCHaiw9JTSssokvh5+ixQHHEWFvbYOhbSxU4WIljnH3Fszrl4DBNJEynmNoh n+yg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724257216; x=1724862016; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vhsRhHHgA460KmlvgmMOROdQkEYqdVaGy9dpXTwKETQ=; b=oFjEK2eCsNLSSGk4cqAh2JGRyJSqjP62/W0ZXMiOMDmUbdq4NCjyXOkdsQvGprwQDQ nbxc46s0lS+7vCE7dH+M4XfWKGouZv+kpbQ+TdEZigSEnDgoH58FQo16QdXgXKHt0eAu hGpuKAgIHRwAuXh3FyA+YMuDWDRyZrueO571FDvHxycYF1W1Ld3/FvZmCr+ZNyS3VrSO +FEs+g6QBi/BX4bGZdV8G9x0TfROb3pNmJDsgF4w1ui7DTgRROPdfSqatEqJtXNMQISI qaLMazANuTdS5yBhVkx8jgJSIwJMYtOxB7E48C3kTPp/zYsihHt8YriNUyN621n4rpIP KscQ== X-Forwarded-Encrypted: i=1; AJvYcCWQlQNS589Jf1zGWCDEmrHfnzJIrY+Yt0YKbhZ0tvo/JnH/lbpOlGAOO2Tzq5o3ut9kBNPF0wqrSQ==@kvack.org X-Gm-Message-State: AOJu0Yx8ucwDtzdTlpaXXtkTOM4kRFpwVB+8dEPc3cA8DIaxN0W0lSyT f67nu9sfgCNj4BegJo2gesnHQ6HG2+Cip0er4ToULXvbNYHd7pdjA86wZVSqFYiKUck9lbE9AZY ElMmTcpPHUmrr7lr97XsS5xqg2RA= X-Google-Smtp-Source: AGHT+IHxLwEOn+yLKvWv3YQVmoIjzuASNvJuOZVGLBWsX/53u/E9LE77DnAjl+3NmlWimETKSzNaaXnlGkRMLdtn3M4= X-Received: by 2002:a05:6358:6184:b0:1b1:aca9:9627 with SMTP id e5c5f4694b2df-1b59f969251mr390945155d.7.1724257216157; Wed, 21 Aug 2024 09:20:16 -0700 (PDT) MIME-Version: 1.0 References: <20240817-mseal-depessimize-v3-0-d8d2e037df30@gmail.com> <20240817-mseal-depessimize-v3-7-d8d2e037df30@gmail.com> In-Reply-To: From: Pedro Falcato Date: Wed, 21 Aug 2024 17:20:04 +0100 Message-ID: Subject: Re: [PATCH v3 7/7] selftests/mm: add more mseal traversal tests To: Jeff Xu Cc: Andrew Morton , "Liam R. Howlett" , Vlastimil Babka , Lorenzo Stoakes , Shuah Khan , linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, oliver.sang@intel.com, torvalds@linux-foundation.org, Michael Ellerman , Kees Cook Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Stat-Signature: phxkp8e6ie41idqkqxczbsyhzi9iu9wq X-Rspam-User: X-Rspamd-Queue-Id: 862FF40021 X-Rspamd-Server: rspam02 X-HE-Tag: 1724257217-596463 X-HE-Meta: U2FsdGVkX19P9d653kP2mVbE1Ov5bPC8dxX0GnvmxznPPZxAaqt7UGk7BDO2BpiMhKeRWcfBMXK60R2uJfg4aeqlYUdKf4Nlylw5cOsXyd1C/8v7ofkMwik5u4/D6sl9c/1ThkMjJIC0FA2tNOu6q0jlf6M+ANpRKIYJobHFM8Hmftp2oL8lMnZsCrr9oZbN/nqaqQOb0Y+Ssj6dcTX7bKUSIO7xMA9WthR6gSL9r4t7LN7DCQOIcUTacQiwlvl+JTHvC4PM9H236VEJ220tQZeO3djl8JDSPop2r3l/KkPH6Fisouq5xNHBgOIRYxDCNygesnzsloRZFHYR16nO0wrC77uwLHlwr10/pafs9G3xovBvSWYeQJuXoNKwpeG/REem7i5QAJxwWF7ZZM/Ud9reIUvMp1zwnAuaOMcLwwALerL0E1P5xMN8VLFk/kCsoZ9WVgWUXYGRYT9PIvYZWzmr9fmw/zd7UR5slrPO1oCsGTF+22vBvAhunbp/OUwkgC+vKjJympIkVPJDkCgenZHuIkWPEaEZIpBekByPAPn3fnR/TonujZo4frCALMVDY8fZsh013RC589b0IBKqP5x5DotpmObBelhHjvYdK0crkgnGGRKjvgyxq2aFEbp+YFQPAgVKrmg+YMZdCRxELOjGxhTSWKvQK4h4CxbaWKgEnPXblwnj6xK2+XU4HgvcI4kvjfYQg1ukZTejGY/gQfMuiQgR1PAKw5ItUjIzc4rGe401n0WAT0SK9ST/QsDnRZ3DXBTVSKjUOvNfuk+sEMO2JGeOFJdYzgylEeIEkXRUT0MxlA4AGWoELJaylzgSaiMTyYIljo46x7+HPwUGfptHbusjmGX8LYNb3d10RimfX26pMG2L2osCwjIryd7dloivXjZlk5R8Osruc5kkGQWuf59SOmePshxKjfNjWcA+u6A/evqnEkFy5hzzrIjeZ7dAgmAxl3qUjwvqsPN pknH+xvU YDb0g81OakbaX4nxnZ3jeiKQgeaFSJ9yUfPdZ4evQcM4vHRleENBudVOlBaSjW21pREjwsKZ9IB38n1afBNXeyxN/gsAM96ibtO+Z8rjHby9wf0O/nkhCs97iQMqR4NIJDZnpK2trANVFtQ54lr5UfeMU0Bl4yLx5g+K5zeaM993gtx7U/VXKwuo8GEg2EyG8F6iQJL2x7G90x5poE6dnDoWHGr8ITg0Qccp4s3yYhoC/B3C6x5t2Ih1C7HIqzLLOwphh5NG4jFnSKHtyYa+lgqprOGXkMEFlZmaJzHrMx4N7TyPACWdMt68mqxQsDig+lw1iQhUgTAYFQHPhb0jUwUh6iA/3/tUruQCti2PRmiNSsnuJLIP0nqO0+g== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Wed, Aug 21, 2024 at 4:56=E2=80=AFPM Jeff Xu wrote= : > > Hi Pedro > > On Fri, Aug 16, 2024 at 5:18=E2=80=AFPM Pedro Falcato wrote: > > > > Add more mseal traversal tests across VMAs, where we could possibly > > screw up sealing checks. These test more across-vma traversal for > > mprotect, munmap and madvise. Particularly, we test for the case where = a > > regular VMA is followed by a sealed VMA. > > > > Signed-off-by: Pedro Falcato > > --- > > tools/testing/selftests/mm/mseal_test.c | 111 ++++++++++++++++++++++++= +++++++- > > 1 file changed, 110 insertions(+), 1 deletion(-) > > > > diff --git a/tools/testing/selftests/mm/mseal_test.c b/tools/testing/se= lftests/mm/mseal_test.c > > index 259bef4945e9..0d4d40fb0f88 100644 > > --- a/tools/testing/selftests/mm/mseal_test.c > > +++ b/tools/testing/selftests/mm/mseal_test.c > > @@ -766,6 +766,42 @@ static void test_seal_mprotect_partial_mprotect(bo= ol seal) > > REPORT_TEST_PASS(); > > } > > > > +static void test_seal_mprotect_partial_mprotect_tail(bool seal) > > +{ > > + void *ptr; > > + unsigned long page_size =3D getpagesize(); > > + unsigned long size =3D 2 * page_size; > > + int ret; > > + int prot; > > + > > + /* > > + * Check if a partial mseal (that results in two vmas) works co= rrectly. > > + * It might mprotect the first, but it'll never touch the secon= d (msealed) vma. > > + */ > > + > > + setup_single_address(size, &ptr); > > + FAIL_TEST_IF_FALSE(ptr !=3D (void *)-1); > > + > > + if (seal) { > > + ret =3D sys_mseal(ptr + page_size, size); > you are allocating 2 pages , and I assume you are sealing the second > page, so the size should be page_size. > ret =3D sys_mseal(ptr + page_size, page_size); Yes, good catch, it appears to be harmless but ofc down to straight luck. I'll send a fixup for this and the other mistake down there. > > > + FAIL_TEST_IF_FALSE(!ret); > > + } > > + > > + ret =3D sys_mprotect(ptr, size, PROT_EXEC); > > + if (seal) > > + FAIL_TEST_IF_FALSE(ret < 0); > > + else > > + FAIL_TEST_IF_FALSE(!ret); > > + > > + if (seal) { > > + FAIL_TEST_IF_FALSE(get_vma_size(ptr + page_size, &prot)= > 0); > > + FAIL_TEST_IF_FALSE(prot =3D=3D 0x4); > To test partial mprotect, the test needs to add the check for the > first page to be changed, Also to avoid the merge, a PROT_NONE page > can to be added in front. No, I'm leaving partial mprotect to be undefined. It doesn't make sense to constraint ourselves, since POSIX wording is already loose. > > > + } > > + > > + REPORT_TEST_PASS(); > > +} > > + > > + > > static void test_seal_mprotect_two_vma_with_gap(bool seal) > > { > > void *ptr; > > @@ -983,6 +1019,41 @@ static void test_seal_munmap_vma_with_gap(bool se= al) > > REPORT_TEST_PASS(); > > } > > > > +static void test_seal_munmap_partial_across_vmas(bool seal) > > +{ > > + void *ptr; > > + unsigned long page_size =3D getpagesize(); > > + unsigned long size =3D 2 * page_size; > > + int ret; > > + int prot; > > + > > + /* > > + * Check if a partial mseal (that results in two vmas) works co= rrectly. > > + * It might unmap the first, but it'll never unmap the second (= msealed) vma. > > + */ > > + > > + setup_single_address(size, &ptr); > > + FAIL_TEST_IF_FALSE(ptr !=3D (void *)-1); > > + > > + if (seal) { > > + ret =3D sys_mseal(ptr + page_size, size); > ret =3D sys_mseal(ptr + page_size, page_size); > > > + FAIL_TEST_IF_FALSE(!ret); > > + } > > + > > + ret =3D sys_munmap(ptr, size); > > + if (seal) > > + FAIL_TEST_IF_FALSE(ret < 0); > > + else > > + FAIL_TEST_IF_FALSE(!ret); > > + > > + if (seal) { > > + FAIL_TEST_IF_FALSE(get_vma_size(ptr + page_size, &prot)= > 0); > > + FAIL_TEST_IF_FALSE(prot =3D=3D 0x4); > To test partial unmap, the test needs to add the check for the first > page to be freed, Also to avoid the merge, a PROT_NONE page needs to > be in front. I'm not testing partial unmap. Partial unmap does not happen. I have told you this before. > > The test_seal_munmap_partial_across_vmas shows the behavior > difference with in-loop approach and out-loop approach. Previously, > both VMAs will not be freed, now the first VMA will be freed, and the > second VMA (sealed) won't. > > This brings to the line you previously mentioned: [1] and I quote: > "munmap is atomic and always has been. It's required by POSIX." This is still true, the comment was a copy-and-paste mindslip. Please read the email thread. It has been fixed up by Andrew. --=20 Pedro