Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp6327936rdb; Thu, 14 Dec 2023 15:21:57 -0800 (PST) X-Google-Smtp-Source: AGHT+IHmS9EDuStvqtTgaZaTw9yWx8q9jTPrwiCftC8N3S4XKCwbYz1zPlGDI2rRRLyW6mkPGur1 X-Received: by 2002:a17:903:1105:b0:1d0:c502:e09d with SMTP id n5-20020a170903110500b001d0c502e09dmr11027319plh.99.1702596117454; Thu, 14 Dec 2023 15:21:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702596117; cv=none; d=google.com; s=arc-20160816; b=YAh1hEmWE8Nx6T1ksl4O7wZTc90DQPlWRuwir+nQL8LPGMuS0jOvjWUvIR8c3xNc9Y x0E3TX958sCR4ObfhVg5VvF6dQdnTPs0pCbO/Q8X5/XkapcH59Q+BvSp5qPmdtfEo7Ou 5emDsQY/jXCcc3dRB6/K5AsmY9xHMngQczFeg6aja1A0SXfmtf77MPgQ0uESv1PRNdAl vv7adhD5o2EoVg25hafInC3nqr7ybR6/qs9++7/Y+PH0DDihpcydoeXfhBbecq8hg9y5 vweK8c9uLQ2TxHDZI3CSzt4s3ttx/lQUzciuDdKmmOdd4vdyBEqWf4HbAROsSEP2HqiV /IeQ== ARC-Message-Signature: i=1; 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=qmbndnjcrhmBBoxS6pcuDX2mGwfUQXEv+7vBpDoTDrg=; fh=4vq79VFy2urA30fiIosh1HO76suyxCLA9JiQCDA5Opc=; b=h7LDGftt6Rhci1o+IE09Jq9AhRlbTm6r17DirJU1DkztUtL/ogBKMxXEU8eRRp+46l ayBwtfS18edtog62zc8Nlwf+l4IQy0MkGkUONPMB+kOBmOpm4nQTBT6vMr/2/7Jv5+4B BxG0+M083XJ0KsjIH3iIY/iih9lpAjSEctoWPOQnVoEMz1NrYTpcuCHIdBz0ZGw2C/tE 6vrtEHuxeAdjyGfZmW0AfCb8cdWTLeMeAoKuxGG6Lcbor9uMmQN10ulYMxQHJ9enHLNQ d2aJvlnRQVQdJhU2VFyCq/7gKiD9Loe0BDWMiS+QyhOE5Z5lrdrDjHyIYn6SRETI4ZnF GpVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=dzzJ5ELw; spf=pass (google.com: domain of linux-kernel+bounces-241-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-241-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id p8-20020a1709026b8800b001d3482dc1b4si4097322plk.369.2023.12.14.15.21.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 15:21:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-241-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=dzzJ5ELw; spf=pass (google.com: domain of linux-kernel+bounces-241-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-241-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 1DA692834F1 for ; Thu, 14 Dec 2023 23:21:57 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 956ED6C6DD; Thu, 14 Dec 2023 23:21:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="dzzJ5ELw" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-qk1-f176.google.com (mail-qk1-f176.google.com [209.85.222.176]) (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 3E5C86C6D7 for ; Thu, 14 Dec 2023 23:21:50 +0000 (UTC) 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-qk1-f176.google.com with SMTP id af79cd13be357-77f8dd477fcso6979785a.0 for ; Thu, 14 Dec 2023 15:21:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1702596109; x=1703200909; 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=qmbndnjcrhmBBoxS6pcuDX2mGwfUQXEv+7vBpDoTDrg=; b=dzzJ5ELwc1qH8EKe/Cyt1XCrGAl9DRHAfuYscFetU0GOQK9uAhTXbE3+i4UQoG/+k2 tQ8sv1oIwK1U4NRkA9dK4AV1IsPEwohaKiEcOe8JYTk8XGMXj5kfCHtXLcMaZ0pS+MwA gNeH52PAJcUOh/zl6a9S4cCaE2zaQmeRFHVc8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702596109; x=1703200909; 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=qmbndnjcrhmBBoxS6pcuDX2mGwfUQXEv+7vBpDoTDrg=; b=hoVi8Uq1oJnHPHnTNk3YKZGw4kiFo4fhry9STK68poKxUA3QEeNCjPQ1Soy8TlMG2F lKyOQqvG2hSv++GukiFDLyh40LfKFsOTXwV/yuvZQlKwd/aOw0AGv45BO6vEODSCxA08 qyK377dOF6wMpzC4DNT7hOJcRcIS3oTtFlIX63v+C2VOnwU3iYjAKZpO202l1or2Wogi bO0v/ZW4MIWBBhLejaRW11yq8VqNyCZrsgzzS+SeLNhyH0ThqX3zeBOAIib+Qq39SOV0 5hO+rVWVUHu8y0U51Ao/c2oQZ4gZibdulHFdoEpMPs7XKL78M+Wp+rteo/CB4xPTatEE WHjA== X-Gm-Message-State: AOJu0YyWPIo037VUW+VEAHcOYpKhAsHDpkvUpr23zoJViKjSnI5henfJ IcoBq/68DtTeh0+1WWVQkfOK239x2vleBlEVj3rBEmNe23BawJxgDDA= X-Received: by 2002:a05:6870:41cc:b0:203:4c85:562f with SMTP id z12-20020a05687041cc00b002034c85562fmr1695983oac.59.1702594390274; Thu, 14 Dec 2023 14:53:10 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20231212231706.2680890-1-jeffxu@chromium.org> <20231212231706.2680890-12-jeffxu@chromium.org> In-Reply-To: From: Jeff Xu Date: Thu, 14 Dec 2023 14:52:58 -0800 Message-ID: Subject: Re: [RFC PATCH v3 11/11] mseal:add documentation To: Linus Torvalds Cc: =?UTF-8?Q?Stephen_R=C3=B6ttger?= , Jeff Xu , akpm@linux-foundation.org, keescook@chromium.org, jannh@google.com, willy@infradead.org, gregkh@linuxfoundation.org, 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 On Thu, Dec 14, 2023 at 12:14=E2=80=AFPM Linus Torvalds wrote: > > On Thu, 14 Dec 2023 at 10:07, Stephen R=C3=B6ttger = wrote: > > > > AIUI, the madvise(DONTNEED) should effectively only change the content = of > > anonymous pages, i.e. it's similar to a memset(0) in that case. That's = why we > > added this special case: if you want to madvise(DONTNEED) an anonymous = page, > > you should have write permissions to the page. > > Hmm. I actually would be happier if we just made that change in > general. Maybe even without sealing, but I agree that it *definitely* > makes sense in general as a sealing thing. > > IOW, just saying > > "madvise(DONTNEED) needs write permissions to an anonymous mapping when = sealed" > > makes 100% sense to me. Having a separate _flag_ to give sensible > semantics is just odd. > > IOW, what I really want is exactly that "sensible semantics, not random f= lags". > > Particularly for new system calls with fairly specialized use, I think > it's very important that the semantics are sensible on a conceptual > level, and that we do not add system calls that are based on "random > implementation issue of the day". > > Yes, yes, then as we have to maintain things long-term, and we hit > some compatibility issue, at *THAT* point we'll end up facing nasty > "we had an implementation that had these semantics in practice, so now > we're stuck with it", but when introducing a new system call, let's > try really hard to start off from those kinds of random things. > > Wouldn't it be lovely if we can just come up with a sane set of "this > is what it means to seal a vma", and enumerate those, and make those > sane conceptual rules be the initial definition. By all means have a > "flags" argument for future cases when we figure out there was > something wrong or the notion needed to be extended, but if we already > *start* with random extensions, I feel there's something wrong with > the whole concept. > > So I would really wish for the first version of > > mseal(start, len, flags); > > to have "flags=3D0" be the one and only case we actually handle > initially, and only add a single PROT_SEAL flag to mmap() that says > "create this mapping already pre-sealed". > > Strive very hard to make sealing be a single VM_SEALED flag in the > vma->vm_flags that we already have, just admit that none of this > matters on 32-bit architectures, so that VM_SEALED can just use one of > the high flags that we have several free of (and that pkeys already > depends on), and make this a standard feature with no #ifdef's. > > Can chrome live with that? And what would the required semantics be? > I'll start the list: > > - you can't unmap or remap in any way (including over-mapping) > > - you can't change protections (but with architecture support like > pkey, you can obviously change the protections indirectly with PKRU > etc) > > - you can't do VM operations that change data without the area being > writable (so the DONTNEED case - maybe there are others) > > - anything else? > > Wouldn't it be lovely to have just a single notion of sealing that is > well-documented and makes sense, and doesn't require people to worry > about odd special cases? > > And yes, we'd have the 'flags' argument for future special cases, and > hope really hard that it's never needed. > Yes, those inputs make a lot of sense ! I will start the next version. In the meantime, if there are more comments, please continue to post, I appreciate those to make the API better and simple to use. -Jeff > Linus >