Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp120436rdb; Mon, 22 Jan 2024 14:10:42 -0800 (PST) X-Google-Smtp-Source: AGHT+IGTZeeBeUSDGGGfeeC6hmcVv6ygn/NCpa+DN/3ka5gc2NLT/48nZd+K6PoqfRSUSTx3O8Q6 X-Received: by 2002:a05:6512:4889:b0:50e:7b61:39d3 with SMTP id eq9-20020a056512488900b0050e7b6139d3mr2322134lfb.83.1705961442522; Mon, 22 Jan 2024 14:10:42 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705961442; cv=pass; d=google.com; s=arc-20160816; b=Kk8tPjhmF4GQof59Ta1CZQS4PbAbu37wN1JUlXnJHidGTxMFqXzhPv8CwLgm3HXToZ ev3CX51ynOHmxHj6/5FOIpmirivmxfztuYqniQpTnImKqhr1KlbIxLstNl8aRzhTyCOq Cl/b7GfNyymRsTzJRa0OZDU5Ay7BKB7NNDmC+uyWEfRIXEJEgnEkKCJ4as6w1a0ldBML FhPtifdFMswEzMWzfyTLDCIXgxh90VUSZRmy7mNud+KyaLCWduSzzLt41jk6OtEEJX7n R/ctcry2CT9DUWcouiSHrOYjMZ5MKPw/0s73ySWUN7JydkR78j9NaxtAsF0ITTt1c2Zm Eoyw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=C1De09a1ONpOwX9iKnxbH9ncVw4V2gLmkFQIVKMLMpk=; fh=ALaTS3TIw8IxGGd/Cdagd6StIEOMGnkrnWqRPFFRBgM=; b=I+gRGjTSeeyLLeLG3q+zh2AERwRYd0mujIr9Cxx5ct51h/ZM+mhxxnDOFyaAAJEdtc ua3sIKD+FXbQTRR9dXMI0N29yFAJ42ILGQJKL152PSAjLikeiVvP0GAnLdISj8PbL8zB yFCc+H0uLtQW0NoR1p67SfAmXfa7yTwktAM+TFl4aryzALu5bpl1tWMRrBUseXXuR7PE EfUwD1F2EBlWGmnIkACaLxNYxZIl/KqN1dX1DHaKtXx8cXCO1LWvxIKoPGAxJTvCP2Yk Q6jHVN8UbrTTPOnW9WkFgymajY/w7yx8ZCXjaLCW3OlDemGXQaCX2VNuG6xqeJj43RlB DOGw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=TLsKLlRe; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-34227-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-34227-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id qu18-20020a170907111200b00a2c1061b99asi10651470ejb.332.2024.01.22.14.10.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jan 2024 14:10:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-34227-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=TLsKLlRe; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-34227-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-34227-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 212661F27039 for ; Mon, 22 Jan 2024 22:10:42 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EAD8548791; Mon, 22 Jan 2024 22:10:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="TLsKLlRe" Received: from mail-ot1-f47.google.com (mail-ot1-f47.google.com [209.85.210.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 73ED6482F1 for ; Mon, 22 Jan 2024 22:10:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.47 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705961432; cv=none; b=gfxdrv75wsLBIzkhF4P9oG5PMBMd7/hWQ8WJn9HrSTHGv2FI/1DzolZoS8yjL9XwmBKmtyvE7BiAeLphXUv+AzCCLoEOL+3RW1MdfPm9jnza11JJyaBe6cZ927YV8zx5bzHLdfJuD35e4u+3IqYNQY5SjtBDkMm+LleXEdU/erQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705961432; c=relaxed/simple; bh=MzQ7DHr1+FpuZdH9Hb5BTp+Mv2zN/eGZ0T2pyoGMqW0=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=UVsogyYjthAUtoTVArBFIXfPyIboERxQRx54cg5Fr9fcM46Vbc4thfd42VAQs1TNyZ5JHa96syLM5PjF5a9S/5R0jzbI0JQFJ50kNLslJtXRXWmK89KT/PJy0PVcdvGXPEhKnYWIaORDXeHuD1zVwpCLqV5mDFfrwCDV3xrFO7Y= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=TLsKLlRe; arc=none smtp.client-ip=209.85.210.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Received: by mail-ot1-f47.google.com with SMTP id 46e09a7af769-6e0a64d9449so2370096a34.2 for ; Mon, 22 Jan 2024 14:10:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1705961429; x=1706566229; darn=vger.kernel.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=C1De09a1ONpOwX9iKnxbH9ncVw4V2gLmkFQIVKMLMpk=; b=TLsKLlRenqShOF79JLnkpgQgzRZ/atrdOwMGa9o6fzzWbl5aRipvxhHOMtmbf7mlyT MkFduhJHUHvvj0wJ7QzVnL3QpMnUo4KQ9NLV1MJLQd3p0fYx1YUvpH48VktR6QYAlF5+ OLZ7uGPeVenkSZEYMbpZFf01WlJy8tWmQr8+Y= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705961429; x=1706566229; 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=C1De09a1ONpOwX9iKnxbH9ncVw4V2gLmkFQIVKMLMpk=; b=HB0dM+zUxe5wDlYEgnK3mJW1wEy/DO26vRJpa6ljUQsGhXuAFP5+gPDJBWBD+zDaYT +RdphayzWxNWuK0jTqLbv+cejWeAqdo5IKG8EU4MuXryHbRbj+24+NhizRAhIEKGLq3w xXo2p6zFudcxDVphrXXr2TVYGaKKwA7k8d4iUazmOL2rX5bexyG7g0QZm8pz0jf0lQSk NnzDgrubiQs2aK3ld6x67xmk+SQ9rMj+TnfM1yRDtsnMosxyY6HfI293ijMpuJe1kms+ hKkM40VO7TLDIiSLAuetT0N5qsL4j57+xohs0kkMDsH3vuUgLaxaleqk/ZXevFDYIrTR Ed4g== X-Gm-Message-State: AOJu0YxufeuPpVFoRTli6emuT82TNt+qFuF7dkQEISpAKQYj6+fTts2c umKrRIjPHYPclxwX/LogljSuQ77iWsIcNxW97F4y7g2QNoCWPzmv979yr7bLRNWGqpbS3EWo9HY kwiqok5X1jCB6oFSg3KXloA5CL2r+/1pYQlGa X-Received: by 2002:a05:6870:e40d:b0:214:807e:8a05 with SMTP id n13-20020a056870e40d00b00214807e8a05mr474569oag.2.1705961429485; Mon, 22 Jan 2024 14:10:29 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240122152905.2220849-1-jeffxu@chromium.org> <726.1705938579@cvs.openbsd.org> In-Reply-To: <726.1705938579@cvs.openbsd.org> From: Jeff Xu Date: Mon, 22 Jan 2024 14:10:17 -0800 Message-ID: Subject: Re: [PATCH v7 0/4] Introduce mseal() To: Theo de Raadt Cc: 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Mon, Jan 22, 2024 at 7:49=E2=80=AFAM Theo de Raadt = wrote: > > Regarding these pieces > > > The PROT_SEAL bit in prot field of mmap(). When present, it marks > > the map sealed since creation. > > OpenBSD won't be doing this. I had PROT_IMMUTABLE as a draft. In my > research I found basically zero circumstances when you userland does > that. The most common circumstance is you create a RW mapping, fill it, > and then change to a more restrictve mapping, and lock it. > > There are a few regions in the addressspace that can be locked while RW. > For instance, the stack. But the kernel does that, not userland. I > found regions where the kernel wants to do this to the address space, > but there is no need to export useless functionality to userland. > I have a feeling that most apps that need to use mmap() in their code are likely using RW mappings. Adding sealing to mmap() could stop those mappings from being executable. Of course, those apps would need to change their code. We can't do it for them. Also, I believe adding this to mmap() has no downsides, only performance gain, as Pedro Falcato pointed out in [1]. [1] https://lore.kernel.org/lkml/CAKbZUD2A+=3Dbp_sd+Q0Yif7NJqMu8p__eb4yguq0= agEcmLH8SDQ@mail.gmail.com/ > OpenBSD now uses this for a high percent of the address space. It might > be worth re-reading a description of the split of responsibility regardin= g > who locks different types of memory in a process; > - kernel (the majority, based upon what ELF layout tell us), > - shared library linker (the next majority, dealing with shared > library mappings and left-overs not determinable at kernel time), > - libc (a small minority, mostly regarding forced mutable objects) > - and the applications themselves (only 1 application today) > > https://lwn.net/Articles/915662/ > > > The MAP_SEALABLE bit in the flags field of mmap(). When present, it mar= ks > > the map as sealable. A map created without MAP_SEALABLE will not suppor= t > > sealing, i.e. mseal() will fail. > > We definately won't be doing this. We allow a process to lock any and al= l > it's memory that isn't locked already, even if it means it is shooting > itself in the foot. > > I think you are going to severely hurt the power of this mechanism, > because you won't be able to lock memory that has been allocated by a > different callsite not under your source-code control which lacks the > MAP_SEALABLE flag. (Which is extremely common with the system-parts of > a process, meaning not just libc but kernel allocated objects). > MAP_SEALABLE was an open discussion item called out on V3 [2] and V4 [3]. I acknowledge that additional coordination would be required if mapping were to be allocated by one software component and sealed in another. However, this is feasible. Considering the side effect of not having this flag (as discussed in V3/V4) and the significant implications of altering the lifetime of the mapping (since unmapping would not be possible), I believe it is reasonable to expect developers to exercise additional care and caution when utilizing memory sealing. [2] https://lore.kernel.org/linux-mm/20231212231706.2680890-2-jeffxu@chromi= um.org/ [3] https://lore.kernel.org/all/20240104185138.169307-1-jeffxu@chromium.org= / > It may be fine inside a program like chrome, but I expect that flag to ma= ke > it harder to use in libc, and it will hinder adoption. > In the case of glibc and linux, as stated in the cover letter, Stephen is working on a change to glibc to add sealing support to the dynamic linker, also I plan to make necessary code changes in the linux kernel.