Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp1090240rdb; Fri, 2 Feb 2024 13:20:51 -0800 (PST) X-Google-Smtp-Source: AGHT+IG2qdwS7FA4lCAQDs57cxcRpfZwu4hE7/tUPIEHoPJeI/OInQXT3tCUkS59VYHPmZ1Y9zxq X-Received: by 2002:a05:6a21:32a5:b0:19c:9f4e:b122 with SMTP id yt37-20020a056a2132a500b0019c9f4eb122mr11043962pzb.20.1706908850958; Fri, 02 Feb 2024 13:20:50 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706908850; cv=pass; d=google.com; s=arc-20160816; b=gJDI2RLfiCfhJ2+t8vW9k4cnmcM8IbGB9KjmDrzIDVJNhyOM+P+I7tOSHY8bQ7qgYT AuyvqHUcQ2Fp5y8CbEbJ8misMU1mneljZQdcv6AWCI597SAU8AV/oEy4RVpmJVMffFCD WZTgtLG2MX/PsUr9fCVmigVfzk0wOcOYR3g+o7ZpA7ksb19B32+FdBO7YCeYeFc8MFQf jkuDnAJWN4Pt6PvQYRKFhQAUehr/XPTWxNanuDjVc6Ap7IhuO6Yp2CbD9UxiaztQiOWd u9qS4GzOMPVwUbkgkkRMnKF5wQZRjmH1Fd2vE6Cc4BJVf41hsBg65pA8TV96kGi66B7T hHnw== 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=92wvK0QB22DZGV3tUKA8OrcYGB+w2iD/0d4E9vYXy90=; fh=mZ/2ctUO2LevsU0eJpsYI/KocNGc0Fquw0UmpqbfaYM=; b=yuCHCMS+9jPV9n2Pmccdjs0o4+uVvahol85VFY/uCkvnwuR3a//t5MSRnCX6aRFuRn IrBXe0f8YR8AP474FgLkcE/9j8D6zG3S+BvDOQoN7idzsZjQjcqY0+fHtHz+pc9UBNJ2 WAiNunte9aWXujCMSuSKm2EVYTthleeOguOY0jPYdpQao2d8UjctLL+QaOEljNodB72I 1Tql3EuyCdK9lbY9WI+m1z6b4rtyVGrR1faCnICXMFygVukoTLh68wXQR4PJ0CAbqfSX cErxycfJRhYUQNrWNEauz0MPSSwcehdTpY5e8+YVOSeDPT/OtJxo03p/oZ1fZStcrqIM F+1A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=gs399+XR; 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-50601-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-50601-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org X-Forwarded-Encrypted: i=1; AJvYcCWC/6s+BhnECLBLITZpgRfuPELKNMCc6Dms4Yqy2R5vxXgHnOZNh8NeXyGEItyI4gb7PH6N+51IFGgSZkcvT1GcYWyU0PeB9s4LfpivYw== Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id r65-20020a632b44000000b005cfbeee4c1dsi603175pgr.314.2024.02.02.13.20.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Feb 2024 13:20:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-50601-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=gs399+XR; 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-50601-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-50601-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 977AC28E7C2 for ; Fri, 2 Feb 2024 21:20:50 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0D99A15E5CD; Fri, 2 Feb 2024 21:20:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="gs399+XR" Received: from mail-oa1-f45.google.com (mail-oa1-f45.google.com [209.85.160.45]) (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 7507EE56D for ; Fri, 2 Feb 2024 21:20:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.45 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706908842; cv=none; b=U62YBNf7OSwv/DdIpiy32f80uTI38m15DcX2L0jYKSChi9QxnRt5DULOQFUN4XhTX7lXMcLzHrHvGaK4w1EorR6YNiaKsbfg69K7zD306ehFh62c0HttIA3Rim9OfjN4PCvGI5tH55vM7t+bfaCUZxN7jnOwQHN7iHOfedNz4UM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706908842; c=relaxed/simple; bh=jUs3FOiHURQSbndNpw9eAyjunPGYP6jiGaFCC4A3PYw=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=oeuAjPueSbpH/+JJUrdrhaDuCjZ6azjAPTJMY5WouppqfYDDdykNdBUqGnrnFS+I6af2ZHx39pRP25CHRhKgmFAXbgL72Cg2cr+BxmVxGMwrtoWrPjwB0w2jDZaL7sA31oHNSHSZfNwPsEF6r5fXOTDXSpKm9WpVRwyMnKzYVqI= 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=gs399+XR; arc=none smtp.client-ip=209.85.160.45 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-oa1-f45.google.com with SMTP id 586e51a60fabf-2191dc7079aso516613fac.0 for ; Fri, 02 Feb 2024 13:20:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1706908839; x=1707513639; 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=92wvK0QB22DZGV3tUKA8OrcYGB+w2iD/0d4E9vYXy90=; b=gs399+XRn/XEHp3VeqU9F0bZepjNpgScajG42mi9KKlHfLQYJHWJbw9bQF8gZCyPgu uar9/rjfPaaX6rFIBJISVFSUXQAghjut/sFem3P8J1chBk9dea7cKYTQ1vP9zAIRFk6V Bf7YzZlQLTA1UCLMhvrREH+4k6Wc5OQsd1UyM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706908839; x=1707513639; 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=92wvK0QB22DZGV3tUKA8OrcYGB+w2iD/0d4E9vYXy90=; b=s78d62BGvAcUhv2TfPeSo2Oued2Aacz6GqhaVuumHyvg7tQ4gr+DsWbsltW0j/8O3e GQ+FAwRXXVhTjfFV6D0JqnFjDMPGQERsX7t8BWpJZ29uL0VDtbFFalWuH13AgJ3Q9Obj /2UshAShM/xTqKqPAep3odQ/lN6646WJ4514vG5Rz4lQyTBtusDOxRSurMHgKOte68/6 44e/uyGy+OrjeAVujMDIQvpnY7jUxWz0tZ5XbMeJtk6jgP9mSCgt6F8LmSvV6RFtPzR9 3PCk46bmcGqNI5TW2QDtIJfDOl7UdFJWFgOrhlQN5ZFQ10srIM1QDQN6Yi2kqmok3h8r cvXA== X-Gm-Message-State: AOJu0YyXvJN9gelci7UwogzzOCA3fbwcibdkyQPt6qVqJqd6wm1YAr1R 5bQVgd9xZ488h5RBqyF9pLDS8PwtWM8ATkUEQrJwk+ha25naE5Fs0JKOEwBtkMoxa4UMDFtuAGl VT70N55Pxw0cVb0w0eURfTaB7ia6lvHEYY95A X-Received: by 2002:a05:6870:7024:b0:214:9ecd:56e8 with SMTP id u36-20020a056870702400b002149ecd56e8mr932493oae.33.1706908839487; Fri, 02 Feb 2024 13:20:39 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240131175027.3287009-1-jeffxu@chromium.org> <20240131193411.opisg5yoyxkwoyil@revolver> <20240201204512.ht3e33yj77kkxi4q@revolver> <58408.1706828083@cvs.openbsd.org> <8744.1706846710@cvs.openbsd.org> <29248.1706850035@cvs.openbsd.org> In-Reply-To: From: Jeff Xu Date: Fri, 2 Feb 2024 13:20:27 -0800 Message-ID: Subject: Re: [PATCH v8 0/4] Introduce mseal To: Pedro Falcato Cc: Theo de Raadt , Jeff Xu , Linus Torvalds , "Liam R. Howlett" , Jonathan Corbet , akpm@linux-foundation.org, keescook@chromium.org, jannh@google.com, sroettger@google.com, willy@infradead.org, gregkh@linuxfoundation.org, usama.anjum@collabora.com, rdunlap@infradead.org, jorgelo@chromium.org, groeck@chromium.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org, dave.hansen@intel.com, linux-hardening@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, Feb 2, 2024 at 10:52=E2=80=AFAM Pedro Falcato wrote: > > On Fri, Feb 2, 2024 at 5:59=E2=80=AFPM Jeff Xu wrot= e: > > > > On Thu, Feb 1, 2024 at 9:00=E2=80=AFPM Theo de Raadt wrote: > > > > > > Jeff Xu wrote: > > > > > > > Even without free. > > > > I personally do not like the heap getting sealed like that. > > > > > > > > Component A. > > > > p=3Dmalloc(4096); > > > > writing something to p. > > > > > > > > Compohave nent B: > > > > mprotect(p,4096, RO) > > > > mseal(p,4096) > > > > > > > > This will split the heap VMA, and prevent the heap from shrinking, = if > > > > this is in a frequent code path, then it might hurt the process's > > > > memory usage. > > > > > > > > The existing code is more likely to use malloc than mmap(), so it i= s > > > > easier for dev to seal a piece of data belonging to another compone= nt. > > > > I hope this pattern is not wide-spreading. > > > > > > > > The ideal way will be just changing the library A to use mmap. > > > > > > I think you are lacking some test programs to see how it actually > > > behaves; the effect is worse than you think, and the impact is immedi= ately > > > visible to the programmer, and the lesson is clear: > > > > > > you can only seal objects which you gaurantee never get recyc= led. > > > > > > Pushing a sealed object back into reuse is a disasterous bug. > > > > > > Noone should call this interface, unless they understand that= . > > > > > > I'll say again, you don't have a test program for various allocators = to > > > understand how it behaves. The failure modes described in your docue= mnts > > > are not correct. > > > > > I understand what you mean: I will add that part to the document: > > Try to recycle a sealed memory is disastrous, e.g. > > p=3Dmalloc(4096); > > mprotect(p,4096,RO) > > mseal(p,4096) > > free(p); > > > > My point is: > > I think sealing an object from the heap is a bad pattern in general, > > even dev doesn't free it. That was one of the reasons for the sealable > > flag, I hope saying this doesn't be perceived as looking for excuses. > > The point you're missing is that adding MAP_SEALABLE reduces > composability. With MAP_SEALABLE, everything that mmaps some part of > the address space that may ever be sealed will need to be modified to > know about MAP_SEALABLE. > > Say you did the same thing for mprotect. MAP_PROTECT would control the > mprotectability of the map. You'd stop: > > p =3D malloc(4096); > mprotect(p, 4096, PROT_READ); > free(p); > > ! But you'd need to change every spot that mmap()'s something to know > about and use MAP_PROTECT: all "producers" of mmap memory would need > to know about the consumers doing mprotect(). So now either all mmap() > callers mindlessly add MAP_PROTECT out of fear the consumers do > mprotect (and you gain nothing from MAP_PROTECT), or the mmap() > callers need to know the consumers call mprotect(), and thus you > introduce a huge layering violation (and you actually lose from having > MAP_PROTECT). > > Hopefully you can map the above to MAP_SEALABLE. Or to any other m*() > operation. For example, if chrome runs on an older glibc that does not > know about MAP_SEALABLE, it will not be able to mseal() its own shared > libraries' .text (even if, yes, that should ideally be left to ld.so). > I think I have heard enough complaints about MAP_SEALABLE from Linux developers and Linus in the last two days to convince myself that it is a bad idea :) For the last time, I was trying to limit the scope of mseal() limited to two known cases. And MAP_SEALABLE is a reversible decision, a system ctrl can turn it off, or we can obsolete it in future. (this was mentioned in the document of V8). I will rest my case. Obviously from the feedback, it is loud and clear that we want to be able to seal all the memory. > IMO, UNIX API design has historically mostly been "play stupid games, > win stupid prizes", which is e.g: why things like close(STDOUT_FILENO) > work. If you close stdout (and don't dup/reopen something to stdout) > and printf(), things will break, and you get to keep both pieces. > There's no O_CLOSEABLE, just as there's no O_DUPABLE. > > -- > Pedro