Received: by 2002:a05:6358:111d:b0:dc:6189:e246 with SMTP id f29csp174079rwi; Wed, 2 Nov 2022 10:33:38 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7/OyL79GAPFW9gkeyTp8UBlBJmbw2KMbuJaGi77qjbIrtLlkKMiT4MQ3Ao77ih3DkBx8g2 X-Received: by 2002:a05:6a00:13a6:b0:56d:426b:4e98 with SMTP id t38-20020a056a0013a600b0056d426b4e98mr20828783pfg.54.1667410418464; Wed, 02 Nov 2022 10:33:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667410418; cv=none; d=google.com; s=arc-20160816; b=uZnpl8Zv13vwQhytpixXhGnSO2Icplp/lTHPDjB+vpkglP117IvBOBD/Stlz8w7o0c 9+OFkJ76xYRG/F1+A+b4SN6wk39ZzZWj+tHo1tgkzlSMPL64+viAtFWVwDBkfcUmLqil TSNHCeqg/91jVa2biKbMFyoTpTjv+Cto3m6vOxEi5Nzg7FoKtCusSPiv07O+GjsCnTs0 Klrd4OQnvNH7SMFSAyvQ0npAx5nMIxMDb6S2Ym0CGcRp7eyUsMA7MjJMPY0zvqMLEBBN fuzsgT3g9KSnvAE4Fxo3D22tMflSWzTkssR5enlzoWG038/7urkWL6fIUiduWbvYARpL qCsQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=RknuEqUoiunPXi2OLjUbhlEwq60lRe2RTsR6hdfQJ0Y=; b=QCDAkLli8I9xiDOlbnBi0NvUUIBxyOIyKm8PGjs3xS1AofWml5eFrvF+VpqiS3yxWP hvE9hmO4BTBSZV5L+PV06Z6/HfZSDSCuJ/kHk6J6LrQibrYKyoIQKnKCw3DNiM+SmmFT lkebo65PQ1sMMsr6a8fczE5q1KzlkpmRvba+MRoGiLB8zIe7fjRfFrIQ4ER4IBkm6a9A b5xiAkx7xNwAoi2rsTRbMqJoh4sCI2y6X5AxEPb6hwlNIdRFOOn9Ri4WFNKZqvPvlXVg br334oOIW+6hfVRsyBG+PAYgsSPxsaDncJLme9pXPLKsPU+f688GnxfX62CiHW9N5tH4 Iq+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=RRnZ2dze; 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 q8-20020a17090311c800b001769b63ec65si20317610plh.483.2022.11.02.10.33.24; Wed, 02 Nov 2022 10:33:38 -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=RRnZ2dze; 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 S230497AbiKBRS2 (ORCPT + 98 others); Wed, 2 Nov 2022 13:18:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44434 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230241AbiKBRSV (ORCPT ); Wed, 2 Nov 2022 13:18:21 -0400 Received: from mail-lj1-x233.google.com (mail-lj1-x233.google.com [IPv6:2a00:1450:4864:20::233]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 08087193D8 for ; Wed, 2 Nov 2022 10:18:20 -0700 (PDT) Received: by mail-lj1-x233.google.com with SMTP id x21so24538363ljg.10 for ; Wed, 02 Nov 2022 10:18:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=RknuEqUoiunPXi2OLjUbhlEwq60lRe2RTsR6hdfQJ0Y=; b=RRnZ2dze/6CLhyKFhxGEw08Ckp4XwE8DWxZ0rZxAOcMdf5vdt9kUpYu0i/LLqPGehj pYwLBE+/5Qto0rQ3PGtpUP8z7cfs5Z97tOSErjIiA7F6Gr0KhuXI0VS03iRzDSRFYUNa ZtYLM10ihngzyi4eQW3AMFVgmfH2JF5B4VVzM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=RknuEqUoiunPXi2OLjUbhlEwq60lRe2RTsR6hdfQJ0Y=; b=FU+zJuEx9DFQgUzOByGiNqfr6QqIRNPrxFhIblz5vekkNfkmK9L3VJy4eOH3RjL5uk pPNyXEu9wmk+j7zlCxlV8/FBR1Q5BYV1Nh/xlfeCTMWvOrusGRIZfxDNqdH4YIMT7X14 WkEC3gV9fIyB1FlICEVZPhJVvSCR6nyXmJ00NjdXd8ZuWEDFDDyH0uzTBNopgJORYGR5 f5DlKiuxjC4L5wLXc7ba+D8adPkwzZ3QpK1otzrD57MzfnBagB2+WKb8y6RYbV5r2J+B CcRzFiZf8CGYLzIYZjH2YQOadkOu9GjzYoHT1lKmyqn0Cx7f0aGysd49v/ZTFIV+JvzA udjw== X-Gm-Message-State: ACrzQf2zgKkVXLZH88mEB4c/9phcXZgihMDf/KCFlYH9SounDNEPGEpX eO/tPO9Ij0jKEg9pItbUeXbLSwRKV5WyfmfcXGqPPw== X-Received: by 2002:a05:651c:19a8:b0:277:3cb2:d9f9 with SMTP id bx40-20020a05651c19a800b002773cb2d9f9mr9918004ljb.278.1667409498411; Wed, 02 Nov 2022 10:18:18 -0700 (PDT) MIME-Version: 1.0 References: <20220805222126.142525-1-jeffxu@google.com> <202208081018.9C782F184C@keescook> <202211011933.DD0979338@keescook> In-Reply-To: <202211011933.DD0979338@keescook> From: Jeff Xu Date: Wed, 2 Nov 2022 10:18:07 -0700 Message-ID: Subject: Re: [PATCH v2 0/5] mm/memfd: MFD_NOEXEC for memfd_create To: Kees Cook Cc: jeffxu@google.com, skhan@linuxfoundation.org, akpm@linux-foundation.org, dmitry.torokhov@gmail.com, dverkamp@chromium.org, hughd@google.com, jorgelo@chromium.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org, mnissler@chromium.org, jannh@google.com, linux-hardening@vger.kernel.org, Aleksa Sarai , dev@opencontainers.org, Christian Brauner Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-3.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=ham 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 Tue, Nov 1, 2022 at 7:45 PM Kees Cook wrote: > > On Tue, Nov 01, 2022 at 04:14:39PM -0700, Jeff Xu wrote: > > Sorry for the long overdue reply. > > No worries! I am a fan of thread necromancy. :) > > > [...] > > 1> memfd_create: > > Add two flags: > > #define MFD_EXEC 0x0008 > > #define MFD_NOEXEC_SEAL 0x0010 > > This lets application to set executable bit explicitly. > > (If application set both, it will be rejected) > > So no MFD_NOEXEC without seal? (I'm fine with that.) > no MFD_NOEXEC because memfd can be chmod to add x after creation, it is not secure. no MFD_EXEC_SEAL because it is better to apply both w and x seal within the same function call, and w seal can't be applied at creation time. > > 2> For old application that doesn't set executable bit: > > Add a pid name-spaced sysctl.kernel.pid_mfd_noexec, with: > > bikeshed: vm.memfd_noexec > (doesn't belong in "kernel", and seems better suited to "vm" than "fs") > SG, will use vm.memfd_noexec > > value = 0: Default_EXEC > > Honor MFD_EXEC and MFD_NOEXEC_SEAL > > When none is set, will fall back to original behavior (EXEC) > > Yeah. Rephrasing for myself to understand more clearly: > > "memfd_create() without MFD_EXEC nor MFD_NOEXEC_SEAL act like MFD_EXEC > was set." > > > value = 1: Default_NOEXEC_SEAL > > Honor MFD_EXEC and MFD_NOEXEC_SEAL > > When none is set, will default to MFD_NOEXEC_SEAL > > "memfd_create() without MFD_EXEC nor MFD_NOEXEC_SEAL act like > MFD_NOEXEC_SEAL was set." > Copy, this is clearer. Thanks. > Also, I think there should be a pr_warn_ratelimited() when > memfd_create() is used without either bit, so that there is some > pressure to please adjust their API calls to explicitly set a bit. > Sure > > 3> Add a pid name-spaced sysctl kernel.pid_mfd_noexec_enforced: with: > > value = 0: default, not enforced. > > value = 1: enforce NOEXEC_SEAL (overwrite everything) > > How about making this just mode "value 2" for the first sysctl? > "memfd_create() without MFD_NOEXEC_SEAL will be rejected." > Good point. Kernel overwriting might not be a good practice. I will add to vm.mfd_noexec. value = 2: "memfd_create() without MFD_NOEXEC_SEAL will be rejected." Thanks! Jeff > -Kees > > -- > Kees Cook