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 58FD4C48286 for ; Fri, 2 Feb 2024 03:15:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7AE326B0071; Thu, 1 Feb 2024 22:15:25 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 735F76B0072; Thu, 1 Feb 2024 22:15:25 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5D6A36B0075; Thu, 1 Feb 2024 22:15:25 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 47D966B0071 for ; Thu, 1 Feb 2024 22:15:25 -0500 (EST) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 18B4040931 for ; Fri, 2 Feb 2024 03:15:25 +0000 (UTC) X-FDA: 81745398210.30.7B2B063 Received: from mail-ed1-f46.google.com (mail-ed1-f46.google.com [209.85.208.46]) by imf23.hostedemail.com (Postfix) with ESMTP id 3FFFD140003 for ; Fri, 2 Feb 2024 03:15:23 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=I4sOrrKG; spf=pass (imf23.hostedemail.com: domain of jeffxu@google.com designates 209.85.208.46 as permitted sender) smtp.mailfrom=jeffxu@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1706843723; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to: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=5tbMa2Y0zXDlCnN04UdSXdSWMrrR/rUx45iZWj/g4cU=; b=g1WFnzdMDXUren98jGPKPZHmnPPx0FLDWW/l4lvjDz16jOqPN/On/NaHsZBkfjJ3HmSNdH 3Qw+95ioyc7omGmx6ysGJT8TBH2ml5G5cycaqAsaQTqvWeJ6B+SxBascNyIrIq0JHjC3Yj 7gqk29bpknvutOK6Ptp+SOXsllqIAUo= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706843723; a=rsa-sha256; cv=none; b=8SyHQ+XNTdcBECAR4H1On10JeiU75PFK8JwjDF9q1IheX9VvIt8g6R8fP/fH4vWOH5ZG4G WN1KCXKtIqYNZyxeamFuWr3mqCUsjUIWKBSAVr8CchwnHzGpkpL9Q30SU0R3eDIP2KHHSr wdggfFOFhybDraE842Uyotn/OLetYzo= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=I4sOrrKG; spf=pass (imf23.hostedemail.com: domain of jeffxu@google.com designates 209.85.208.46 as permitted sender) smtp.mailfrom=jeffxu@google.com; dmarc=pass (policy=reject) header.from=google.com Received: by mail-ed1-f46.google.com with SMTP id 4fb4d7f45d1cf-55f85a2a43fso4186a12.1 for ; Thu, 01 Feb 2024 19:15:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1706843722; x=1707448522; darn=kvack.org; h=content-transfer-encoding:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=5tbMa2Y0zXDlCnN04UdSXdSWMrrR/rUx45iZWj/g4cU=; b=I4sOrrKG5L0LyiVPw2pjuho9sRJ//pLOjqFBSCLivQ4ICRjNxnl3uA+3+fBMnE9iFu VoIRvy2ufDGLKEsuOK1h3UbBejvTCFv8AS26VmQlIo5kxqgljZnPuug5D4yVE/8ZB+ij gaKCugrEz3Xnyx1ZtmelkS0wkPQFuDc0/14Beh309Mvbu+4VxQg12LNrSKLDwm7OqJf8 7h2Q3tuz+aSW0d5GODAW4RHua0hQA6pTQKvD5eTaxrha9QYZjZs6PiXy9GuSP8ws2YIb tChQtoYSjBMnGhCyY20D7H8HcA1WfXRPTYvGktQ6plyOPdRW15oqjDhv4EggALkpn/yN hBAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706843722; x=1707448522; h=content-transfer-encoding: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=5tbMa2Y0zXDlCnN04UdSXdSWMrrR/rUx45iZWj/g4cU=; b=YavjrKLSnTB5ttKPu2hl0kCWnyaMKbjk/rRGg4BAgH8nFRemCBYq2VU5xroajUnryI bHMBX9kx9qBBX8y74KW1bqwT/zFuKeZq2t5aIqusEIPTHSLDR1oCJczmyDlWrnaxjRUk DOMOx6aFEaD/3bzf5f6opPF1Xhg7ut5k6pmJkkM3z1vk6gaXao7cW+4CSG1v7yKLx2k5 2bsMY6G8Fw8F1K45DGGanoEEwxlLyqED+WfCOwU1dXUttddtBMgYu7ZccCKcFYV6xnLH jG+ygx4yytEvcP/3e9PZ3g5Yj4FVEaeSaathE+WMyFAcKnqehErHiiWr4G6Xuz8SL7Cv VzAw== X-Gm-Message-State: AOJu0Yx5eDTaQ7n5d9film3l/x6PxztwwbkiGiBMbSt7u54hOzNDLSBv p0QUuGYJa8wBRbdve2G+Vs/JQ/vD6aUw/g5rmP8KoljFbwHSDcC4tzYOIbh9KgKCqzVYBzP71vn Rxs2HGHb7Y0RHxIqdZv+FhDN26ciD/JJQ+lgJ X-Google-Smtp-Source: AGHT+IHeBmo0iI/CF7yQpc5a3P4jwIWNuulPfEyk+hpP8ZFTKhZLVbX0RzAe8SgBRYbu8IMS8jXp352GwiCcAquWmAo= X-Received: by 2002:a50:d598:0:b0:55f:e704:85ce with SMTP id v24-20020a50d598000000b0055fe70485cemr37702edi.3.1706843721564; Thu, 01 Feb 2024 19:15:21 -0800 (PST) MIME-Version: 1.0 References: <20240131175027.3287009-1-jeffxu@chromium.org> <20240131193411.opisg5yoyxkwoyil@revolver> <20240201204512.ht3e33yj77kkxi4q@revolver> In-Reply-To: <20240201204512.ht3e33yj77kkxi4q@revolver> From: Jeff Xu Date: Thu, 1 Feb 2024 19:14:42 -0800 Message-ID: Subject: Re: [PATCH v8 0/4] Introduce mseal To: "Liam R. Howlett" , Jeff Xu , Jonathan Corbet , akpm@linux-foundation.org, keescook@chromium.org, jannh@google.com, sroettger@google.com, willy@infradead.org, gregkh@linuxfoundation.org, torvalds@linux-foundation.org, usama.anjum@collabora.com, rdunlap@infradead.org, jeffxu@google.com, jorgelo@chromium.org, groeck@chromium.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org, pedro.falcato@gmail.com, dave.hansen@intel.com, linux-hardening@vger.kernel.org, deraadt@openbsd.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Stat-Signature: yzeqejfys8oaa18s1ru1xtxb9dyynrog X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 3FFFD140003 X-Rspam-User: X-HE-Tag: 1706843723-911496 X-HE-Meta: U2FsdGVkX18lKqZW2cGdBvTDQRdfg7p6X3JbAF7Zp1mznLe66CzavitA9DiyYfzX4kS0Jy3H/62vogcXv5XwOfWDp0ngfP+QeD3n3lV+uju9SufuaqglBgpVfzLz2oTU2mKrqBR3R3wUKMpjQAJ2DUqDVz6meedZPn6TkiUw8/cJe7h4/sU8gGeZTh6rOdjm0R65K3b+0tQi2O61cfBY4G4svaKLK0/9Zug5J28idAPvjKhIwWM88B4jb4uEr3YR1XIS9k69XPMPYtyQwY0P3T0aASkv0HRzyy2rQ0cWQyoj7hsHJBxT9vAxbLbyvYpsHaWdOe8+EAORAyolTn7pbj+9K9B4A52GD7DD7MLOzxwSYrM5WbgzgopSU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1od6WvYBTZc= 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, Feb 1, 2024 at 12:45=E2=80=AFPM Liam R. Howlett wrote: > > * Jeff Xu [240131 20:27]: > > On Wed, Jan 31, 2024 at 11:34=E2=80=AFAM Liam R. Howlett > > wrote: > > > > > Having to opt-in to allowing mseal will probably not work well. I'm leaving the opt-in discussion in Linus's thread. > Initial library mappings happen in one huge chunk then it's cut up into > smaller VMAs, at least that's what I see with my maple tree tracing. If > you opt-in, then the entire library will have to opt-in and so the > 'discourage inadvertent sealing' argument is not very strong. > Regarding "The initial library mappings happen in one huge chunk then it is cut up into smaller VMAS", this is not a problem. As example of elf loading (fs/binfmt_elf.c), there is just a few places to pass in what type of memory to be allocated, e.g. MAP_PRIVATE, MAP_FIXED_NOREPLACE, we can add MAP_SEALABLE at those places. If glic does additional splitting on the memory range, by using mprotect(), then the MAP_SEALABLE is automatically applied after splitting. If glic uses mmap(MAP_FIXED), then it should use mmap(MAP_FIXED|MAP_SEALABL= E). > It also makes a somewhat messy tracking of inheritance of the attribute > across splitting, MAP_FIXED replacement, vma_move, vma_copy. I think > most of this is forced on the user? > The inheritance is the same as other VMA flags. > It makes your call less flexible, it means you have to hope that the VMA > origin was blessed before you decide you want to mseal it. > > What if you want to ensure the library mapped by a parent or on launch > is mseal'ed? > > What about the initial relocated VMA (expand/shrink of VMA)? > > Creating something as "non-sealable" is pointless. If you don't want it > sealed, then don't mseal() that region. > > If your use case doesn't need it, then can we please drop the opt-in > behaviour and just have all VMAs treated the same? > > If it does need it, can you explain why? > > The glibc relocation/fixup will then work. glibc could mseal once it is > complete - or an application could bypass glibc support and use the > feature itself. Yes. That is the idea. > > If we proceed to remove the MAP_SEALABLE flag to mmap, then we have the > heap/stack concerns. We can either let people shoot their own feet off > or try to protect them. > > Right now, you seem to be trying to protect them. Keeping with that, I > guess we could either get the kernel to mark those VMAs or tell some > other way? I'd suggest a range, but people do very strange things with > these special VMAs [1]. I don't think you can predict enough crazy > actions to make a difference in trying to protect people. > > There are far fewer VMAs that should not be allowed to be mseal'ed than > should be, and the kernel creates those so it seems logical to only let > the kernel opt-out on those ones. > > I'd rather just let people shoot themselves and return an error. > > I also hope it reduces the complexity of this code while increasing the > flexibility of the feature. As stated before, we remove the dependency > of needing support from the initial loader. > > Merging VMAs > I can see this going Very Bad with brk + mseal. But, again, if someone > decides to mseal these VMAs then they should expect Bad Things to > happen (or maybe they know what they are doing even in some complex > situation?) > > vma_merge() can also expand a VMA. I think this is okay as it checks > for the same flags, so you will allow VMA expansion of two (or three) > vma areas to become one. Is this okay in your model? > > > > > > I mean, you specifically state that this is a 'very specific > > > requirement' in your cover letter. Does this mean even other browser= s > > > have no use for it? > > > > > No, I don=E2=80=99t mean =E2=80=9Cother browsers have no use for it=E2= =80=9D. > > > > About specific requirements from Chrome, that refers to "The lifetime > > of those mappings are not tied to the lifetime of the process, which > > is not the case of libc" as in the cover letter. This addition to the > > cover letter was made in V3, thus, it might be beneficial to provide > > additional context to help answer the question. > > > > This patch series begins with multiple-bit approaches (v1,v2,v3), the > > rationale for this is that I am uncertain if Chrome's specific needs > > are common enough for other use cases. Consequently, I am unable to > > make this decision myself without input from the community. To > > accommodate this, multiple bits are selected initially due to their > > adaptability. > > > > Since V1, after hearing from the community, Chrome has changed its > > design (no longer relying on separating out mprotect), and Linus > > acknowledged the defect of madvise(DONOTNEED) [1]. With those inputs, > > today mseal() has a simple design that: > > - meet Chrome's specific needs. > > How many VMAs will chrome have that are mseal'ed? Is this a common > operation? > > PROT_SEAL seems like an extra flag we could drop. I don't expect we'll > be sealing enough VMAs that a hand full of extra syscalls would make a > difference? > > > - meet Libc's needs. > > What needs of libc are you referring to? I'm looking through the > version changelog and I guess you mean return EPERM? > I meant libc's sealing RO part of the elf binary, those memory's lifetime are associated with the lifetime of the process. > > - Chrome's specific need doesn't interfere with Libc's. > > > > [1] https://lore.kernel.org/all/CAHk-=3DwiVhHmnXviy1xqStLRozC4ziSugTk= =3D1JOc8ORWd2_0h7g@mail.gmail.com/ > > Linus said he'd be happier if we made the change in general. > > > > > > I am very concerned this feature will land and have to be maintained = by > > > the core mm people for the one user it was specifically targeting. > > > > > See above. This feature is not specifically targeting Chrome. > > > > > Can we also get some benchmarking on the impact of this feature? I > > > believe my answer in v7 removed the worst offender, but since there i= s > > > no benchmarking we really are guessing (educated or not, hard data wo= uld > > > help). We still have an extra loop in madvise, mprotect_pkey, mremap= _to > > > (and mreamp syscall?). > > > > > Yes. There is an extra loop in mmap(FIXED), munmap(), > > madvise(DONOTNEED), mremap(), to emulate the VMAs for the given > > address range. I suspect the impact would be low, but having some hard > > data would be good. I will see what I can find to assist the perf > > testing. If you have a specific test suite in mind, I can also try it. > > You should look at mmtests [2]. But since you are adding loops across > VMA ranges, you need to test loops across several ranges of VMAs. That > is, it would be good to see what happens on 1, 3, 6, 12, 24 VMAs, or > some subset of small and large numbers to get an idea of complexity we > are adding. My hope is that the looping will be cache-hot in the maple > tree and have minimum effect. > > In my personal testing, I've seen munmap often do a single VMA, or 3, or > more rare 7 on x86_64. There should be some good starting points in > mmtests for the common operations. > Thanks. Will do. > [1] https://github.com/linux-test-project/ltp/blob/master/testcases/kerne= l/mem/mmapstress/mmapstress03.c > [2] https://github.com/gormanm/mmtests > > Thanks, > Liam