Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1509666rwb; Wed, 14 Dec 2022 11:03:49 -0800 (PST) X-Google-Smtp-Source: AA0mqf6I+q3jCDYnO1r9sTTc5a15iba6MJYJeSy+0num/UwfCKur3yITSXWyghvQOLG3gQ4D/JSf X-Received: by 2002:a05:6402:4486:b0:46d:53d7:d21e with SMTP id er6-20020a056402448600b0046d53d7d21emr23199695edb.27.1671044628821; Wed, 14 Dec 2022 11:03:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671044628; cv=none; d=google.com; s=arc-20160816; b=P/L5vyQMyMxygBYbhlC5mP+JWT8YJauplQfsTXReW7tMG8M8QFHj5bZAAomT78tI14 XyNE9+QIlNLg85Glz3Hb+RFrZJFg6ir52frPqaC0pq3/DXGDhJ6hHjRGrrLpjsON1XvN 0DYzFW9g7ot8OT5bAgrBtEOaYOfFJ8oDN1soTG3hHiyX6r5Yxk/1gEX6bPciLrKYQDse iMkoTIZGqVeHXzRfIWu4/+hLBKiRRvG09OgCx7lxZ/sprPYOIl98rHu3z7G0z2vwg+Fk DZc66aBxAONYbIWal/WGAgtYrHyBjx/3joqtJloeCXpnVh+Vq7qReAk89nNTND4sqVYa q9rA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=x9cSnaEhv8Xds1q1FVg4f4vmMN7yeuDq7gGdjSEFO6Y=; b=Y11mT8Ww1ca5XnfPH5wnMgFBVjina7Rq2pwuNhAoR41XzvfG2mAG0n/DYg6cIKA4Mk LLPM5o+Vienev5Rx5JL3wMcQ0fTokGpkxDm9uw33XvK8tOteuGmu2ppxpKjjMrXsS0J+ hQldcDQbqunjln5lunuhAB49XyyMCv18lNYD9RzB4Rh3UGJ8cmCUv5dGaZvJE1LzVBcE sLtYXp4K1+ytP2VerGb8sG6Bc63ufz9HF012eNwfxxeK9hFaYIJMdHH03MFA5HzXxX+h wQVeLCeduCKlx8vL7JngGfDcqq1euwf7U9ZSJJeQG5l/ZaVt1UQLEbsYaaAS643DAsA5 CuIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="DPayc+N/"; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q14-20020a056402518e00b0047338d1bfabsi347746edd.164.2022.12.14.11.03.22; Wed, 14 Dec 2022 11:03:48 -0800 (PST) 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="DPayc+N/"; 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 S238938AbiLNSxn (ORCPT + 70 others); Wed, 14 Dec 2022 13:53:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58962 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238896AbiLNSx1 (ORCPT ); Wed, 14 Dec 2022 13:53:27 -0500 Received: from mail-pg1-x52c.google.com (mail-pg1-x52c.google.com [IPv6:2607:f8b0:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AA0302A972 for ; Wed, 14 Dec 2022 10:53:20 -0800 (PST) Received: by mail-pg1-x52c.google.com with SMTP id 36so2583987pgp.10 for ; Wed, 14 Dec 2022 10:53:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=x9cSnaEhv8Xds1q1FVg4f4vmMN7yeuDq7gGdjSEFO6Y=; b=DPayc+N/6klm+cJJopr92jIZbcDzMcXAgHRTd0IdOF/l4lVMTfSv9uiMdbB9vgE7Rn KbN0Mf0w8PPxXiyyFo2dcpPrOOs/0smlRbhGYtuM7nD8UC7C5xF9GWVy9VrRO8OTEMv3 4YqQIBNhShJXwz7nnmrlPdy5R/1q13TzzW7ZY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=x9cSnaEhv8Xds1q1FVg4f4vmMN7yeuDq7gGdjSEFO6Y=; b=FaPF2sk5ns+aHmrSUWuNipBYz6vtpT1E3SNOhRC0Vb67I1HR2zHpLZf6zpiTAjc+Jv Ph5PbB7K6dfoe8UesdHoKGcO7sk2Q4h1D0lwIQjzqmmfgUAGAeT9oz7fKkKXwtBy+qkG SzRsu32lQVWpNShS0xLVV1qVsfTvKtOckUSoe9mFFf6anHXqnQB+t7aLJJCQwtONZE3H cpy52AobdYNdYhYLzjUduYwaqNOIsi9exlGrgtXjkIcjsK8PQFGEaiVsUPAODflfswqU IjK7vKItD+c7Rruq1baarQ3z3xTrHWKGhX9y+0AvEMzP4hYl8pDkHTpAeE6HgZwrYnOV +ohw== X-Gm-Message-State: ANoB5pmRTzkVDA4QlbD87lTwTzE4hkVt6V70F3/rp9HmqfaP9RUSQKUJ nE09SI1LM9xDI4dbu473m6+K3Q== X-Received: by 2002:a05:6a00:791:b0:577:f836:6bcb with SMTP id g17-20020a056a00079100b00577f8366bcbmr23822313pfu.29.1671044000031; Wed, 14 Dec 2022 10:53:20 -0800 (PST) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id c129-20020a624e87000000b0056b9ec7e2desm198403pfb.125.2022.12.14.10.53.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Dec 2022 10:53:19 -0800 (PST) Date: Wed, 14 Dec 2022 10:53:19 -0800 From: Kees Cook To: jeffxu@chromium.org Cc: skhan@linuxfoundation.org, 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, kernel test robot Subject: Re: [PATCH v7 3/6] mm/memfd: add MFD_NOEXEC_SEAL and MFD_EXEC Message-ID: <202212141053.DD016F79B@keescook> References: <20221209160453.3246150-1-jeffxu@google.com> <20221209160453.3246150-4-jeffxu@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221209160453.3246150-4-jeffxu@google.com> 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 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 On Fri, Dec 09, 2022 at 04:04:50PM +0000, jeffxu@chromium.org wrote: > From: Jeff Xu > > The new MFD_NOEXEC_SEAL and MFD_EXEC flags allows application to > set executable bit at creation time (memfd_create). > > 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 sysctl allows finer control of memfd_create for old-software > that doesn't set the executable bit, for example, a container with > vm.memfd_noexec=1 means the old-software will create non-executable > memfd by default. Also, the value of memfd_noexec is passed to child > namespace at creation time. For example, if the init namespace has > vm.memfd_noexec=2, all its children namespaces will be created with 2. > > Signed-off-by: Jeff Xu Reviewed-by: Kees Cook -- Kees Cook