From patchwork Thu Jun 29 23:25:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Xu X-Patchwork-Id: 13297420 Return-Path: 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 9C8F7C001B3 for ; Thu, 29 Jun 2023 23:25:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DACD38D0002; Thu, 29 Jun 2023 19:25:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D5D788D0001; Thu, 29 Jun 2023 19:25:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C25008D0002; Thu, 29 Jun 2023 19:25:08 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id AF6C38D0001 for ; Thu, 29 Jun 2023 19:25:08 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 7C9BF160CEB for ; Thu, 29 Jun 2023 23:25:08 +0000 (UTC) X-FDA: 80957368296.12.ED404A3 Received: from mail-ot1-f47.google.com (mail-ot1-f47.google.com [209.85.210.47]) by imf23.hostedemail.com (Postfix) with ESMTP id BA8F8140018 for ; Thu, 29 Jun 2023 23:25:06 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=DIOrkzvu; dmarc=pass (policy=none) header.from=chromium.org; spf=pass (imf23.hostedemail.com: domain of jeffxu@chromium.org designates 209.85.210.47 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=1688081106; 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-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=8XkUN0EizrcPJdxYDyml9MD9K5nwnJEgupZt44caww4=; b=T8hkTLUCJOVoTafF6lmSaKwY/PgWBBbsS4tva4TW9MV3XpdtbDWCiIS+rIhQNWc8f0DZf6 uwtKgNfgUMW5krJFrtldYpneGsj/VeRhIwreHRwuqH7agQKD5v9xCWHQRcxi+8HCbiKIcx FZZT1InwnDJp9z01Js5mFHiFLYY74y8= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=DIOrkzvu; dmarc=pass (policy=none) header.from=chromium.org; spf=pass (imf23.hostedemail.com: domain of jeffxu@chromium.org designates 209.85.210.47 as permitted sender) smtp.mailfrom=jeffxu@chromium.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1688081106; a=rsa-sha256; cv=none; b=rLlwIYMlYJy0q6V2dowdHOYg+G+2jhZks9chYvlsqi5BgTAMj0fK2JoGh1xVJmUDaSjA+0 gwykmSjcJGFZgG1/+Uaf3MISCsHbwtzNBxU3qnQjbOhJBVg7lwR4omeq6GLwTcemQ+Txqb 2CbS7h4q+jk729u0/DUfRd2VLTxY6Ac= Received: by mail-ot1-f47.google.com with SMTP id 46e09a7af769-6b708b97418so1031053a34.3 for ; Thu, 29 Jun 2023 16:25:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1688081106; x=1690673106; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=8XkUN0EizrcPJdxYDyml9MD9K5nwnJEgupZt44caww4=; b=DIOrkzvu8itXrRDVqrYwNUO8RR/O0uEKATtMBGoLT7ZDMAULfOV2+XLpRMwb4lSo1H o8f4vm7uBwP6nRhUwyvViY15Yn73fB6S5rSl+En04NKl9NuKOjDAks0aqXtGB6itZkTx hFE5wR4rTEM4DrLYzlMegMS5O2+oAyJQsqHkE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688081106; x=1690673106; 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=8XkUN0EizrcPJdxYDyml9MD9K5nwnJEgupZt44caww4=; b=crIcODDDuM2tCZ3IUNAG3J0+SsZ5MtkukexZgMvnk8pMOhY94mNOXedwA77aBUTYwV 1vhRLT+WASzqKDVDitNi72ijf714msUC7Y3vGWyJKyDdLeGvXx3Gid4HidT4vCPh+Oc2 pkr6g6qPYOcytTOMFzvBDvFXOgJRRAI8Jl58X6+ULjkNUnTUJjjZsdYTkLnSyRlKtG9q 8weN9Xw4faA5gCNht6gRM49vjnFXzxqWDo6hODQn6Ff+P15MjDgeVPQZ51MjVG5U0BLa TRe34CUOw8qDNGZYwWBf7d7nJhEqGuFDp4meU1OlrZae4la4ASAgbPC5VLNBT7BrDHfX wJsw== X-Gm-Message-State: AC+VfDzwXX97tYpOZChnSesBuFxyHBSdWr7+elbXcKTVts4P8o4+Tp++ 7kYjADEg2Mx8TywN52oevB9nxg== X-Google-Smtp-Source: APBJJlGFQhB9pXlX/BZEhpArHhanMF0PsxvAgS8Ray5hkbYflejU/wjfaf/Ywe+hLWqeUIiTbaazMw== X-Received: by 2002:a05:6870:3c8c:b0:1aa:9eb6:974d with SMTP id gl12-20020a0568703c8c00b001aa9eb6974dmr1593876oab.41.1688081105835; Thu, 29 Jun 2023 16:25:05 -0700 (PDT) Received: from localhost (183.43.230.35.bc.googleusercontent.com. [35.230.43.183]) by smtp.gmail.com with UTF8SMTPSA id g15-20020a17090ace8f00b002636e5c224asm573038pju.56.2023.06.29.16.25.05 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 29 Jun 2023 16:25:05 -0700 (PDT) From: jeffxu@chromium.org To: skhan@linuxfoundation.org, keescook@chromium.org Cc: akpm@linux-foundation.org, dmitry.torokhov@gmail.com, dverkamp@chromium.org, hughd@google.com, jeffxu@google.com, jorgelo@chromium.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org, jannh@google.com, linux-hardening@vger.kernel.org, linux-security-module@vger.kernel.org, Dominique Martinet Subject: [PATCH] Documentation: mm/memfd: vm.memfd_noexec Date: Thu, 29 Jun 2023 23:25:01 +0000 Message-ID: <20230629232501.4157671-1-jeffxu@google.com> X-Mailer: git-send-email 2.41.0.255.g8b1d071c50-goog MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: kt7y7zczik6jxjbgsgq9ieotzkzynmhw X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: BA8F8140018 X-HE-Tag: 1688081106-344923 X-HE-Meta: U2FsdGVkX198jcWNuh2o7RCJI36MdDG3V0whB/dygkFILxDSnh8+mMAmuF0bYjqCZ8aYsnMgYw07GcDbbHPS+0mADxiUCRnOTqXDzn3e8kXqZujhM4xrOPy3T9v/lYDYZSf90bKjitRdHwdkkkIHbtzn+m2HUFM1O2s3+BH0vqPDc1nnRkPCDG+JZB0nLKC9f8XUaRW1xBzWZBj3Cx733LVV0CUSCEsqHdGJ9C6Q5oZbjPOz8iWoh6gxRxiCFVmsHOmM+mjaChQ0V4U9TF70WtTYPJ97hxkzaJghHJR0fY3gfYIhtGzgQGVcSLO0MrJGgsEqBE6gfzIR22DbPAIWSwcZBzumvc91+DkbDHxsygTCyy3nPpFX+kdeGHNj5xZxhRUKlRZZYJNx4Pt6rsS9E1sCSK7byw+/ZG/bC0efgFPqVfazgBPVKs8C8I0ksNs1bgnp7qK4JfRaZYu/GDqL/2wDEkK6tQDKj5zLQO5PV2kaINzQ989bMEls9T2mjy7XHsm6ZwmCVGAV5l6wscfRan2Kwv05J4hxpHXkJvunQ157MYb6ILwlhMSuETdvIqxfn6KAIv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kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Jeff Xu Add documentation for sysctl vm.memfd_noexec Link:https://lore.kernel.org/linux-mm/CABi2SkXUX_QqTQ10Yx9bBUGpN1wByOi_=gZU6WEy5a8MaQY3Jw@mail.gmail.com/T/ Reported-by: Dominique Martinet Signed-off-by: Jeff Xu --- Documentation/admin-guide/sysctl/vm.rst | 29 +++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/Documentation/admin-guide/sysctl/vm.rst b/Documentation/admin-guide/sysctl/vm.rst index 45ba1f4dc004..71923c3d7044 100644 --- a/Documentation/admin-guide/sysctl/vm.rst +++ b/Documentation/admin-guide/sysctl/vm.rst @@ -424,6 +424,35 @@ e.g., up to one or two maps per allocation. The default value is 65530. +memfd_noexec: +============= +This pid namespaced sysctl controls memfd_create(). + +The new MFD_NOEXEC_SEAL and MFD_EXEC flags of memfd_create() allows +application to set executable bit at creation time. + +When MFD_NOEXEC_SEAL is set, memfd is created without executable bit +(mode:0666), and sealed with F_SEAL_EXEC, so it can't be chmod to +be executable (mode: 0777) after creation. + +when MFD_EXEC flag is set, memfd is created with executable bit +(mode:0777), this is the same as the old behavior of memfd_create. + +The new pid namespaced sysctl vm.memfd_noexec has 3 values: +0: memfd_create() without MFD_EXEC nor MFD_NOEXEC_SEAL acts like + MFD_EXEC was set. +1: memfd_create() without MFD_EXEC nor MFD_NOEXEC_SEAL acts like + MFD_NOEXEC_SEAL was set. +2: memfd_create() without MFD_NOEXEC_SEAL will be rejected. + +The default value is 0. + +Once set, it can't be downgraded at runtime, i.e. 2=>1, 1=>0 +are denied. + +This is pid namespaced sysctl, child processes inherit the parent +process's pid at the time of fork. Changes to the parent process +after fork are not automatically propagated to the child process. memory_failure_early_kill: ==========================