Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp605548rdb; Thu, 1 Feb 2024 20:04:23 -0800 (PST) X-Google-Smtp-Source: AGHT+IHe36bKtGum32RmtECMeo4mWkKbwR5tdoKjVNPU6Gl548XBVwfNlcb09gOyZZJvQJseQjv0 X-Received: by 2002:a17:906:ca4b:b0:a36:71c1:2ebb with SMTP id jx11-20020a170906ca4b00b00a3671c12ebbmr577784ejb.51.1706846663451; Thu, 01 Feb 2024 20:04:23 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706846663; cv=pass; d=google.com; s=arc-20160816; b=DKyaAjK5B4Za+25RO/+uue1KL8XQeFJPjU6H8zHxXm6g0z2vlPbIb7U9EqhjrmOEfs KOrlS3C6HcBwsk/cDcXyiCZg9uIhubgZen/hRvK//P4RVZmaP1e3ZuxuJsEUTNka1RZA WokKoCi98fnbDow376S6Sbkql9fx9yKPbKy7rylZgXQ3lrnKiTQRePJLHwJFd1PKAMMH J0TSXom359eZgndok7U40b3nN3yWc5N9LNhQzZgDXIgpWcn4bTQxy6SaXgHdLccCf4fh ipredAhRqBLBNBiQXLnrDwaqoahwBqPNqcEjAzlNWCQqHCIR19Pofs8yVI41eO3SPIaO y+RA== 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=UBPcz0GP5Gh1HSYLOPzBAm/cEGRCFW+Rm8/XCSszjkI=; fh=rlM+t8+a3xnEd5MUazEVR2vu+kblV4pmzvq/4eht8jw=; b=uLNBKa/B6kp2cKCNh/LvEb73ifkr+869d50SD90of8dQLw7ZeV2oQK8gwaOuu9aw2K /pqQTmjdzim7d4wPgMAakjq0wR7va9kc0/Sy8igSFYOevCunXxgJTnEfiE3FGpe0Vozd dn5bSVdWAPn0k4jqnY7QaZGwYzi1xNAK4VWaxgTm4crrvML/CPVzS0hwDRMM85ZOht2j HLohmUExRQ4PGorof9W+BBwUKCvQRtkejRfQMFXmafh5SAkn+eST0Cq067ibWi23VwSM qIc14dVh4SG0tl37k05k4GOF90F68TDfq2hDJS6xgFv+HKHJF/aWv7jA/ZocZb26dI4g QvgQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=VvdBz1nl; 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-49168-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49168-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; AJvYcCVx9XhRRAfNPon42xvan78AAbk1UZUPEHkskqrrZwxw1allrA6XbtFh1sBkDz98UW1VPRj75l+wdMmT5l20PyxQ1gUgceEDBPgZbwmDew== Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id cd21-20020a170906b35500b00a35ddad87e5si432760ejb.930.2024.02.01.20.04.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 20:04:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-49168-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=VvdBz1nl; 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-49168-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49168-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 0CFA31F280A2 for ; Fri, 2 Feb 2024 04:04:23 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3A9CEDF5D; Fri, 2 Feb 2024 04:04:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="VvdBz1nl" Received: from mail-oa1-f43.google.com (mail-oa1-f43.google.com [209.85.160.43]) (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 9049AE549 for ; Fri, 2 Feb 2024 04:03:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.43 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706846640; cv=none; b=HtcY1YTO6jphbA0I3uJcTkDPIbPwKU0FkXZmxBG3XOuilxDF5BXFYPn6lZfhqB47Q9tAk4j6E9tmzfiGrn934fYKd7Z+T2iJJrJ1iQTvm/waYE6690DXqHmSreb+6Cp8q0Po9iJ7gFgSb/QHers6lBnTPgIpj0Fmy90cEdA4KOM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706846640; c=relaxed/simple; bh=4eaGVcAq7zTNWzIKHGaRDBxIEfRMATFqDOHfO1lQH8Y=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=ZxAg2S4pZhsYEn/hBxApVMxFGwL4QizC8PIlSjgH/WbNKbMZax4OO3oncE01Ns1KG2aq16Ft/jREqytXC603AQQIFFM95QV/WqS89TDwLUJ1Ik0Zi3iu0q19D5iuxuqiRSVe5khzrRk3+hSRYMjRsk2aAEKcysMrqnrEF1Z2Wfw= 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=VvdBz1nl; arc=none smtp.client-ip=209.85.160.43 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-f43.google.com with SMTP id 586e51a60fabf-219108b8e9cso211064fac.2 for ; Thu, 01 Feb 2024 20:03:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1706846637; x=1707451437; 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=UBPcz0GP5Gh1HSYLOPzBAm/cEGRCFW+Rm8/XCSszjkI=; b=VvdBz1nlcgqlNER9AlHRBIAmL68JjrS4MJow0N2ZhzSZZQN9yYTT5MHT8vaguL23CE STzyaGK4GAEqSzCBc+XB7QKQbelxmqjCa4M5MQO71hMdfWzMMj6VMmd/V3v8ZhHr1Brv 3NYvUQ1vnKLA4PA+bOzPugw52WmcusNcqFzSs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706846637; x=1707451437; 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=UBPcz0GP5Gh1HSYLOPzBAm/cEGRCFW+Rm8/XCSszjkI=; b=eaGE6potlhV7lxzB7xQF9vEUSZz+W6FXVJLT6FydkiNB/gSR/UW8rrCKQHybUEUyER Etw+SsrBX32Y5IAgycBfJBjn6v1hXnzieqsiQZUcZS7HrDPcOBTkgDFRQA3tgfCy0dnL 4aONYBy/RhLr2sNG+bG+mkCxsiYTTVzjBIW7TudGOhyB98y5b7adLxSfbkFW7B2GMGL3 y/DEKgE8bYLVMRGbWRTMM3X15tsv3qg078ZDqdxcpGZ39LzvlLHjsh9jzLUZvMLK/2Y6 PM3dwzXURe5bXDUA7ixv5mdZLcWgHE8WrZdhiW4nciGaJ0imyolE2B3kVN32w8AW7wQ+ Qzpg== X-Gm-Message-State: AOJu0YygAUqtWBs1X+KV+EmdME83TuZI4OU6CYvPn9M37iaNy5yteDAV NGhGfXZwipqLkrUdgi58nYqhuPlc4zdaMlSrpPHCSj2Yqwwe8Hza+qxophti2gsnyr3DYO3XTB3 Vrz8WhUXFY9zf+Hu0DVqlSFDBVJ2qtglXSL+6 X-Received: by 2002:a05:6870:40c1:b0:218:e4c3:e34 with SMTP id l1-20020a05687040c100b00218e4c30e34mr4696738oal.55.1706846637645; Thu, 01 Feb 2024 20:03:57 -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> In-Reply-To: <96087.1706846050@cvs.openbsd.org> From: Jeff Xu Date: Thu, 1 Feb 2024 20:03:45 -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 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 wrote: > > > > [PATCH v8 2/4] mseal: add mseal syscall > > > [...] > > > > +/* > > > > + * The PROT_SEAL defines memory sealing in the prot argument of mm= ap(). > > > > + */ > > > > +#define PROT_SEAL 0x04000000 /* _BITUL(26) */ > > > > + > > > > /* 0x01 - 0x03 are defined in linux/mman.h */ > > > > #define MAP_TYPE 0x0f /* Mask for type of mapping *= / > > > > #define MAP_FIXED 0x10 /* Interpret addr exactly */ > > > > @@ -33,6 +38,9 @@ > > > > #define MAP_UNINITIALIZED 0x4000000 /* For anonymous mmap, memory= 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 new sy= scall, but > > > it actually adds three new UAPIs, only one of which is the new syscal= l. The > > > other two new UAPIs are new flags to the mmap syscall. > > > > > The description does include all three. I could update the patch title. > > > > > Based on recent discussions, it seems the usefulness of the new mmap = flags has > > > not yet been established. Note also that there are only a limited nu= mber of > > > mmap flags remaining, so we should be careful about allocating them. > > > > > > Therefore, why not start by just adding the mseal syscall, without th= e new mmap > > > flags alongside it? > > > > > > I'll also note that the existing PROT_* flags seem to be conventional= ly used for > > > the CPU page protections, as opposed to kernel-specific properties 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 j= ust adding > > > sys_mseal(). Some reviewers may not have noticed or considered the n= ew flags. > > > > > MAP_ flags is more used for type of mapping, such as MAP_FIXED_NOREPLAC= E. > > > > 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, we emulate the SVr4 behavior. Sigh. */ error =3D vm_mmap(NULL, 0, PAGE_SIZE, PROT_READ | PROT_EXEC, <-- add PROT_SEAL 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. > Please don't write it as a vague essay. > > Instead, take a piece of existing code, write a diff, and show your work. > > Then explain that diff, justify why doing the PROT_SEAL as an argument > of mprotect() or mmap() is a required improvement, and show your Linux > developer peers that you can do computer science. > > I did the same work in OpenBSD, at least 25% time over 2 years, and I > had to prove my work inside my development community. I had to prove > that it worked system wide, not in 1 program, with hand-waving for the > rest. If I had said "Looks, it works in ssh, trust me it works in other > programs", it would not have gone further. > > glibc is the best example to demonstrate, but smaller examples might > convince.