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 74A7CD374BF for ; Thu, 17 Oct 2024 16:20:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E17BD6B0083; Thu, 17 Oct 2024 12:20:35 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DC7D76B0085; Thu, 17 Oct 2024 12:20:35 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C682C6B0088; Thu, 17 Oct 2024 12:20:35 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id A72796B0083 for ; Thu, 17 Oct 2024 12:20:35 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id C3113A14FF for ; Thu, 17 Oct 2024 16:20:14 +0000 (UTC) X-FDA: 82683606936.21.DFFA01C Received: from mail-oa1-f46.google.com (mail-oa1-f46.google.com [209.85.160.46]) by imf12.hostedemail.com (Postfix) with ESMTP id 8715040018 for ; Thu, 17 Oct 2024 16:20:28 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b="MW9/86C4"; spf=pass (imf12.hostedemail.com: domain of jeffxu@chromium.org designates 209.85.160.46 as permitted sender) smtp.mailfrom=jeffxu@chromium.org; dmarc=pass (policy=none) header.from=chromium.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1729181887; 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=QymMmt19qYyptlPRJSRQk64je7D5NwoBdyyf/N0dpQM=; b=j0r1fQ91nRf+kQRmXXfLraSnzJyZaAGoFQ74ZCkJn4MCuTsfcueFTzJu7O/y3CrDHMVKPC ArV8iCwjXSz2I4xvNlEBd0teu6ZjA9VdKtjmw3f3A+iU9HjsPBWKUVWx8U+hdw2oVYmdfW /qxr3l8N7dWhVtTxaK+qHqXlhzJyWGM= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1729181887; a=rsa-sha256; cv=none; b=zY94ARa1rL7d91U1n2fMrE2iqExQQ0zzPUFPU/OUx6yxG6DAxXPW7MEqGymU0bS6gHkLch 5exaEFUCmcwmB1gfTX+71IEAPzKO6z+pxeYkL1mAqhnvosGe55bEsdyKKlZXfreg3FsJpZ r+JqGz8E33H6gs6BsKCSzfnpRztQiuI= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b="MW9/86C4"; spf=pass (imf12.hostedemail.com: domain of jeffxu@chromium.org designates 209.85.160.46 as permitted sender) smtp.mailfrom=jeffxu@chromium.org; dmarc=pass (policy=none) header.from=chromium.org Received: by mail-oa1-f46.google.com with SMTP id 586e51a60fabf-28893cc3acdso165281fac.2 for ; Thu, 17 Oct 2024 09:20:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1729182032; x=1729786832; 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=QymMmt19qYyptlPRJSRQk64je7D5NwoBdyyf/N0dpQM=; b=MW9/86C40d+rww4jsiRX1vbIYz/7O+OOLq7v7WTYt+Ft3dg3IFdj4LheH6hxkI0+Qv 5eXgRPjCQLMrrbSmAtqZ9I1KE90pqEn8ybgFvGVZ5Wo49ciyRwwRMGv0nfwfL0NjMczT mIGpkUTnVoSiw53CnRXarqnESAogege+Ank5M= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729182032; x=1729786832; 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=QymMmt19qYyptlPRJSRQk64je7D5NwoBdyyf/N0dpQM=; b=TRZQ+1pd9ORjsvv8XPcj4eijidZUnpxEul/VWN7+ry0RQ4AlTGsc5FlO0XLUrjJWQX GlCHcw8dLWS0VUMMk7IYAmP98+lUUwnURAiHCkMbQaI4SUDyAw4pSm0mOu/Qc40EeyiV XlnvTkzp0zYg6qmAxxg6c70dpx88lIHX15Ma3vMv7OvkeVaLTsCoqCCGA7A/G6NwZHIi FIoWubn2PLjZl8o5yBT0TWIvEjKGNnRbmv5kowJ4Wa+G2PIyAiR7jC+wS/bDXAW/cVTY A1TSjiFT+Kjc5TUnR0aUMqO9dMU3ZsZXo4Ih8Vevxx6dEuDm5o3+ADRJk7gSnAPqOj+J RrvQ== X-Forwarded-Encrypted: i=1; AJvYcCWGqddKEk5ylKgOtJ+HK1LSab7i8rWChb4DEAH2bTQalBti5CmBy78Cd5r7u9XzvgRU4KVOi2UvpA==@kvack.org X-Gm-Message-State: AOJu0Yw+NUhvN3mNL0Bd1gyg/SqUW7fGkrcXk9BhL5ooAcC2xjC/oUjs ngu3xwU9WyN/krlh+39ad7P352A6kGWJe//i8rAnemv/TIwGIZW/7hqKA+bdl9cgNVVsgOa1/9L ABFJzu0heUg2aBl/1ZJXU2POa3Q4Pncc2frlw X-Google-Smtp-Source: AGHT+IEAm4HkCe9fIJHtz5qGXaYcmz/2XucghwW7VoOOeqPX9ksuhDwSqQ6czP4kSZBu+AN3pwdMvWnVobwSCyu8uSM= X-Received: by 2002:a05:6870:2101:b0:26f:d381:fd31 with SMTP id 586e51a60fabf-2890c62049fmr974665fac.1.1729182032028; Thu, 17 Oct 2024 09:20:32 -0700 (PDT) MIME-Version: 1.0 References: <20241017022627.3112811-1-jeffxu@chromium.org> <3a1bbbdf-1281-4f44-857d-58cba583e3da@lucifer.local> In-Reply-To: <3a1bbbdf-1281-4f44-857d-58cba583e3da@lucifer.local> From: Jeff Xu Date: Thu, 17 Oct 2024 09:20:20 -0700 Message-ID: Subject: Re: [PATCH] munmap sealed memory cause memory to split (bug) To: Lorenzo Stoakes Cc: akpm@linux-foundation.org, keescook@chromium.org, torvalds@linux-foundation.org, usama.anjum@collabora.com, corbet@lwn.net, Liam.Howlett@oracle.com, jeffxu@google.com, jorgelo@chromium.org, groeck@chromium.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org, jannh@google.com, sroettger@google.com, pedro.falcato@gmail.com, linux-hardening@vger.kernel.org, willy@infradead.org, gregkh@linuxfoundation.org, deraadt@openbsd.org, surenb@google.com, merimus@google.com, rdunlap@infradead.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 8715040018 X-Stat-Signature: yk4qzugqkwiwnq1qwxxdfk8e5wfej3g9 X-HE-Tag: 1729182028-184485 X-HE-Meta: U2FsdGVkX1+t9N0ph4E7a14GnCh+QDTOhReV34rvuXxXJ+dC8iZb04lOB8YbMB3MBV7D5JDxf5a8BL38RNjB77dhhOCz02qSp35Lqt+/J1M/hhcCCxWr4HuJ2G8yxtfXEUnEvIw29n6Dog0SlyXw6uqaPMtywO/5qt65vYrhVI94NY4DajYKwUbtVCtl3rbR3tA9pThNKxBWo7Z1VOf7mRneYrbaOQVAe4aSNA8MLvq7NgvGathP9Lt/p6e1ryY0vj3hNXlK4KcJTE29QSHI01O+RYcQXi8xW6+QoRpdRbg2YfmdMeb/gM+9mlGpPEYekXzkjzTmPjed9Nw7PYH/lOYDA3sq+7x1PZ7GCtn+Aogmw+6i2kNzfy10ZosDn8PdJTBFVDDbRbG/g3DPiBiVGkouV4coJgD9L470FdxFQNJQx4GAbukz267WzsPXMQDUu68mWM9e0iIZsLhTwFnEdEAX6R3e2ghtIM0a3wKfuQ8Jt3lJKUj7swM1KG2HR9APXWUTHss+4WbGUwlARAAC5snGIPpQXsuDNPzyBV0Z+RClwaLsjPruKSD/eUl5Hy4b1M6nWgI31tEFKE5dBFoLfQnWVyg5jizqYZhCfa/PwE87G6DkPas/nB+fGTe4StBc7h7H+GPRf6S9x0n5bSWrlat/VAm5BL/dbVlGEyenKvF/nEEKpJHJcRyBBm4YOY/KB2xLjMFnbdYt8tXEqa/SmsJ3pIooLRG34AQqLMS3UJ+df1mG5C8t1K9OBtDGJ+JxJnxuzRVHspiicRA55X8+I8tc9yZFfZoiRISClUCsbaMTBm0rOj0yHTto03JRUZjFRfDiK2VWTYg4BhZRaY8xHWkv5Uvz6Sw9Wu6eCg3tIPlcX6oZRluwsgVlahcBFZ1WZwDWvwylPE2+yhYICBiguI2W+6zfO/sTAsNByqNg07lQN2o5uCEv5Kys30BoiWl/WcF17by2cXBqwh+S17w 8Dj0O0PY YO9nJE0ys7nr5KtS1VkihClV5tJyffmm/n1v74SVj84hIRiivx21WWDz9jSULJtq45d0SV7F+/Oo3uj3MR8XQ6p375g6UDywfTSFZHblLYZzsvIA7JoQJl5QtTcWAA49rL0oTwHRDtaP0wSOIGcEDvMM89zITLMZi+1eFRTXLBrDjmb8adMZlPWzUsSsblF9zGvJUJ7vLlzQbtNbckwr/BQIL0oz6M7yipMm5TDAiXCaUq4C/yWQI4wEgrpv0Gl4rG0a0seoUmwI/8ovXFDNq0d4/ZF85N9mKGWvj1KNlahCRCn+wnkMIAmTbb4bXkwwX04rBSh6hVUOv5vAXsz53F9+2lA== 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 Thu, Oct 17, 2024 at 1:18=E2=80=AFAM Lorenzo Stoakes wrote: > > NACK. Greg's bot got to it but... > > As per Greg's bot, no signed-off-by line. > Sorry for confusion, I wasn't meant to send this as a PATCH, but reporting the issue. The diff was just sent as reference to repro the bug, and I forgot to remove PATCH from the title. I apologize for the confusion. -Jeff > The subject should be something about adding a test. > > You later say you are somehow dependning on things (what?) to make this w= ork but > it's broken. > > Jeff - you're doing things that were raised on previous reviews as if we > never said them. It's starting to get annoying now. Please try to listen = to > upstream. > > On Thu, Oct 17, 2024 at 02:26:27AM +0000, jeffxu@chromium.org wrote: > > From: Jeff Xu > > > > It appears there is a regression on the latest mm, > > when munmap sealed memory, it can cause unexpected VMA split. > > E.g. repro use this test. > > This is an unacceptably short commit message. You've been told about this > before. > > > --- > > tools/testing/selftests/mm/mseal_test.c | 76 +++++++++++++++++++++++++ > > 1 file changed, 76 insertions(+) > > > > diff --git a/tools/testing/selftests/mm/mseal_test.c b/tools/testing/se= lftests/mm/mseal_test.c > > index fa74dbe4a684..0af33e13b606 100644 > > --- a/tools/testing/selftests/mm/mseal_test.c > > +++ b/tools/testing/selftests/mm/mseal_test.c > > @@ -1969,6 +1969,79 @@ static void test_madvise_filebacked_was_writable= (bool seal) > > REPORT_TEST_PASS(); > > } > > > > +static void test_munmap_free_multiple_ranges_with_split(bool seal) > > +{ > > + void *ptr; > > + unsigned long page_size =3D getpagesize(); > > + unsigned long size =3D 12 * page_size; > > + int ret; > > + int prot; > > + > > + setup_single_address(size, &ptr); > > + FAIL_TEST_IF_FALSE(ptr !=3D (void *)-1); > > I'm not going to accept any test where you do: > > FAIL_TEST_IF_FALSE() > > As that's totally unreadable. I asked you before for justification and yo= u > didn't provide it, no other tests appear to do this, I wrote thousands of > lines of tests recently without doing this - stop it. > > Also referene MAP_FAILED here please. You've been told before. > > > + > > + /* seal the middle 4 page */ > > + if (seal) { > > + ret =3D sys_mseal(ptr + 4 * page_size, 4 * page_size); > > + FAIL_TEST_IF_FALSE(!ret); > > + > > + size =3D get_vma_size(ptr, &prot); > > + FAIL_TEST_IF_FALSE(size =3D=3D 4 * page_size); > > + FAIL_TEST_IF_FALSE(prot =3D=3D 4); > > Again, you've been told before, stop referencing numbers instead of > PROT_... flags. > > OK I'm stopping at this point, you _must listen to review_ Jeff. > > > + > > + size =3D get_vma_size(ptr + 4 * page_size, &prot); > > + FAIL_TEST_IF_FALSE(size =3D=3D 4 * page_size); > > + FAIL_TEST_IF_FALSE(prot =3D=3D 4); > > + > > + size =3D get_vma_size(ptr + 8 * page_size, &prot); > > + FAIL_TEST_IF_FALSE(size =3D=3D 4 * page_size); > > + FAIL_TEST_IF_FALSE(prot =3D=3D 4); > > + } > > + > > + /* munmap 4 pages from the third page */ > > + ret =3D sys_munmap(ptr + 2 * page_size, 4 * page_size); > > + if (seal) { > > + FAIL_TEST_IF_FALSE(ret); > > + FAIL_TEST_IF_FALSE(errno =3D=3D EPERM); > > + > > + size =3D get_vma_size(ptr, &prot); > > + FAIL_TEST_IF_FALSE(size =3D=3D 4 * page_size); > > + FAIL_TEST_IF_FALSE(prot =3D=3D 4); > > + > > + size =3D get_vma_size(ptr + 4 * page_size, &prot); > > + FAIL_TEST_IF_FALSE(size =3D=3D 4 * page_size); > > + FAIL_TEST_IF_FALSE(prot =3D=3D 4); > > + > > + size =3D get_vma_size(ptr + 8 * page_size, &prot); > > + FAIL_TEST_IF_FALSE(size =3D=3D 4 * page_size); > > + FAIL_TEST_IF_FALSE(prot =3D=3D 4); > > + } else > > + FAIL_TEST_IF_FALSE(!ret); > > + > > + /* munmap 4 pages from the sealed page */ > > + ret =3D sys_munmap(ptr + 6 * page_size, 4 * page_size); > > + if (seal) { > > + FAIL_TEST_IF_FALSE(ret); > > + FAIL_TEST_IF_FALSE(errno =3D=3D EPERM); > > + > > + size =3D get_vma_size(ptr + 4 * page_size, &prot); > > + FAIL_TEST_IF_FALSE(size =3D=3D 4 * page_size); > > + FAIL_TEST_IF_FALSE(prot =3D=3D 4); > > + > > + size =3D get_vma_size(ptr + 4 * page_size, &prot); > > + FAIL_TEST_IF_FALSE(size =3D=3D 4 * page_size); > > + FAIL_TEST_IF_FALSE(prot =3D=3D 4); > > + > > + size =3D get_vma_size(ptr + 8 * page_size, &prot); > > + FAIL_TEST_IF_FALSE(size =3D=3D 4 * page_size); > > + FAIL_TEST_IF_FALSE(prot =3D=3D 4); > > + } else > > + FAIL_TEST_IF_FALSE(!ret); > > + > > + REPORT_TEST_PASS(); > > +} > > + > > + > > int main(int argc, char **argv) > > { > > bool test_seal =3D seal_support(); > > @@ -2099,5 +2172,8 @@ int main(int argc, char **argv) > > test_madvise_filebacked_was_writable(false); > > test_madvise_filebacked_was_writable(true); > > > > + test_munmap_free_multiple_ranges_with_split(false); > > + test_munmap_free_multiple_ranges_with_split(true); > > + > > ksft_finished(); > > } > > -- > > 2.47.0.rc1.288.g06298d1525-goog > >