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 7C421C52D7C for ; Wed, 21 Aug 2024 17:28:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C541A6B0149; Wed, 21 Aug 2024 13:28:53 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BDC526B014D; Wed, 21 Aug 2024 13:28:53 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A2EE96B014E; Wed, 21 Aug 2024 13:28:53 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 811406B0149 for ; Wed, 21 Aug 2024 13:28:53 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id D8BAFA0F71 for ; Wed, 21 Aug 2024 17:28:52 +0000 (UTC) X-FDA: 82476937704.12.8C83DA6 Received: from mail-vk1-f179.google.com (mail-vk1-f179.google.com [209.85.221.179]) by imf05.hostedemail.com (Postfix) with ESMTP id 120FC100013 for ; Wed, 21 Aug 2024 17:28:50 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=QA8kmrqV; spf=pass (imf05.hostedemail.com: domain of pedro.falcato@gmail.com designates 209.85.221.179 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=1724261268; 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=TJUfXZNp1ibF0u5btatjwqh4T7on3PeFlzU17jC4Trs=; b=iEXalTst4gcPlc/LLYWXGh4pmLQQb34UnQYfpBmuAern1BVJ+Yk30G39roYVksArEYy6QJ po5KmkaJfqfPSokWuirzBN5OPK/toPu1/54I0/JNgm9RIjaS9SAFG67LbYIAtBKt0lvgRy BX34Kd7vv1cFM0hO5TQG7+l4cnLvuaQ= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=QA8kmrqV; spf=pass (imf05.hostedemail.com: domain of pedro.falcato@gmail.com designates 209.85.221.179 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=1724261268; a=rsa-sha256; cv=none; b=J6HWGWgSTDXS7c0mPKTfKV8rVAVGArgriClug0g+mNoYW1YnVIcnIR1PCTtKgrzcbXstX1 0cWcrpvh4jxT+D9G8iPvzEvlfiGdtW1bnhnFJvghCfe6EYRJYUw3VLgsaVfUj/o+8tv/n+ HGERaXRkEax2e1+cdUAXNSMrBCa8KYw= Received: by mail-vk1-f179.google.com with SMTP id 71dfb90a1353d-4fcf9102c8bso273001e0c.2 for ; Wed, 21 Aug 2024 10:28:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724261330; x=1724866130; 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=TJUfXZNp1ibF0u5btatjwqh4T7on3PeFlzU17jC4Trs=; b=QA8kmrqVSy9jVVtt7Pa0SAoRBBZzPbmQUblRFC4MwNRa/CuNzm1p5QDJDQcAzVPGkw livLrCOGORRw2FRDXkkpOPqouiATirlT+QenKXDfwQG/mwWSomHfAr39bUMLInzYgV1k 36KFrefrON9Kb2HuaOn2HurVR+x2KDioJLRlkHVdcfNFJ/3jl0P/fHlm5Cgprrx5+aQM syb5TZQTC7O2MwFNnRsKSOug8x6VMgwWoIU0Flu56tYivFxAeAoBDLXZH5JzYMhoStrk 3xOV1a2RDeOZpLjkoJRV6MVEVLTPk4yxYwB+9s1oyzAdTHOmrGVxmRY1941id4YbdKS2 Zrpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724261330; x=1724866130; 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=TJUfXZNp1ibF0u5btatjwqh4T7on3PeFlzU17jC4Trs=; b=QZWsLGuBfYWJiircKody08dDvzcr8iqcFNtR9hZ+q46cBVMkPKkeU/xWTn/uXMyBiD 32yHaez4SItJb0NlPbFUsxzCR1V3241tmUHWvPTq7MiheLAPxIepAvqlUV63m/Qw9A9U AN3VrloBG2cf5FrIjp44bWg9npJr+pDwYxJV93WQWPgGiCDvP4HB3iDdNFyuyqdmYu2V rD5lvIniRDOH1+ZA8Iv7yelvuNxCyEFGbUMA+pMdlXH4E93ibDNPSeBHGgv96uU63QCF +7X9irAeswwjQCw8XIc9+gTFM1tEdfcuVoDDTs22xSBI5Nzaah0I9HcZNboKJZUB5LEW EZrA== X-Forwarded-Encrypted: i=1; AJvYcCU/iD5x17OPUXHXqMND+9Ze4+bGz5h7DmixwQNw+5TjEoGZs8m+IKASHMQh/cXa53vo7Q4yDqL9wQ==@kvack.org X-Gm-Message-State: AOJu0YycwvtvZBqtTnvXTqdEJpo0z7GM7Et6Ti3UHqB0fkX++6ogtsyh MwSeKRX/cOw/i/7BNpN4rXCKEtd0/TelOKwopAgAglzFAOV9LrZITyzN/tbrUekJoGtGcZstjZ7 NYIln60+PHrz7te7qFQiCtQMXcCA= X-Google-Smtp-Source: AGHT+IGyAeC7+IBJ6/fu09d9M/b2IU20lDn/RAHi2m82VXURQN4bEA0s+Lc6bSExM1DhEAEm43xMBpByuyIwQ6yjZb4= X-Received: by 2002:a05:6122:35c4:b0:4f2:a973:8ae with SMTP id 71dfb90a1353d-4fcf1b53051mr3654908e0c.5.1724261329747; Wed, 21 Aug 2024 10:28:49 -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 18:28:38 +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: 45hn753crh159frohu8afdaxk9m1gqsr X-Rspam-User: X-Rspamd-Queue-Id: 120FC100013 X-Rspamd-Server: rspam02 X-HE-Tag: 1724261330-440932 X-HE-Meta: U2FsdGVkX1+h4LqZhnnidz0I11RGxw4RT+jufuwhBLBDpl6E0CDZPkLgdo5O/Q39jWhvBC1bP8YjVNJmCJLl/xiUjtGjA+hG1CSAT8v3k7GgqK3npxq5Vj/ikB07OXl38a7m4kqGMn/0D/3brPX2ec5RWMsoXc1t9up/I96UZTjYgucsgQXl0Vnk8mXHPfjYZBBLn9+kntD7sdmddaXJodRHvAqqY2XsH/4zjf05Tbjauw7SwvBj1fSxo41GkcXVh+HWQsVHeCGEKPVISg+e1P/KblqhIq2TufZERThrhn+tux/dNdb95mLKRN43QJCSEqouvtIrNLrhp/cm/pwhvyBLFHn5a61f6f5G38+5b1vmcKRTDk0U3Yuwlz2YTFLoqUirwV+VIxMZos+MeHDah6CgUkY/cVxpI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ests=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 5:27=E2=80=AFPM Jeff Xu wrote= : > > On Wed, Aug 21, 2024 at 9:20=E2=80=AFAM Pedro Falcato wrote: > > > > On Wed, Aug 21, 2024 at 4:56=E2=80=AFPM Jeff Xu w= rote: > > > > > > 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 wh= ere 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/testin= g/selftests/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_mprotec= t(bool 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) work= s correctly. > > > > + * It might mprotect the first, but it'll never touch the s= econd (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 luc= k. > > 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, &p= rot) > 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(boo= l seal) > > > > 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) work= s correctly. > > > > + * It might unmap the first, but it'll never unmap the seco= nd (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, &p= rot) > 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. > > > ok. Then this test should be as below ? (need to add PROT_NONE page > before and after) > size =3D get_vma_size(ptr, &prot); > FAIL_TEST_IF_FALSE(size =3D=3D 2 * page_size); > FAIL_TEST_IF_FALSE(prot=3D=3D0x4) That doesn't work because this region spans two vmas. I'll write something similar for the fixup. > > > > > > > > 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. > > > Which thread/patch by Andrew ? Could you please send it to me ? (I > might missed that) This thread and this patch: https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patche= s/selftests-mm-add-more-mseal-traversal-tests-fix.patch --=20 Pedro