Received: by 2002:a89:d88:0:b0:1fa:5c73:8e2d with SMTP id eb8csp301910lqb; Thu, 23 May 2024 20:39:56 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXIsX7/YVzCy0U8bW56Niit4mL9b7iRDPlNKS6zC0lwqzeYz7T36kR2aaTKlFa+oVg7FDcziCWRbLFmD62Cb4wPSfp6tsJpRxcHvGHF0w== X-Google-Smtp-Source: AGHT+IFleObvZxCgmbKuEuf1VqzcwY6pKGLV6qFhZRrv68DnFsrz3lmbfZYcnnNKF4TYTywsQsbj X-Received: by 2002:a50:ab47:0:b0:574:ea68:a813 with SMTP id 4fb4d7f45d1cf-578519a1dbcmr491710a12.32.1716521995929; Thu, 23 May 2024 20:39:55 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716521995; cv=pass; d=google.com; s=arc-20160816; b=DxEnVvGa+cGc8icdgtnq16u/+PKmUmrFlHguVvQynas87QGYe+q+ICylRB6usSi96X mjdB1wkLeULt3db7QjQMcH4qulZDY3iGbjX16mS1F/Ut7etoxYxJlM6Vm7CTdOHR61Eu Kx3OgzMazOZnWN0c8/Dd4g5EqwmIBXWC1MW9dFCHDSJ2n3qQPCgSftCgSrcXVyjPEitA Y3M/mGWPWA/yXYWn6de6mUCo1lDek/s8aiC9v0Vg3rgAi0qvV+9i/bGly9UA9+ShJqzX J+Qq0Ec3HCIA5uZnX8rhQqdHygElIpGemjUc4icg8ocJdaaIV1bYnppc6EMCtiY+zJ3W WSvg== 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=ZZM+C443YkAbqJrVfa7/d/V0qYnAraDfxHHb3nzF0+w=; fh=TTvX6n9nOjeSqKJXuyI/o7eQ1+PZn2J3rplunBEyzI4=; b=XtuGCmvM/rmsQNdED7XQuR3kZekU++W0ek7pIEzVtTS1LW5lwMNUvK5AV7BlEMhbaR /5U2fRcnhoGM+8gVA2weEVsZD14CmfasGURYoZzcDaHC7+O1MTsCpgEqjChhaeB2ddYs GAODtggU7x9LYNFFquG5wuQcnDoq1rfqI5lvtzTojriM8dU9qTpfU3UGory/BP4+0uYH 8+BAEKn8uYgmWPDCfwWLbOLSLDFkXBfEjoPeKNDSvj1uQLyLxp4gAWj2K0dW5mQ2JKx3 qrUNRcaDITlID9Ae44+VeVEqQ+F4FaPzqUNeYZyf9RoUfEUzfzigFpEyr7KL5UvC8JYK MLfw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="U/W/eTrJ"; 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-188267-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-188267-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id 4fb4d7f45d1cf-578524b54ffsi375115a12.544.2024.05.23.20.39.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 May 2024 20:39:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-188267-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="U/W/eTrJ"; 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-188267-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-188267-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 7884F1F21904 for ; Fri, 24 May 2024 03:39:55 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A2BA63770D; Fri, 24 May 2024 03:39:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="U/W/eTrJ" Received: from mail-pg1-f172.google.com (mail-pg1-f172.google.com [209.85.215.172]) (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 561B322F03 for ; Fri, 24 May 2024 03:39:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716521984; cv=none; b=IIA2H6/F1t4cSKAIr69rTNI4O+acfGNgUY81n3bcH8he683i/b2YNaiPCynYjfblZMYRMM9yDqyd1Eg9FHt9RCTot3bGvxO/QNvTIE8UN70PcVxMyi5df+nKLp3QMIgV1ox1ZaoJWhk1w76V5eH+1Vk98XdDY1D8D2uE2aizOZo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716521984; c=relaxed/simple; bh=P8hmXNe9pVfxehRdEFph7gYxFMRHhtBZuM9VKZou2o0=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type; b=GkEd2prHRYQZ0ROn3K1RwRledpaSEMQmjo7njlI4keX/cNgztEnZV4TPQAS2gaf18pbk/0aZgegwOSHiLKJHedETbkYVhCBeHCHK70oLLgKMd+TOPwHtCx8RjDZxt7j62toXGgGoe2Cu6IMm9PX91jSkS651aT8vJ8SuL22+Fes= 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=U/W/eTrJ; arc=none smtp.client-ip=209.85.215.172 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-pg1-f172.google.com with SMTP id 41be03b00d2f7-657a07878easo2656839a12.0 for ; Thu, 23 May 2024 20:39:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1716521982; x=1717126782; 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=ZZM+C443YkAbqJrVfa7/d/V0qYnAraDfxHHb3nzF0+w=; b=U/W/eTrJ7Ed6VUBIzN5zPDPOZz6RZvoLRrQHLJ03VSYFLfEHQx5dLddic6gvUSSoWY VjwDP9OfGDToWqcKtf4LBNKI+M/8amM/Jc93Boy/q6Wf0vSbmMtiU20bIlxVL+5f210F vxVlEnzN5YKJF+RNmPPoiRmYd7z7psp2e6Sag= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716521982; x=1717126782; 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=ZZM+C443YkAbqJrVfa7/d/V0qYnAraDfxHHb3nzF0+w=; b=CdHr1Utqn4DH8fbE4vzGsU1h3+LyneB+0iHo+4uH4uclThgIuiRhbXhY9blW58jdzH otMNILSq3N75nvffdZNnNzOBRpp7ua/NDckIxXB1ZoIx20plNeCBGTekwoU9s6kb5xTh 7MiSANzQEWw3sb0zVx9ITlChVzFajIglsj8CrlxO3Bck+3giiBFcFl7sUwbGsHAOqvhN drW8IOAJvhq9A53VNhDpAUPAqUzl21tAjzu0SUaZMsTXksepw5PQJ7EPLFAhkQbe9maS XKojPbA+zOfe0w+31k3qjz7mpWHovZ6eAtyrMkAx86hdUlOJtb6BPOgytp8EnfOhvU0N yXAw== X-Forwarded-Encrypted: i=1; AJvYcCXvqqdFJs7x05V+F+PZpAVixvqZpjFjRFpaHw2pyctqqkCzzbG0re4DCiROkJ2caxrW1kaAXJcz0QdNTYeabNbJ4NHZmZWLqjfjoh1c X-Gm-Message-State: AOJu0YwEOm1mROeEMfRUaQKFoLjEtfIkx46ZDH28NPDg+nsFEqTojwej efkVEkm71ukQMzI7zy10q8kMrKkHGDupF04+6Q4N3Zk/N+A6QYTaKKFJs3p7ag== X-Received: by 2002:a17:90a:d18b:b0:2bd:92b3:a18c with SMTP id 98e67ed59e1d1-2bf5e84acc5mr1266399a91.3.1716521982456; Thu, 23 May 2024 20:39:42 -0700 (PDT) Received: from localhost (197.59.83.34.bc.googleusercontent.com. [34.83.59.197]) by smtp.gmail.com with UTF8SMTPSA id 98e67ed59e1d1-2bf5f61272fsm405503a91.27.2024.05.23.20.39.42 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 23 May 2024 20:39:42 -0700 (PDT) From: jeffxu@chromium.org To: jeffxu@google.com Cc: jeffxu@chromium.org, akpm@linux-foundation.org, cyphar@cyphar.com, dmitry.torokhov@gmail.com, dverkamp@chromium.org, hughd@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 Subject: [PATCH v2 0/2] memfd: fix MFD_NOEXEC_SEAL to be non-sealable Date: Fri, 24 May 2024 03:39:29 +0000 Message-ID: <20240524033933.135049-1-jeffxu@google.com> X-Mailer: git-send-email 2.45.1.288.g0e0cd299f1-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 By default, memfd_create() creates a non-sealable MFD, unless the MFD_ALLOW_SEALING flag is set. When the MFD_NOEXEC_SEAL flag is initially introduced, the MFD created with that flag is sealable, even though MFD_ALLOW_SEALING is not set. This patch changes MFD_NOEXEC_SEAL to be non-sealable by default, unless MFD_ALLOW_SEALING is explicitly set. This is a non-backward compatible change. However, as MFD_NOEXEC_SEAL is new, we expect not many applications will rely on the nature of MFD_NOEXEC_SEAL being sealable. In most cases, the application already sets MFD_ALLOW_SEALING if they need a sealable MFD. Additionally, this enhances the useability of pid namespace sysctl vm.memfd_noexec. When vm.memfd_noexec equals 1 or 2, the kernel will add MFD_NOEXEC_SEAL if mfd_create does not specify MFD_EXEC or MFD_NOEXEC_SEAL, and the addition of MFD_NOEXEC_SEAL enables the MFD to be sealable. This means, any application that does not desire this behavior will be unable to utilize vm.memfd_noexec = 1 or 2 to migrate/enforce non-executable MFD. This adjustment ensures that applications can anticipate that the sealable characteristic will remain unmodified by vm.memfd_noexec. This patch was initially developed by Barnabás Pőcze, and Barnabás used Debian Code Search and GitHub to try to find potential breakages and could only find a single one. Dbus-broker's memfd_create() wrapper is aware of this implicit `MFD_ALLOW_SEALING` behavior, and tries to work around it [1]. This workaround will break. Luckily, this only affects the test suite, it does not affect the normal operations of dbus-broker. There is a PR with a fix[2]. In addition, David Rheinsberg also raised similar fix in [3] [1]: https://github.com/bus1/dbus-broker/blob/9eb0b7e5826fc76cad7b025bc46f267d4a8784cb/src/util/misc.c#L114 [2]: https://github.com/bus1/dbus-broker/pull/366 [3]: https://lore.kernel.org/lkml/20230714114753.170814-1-david@readahead.eu/ History ====== V2: update commit message. add testcase for vm.memfd_noexec add documentation. V1: https://lore.kernel.org/lkml/20240513191544.94754-1-pobrn@protonmail.com/ Jeff Xu (2): memfd: fix MFD_NOEXEC_SEAL to be non-sealable by default memfd:add MEMFD_NOEXEC_SEAL documentation Documentation/userspace-api/index.rst | 1 + Documentation/userspace-api/mfd_noexec.rst | 90 ++++++++++++++++++++++ mm/memfd.c | 9 +-- tools/testing/selftests/memfd/memfd_test.c | 26 ++++++- 4 files changed, 120 insertions(+), 6 deletions(-) create mode 100644 Documentation/userspace-api/mfd_noexec.rst -- 2.45.1.288.g0e0cd299f1-goog