Received: by 2002:ab2:69cc:0:b0:1fd:c486:4f03 with SMTP id n12csp105725lqp; Mon, 10 Jun 2024 20:49:26 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCX1Cvr+RWoz5JrWBZ8/iJwazo9v2s6UiGyB3FaUD15VlzvSIO99qPGDgdCtSGsR24FV7rmmg+j68zCVmsckDKajfUPrhwVTj1thUpMVuQ== X-Google-Smtp-Source: AGHT+IFy3aPqJKQsA0r6ioIzg6FUdyXKLZZexWdxz6Iejndwf7htYH2CElivkIawq2RF4QIcVN1Y X-Received: by 2002:ac8:5912:0:b0:43d:e767:f106 with SMTP id d75a77b69052e-4413b2d6e26mr26467631cf.30.1718077766232; Mon, 10 Jun 2024 20:49:26 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718077766; cv=pass; d=google.com; s=arc-20160816; b=eQLOYU2g2pWCCVDSl0dy9cAwpZ2Op6rjHFfFEsFYmp696d/P/cVcmzsxblBQUE3M5d jfFtapeDZpXKM04J1Z4p8cOyO1ABwSe7FBakvWB16OCNDiAGIqe3rZ8O8zEKLuj5AbGm O2fLslYDCF1+zNKHOwehhXGO7XctrgqYqqqy5EzcJa2VRk0g9SzDxB115Ci6XFwiZ4a1 l0+oL6a13Sh9PjD4c8q166wthMQBhxlqZ/3i0j37VXY301Q2Fj74BYKSYRR8Nw/86oZ1 R2Lzw7KXwd4rOrELPVFCZpC0Jm15EK3MRWedYl2vj7T4HHPsMrE1voxe/2oORgHzLcH6 Dymg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=zbet/qCsm/2TCPHjObU4qdEEAftnzY0yLDlxMiRcwWc=; fh=6HV9AVkGi6ZnJdSksWVuyK0o7LlBSBUtmx/UqI879NQ=; b=oVHu26iPe9pxB77CU5a542viEGZVYPeNurDe6QkkmwEFBXo9wOARvVtchTCVKeByU8 teNAWh82ttFRFfuzcn5ad4uYTGAPHSYK/ERcmjmwg6tx799zfFV0JBG0lxJaK4PisBao 1nSRRDP4vX2s8Hg4Y1GMIuj43XYMwCvg7IH103rtLeuM5/IcEVS9KOzj2It0Wd8bquX/ BxYUUSImWIyPBLJy5ptgRXYqvIYdy6Cg7zAswQaUeuqjGa4m8YxB61KwaqxKOO6n5TdX Wps8IcIn0lE9rrHz3khtWJZRSC8j8927EQ3rqGfU9QWtz+jPFDkj5XLpBwZSoaxwY0nn 7yig==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=aJmJ0s1n; 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-209229-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-209229-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id d75a77b69052e-44038a6e78csi122511161cf.156.2024.06.10.20.49.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jun 2024 20:49:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-209229-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=aJmJ0s1n; 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-209229-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-209229-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id CE1411C21C9F for ; Tue, 11 Jun 2024 03:49:25 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6D4B816FF3F; Tue, 11 Jun 2024 03:49:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="aJmJ0s1n" Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) (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 037A764B for ; Tue, 11 Jun 2024 03:49:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.174 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718077749; cv=none; b=JEv6/orRK/jbFpp7PumYrvKQmDVZyaLw1T91u0Q9KTjWhMOlJkSEbh3zeQLmuE9VfwVBd5B4nohp/GZqGSAUHBXX/0VK1mlICg6d+v7b6ob/xLgv8JIj4J23J7eHpbVvkf8lPsVYVZATSD0gbihtGE/o+4yXADTGdG/EM1bD7/0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718077749; c=relaxed/simple; bh=mvTHHduyDyQDcSxw/5hAysI9ob7z1i3HgWonMeyK0hQ=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type; b=pT+LqAeAEOr2XUR23fho2gDyu0lTiIZKtGnYO+SayNv3ClTeSoSQbBeYDSoHJo7+tKmDGofAAANHbY02cPiSqpUd3ieyHcjGoi51875YFTq6yC3JF0OAsq1Pc/iLlKKV2hPMHOOhlvDzT8klLieM2qN3pOqQ6uBySebr8hjvk4U= 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=aJmJ0s1n; arc=none smtp.client-ip=209.85.214.174 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-pl1-f174.google.com with SMTP id d9443c01a7336-1f6f1677b26so17313905ad.0 for ; Mon, 10 Jun 2024 20:49:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1718077747; x=1718682547; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=zbet/qCsm/2TCPHjObU4qdEEAftnzY0yLDlxMiRcwWc=; b=aJmJ0s1nNCfok8MN5htb3ghFfug89AbR6nQZ3dodzgMbQzYF14rEzCz0ZHUiLP8bUR AfvBPAozQFav9HDj2Gz5iKDBFyBCrlhiLbZ6i3ZPQ9cHgYUgvHnv5W1fa2zKIpwwmScc hrosDXehtUM5lw1lQ7AkQfi8BGOVgsm7bsf9E= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718077747; x=1718682547; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=zbet/qCsm/2TCPHjObU4qdEEAftnzY0yLDlxMiRcwWc=; b=drmUzdpLSBCOB8Xrk7vowgSvQTgtZi3knNBFcmJWY3OkoK+1dSGrFWRiGoMGeFLdAY era/XhImCaNx0kYNrjFBlhy87qXIuYFeELyiRFhKkI2Ldu2CZkacBM6lw0AQocxv6k7u iGEe14CUjuGKCFsv1PPxPOVAho8I1GlhwUZzRJlDaSR2pSI4vpbngvNiGD4oSyTyv7Lv I87MF6qFuikMrgWjAl3Yx696H25Ourqt+3ZIOMddJf2d7TOc7BdieEqE71WPZR2BZbB3 5VHyxthSatYa2jJsoq7nfhHwb7LXmw1RUWhYDJUIq7BC9iCIAdpJnfkJCufd1NDFtoYO 3aXg== X-Forwarded-Encrypted: i=1; AJvYcCVHf0ER0E48/im9oENYTfh0uiV3L03i997an/6iL8yqfVcSYwPBGGtr/zn42m4P4fb2wMRZ7nG7YPSlmXoYDu6K+R5+0VdLshncfaLd X-Gm-Message-State: AOJu0YyI6M/FEdTYQic+LvPCmN+DCmxycTZKXX+NGtizyqy05yQHCxK8 eBKd/G8TzQwp6BWy8JrzW808uo+MREUsuzJJpN7cl++k6b7uS4uY4psDZRdVoQ== X-Received: by 2002:a17:902:a617:b0:1f7:1b42:42f3 with SMTP id d9443c01a7336-1f7287bc2a5mr14848415ad.18.1718077747267; Mon, 10 Jun 2024 20:49:07 -0700 (PDT) Received: from localhost (213.126.145.34.bc.googleusercontent.com. [34.145.126.213]) by smtp.gmail.com with UTF8SMTPSA id d9443c01a7336-1f6bd7e05d4sm90373605ad.191.2024.06.10.20.49.06 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 10 Jun 2024 20:49:06 -0700 (PDT) From: jeffxu@chromium.org To: rdunlap@infradead.org Cc: akpm@linux-foundation.org, cyphar@cyphar.com, david@readahead.eu, dmitry.torokhov@gmail.com, dverkamp@chromium.org, hughd@google.com, jeffxu@chromium.org, jeffxu@google.com, jorgelo@chromium.org, keescook@chromium.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org, pobrn@protonmail.com, skhan@linuxfoundation.org, stable@vger.kernel.org Subject: [PATCH v2 0/1] mm/memfd: add documentation for MFD_NOEXEC_SEAL Date: Tue, 11 Jun 2024 03:49:00 +0000 Message-ID: <20240611034903.3456796-1-jeffxu@chromium.org> X-Mailer: git-send-email 2.45.2.505.gda0bf45e8d-goog Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Jeff Xu When MFD_NOEXEC_SEAL was introduced, there was one big mistake: it didn't have proper documentation. This led to a lot of confusion, especially about whether or not memfd created with the MFD_NOEXEC_SEAL flag is sealable. Before MFD_NOEXEC_SEAL, memfd had to explicitly set MFD_ALLOW_SEALING to be sealable, so it's a fair question. As one might have noticed, unlike other flags in memfd_create, MFD_NOEXEC_SEAL is actually a combination of multiple flags. The idea is to make it easier to use memfd in the most common way, which is NOEXEC + F_SEAL_EXEC + MFD_ALLOW_SEALING. This works with sysctl vm.noexec to help existing applications move to a more secure way of using memfd. Proposals have been made to put MFD_NOEXEC_SEAL non-sealable, unless MFD_ALLOW_SEALING is set, to be consistent with other flags [1] [2], Those are based on the viewpoint that each flag is an atomic unit, which is a reasonable assumption. However, MFD_NOEXEC_SEAL was designed with the intent of promoting the most secure method of using memfd, therefore a combination of multiple functionalities into one bit. Furthermore, the MFD_NOEXEC_SEAL has been added for more than one year, and multiple applications and distributions have backported and utilized it. Altering ABI now presents a degree of risk and may lead to disruption. MFD_NOEXEC_SEAL is a new flag, and applications must change their code to use it. There is no backward compatibility problem. When sysctl vm.noexec == 1 or 2, applications that don't set MFD_NOEXEC_SEAL or MFD_EXEC will get MFD_NOEXEC_SEAL memfd. And old-application might break, that is by-design, in such a system vm.noexec = 0 shall be used. Also no backward compatibility problem. I propose to include this documentation patch to assist in clarifying the semantics of MFD_NOEXEC_SEAL, thereby preventing any potential future confusion. This patch supersede previous patch which is trying different direction [3], and please remove [2] from mm-unstable branch when applying this patch. Finally, I would like to express my gratitude to David Rheinsberg and Barnabás Pőcze for initiating the discussion on the topic of sealability. [1] https://lore.kernel.org/lkml/20230714114753.170814-1-david@readahead.eu/ [2] https://lore.kernel.org/lkml/20240513191544.94754-1-pobrn@protonmail.com/ [3] https://lore.kernel.org/lkml/20240524033933.135049-1-jeffxu@google.com/ v2: Update according to Randy Dunlap' comments. v1: https://lore.kernel.org/linux-mm/20240607203543.2151433-1-jeffxu@google.com/ Jeff Xu (1): mm/memfd: add documentation for MFD_NOEXEC_SEAL MFD_EXEC Documentation/userspace-api/index.rst | 1 + Documentation/userspace-api/mfd_noexec.rst | 86 ++++++++++++++++++++++ 2 files changed, 87 insertions(+) create mode 100644 Documentation/userspace-api/mfd_noexec.rst -- 2.45.2.505.gda0bf45e8d-goog