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 25DB2C3DA4A for ; Fri, 16 Aug 2024 17:07:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B03FC8D007E; Fri, 16 Aug 2024 13:07:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AB3586B0125; Fri, 16 Aug 2024 13:07:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 92CD18D007E; Fri, 16 Aug 2024 13:07:29 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 797C46B00E6 for ; Fri, 16 Aug 2024 13:07:29 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 3C40840173 for ; Fri, 16 Aug 2024 17:07:29 +0000 (UTC) X-FDA: 82458739818.23.8A7DD6F Received: from mail-oa1-f41.google.com (mail-oa1-f41.google.com [209.85.160.41]) by imf21.hostedemail.com (Postfix) with ESMTP id 2F7CB1C0021 for ; Fri, 16 Aug 2024 17:07:25 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b="GAFc+tm/"; spf=pass (imf21.hostedemail.com: domain of jeffxu@chromium.org designates 209.85.160.41 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=1723827972; 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=w/TbnC7SDugjkAEdThzf4HRCowQ6gi7ofcD1sIuLidM=; b=gvBmwB4I2FoNqZO2PPAqLgdJC93PI0yFn58Y+GAGMc030EpQQqDcjmAawtE7oQNGeLmNF3 gDUEuXRRSW4sFF/iN0KdTkJftYU4MW/NQnjP1lYps1XASXouqsAQMA1yz13bFhWlHEe1QK aV6IZD35R+QKIQpWzkYxLTn/QJnNxPM= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1723827972; a=rsa-sha256; cv=none; b=AzEcJxJtYPMC/VxKDByFcvTqadWoz7sSOzUX6Eft+CQHnhskwBDS0Y9kAv7wzV+qvNVaIr EEI3iG0uSoRRN5aIaynIR69Posx3bL6ydZPAjrYMU+3j11+3MAo3F6Wua25bWaQ3HI5IIW vxxtXrHQoSVfrayF0ZWSitGq9Xw9Gks= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b="GAFc+tm/"; spf=pass (imf21.hostedemail.com: domain of jeffxu@chromium.org designates 209.85.160.41 as permitted sender) smtp.mailfrom=jeffxu@chromium.org; dmarc=pass (policy=none) header.from=chromium.org Received: by mail-oa1-f41.google.com with SMTP id 586e51a60fabf-2700d796019so1004773fac.2 for ; Fri, 16 Aug 2024 10:07:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1723828045; x=1724432845; 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=w/TbnC7SDugjkAEdThzf4HRCowQ6gi7ofcD1sIuLidM=; b=GAFc+tm/4AskOvMnhMiYRohmMV9dTMcEUF4W5QG/sg/5zeb9sJopBWUSF4mAnhCXdT muKLV+99HB+Y0lp1N0nTcJo+r+ArqgVzA1ogzlmkcNSrcgvDYCS1VNMPPtPltdc1DBLe 626a4dL2rz9Gvj/s4JVhiVzLCyIvauUG5la6o= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723828045; x=1724432845; 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=w/TbnC7SDugjkAEdThzf4HRCowQ6gi7ofcD1sIuLidM=; b=masZjks8Dzu3ziwDhqpABSEJSmbKx12cNtldy8afEXdBjEtFRJz/Etcu63WZGLzaeT nZNjbAQFL5UgPFSm7PQ6V5GKVe+K7aumA/RbD7whdtnlNj/7vZHaTOsBaJ1x66+P98y3 huXD8RLS22g6bZZlEAuxRns5VJTDdQp90Kktg4Nt1+oIP5M8xLAc6Wbh1GEQNnDwyQzL bsh1qSXv8WRc3ghl1aTNoUiJTZpYWXxFX6O3zr25ObKmcbcKod3G7+X8fBFJgNryhAg+ 0SAHEiVzrTsJI6ObQmf4QTr1LpaWf5o3Ed5Hwjhc2OlxggpLbz0bU6ZnJyQvcVx538Kh rmZg== X-Forwarded-Encrypted: i=1; AJvYcCVYeoCc6cMrRhM5FjmFTfBhl9MIRFpKeQ5scLPCCmsjkKrxOeFdWXymV1/3JZs4FVSMP6g/anUqPSOSaxoBjk60EYo= X-Gm-Message-State: AOJu0Yx61B+l0cBTlym3LxwH3RrGOic7un+WtSpx26/4BxfEVRrpzStT ydLJwkERS52qMUWcp/SX1Dw4KU/I3G0zfrifD1xFUMxwLqAmUYwuND6hMeJPy8zRXJxSxj68Qpt qQntwwsvuHaxk1/Lk9hXsxXGgIS2kv1qcnVGM X-Google-Smtp-Source: AGHT+IGn2rF9eff35N4MIjswWFYWfxqOZA2OskqRvJPd4hifLbnwIUjs8vvvZEV8UAYhKGuOWprvlQZbMLz2YSLnemc= X-Received: by 2002:a05:6870:524f:b0:250:756b:b1ed with SMTP id 586e51a60fabf-2701c394beamr4195068fac.19.1723828044686; Fri, 16 Aug 2024 10:07:24 -0700 (PDT) MIME-Version: 1.0 References: <20240807211309.2729719-1-pedro.falcato@gmail.com> <20240808161226.b853642c0ecf530b5cef2ecc@linux-foundation.org> In-Reply-To: From: Jeff Xu Date: Fri, 16 Aug 2024 10:07:12 -0700 Message-ID: Subject: Re: [PATCH v2 0/6] mm: Optimize mseal checks To: Pedro Falcato Cc: Jeff Xu , Andrew Morton , "Liam R. Howlett" , Vlastimil Babka , Lorenzo Stoakes , linux-mm@kvack.org, linux-kernel@vger.kernel.org, oliver.sang@intel.com, torvalds@linux-foundation.org, Michael Ellerman Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 2F7CB1C0021 X-Stat-Signature: ytsytwqjqnrmcn5dagdf99dyy3ihh5fy X-HE-Tag: 1723828045-974753 X-HE-Meta: U2FsdGVkX19l/Z0ZuuaabSWNLbXyBsuoUAIOSFj0uCmsnCaGdc7PLBI4/08AzcO1MC9dXzW5Sx4haAZawYZLaXod5ywU7RW7wKyPfTbPk8UCV9RmgCmqjBi+fMDTU+3NhROry/w6FtW2bPLWumffaY+Ul5t2+WBM5LSZYmK3jVKE72jFWzKnp5D8fU18DDmFtRVOmhA4ao4KPzn7pztl+4IbudzTDoK0yZhLv+/ALYYetlnHVec9FnXhSmGHLgb7YGDqhHQrlRLwfyhskXpqd/XBtDNOR1uOsMIt0QlieaKZthMe1oWd/CUvIkKvmP0CkEWP2KlgqWQ0okCD4/lonbzMGCa8TK+sSETf++/6CXTjtxxALYoy8CGUsyVTJU2wh7Z12ZTA29+KZg/jq6M+nchfRdZUcPEHI5PJh3fbOmfwQIYJwS8RcZHRZE/OGnNGxeokZ7vnGoox/A6jHxLnIDPv4CteRaWFYKH2/AHAMKyCwn+CzgI+NOYN5V392Mt3epdvL6YOuLdRJku5fNU7H18xJnMiueyHYbnIm+EnQhlAIfBaffl4+V+5SmcFVqPo5is0x48pFfO0kqmYyUC9vPfunGk3/gc2E620ZnsvH8g5Z2r+B7az5f5wxdBsGR8Fy63E44it2vKBV7OLzC3tELMErPeyBk9JRdjACkZ4QEJ6LUQVUXkLwfRB5Yzng11L1noGEOU+32z2MrGzjEX8Iy1fQfwgeIt6oUjtsm/kZfrNIPSaWOidEk05CsdkhgX5m0g5H+58XoLPjDQsJfwc3TrlMUUOoR/KmmC715QIZ0IW83qmNj2fzlhGA2wWdZUeaI50A20fTgfcupfNhthFvD4eiO0Rq7SgGHXoeYzdSflVfhyp3jpqCZr0qiEa6TLhmhv/ZJwNiRVEtC8lQujAqNsJWsB2zkYjS3fdn0oS/arScJQZx6D6NKF4oxRRdIC1gXgdH8ZZ7CwsoQrflu6 YarPTJ0c 8NJH8E43kIU9C82uNHAHeuYE4UrkzN3uLHzHtK2Kmkaj7j4IYNmSYG+TpihD0o5SSYDHqAPo0AOvjsBSfQ92K+JWWSDb60eMVYbpkOP1DCGxuMGmOf1O1BzVr/hfxP8t17O2yQDy0GI4azq3zmUV/M3dREp8iuzBbQAa8LfczYM79/qlxlavakwdjvMO2rRywh++nGOZzDW2MAkd3T8w7TKrSF3Zvn7VG3bC3ulHmrv7Kfs0p8UXv1SWmxY/Gove1Gr7jFCB8vUScPt28Rf7BrKJhoQ+sGoDO3OlPqmP5gW3unfLIxa//YutuROPpJ86uIQ5bY7cvjh8HYbC2x+TNAZV7M8lPg7l3HKrAfws6Hw5SV+0yju7OF2wha07P54nrCPW/UFBF5cAAdprjH1EBp62fq9tXnpHB2DB0VSUrGGhrboxubzFmgZO0tt4gj+Bj3gsHr+5qOTmsp7Y+rzdemain6pxt1+YF57wUPeECAUqshisdfJb1fLUndx7dC6j0tB6agJPRLlDD1jY= 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: Hi Pedro On Thu, Aug 15, 2024 at 6:58=E2=80=AFPM Pedro Falcato wrote: > > On Thu, Aug 15, 2024 at 11:10=E2=80=AFPM Jeff Xu wr= ote: > > > > Hi Andrew, Pedro > > > > On Thu, Aug 8, 2024 at 6:03=E2=80=AFPM Jeff Xu wrot= e: > > > > > > On Thu, Aug 8, 2024 at 5:34=E2=80=AFPM Pedro Falcato wrote: > > > > > > > > On Fri, Aug 9, 2024 at 12:12=E2=80=AFAM Andrew Morton wrote: > > > > > > > > > > On Wed, 7 Aug 2024 22:13:03 +0100 Pedro Falcato wrote: > > > > > > > > > > > This series also depends on (and will eventually very slightly = conflict with) > > > > > > the powerpc series that removes arch_unmap[2]. > > > > > > > > > > That's awkward. Please describe the dependency? > > > > > > > > One of the transformations done in this patch series (patch 2) assu= mes > > > > that arch_unmap either doesn't exist or does nothing. > > > > PPC is the only architecture with an arch_unmap implementation, and > > > > through the series I linked they're going to make it work via > > > > ->close(). > > > > > > > > What's the easiest way to deal with this? Can the PPC series go > > > > through the mm tree? > > > > > > > This patch can't be merged until arch_unmap() is all removed (ppc cha= nge) > > > > > > Also I'm still doing a test/reviewing for this patch, perhaps it is > > > better to wait till my test is done. > > > > > Sorry that I'm late for updating this thread. > > > > With removing arch_unmap() change landed , there is no dependency for > > the patch. However: I have other comments: > > > > 1. Testing > > Testing is 90% of work when I modify kernel code and send a patch. So > > I'm a little disappointed that this patch doesn't have any test > > updates or add new tests. Which makes me less confident about the > > regression risk on mseal itself, i.e. a sealed mapping being > > overwritten by mprotect/mmap/mremap/munmap. I have posted the comment > > in [1], and I would like to repeat it to stress my point. > > > > The V2 series doesn't have selftest change which indicates lack of > > testing. The out-of-loop check is positioned nearer to the API entry > > point and separated from internal business logic, thereby minimizing > > the testing requirements. However, as we move the sealing check > > further inward and intertwine it with business logic, greater test > > coverage becomes necessary to ensure the correctness of sealing > > is preserved. > > Sorry, cut the crap. Your backhanded concerns are very funny. > mseal was _your_ feature. You wrote the tests. You either didn't write > or didn't understand what kinds of tests need/should be done, > otherwise you would've done them. I wrote some code to fix the awful > performance hit. It is a _fix_, not a feature. Your previous mseal > tests should've covered this. If they didn't, that's okay (we all make > mistakes), but pushing your problems onto me is seriously laughable. > I posted the comments about the lack of a test update in V2 last monday, there is no response from you until Thursday night (which is OK). If you were expecting me to update the test cases and to support your patch series, you should explicitly call it out. So your point here is that you wrote the code, passed the existing selftest, fixed the perf, and the job is done. If the test doesn't cover the new cases you added, it is not your problem, you only need to care about perf part. This is how regression happened in past, e.g. commit 77795f900e2a07c1cbedc375789aefb43843b6c2 Author: Liam R. Howlett Date: Tue Jun 6 14:29:12 2023 -0400 mm/mprotect: fix do_mprotect_pkey() limit check The return of do_mprotect_pkey() can still be incorrectly returned as success if there is a gap that spans to or beyond the end address passe= d in. Update the check to ensure that the end address has indeed been se= en. Link: https://lore.kernel.org/all/CABi2SkXjN+5iFoBhxk71t3cmunTk-s=3DrB4= T7qo0UQRh17s49PQ@mail.gmail.com/ Link: https://lkml.kernel.org/r/20230606182912.586576-1-Liam.Howlett@or= acle.com Fixes: 82f951340f25 ("mm/mprotect: fix do_mprotect_pkey() return on err= or") Signed-off-by: Liam R. Howlett Reported-by: Jeff Xu Reviewed-by: Lorenzo Stoakes Acked-by: David Hildenbrand Acked-by: Vlastimil Babka Cc: Signed-off-by: Andrew Morton Had not I wrote selftest to discover this mprotect regression, it would go unnoticed and stay that way. My point is: the existing selftest for mseal is written for out-loop, and will not fully test in-loop. Your patch has made a big change to mseal, more tests are needed. To move forward from this situation for your patch series, either you or me will need to update the tests. How about sharing the load ? > I seriously have no words. > I want to stress I have no way to test real software that uses mseal > because APPARENTLY THERE IS NONE. THE FEATURE ADDED EXPLICITLY FOR > CHROMIUM IS NOT USED BY UPSTREAM CHROMIUM. > The testing is about making sure that sealing is preserved after mmap/mremap/munmap/mprotect call, there is no real software that will do that kind of testing, even in the future, selftest is the only way. Security features never come quickly, adding syscall to the kernel is the first step to allow apps to use it. > > > > 2 perf testing > > stress-ng is not stable in my test with Chromebook, and I'm requesting > > Oliver to take more samples [2] . This due diligence assures that > > this patch accurately fulfills its purpose. The in-loop approach adds > > complexity to the code, i.e. future dev is harder to understand the > > sealing logic. Additionally, it sacrifices a security feature that > > makes it harder for an attacker to modify mapping (currently if an > > attacker uses munmap with a large address range, if one of the > > addresses is sealed, the entire range is not modified. In the in-loop > > approach, memory will be unmapped till it hits the sealed memory). > > Wrong. munmap is atomic and always has been. It's required by POSIX. > Please run this test on the latest kernel branch to verify: static void test_munmap_free_multiple_ranges(bool seal) { void *ptr; unsigned long page_size =3D getpagesize(); unsigned long size =3D 8 * page_size; int ret; int prot; setup_single_address(size, &ptr); FAIL_TEST_IF_FALSE(ptr !=3D (void *)-1); /* unmap one page from beginning. */ ret =3D sys_munmap(ptr, page_size); FAIL_TEST_IF_FALSE(!ret); /* unmap one page from middle. */ ret =3D sys_munmap(ptr + 4 * page_size, page_size); FAIL_TEST_IF_FALSE(!ret); /* seal the last page */ if (seal) { ret =3D sys_mseal(ptr + 7 * page_size, page_size); FAIL_TEST_IF_FALSE(!ret); } /* munmap all 8 pages from beginning */ ret =3D sys_munmap(ptr, 8 * page_size); if (seal) { FAIL_TEST_IF_FALSE(ret < 0); /* verify none of existing pages in the range are unmapped= */ size =3D get_vma_size(ptr + page_size, &prot); FAIL_TEST_IF_FALSE(size =3D=3D 3 * page_size); FAIL_TEST_IF_FALSE(prot =3D=3D 4); size =3D get_vma_size(ptr + 5 * page_size, &prot); FAIL_TEST_IF_FALSE(size =3D=3D 2 * page_size); FAIL_TEST_IF_FALSE(prot =3D=3D 4); size =3D get_vma_size(ptr + 7 * page_size, &prot); FAIL_TEST_IF_FALSE(size =3D=3D 1 * page_size); FAIL_TEST_IF_FALSE(prot =3D=3D 4); } else { FAIL_TEST_IF_FALSE(!ret); /* verify all pages are unmapped */ for (int i =3D 0; i < 8; i++) { size =3D get_vma_size(ptr, &prot); FAIL_TEST_IF_FALSE(size =3D=3D 0); } } REPORT_TEST_PASS(); } test_munmap_free_multiple_ranges(true) test_munmap_free_multiple_ranges(false) > I would also ask you to back these partial mprotect (assuming that's > what you meant) concerns with a real attack that takes this into > account, instead of hand waving "security". > While noting that all of these operations can already partially fail, > this is not new (and is explicitly permitted by POSIX for > syscalls-not-named-munmap). > As defence gets stronger, with seccomp,selinux,landlock, attackers now have to find an easier route. > > Therefore, I would like to ascertain the gain. > > The gain is real. I've proven it with will-it-scale, Oliver ran his > tests and found the regression to be gone (and they do seem to do > proper statistical analysis). > I would wager you to find a workload or hardware where *doing > substantially less work* makes for slower code. > > > > > 3 mremap refactor work. > > mremap refactoring is not related to these mmap regressions. In the v3 > I'm cleaning up and sending out tomorrow, I minimally change mremap > (as Liam wanted). > If the test issue is not resolved, V3 will be in the same situation as V2. Best Regards, -Jeff > -- > Pedro