Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp611270rdb; Thu, 1 Feb 2024 20:22:54 -0800 (PST) X-Google-Smtp-Source: AGHT+IF5cpo0X7fGZ1bDBcWE4uwHE+cqNgW1Nk/AIdrOZ+2TFoqHfhflzTjY8bZdwGkW2naXAsGX X-Received: by 2002:a50:fc14:0:b0:55f:fa5d:af6a with SMTP id i20-20020a50fc14000000b0055ffa5daf6amr78591edr.12.1706847773801; Thu, 01 Feb 2024 20:22:53 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706847773; cv=pass; d=google.com; s=arc-20160816; b=DG48AKRocWuYLP6Ib5sjrb5le2bdKNxJ2FPyEiCJmszDjGzNBFr9fmGnQ2Oo4vmMPm UxAgoOGZi23bLnznloki+LuhprZGJz6Btth9y8Zmz8GGl8u1f+JCCJx9su/eA+aLF8cC paQiHv+/Oeo9wgw7h7qywx7+xjLoZ+oKmUQQ/g1Zyl4LcC1t7I1zvehLxywdRKRDFhkx GuYAHrBADZJr3uYm9nja5PZzeE+zaN0htBjkWqJujkC8t8oug0hHdBIhpLEnLNkUHdMU TOod1vaQlu9iZknoewnx1Ibty35xj3ZVR2h4JEHrHvOZPd4kz8L5o5aeooQmD99jCk4/ TD3w== 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=GY7gduymNb2zU8foO6bHqxA7R4wx0/8BTl8lBqhvbv0=; fh=rEAM2G2LGeP6prYxyS1xgqKWYpo7BEg3KC80ZhoGLvE=; b=LaMR0ANxMx5Z6xBIFfxGG7Ixy1JArhM5YF7mUcJ+TqfyBlIe1NMqVVhTKQnh2ZP1H7 aQBLIf+m9XHh1iR767ddXOoIbvQRIxVB22cIJn9zVJQOjhglO777lllXVv9ycj031hsE T6knUhaTjf90nnjweNHzVVmhCTmrhL+Wk1GLhPPZE6Q+/aQMkDmIvE16vtUQR7vFhK+M ObqCRCFPhh2g/HyOympYfwdCRrLYr2h3sM/UulDLFQd5H/TPYkkMUkYngSN0BSmyxCr+ W8fqV034aLurm6Q5MKZU+NaILnSWov8UFpfQhjZTRfhgsxkO5Yejo0x3IhsOWwmeW8nJ JQ7Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=aQyZUZTw; 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-49189-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49189-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; AJvYcCUiq6Hy6IOdLKYoRL78PWZbO18KplNTNesX4T0Y6tr4nMS19T7TG4EW3gUx3EfpFEPGyV+7WkPmrIN+zSxOQbq11X6yefgCbYnlGpULJg== Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id a12-20020aa7d74c000000b0055fec51fafdsi306820eds.646.2024.02.01.20.22.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 20:22:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-49189-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=aQyZUZTw; 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-49189-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49189-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 61E291F2227B for ; Fri, 2 Feb 2024 04:22:53 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 93FF4E56B; Fri, 2 Feb 2024 04:22:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="aQyZUZTw" Received: from mail-oa1-f48.google.com (mail-oa1-f48.google.com [209.85.160.48]) (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 0059BE56D for ; Fri, 2 Feb 2024 04:22:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.48 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706847763; cv=none; b=KeFFa+Qfq950crjQhyXMykEmzvLJfFYRFLlWeNp6Guw6vQkE0ic0WVy33DotBU+zLlctnOoKJj50JBSCRDoYU22d1mgroX+8L7Ew6+IwNA44kbrpWMuzr6zEnPegZRyQLFNpkYpsNK4rjHtEk/2uluIu1UnywSvaNXAXtq5sFgI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706847763; c=relaxed/simple; bh=vA7tvTQxROFPNSNZmoB+xRvwpT15aZOnZMRAVU3yE5g=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=mXpuE11VILHLCZpMXpPe8Jr/9AOUp41p6J3PwOm4i66N/HMf7jwpCJjU+qImp0TjqEjzlhA0b2l16ChYENkhuUiLiysqPTsL+/7A6WBp75lJeY4dBGypHkHn0Wn5J1+0ubsDtd8aPjTjOdSqpgy+Vxe7EpyXdkhSljqNgoSWzt8= 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=aQyZUZTw; arc=none smtp.client-ip=209.85.160.48 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-f48.google.com with SMTP id 586e51a60fabf-2046b2cd2d3so1216450fac.0 for ; Thu, 01 Feb 2024 20:22:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1706847761; x=1707452561; 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=GY7gduymNb2zU8foO6bHqxA7R4wx0/8BTl8lBqhvbv0=; b=aQyZUZTwSfdF9GVvvBhz9gla/Tj8GAEMgMn00U2j9246xVlcC7/RgWmIPXJRmFr7lS xV3xp2Fm31nUIgTJNupttWMcGq7VZmsGzkCg76sftejdNg9ZpoFDoMyNe9EilkOyT48d CJnMT2kkU7v8cCpYt2lCKZtj389I+MuqeFZQ4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706847761; x=1707452561; 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=GY7gduymNb2zU8foO6bHqxA7R4wx0/8BTl8lBqhvbv0=; b=jkuYIR/zzUlvr0muAKPFneB5eVaEYCcJRcJB8wA1zksjFCg4Z1O9QDOi/5PkVJvX/3 r6SGhQY4JU3qoIlWqUSRYmNgxcM2etxxaAsEOGUDxmaILedz+o7YnF9lblKZmv654TQ7 WI5zHXhJZ/9tAYpfs9IGBXecLPstYueIlcRkj2kXW/nntMVLMAtbuP41e2oT5KDQfWYM WBjVKZw6+9KDBYZMqwXBYNvTY5NeSBFdELBtnzjr2lz2XWGQMdEHeMvngrxQ5oXbU2ON kzqZq9QjMdEOfruYFDh/7n4UGzmPErG7jMNarM9RJKcBtG1azPpBfgRGAB46xpgGGwj5 5/1g== X-Gm-Message-State: AOJu0YxVFWoADi8fSgpxEDSd2R1FAQs7GbbshGFk7EuyAW5Z/OSn74tL cYVgqbF4jyNioaSCnhLmM7fMOwSqVIy/AK5Cm4F6iyI2A0sOOcTf/Tf1AXGkQHq1AK5cxOGCukl nAW2Y0d3bD3uSwX1jiM17Xw49PG7B7PYM1xif X-Received: by 2002:a05:6870:7908:b0:214:2a08:897d with SMTP id hg8-20020a056870790800b002142a08897dmr8699235oab.46.1706847761083; Thu, 01 Feb 2024 20:22:41 -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> <20240131175027.3287009-3-jeffxu@chromium.org> <20240201231151.GA41472@sol.localdomain> <96087.1706846050@cvs.openbsd.org> <72434.1706847038@cvs.openbsd.org> In-Reply-To: <72434.1706847038@cvs.openbsd.org> From: Jeff Xu Date: Thu, 1 Feb 2024 20:22:29 -0800 Message-ID: Subject: Re: [PATCH v8 2/4] mseal: add mseal syscall To: Theo de Raadt Cc: Eric Biggers , 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 Thu, Feb 1, 2024 at 8:10=E2=80=AFPM Theo de Raadt = wrote: > > Jeff Xu wrote: > > > On Thu, Feb 1, 2024 at 7:54=E2=80=AFPM Theo de Raadt wrote: > > > > > > Jeff Xu wrote: > > > > > > > On Thu, Feb 1, 2024 at 3:11=E2=80=AFPM Eric Biggers wrote: > > > > > > > > > > On Wed, Jan 31, 2024 at 05:50:24PM +0000, jeffxu@chromium.org wro= te: > > > > > > [PATCH v8 2/4] mseal: add mseal syscall > > > > > [...] > > > > > > +/* > > > > > > + * The PROT_SEAL defines memory sealing in the prot argument o= f mmap(). > > > > > > + */ > > > > > > +#define PROT_SEAL 0x04000000 /* _BITUL(26) */ > > > > > > + > > > > > > /* 0x01 - 0x03 are defined in linux/mman.h */ > > > > > > #define MAP_TYPE 0x0f /* Mask for type of mappi= ng */ > > > > > > #define MAP_FIXED 0x10 /* Interpret addr exactly= */ > > > > > > @@ -33,6 +38,9 @@ > > > > > > #define MAP_UNINITIALIZED 0x4000000 /* For anonymous mmap, me= mory could be > > > > > > * uninitialized */ > > > > > > > > > > > > +/* map is sealable */ > > > > > > +#define MAP_SEALABLE 0x8000000 /* _BITUL(27) */ > > > > > > > > > > IMO this patch is misleading, as it claims to just be adding a ne= w syscall, but > > > > > it actually adds three new UAPIs, only one of which is the new sy= scall. The > > > > > other two new UAPIs are new flags to the mmap syscall. > > > > > > > > > The description does include all three. I could update the patch ti= tle. > > > > > > > > > Based on recent discussions, it seems the usefulness of the new m= map flags has > > > > > not yet been established. Note also that there are only a limite= d number of > > > > > mmap flags remaining, so we should be careful about allocating th= em. > > > > > > > > > > Therefore, why not start by just adding the mseal syscall, withou= t the new mmap > > > > > flags alongside it? > > > > > > > > > > I'll also note that the existing PROT_* flags seem to be conventi= onally used for > > > > > the CPU page protections, as opposed to kernel-specific propertie= s of the VMA > > > > > object. As such, PROT_SEAL feels a bit out of place anyway. If = it's added at > > > > > all it perhaps should be a MAP_* flag, not PROT_*. I'm not sure = this aspect has > > > > > been properly discussed yet, seeing as the patchset is presented = as just adding > > > > > sys_mseal(). Some reviewers may not have noticed or considered t= he new flags. > > > > > > > > > MAP_ flags is more used for type of mapping, such as MAP_FIXED_NORE= PLACE. > > > > > > > > The PROT_SEAL might make more sense because sealing the protection = bit > > > > is the main functionality of the sealing at this moment. > > > > > > Jeff, please show a piece of software that needs to do PROT_SEAL as > > > mprotect() or mmap() argument. > > > > > I didn't propose mprotect(). > > > > for mmap() here is a potential use case: > > > > fs/binfmt_elf.c > > if (current->personality & MMAP_PAGE_ZERO) { > > /* Why this, you ask??? Well SVr4 maps page 0 as read-= only, > > and some applications "depend" upon this behavior. > > Since we do not have the power to recompile these, w= e > > emulate the SVr4 behavior. Sigh. */ > > > > error =3D vm_mmap(NULL, 0, PAGE_SIZE, > > PROT_READ | PROT_EXEC, <-- add PROT_S= EAL > > MAP_FIXED | MAP_PRIVATE, 0); > > } > > > > I don't see the benefit of RWX page 0, which might make a null > > pointers error to become executable for some code. > > > > And this is a lot faster than doing the operation as a second step? > > > But anyways, that's kernel code. It is not userland exposed API used > by programs. > > The question is the damage you create by adding API exposed to > userland (since this is Linux: forever). > > I should be the first person thrilled to see Linux make API/ABI mistakes > they have to support forever, but I can't be that person. > Point taken. I can remove PROT_SEAL. > >