Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp304096rwb; Wed, 14 Dec 2022 17:45:42 -0800 (PST) X-Google-Smtp-Source: AA0mqf4Stefa+CpptxlQVlpe+8MfDtMGeO35UE2Qr6q1Fz87NCJJp6bjPs9U7/dnclbLtmLY59O1 X-Received: by 2002:a17:907:6e0f:b0:7c4:f343:77a8 with SMTP id sd15-20020a1709076e0f00b007c4f34377a8mr4346199ejc.9.1671068742019; Wed, 14 Dec 2022 17:45:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671068742; cv=none; d=google.com; s=arc-20160816; b=iy90Yr4sk6K681wek7HXQQ9nhPQ2qcCyJtGVAFSiF0wR62L/V0VC/AF1TDVhH5bXPy sOecLRWVtb03W6MPug2HqGnuWWDJFOoi3S58QH5mmU+UqN5FJZ6QH2oK2WRqTiEZJipk 2Bc/1ewMmAK+ryW/z1Xe4e2khTO3M1YplysjZwCxGlgmU8c17ZHAB2dkTQsvq9RuQPTc RsW/ub4D3X7K94M1uKo9D/2RjC5Jz1ldiBSTH6SXqyd+TRbOSm0R53HBN+se1zl8tlJI LrPR3emCQoL1mqKGtEB4ZkW8tsilqMyaf4WhcpFe0V35DiyH3ou+Bp8OoRaOwpTDzSkI 8deg== 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-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=4/QZI1b9BuX09J6n+wRULrAcCHBLRMc57Wa6cWYocm8=; b=dL8ElMfpMAQ8N3ZixWeHjFPVZz56oObdDJTWvJalYSB2E3ifu0RIWncZBaAyOb5zru ny/yt87hNMVq2XHMpmRRkq5VgOvdWC1SJkViAKJ3GaudFBC6Tjl6I1WWX0PcumwPp80a r61/f4kclPamNZ8sTPjML+IZo3OlMMNacpePf0MFSYGz045WPceXea1pBSO+wUMtATU3 L0oh18VgDcNAEl6hYpx3paE1lV6oxIvDaHGrVtyy4OYqYteMxextkpT900BNrJjGT9vW 1w58FKFH8OXmyP4kO9yDCJ+PzYo5qUAazhceOEMAA4IVaqntCMzUv25CgunLyg6jFB+e 8QUQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Wzg4FSPk; 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 r7-20020aa7cfc7000000b0046cdae33434si12443047edy.333.2022.12.14.17.45.25; Wed, 14 Dec 2022 17:45:41 -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=Wzg4FSPk; 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 S229670AbiLOANJ (ORCPT + 69 others); Wed, 14 Dec 2022 19:13:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33866 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229679AbiLOAMm (ORCPT ); Wed, 14 Dec 2022 19:12:42 -0500 Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 36939E0F3 for ; Wed, 14 Dec 2022 16:08:29 -0800 (PST) Received: by mail-pl1-x62f.google.com with SMTP id m4so5139017pls.4 for ; Wed, 14 Dec 2022 16:08:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=4/QZI1b9BuX09J6n+wRULrAcCHBLRMc57Wa6cWYocm8=; b=Wzg4FSPkMKRRRymHOhnFtx/uU+954Ka/2q+TGUz8LCNuqKtyxXNza/SUzgyRSht8Yu pYECEzcWeYbJFvm5+Mskz4amT5qYPptMoWlmBw6QHeEPYgXGSUOcC4B5nmigD5eI/bLr hH8153HNw5wyiNl3Xoe4FZOUUFmeU83Q+zrLE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-transfer-encoding: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=4/QZI1b9BuX09J6n+wRULrAcCHBLRMc57Wa6cWYocm8=; b=MfGCTnfmFJAO+YM2CpB/HLl20p6sXcXR/gjXbQ4Ec6rR6Lk1A2oT9l9vlNRPGN7Njz 6Ka7DoRZgTYqWGy5Rqya9hmRR0oo23hdoqFZQsBdL0L1On14MJ9gktWoqjLxJZ7nylzh Ondwqi3U7lciN1FavInY8L+g41JoyGvsJABWYBrhNPcze1RMx7x+vUwyN+2ikrvZvJHb 10AWRQVzKk5AFy83LQdc8K2E7IKqIZVV50+9kTnMJlYZxXpOMtU4hAZCe7FVP+7x8vTT uBzeEVGhkRx+UTeAfo4LFEfg+hkbWlV6RSh2ke99R2eKAtoeuReZKYXN7pnKv1mix6+e ZOLw== X-Gm-Message-State: ANoB5pmBIaoB/K8h3yq77izD1TJntilPLZmaRRwPA6WfGbKCfIn9v7wK 1DB97ny2MlUAQ9aBAizTkKxjrZWcpGgh7SID X-Received: by 2002:a17:90a:788f:b0:218:7744:72f9 with SMTP id x15-20020a17090a788f00b00218774472f9mr27145347pjk.26.1671062908706; Wed, 14 Dec 2022 16:08:28 -0800 (PST) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id oa9-20020a17090b1bc900b0020a81cf4a9asm1921231pjb.14.2022.12.14.16.08.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Dec 2022 16:08:28 -0800 (PST) Date: Wed, 14 Dec 2022 16:08:27 -0800 From: Kees Cook To: Jeff Xu , akpm@linux-foundation.org Cc: jeffxu@chromium.org, skhan@linuxfoundation.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, jannh@google.com, linux-hardening@vger.kernel.org, linux-security-module@vger.kernel.org Subject: Re: [PATCH v7 0/6] mm/memfd: introduce MFD_NOEXEC_SEAL and MFD_EXEC Message-ID: <202212141607.D2D986C076@keescook> References: <20221209160453.3246150-1-jeffxu@google.com> <202212141053.7F5D1F6@keescook> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: 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=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 Wed, Dec 14, 2022 at 03:32:16PM -0800, Jeff Xu wrote: > On Wed, Dec 14, 2022 at 10:54 AM Kees Cook wrote: > > > > On Fri, Dec 09, 2022 at 04:04:47PM +0000, jeffxu@chromium.org wrote: > > > From: Jeff Xu > > > > > > Since Linux introduced the memfd feature, memfd have always had their > > > execute bit set, and the memfd_create() syscall doesn't allow setting > > > it differently. > > > > > > However, in a secure by default system, such as ChromeOS, (where all > > > executables should come from the rootfs, which is protected by Verified > > > boot), this executable nature of memfd opens a door for NoExec bypass > > > and enables “confused deputy attack”. E.g, in VRP bug [1]: cros_vm > > > process created a memfd to share the content with an external process, > > > however the memfd is overwritten and used for executing arbitrary code > > > and root escalation. [2] lists more VRP in this kind. > > > > > > On the other hand, executable memfd has its legit use, runc uses memfd’s > > > seal and executable feature to copy the contents of the binary then > > > execute them, for such system, we need a solution to differentiate runc's > > > use of executable memfds and an attacker's [3]. > > > > > > To address those above, this set of patches add following: > > > 1> Let memfd_create() set X bit at creation time. > > > 2> Let memfd to be sealed for modifying X bit. > > > 3> A new pid namespace sysctl: vm.memfd_noexec to control the behavior of > > > X bit.For example, if a container has vm.memfd_noexec=2, then > > > memfd_create() without MFD_NOEXEC_SEAL will be rejected. > > > 4> A new security hook in memfd_create(). This make it possible to a new > > > LSM, which rejects or allows executable memfd based on its security policy. > > > > I think patch 1-5 look good to land. The LSM hook seems separable, and > > could continue on its own. Thoughts? > > > Agreed. > > > (Which tree should memfd change go through?) > > > I'm not sure, is there a recommendation ? It looks like it's traditionally through akpm's tree. Andrew, will you carry patches 1-5? Thanks! -- Kees Cook