Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1349320rwb; Thu, 15 Dec 2022 09:04:34 -0800 (PST) X-Google-Smtp-Source: AA0mqf7lP02VQT3cW0d9iYLXYemp3gpi8zne5z1wzvEv4NAp2mseGiDgn12K12pa2CL4LyEaktnu X-Received: by 2002:a05:6402:5305:b0:462:6ace:34cb with SMTP id eo5-20020a056402530500b004626ace34cbmr24335520edb.0.1671123874612; Thu, 15 Dec 2022 09:04:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671123874; cv=none; d=google.com; s=arc-20160816; b=hI2r1Ok7k6+qIdnxHKmPV46at/suSo4hycr/ioP6M9xuhSWBiQEzHV0goU8enXDnLy Qexse7xV/QmZvKo0nfd+Ml5owZyDar+YB4LXh6QRNDVAxW0rWk+PMvxVDghHYFCQYX2k NXfQY4lFfCrDU1kCScH4sp8gWhi2n9BQs23GFVIjrdAroxLOIp2IbvKABrkzzKdx6PhF 0SJSrOBliySr/sWhFyiFYFzmna9M2zTfFUqcqnw40sEpBNaKbBdoZo8NE8mB0oVRgrXn 94Fwd8WpiyumEJfIZYceIz4Y7o9rkpwqdmZnViptOfDxOFdkWgtkZdx428UFpJhdk1pK vj9Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=DOs+4sldiwGC1XG54dp5mVgT4uLPOQwpbZy8XgG5P7U=; b=OHOIGrDtx4O1Szsc8C1ivzrjV2lNC8v3cRBJD9e/sapQIqB0JKWrya2Kpvb+UAuJxe 5QJqzkomcnipYKxGTm0jxjcebczkWidV6l3VaqsLGZlxwsSoarGPIjUW0Mz7/siUftUQ PpeGQxKNBGLHABeq3XJW+mLwePhrtTznCqb4DiE+SlqgPO4fVFUIgPrDF9dmciPdWip7 oQWbpu+JobmYPrSk3IduGteR7j1c8DGul+n8u8QjyE9Rjd4ZQHuY8BcnWB4I24N3me2w yL5N17vBBCn2y9Cgc9dbm2+pQkhjyOgsKnS2mkBRcYQ/ODSB+pjaM3VCYqJKtFZkxB04 c/gA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=BwAd8aLP; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dz9-20020a0564021d4900b0045c98bb5359si15104393edb.590.2022.12.15.09.04.16; Thu, 15 Dec 2022 09:04:34 -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=@google.com header.s=20210112 header.b=BwAd8aLP; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230342AbiLOQ4P (ORCPT + 68 others); Thu, 15 Dec 2022 11:56:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48294 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230323AbiLOQ4J (ORCPT ); Thu, 15 Dec 2022 11:56:09 -0500 Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 53DCBD70 for ; Thu, 15 Dec 2022 08:56:04 -0800 (PST) Received: by mail-pj1-x102a.google.com with SMTP id u15-20020a17090a3fcf00b002191825cf02so3262754pjm.2 for ; Thu, 15 Dec 2022 08:56:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=DOs+4sldiwGC1XG54dp5mVgT4uLPOQwpbZy8XgG5P7U=; b=BwAd8aLPF5gd7FIHoISnAe0Zyh/n9acpz7ASV5bArM8hi+12M+FokUGMCFBYex8YYT nxAxlAOtheavS0XJFp986uZEh6iP0Ge1ESokWEFBokuizRQABamacozxfHoHFFmuc1ig og9sJEbM9bDah05cislLrAkqozwsfBmeI2c0IATzpQQH3Shewyh+bhXQoOzGvx/VhhF4 q0IchDuQ9ETeLCwyhWh4KMyKbH1/EIDfepr0bi0OHiqJSTjhJ7A3Nxt8kXYoynQWbMgP NFZaNJrEnOv3E7GDTrJU47AoUmR++UPFYGrV0RFmWai23NVv2rwcyUqZetoHP0TjnvhP tb3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding: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=DOs+4sldiwGC1XG54dp5mVgT4uLPOQwpbZy8XgG5P7U=; b=5JwFo1jXOBKPxhZSOYALuBJEMvLhVcs9KLICCJLTyz92ptIYdKB1N4TIP9jauHogBO aJguoS2Aypa0f5IEEsIRtaI9Ynk9tT9enwneeCliKHWGXDDZQsondk8MO7drGR+0ulhb pb6UkNQfU3A/H/+xfdyih6XYxVjT5rvHS2Qy8FKGK39YhwL92e3/qYVv4bBULLoY4HME GeFEsT3WPqy/vlSiN2870LVQy6kOhmhgLmCZTrEs+l/yBtCkZZOEfBXlRFteN/B62Gnv Z80KrAw9mD+Pq1Q1Wz6AvAMSzq+0Av5yMXI9b+GJTNDkicGxscGHw1KjpoTyLXBQwknz z7Jw== X-Gm-Message-State: AFqh2kqifr1ooEdPcf80cVX6kMbS3O2ZwUSLHx98eA6W6VWlKsDQ76cv 263CTXdqiCG7kpkNCI7tADoflmDHoObxMeJXlH3zwg== X-Received: by 2002:a17:90a:4612:b0:219:a43b:1006 with SMTP id w18-20020a17090a461200b00219a43b1006mr786360pjg.195.1671123363557; Thu, 15 Dec 2022 08:56:03 -0800 (PST) MIME-Version: 1.0 References: <20221209160453.3246150-1-jeffxu@google.com> <202212141053.7F5D1F6@keescook> <202212141607.D2D986C076@keescook> In-Reply-To: <202212141607.D2D986C076@keescook> From: Jeff Xu Date: Thu, 15 Dec 2022 08:55:26 -0800 Message-ID: Subject: Re: [PATCH v7 0/6] mm/memfd: introduce MFD_NOEXEC_SEAL and MFD_EXEC To: Kees Cook Cc: akpm@linux-foundation.org, 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL 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 Wed, Dec 14, 2022 at 4:08 PM Kees Cook wrote: > > On Wed, Dec 14, 2022 at 03:32:16PM -0800, Jeff Xu wrote: > > On Wed, Dec 14, 2022 at 10:54 AM Kees Cook wrot= e: > > > > > > 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 the= ir > > > > execute bit set, and the memfd_create() syscall doesn't allow setti= ng > > > > it differently. > > > > > > > > However, in a secure by default system, such as ChromeOS, (where al= l > > > > executables should come from the rootfs, which is protected by Veri= fied > > > > boot), this executable nature of memfd opens a door for NoExec bypa= ss > > > > and enables =E2=80=9Cconfused deputy attack=E2=80=9D. E.g, in VRP = bug [1]: cros_vm > > > > process created a memfd to share the content with an external proce= ss, > > > > however the memfd is overwritten and used for executing arbitrary c= ode > > > > and root escalation. [2] lists more VRP in this kind. > > > > > > > > On the other hand, executable memfd has its legit use, runc uses me= mfd=E2=80=99s > > > > 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 behav= ior of > > > > X bit.For example, if a container has vm.memfd_noexec=3D2, 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, an= d > > > 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? > Hi Andrew, if you are taking this, V8 is the latest that contains patch 1-5= . Thanks Jeff > Thanks! > > -- > Kees Cook