Message ID | 20221207154939.2532830-1-jeffxu@google.com |
---|---|
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp260123wrr; Wed, 7 Dec 2022 07:50:53 -0800 (PST) X-Google-Smtp-Source: AA0mqf7u43Rx4lbcNWcBTFLTOiupmRMjILy6L6CH345DXRBsAamG8OKhRXfeCBlafZn93P0l3iG6 X-Received: by 2002:a17:906:e93:b0:7c1:27b:d597 with SMTP id p19-20020a1709060e9300b007c1027bd597mr8611260ejf.249.1670428253584; Wed, 07 Dec 2022 07:50:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670428253; cv=none; d=google.com; s=arc-20160816; b=ZhkqQa5n77te0MT65n4dGaO+PNjJrN5DuYSKeurU5f/74rgvDL4JvXs42/T3R12FyZ D14mgLfburxkEPXKoorsIuPtXvF02tkfbt6IW/cB5krmLD9gLZd035eXRaZYCf83iQT9 mF24xy14ayL87DwszAFz8tKzJ4e4arBH8n1AUKXFHnAPyPiwzZB6kNhENfO+iQKEsWH4 mazj+IKfQr77F+WF9CwEKL/P3EG93KtzlNFIVo24ErmhP8qBrh5NHaEUosANTNAAHApW VdJsnyvRs5MmtX9hNo4EW+bT8PAcNiBQT5yxyH7qeUanNGILxC6IJPv89kpDwFzepST/ YEHQ== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=SebK6VeMwVI8zNPc+AGDZ/foDvzVT7LenZ1q5aL6Vd0=; b=jIb0u5TipFz7vSYtO6XEQ11uJEY4Awi41FOGlAuMpzNI6lzUm6zOIL4dpRFpErImj6 zwcNPIRIXHLz8BZUtp/abWPsD1EKpuhzk/kIvoGt+YEX6LMY6ZRwGMszJQ+bFAzaaQTA fQMs1LGwqF+qYs65MfSzLsImUWZZw7HS5UOR1w4tCFow2bNCkr8lkeyYciRH7yq4nRQn l8KQQpBTQUmSGY13mNfpc4Jpa6WLdZy81G8eTvYU/jwBhbodkPOWcjVY5y6jQj4G63wx byIyg5DY7KFtCnYNzynq6aPj9LBvXxOQqsBr81m13BlA35WOUpe+gyJCmInY53MTSMmo C2vw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=bXpIMlKZ; 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 f22-20020a056402195600b0046af4b03015si4669651edz.8.2022.12.07.07.50.28; Wed, 07 Dec 2022 07:50:53 -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=bXpIMlKZ; 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 S229449AbiLGPtt (ORCPT <rfc822;foxyelen666@gmail.com> + 99 others); Wed, 7 Dec 2022 10:49:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50614 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229603AbiLGPtq (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 7 Dec 2022 10:49:46 -0500 Received: from mail-pj1-x102e.google.com (mail-pj1-x102e.google.com [IPv6:2607:f8b0:4864:20::102e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2A14024951 for <linux-kernel@vger.kernel.org>; Wed, 7 Dec 2022 07:49:45 -0800 (PST) Received: by mail-pj1-x102e.google.com with SMTP id t11-20020a17090a024b00b0021932afece4so1814352pje.5 for <linux-kernel@vger.kernel.org>; Wed, 07 Dec 2022 07:49:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=SebK6VeMwVI8zNPc+AGDZ/foDvzVT7LenZ1q5aL6Vd0=; b=bXpIMlKZLOugUItEp+yK3IZEPErrpxgFQ3yGo+icXLxideMkE4N9Fl1V9tRqJmVJKL kkGO+i3x5P4gqnCUXgxjG6vCaQUG4ifV0IyOaZqXC1wAIy4PoD6cdcnJ+oJrZBc/aqiq xPr95nZlhxEuoy7lqLgIC5sVkXFhlAxbDK/BU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=SebK6VeMwVI8zNPc+AGDZ/foDvzVT7LenZ1q5aL6Vd0=; b=edY1uHiJ02H+fb9Gjv3Bf0SPswxBV1qLY1X8i7MaDNuqnXZ/QYsBw0+TOx4AeopMG5 8OdbBM5LyTlZSwMn3MG6s0dubfwkA6hNb1L4ah5ooq1ORL7WOqbpqoBD6IqW4RR2R7Zh I4Hqhj7oOzIFjWPYwvX6eIfanmEyXXmB3DhuKk+N0dtGs99LFBZQaAGmh2h/wYqAa/vh UdWvv3hmoSdJIERQohQreDEvUxpxSAARKxqpgGOLGRGKovd3wXwNfsySdCqQemhdYQLc SNA7ugwTnWJlrUoxsUt1S78zSetaCgFmgIxyA+K3mRW+YgwczC+kg9TdLxX1ahT38PAK hEFw== X-Gm-Message-State: ANoB5pkvCGw2TKXDj1Q6AYganIQdd35YaVDBv2o4pnXElcplwvBvALNu gGfsQkNTDLHWnOqC8c5EFjlSKw== X-Received: by 2002:a17:902:9a82:b0:189:e085:8416 with SMTP id w2-20020a1709029a8200b00189e0858416mr714393plp.17.1670428184683; Wed, 07 Dec 2022 07:49:44 -0800 (PST) Received: from jeffxud.c.googlers.com.com (30.202.168.34.bc.googleusercontent.com. [34.168.202.30]) by smtp.gmail.com with ESMTPSA id a9-20020a170902ecc900b0017f7628cbddsm14920934plh.30.2022.12.07.07.49.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Dec 2022 07:49:44 -0800 (PST) From: jeffxu@chromium.org To: skhan@linuxfoundation.org, keescook@chromium.org Cc: 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 Subject: [PATCH v6 0/6] mm/memfd: introduce MFD_NOEXEC_SEAL and MFD_EXEC Date: Wed, 7 Dec 2022 15:49:33 +0000 Message-Id: <20221207154939.2532830-1-jeffxu@google.com> X-Mailer: git-send-email 2.39.0.rc0.267.gcb52ba06e7-goog MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1751570976388539365?= X-GMAIL-MSGID: =?utf-8?q?1751570976388539365?= |
Series |
mm/memfd: introduce MFD_NOEXEC_SEAL and MFD_EXEC
|
|
Message
Jeff Xu
Dec. 7, 2022, 3:49 p.m. UTC
From: Jeff Xu <jeffxu@google.com>
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.
This is V6 version of patch: see [4] [5] [6] [7] for previous versions.
[1] https://crbug.com/1305411
[2] https://bugs.chromium.org/p/chromium/issues/list?q=type%3Dbug-security%20memfd%20escalation&can=1
[3] https://lwn.net/Articles/781013/
[4] https://lwn.net/Articles/890096/
[5] https://lore.kernel.org/lkml/20220805222126.142525-1-jeffxu@google.com/
[6] https://lore.kernel.org/lkml/20221202013404.163143-1-jeffxu@google.com/
[7] https://lore.kernel.org/lkml/20221206152358.1966099-1-jeffxu@google.com/
Daniel Verkamp (2):
mm/memfd: add F_SEAL_EXEC
selftests/memfd: add tests for F_SEAL_EXEC
Jeff Xu (4):
mm/memfd: add MFD_NOEXEC_SEAL and MFD_EXEC
mm/memfd: Add write seals when apply SEAL_EXEC to executable memfd
selftests/memfd: add tests for MFD_NOEXEC_SEAL MFD_EXEC
mm/memfd: security hook for memfd_create
include/linux/lsm_hook_defs.h | 1 +
include/linux/lsm_hooks.h | 4 +
include/linux/pid_namespace.h | 19 ++
include/linux/security.h | 6 +
include/uapi/linux/fcntl.h | 1 +
include/uapi/linux/memfd.h | 4 +
kernel/pid_namespace.c | 5 +
kernel/pid_sysctl.h | 59 ++++
mm/memfd.c | 61 +++-
mm/shmem.c | 6 +
security/security.c | 13 +
tools/testing/selftests/memfd/fuse_test.c | 1 +
tools/testing/selftests/memfd/memfd_test.c | 348 ++++++++++++++++++++-
13 files changed, 525 insertions(+), 3 deletions(-)
create mode 100644 kernel/pid_sysctl.h
base-commit: eb7081409f94a9a8608593d0fb63a1aa3d6f95d8
Comments
On Wed, Dec 07, 2022 at 03:49:33PM +0000, jeffxu@chromium.org wrote: > This is V6 version of patch: see [4] [5] [6] [7] for previous versions. When sending a new version, can you include an overview of what changed between this version and the prior version? This helps reviewers who are following along, so it's easier to focus our attention on the differences. Also, it's helpful to version the links: > [4] https://lwn.net/Articles/890096/ > [5] https://lore.kernel.org/lkml/20220805222126.142525-1-jeffxu@google.com/ > [6] https://lore.kernel.org/lkml/20221202013404.163143-1-jeffxu@google.com/ > [7] https://lore.kernel.org/lkml/20221206152358.1966099-1-jeffxu@google.com/ e.g.: v6: - moved foo to bar - improve comments for baz v5: https://lore.kernel.org/lkml/20221206152358.1966099-1-jeffxu@google.com/ v3: https://lore.kernel.org/lkml/20221202013404.163143-1-jeffxu@google.com/ v2: ...etc -Kees
On Thu, Dec 8, 2022 at 8:13 AM Kees Cook <keescook@chromium.org> wrote: > > On Wed, Dec 07, 2022 at 03:49:33PM +0000, jeffxu@chromium.org wrote: > > This is V6 version of patch: see [4] [5] [6] [7] for previous versions. > > When sending a new version, can you include an overview of what changed > between this version and the prior version? This helps reviewers who are > following along, so it's easier to focus our attention on the > differences. Also, it's helpful to version the links: > > > [4] https://lwn.net/Articles/890096/ > > [5] https://lore.kernel.org/lkml/20220805222126.142525-1-jeffxu@google.com/ > > [6] https://lore.kernel.org/lkml/20221202013404.163143-1-jeffxu@google.com/ > > [7] https://lore.kernel.org/lkml/20221206152358.1966099-1-jeffxu@google.com/ > > e.g.: > > v6: > - moved foo to bar > - improve comments for baz > v5: https://lore.kernel.org/lkml/20221206152358.1966099-1-jeffxu@google.com/ > v3: https://lore.kernel.org/lkml/20221202013404.163143-1-jeffxu@google.com/ > v2: ...etc > Will do! Much appreciated for helping me through the process of my first patch in the kernel. Jeff > -Kees > > -- > Kees Cook
On Thu, Dec 08, 2022 at 10:33:19AM -0800, Jeff Xu wrote: > On Thu, Dec 8, 2022 at 8:13 AM Kees Cook <keescook@chromium.org> wrote: > > > > On Wed, Dec 07, 2022 at 03:49:33PM +0000, jeffxu@chromium.org wrote: > > > This is V6 version of patch: see [4] [5] [6] [7] for previous versions. > > > > When sending a new version, can you include an overview of what changed > > between this version and the prior version? This helps reviewers who are > > following along, so it's easier to focus our attention on the > > differences. Also, it's helpful to version the links: > > > > > [4] https://lwn.net/Articles/890096/ > > > [5] https://lore.kernel.org/lkml/20220805222126.142525-1-jeffxu@google.com/ > > > [6] https://lore.kernel.org/lkml/20221202013404.163143-1-jeffxu@google.com/ > > > [7] https://lore.kernel.org/lkml/20221206152358.1966099-1-jeffxu@google.com/ > > > > e.g.: > > > > v6: > > - moved foo to bar > > - improve comments for baz > > v5: https://lore.kernel.org/lkml/20221206152358.1966099-1-jeffxu@google.com/ > > v3: https://lore.kernel.org/lkml/20221202013404.163143-1-jeffxu@google.com/ > > v2: ...etc > > > Will do! > Much appreciated for helping me through the process of my first patch > in the kernel. Happy to help! I'm excited to see this gap in memfd security closed. :)