Message ID | 20240524033933.135049-1-jeffxu@google.com (mailing list archive) |
---|---|
Headers | show
Return-Path: <owner-linux-mm@kvack.org> X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 67D01C25B74 for <linux-mm@archiver.kernel.org>; Fri, 24 May 2024 03:39:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 056FA6B009D; Thu, 23 May 2024 23:39:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 006E46B009E; Thu, 23 May 2024 23:39:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E37B86B009F; Thu, 23 May 2024 23:39:45 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id C638E6B009D for <linux-mm@kvack.org>; Thu, 23 May 2024 23:39:45 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 8E2B9A07A2 for <linux-mm@kvack.org>; Fri, 24 May 2024 03:39:45 +0000 (UTC) X-FDA: 82151885130.19.42D317F Received: from mail-pj1-f50.google.com (mail-pj1-f50.google.com [209.85.216.50]) by imf09.hostedemail.com (Postfix) with ESMTP id BEA5A14000C for <linux-mm@kvack.org>; Fri, 24 May 2024 03:39:43 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=ZCCv44Cu; dmarc=pass (policy=none) header.from=chromium.org; spf=pass (imf09.hostedemail.com: domain of jeffxu@chromium.org designates 209.85.216.50 as permitted sender) smtp.mailfrom=jeffxu@chromium.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1716521983; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:in-reply-to: references:dkim-signature; bh=ZZM+C443YkAbqJrVfa7/d/V0qYnAraDfxHHb3nzF0+w=; b=0PPQUqiPuITELJmaxwN69lGeyHShUHMnP2x6aGoxUCFoemecXnsSY9HTcFrVMmIjpeFj6w pDvhc2YvNLEWz23Vz8TChHqKi3sP7L0bJ0nMtzKWq4l4eX1C0J2i5FS4fCLNPLMcbseefR 1JtRvGbH9xsqr/zmyZJbWRocO+iO7gE= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=ZCCv44Cu; dmarc=pass (policy=none) header.from=chromium.org; spf=pass (imf09.hostedemail.com: domain of jeffxu@chromium.org designates 209.85.216.50 as permitted sender) smtp.mailfrom=jeffxu@chromium.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1716521983; a=rsa-sha256; cv=none; b=XTeFPBH6pd8kcuiKzqSrLNEtiuSWZoI13GKcPsf5YIlxIuGo6xsHo9PFe57z7Jg6aNTRbh p37HKkKs7lCaPMIGYIvTLhjPL7KHbRvSfqxzSyZEJ2AJVBkAoVP9sOFzc96xAmwcjq2AdX LMZCaN4iQDp6rUkv4s1p7YbInVGW+dg= Received: by mail-pj1-f50.google.com with SMTP id 98e67ed59e1d1-2bf5baa2773so427474a91.0 for <linux-mm@kvack.org>; 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=kvack.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=ZCCv44CuPvJKTFn6jBt4GBDty8ykyPt5Krz4zDGyjIHQOepzL++U0w4OZXt5Cgx6S1 OlE4R4KlDROCQ0b5JOFkigdlIwmR41BMizdEx6o4b5+HGjCn9ZZh5UwQ2+npHmws0IVw OYcdcwRH3IuK46A2+LtWftTpV+EcFOdzs7k1Q= 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=PPZVUVx5NSuRVXKuxh9zGbKvAvvZic1ZiOTyId3I52lie5TDZKrs/b6AN5mirA2hny 7iL8WTAnDYpRAAfshiO9QdHggQrR+cUx8fI+uK1FtwEpqSPiEkNkAwCBirkvvYwmebD0 to5hbONc9TdbFAePNArjBcLpVF3i9bq+Cq5px8BcANR2Rp/9woLBnHSypRPpRdA4gdY6 8jpsLKxGXRffcu3fT15RW3hM92s3KbyQLw2kullNYEUQNxWibc1VZE2gNlKuyebP8FcK THIOGKerjQaLB8myzLyFXLHnLMv0xtl7xjWnQsqsJeYFmVkZYgz2qgjg2UmDbD6mWB4k QhIg== X-Forwarded-Encrypted: i=1; AJvYcCWONU7RAYhK2mPTGMwhyG2L2G9avHa+lrDoeaEkiI1HUWYZhxIL/aUjiQqfnuh1qASNFQBQVjlyx17jGHADfEbo7v8= X-Gm-Message-State: AOJu0Yy75c51J7pz1WI85LLkhXpLgDVN/YZj3jOCPZPG8XTWTn2pCohf TZTR4jvJnF9cGWZn2Tv5JukoEckcSncyLYCmqgc8MbYeof5YoHO87J/YM7He5A== X-Google-Smtp-Source: AGHT+IERupiu47qJljsmVu1JdjLbKzVfc9DMWEHXDw9WaIvbcwYeeqWAwGzBdeP97EVsJttoCi5QSg== 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 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: BEA5A14000C X-Stat-Signature: 74xnhyrersxnefuf9wknqi6d7uddsf57 X-Rspam-User: X-Rspamd-Server: rspam04 X-HE-Tag: 1716521983-823770 X-HE-Meta: U2FsdGVkX1+VBK826hAI2cowHvAa8EdbE20lVEXJBQfeYdzahSNzULo6ynmD6OvvriZ/nhVLiaR/6djx7xtnDtz7vjW6/nMXurccUdTcDlt/NBnzXLoC4CCsHbtBABifH015kGzE4U6p04ThYJgWVcH4KB0k+bs8ixqUIoJV/CDnZIRg6XqAhe7WkgPSx/zX0vIExmi7x1EHlTKkH0cTLMTJL+oNSxmQt79uJzZoMpSaDjU44GtOSnbRVtH4z63taPPXM9evXnlWB5HI8oqzQMoQ3Rl9NGERcFvJQgCHfhWVuRzqow5FnVlzvIqWBwujFN3Az8FnckPCN1KIqE3mtQlh1Fb1f+l/uqQZpRH32dmlHTWGOQVjKfXI9lOpQF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QKn4KSKZNaPLHaXp1zHa7QzVV/Zen4tFRgpMoQuJ13jtgFFmz/7b/Kqbpl7ngFUEKryoQobF9mR/95lZVw5au+W3084aBM5Rd7RRlYWLgkmIqbWz7tbB8UOBbAtCguWj6J7ak+Ha49+BJn37UzUAJRgSr5J3ZZ4jVdxnbTWnGiGlE4GD/709qcui5qUvpgrkwrjATBQDrkbgZVFU= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: <linux-mm.kvack.org> List-Subscribe: <mailto:majordomo@kvack.org> List-Unsubscribe: <mailto:majordomo@kvack.org> |
Series |
memfd: fix MFD_NOEXEC_SEAL to be non-sealable
|
expand
|
From: Jeff Xu <jeffxu@google.com> 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