From patchwork Fri Jun 30 03:25:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Xu X-Patchwork-Id: 114545 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp10079241vqr; Thu, 29 Jun 2023 20:43:49 -0700 (PDT) X-Google-Smtp-Source: APBJJlEX7JGAHVZLLBkN5i+WzEQMMRZ1xGukxWCJ1eErYB9E4JSwYTvMRkK6Cx5yR/RD7EqSb1VJ X-Received: by 2002:a17:903:786:b0:1b3:ec39:f42c with SMTP id kn6-20020a170903078600b001b3ec39f42cmr1063470plb.5.1688096629455; Thu, 29 Jun 2023 20:43:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688096629; cv=none; d=google.com; s=arc-20160816; b=HC6eWVWGxosMmIObXuw0ELnVZ75+5vMhosfQuSRXPjjid65snYUrZ3dnzv0N/0UYQ2 nic2gAhttRJT7M57qyw11AfoVXtpNTbxBq30zecv80ANVxjwAtS6rTWZmkNbe0Dpe0xq xmC+xFSrJ5H11J3VCV+tWbH6xPlzH1Ru6l5fr5V05KG8UzCr+xPskcsAWJeHlyIJojUj JMNqyoilMcO8PSMFpjTO32IGvJxZ4qQesOojGq58uRMdiXu1ruVuBQ/r3l1D31VMMs+Q iYFIlJtbT63GJrZCWq3OVViBuiUGZPZ/rxT9LICIJhnFsqYuUa0rAXn69Zs6nj4r91bY b07Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=gG0p2NxJxfYPPHk57XaDb7PRgK5Ncrcc/zrK6bcWJBo=; fh=+wFwOUChBMDyUEg63FIGralHY9qRggLvyZTCULGydUc=; b=CAdyBzdyJtkIhyTXg5EDexyDW9wRaeluEoRES/4hDJP2Nh1D/qTygdGwVnv2nDT5gS Yrsg+St1Zn+vg/oiQ0l2JUrr2Q30Dd8xzXQNfO663kw/zwpLoDZmOeDoew4/z9Jnb8cx HRTEhCYsOJk2G3QBPYcgmOA4cMJ54VtAuHExXiMFCyz1ng43l4UUSwMz6DP5Z/r4ZOyE nDj4es4Vjv/6mdQnJ0Zb1zzeUj3i5ihIgMU3ZOoI1jmS7CK2P3jyCQ1nOEvqbrIiBl1h f8ERIoMJf10r/6J/ea00iz2XQ+vtWk5YMQQ9opHl7YEjaeGkhNT+kLOiXpnd0Lm57tNw aH3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=bWbcBjLe; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p8-20020a170902e74800b001b849afa713si3073949plf.4.2023.06.29.20.43.36; Thu, 29 Jun 2023 20:43:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=bWbcBjLe; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231984AbjF3DZq (ORCPT + 99 others); Thu, 29 Jun 2023 23:25:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41390 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231655AbjF3DZk (ORCPT ); Thu, 29 Jun 2023 23:25:40 -0400 Received: from mail-pf1-x42d.google.com (mail-pf1-x42d.google.com [IPv6:2607:f8b0:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3197D35A0 for ; Thu, 29 Jun 2023 20:25:39 -0700 (PDT) Received: by mail-pf1-x42d.google.com with SMTP id d2e1a72fcca58-666edfc50deso892122b3a.0 for ; Thu, 29 Jun 2023 20:25:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1688095538; x=1690687538; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=gG0p2NxJxfYPPHk57XaDb7PRgK5Ncrcc/zrK6bcWJBo=; b=bWbcBjLe/HmjBUDi0chJKHI1VfwXeVHFrwoWQ6d5F3ktM+1Hx4SU0oGAk43uPUCNJS fay+/AQYi1YyouUv9X87uiVa71QR3+42BgL6odKqwm0xDf4ur4NY6vRttiQcU8fa9H7C BbtQfAx2ouVJRy+ccgkoOOaFpSGcWKEme9h7w= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688095538; x=1690687538; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=gG0p2NxJxfYPPHk57XaDb7PRgK5Ncrcc/zrK6bcWJBo=; b=RDlw+m5j7nWvwhCmL4Lh/EWtyjGL4LgAnc7+5RonwUhgDO6nIEW6UPV5e9whlbNHH7 5SIIFk0Ukd6U9ckuRPi6FvB/pGBvmSsFqJYGYe4wupGPiSTmp1tD8+fVpUG2RUwHjWgQ 8zwzioUYwNtAuonuklRZ6bLgJQFBMmY92gYg3HF0a3h8+71TzW3lJIBZRROqLE3RM3wh AxYMwBFmFgMJw9pqoBBvj9aDrgha3GJ0R6ovgJC6eF321QuhMuWlPcDqA0euo5lwySEF eLrjuIlrWPWLA9D4bA2hUsPlUIjp0uf8xcfrKZ/4YtnEr1320m2JwnOWjHBjFJCgI2xf r06Q== X-Gm-Message-State: AC+VfDyYeVIY++PMYXdoOdICshGgk8myUm5nnqLiKLm/+wDeqyZvr6MI tGyLD4UWu1i6sRXJhn45iTb4Bg== X-Received: by 2002:a05:6a00:27aa:b0:657:1fe5:eb63 with SMTP id bd42-20020a056a0027aa00b006571fe5eb63mr7433745pfb.7.1688095538633; Thu, 29 Jun 2023 20:25:38 -0700 (PDT) Received: from localhost (183.43.230.35.bc.googleusercontent.com. [35.230.43.183]) by smtp.gmail.com with UTF8SMTPSA id f4-20020aa78b04000000b0064fd4a6b306sm8973599pfd.76.2023.06.29.20.25.38 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 29 Jun 2023 20:25:38 -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, asmadeus@codewreck.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 Subject: [PATCH v3 1/1] Documentation: mm/memfd: vm.memfd_noexec Date: Fri, 30 Jun 2023 03:25:35 +0000 Message-ID: <20230630032535.625390-2-jeffxu@google.com> X-Mailer: git-send-email 2.41.0.255.g8b1d071c50-goog In-Reply-To: <20230630032535.625390-1-jeffxu@google.com> References: <20230630032535.625390-1-jeffxu@google.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1770097611428534613?= X-GMAIL-MSGID: =?utf-8?q?1770097611428534613?= 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 | 30 +++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/Documentation/admin-guide/sysctl/vm.rst b/Documentation/admin-guide/sysctl/vm.rst index 45ba1f4dc004..621588041a9e 100644 --- a/Documentation/admin-guide/sysctl/vm.rst +++ b/Documentation/admin-guide/sysctl/vm.rst @@ -424,6 +424,36 @@ 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 memfd_noexec at the time of fork. Changes to the parent +process after fork are not automatically propagated to the child +process. memory_failure_early_kill: ==========================