From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1EE43C4332F for ; Thu, 15 Dec 2022 00:08:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4E6CC8E0003; Wed, 14 Dec 2022 19:08:33 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 46DC88E0002; Wed, 14 Dec 2022 19:08:33 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 30E4D8E0003; Wed, 14 Dec 2022 19:08:33 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 1A65B8E0002 for ; Wed, 14 Dec 2022 19:08:33 -0500 (EST) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id B0579C0D29 for ; Thu, 15 Dec 2022 00:08:32 +0000 (UTC) X-FDA: 80242604064.05.0C244DC Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) by imf11.hostedemail.com (Postfix) with ESMTP id 09DCA40003 for ; Thu, 15 Dec 2022 00:08:29 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=Wzg4FSPk; spf=pass (imf11.hostedemail.com: domain of keescook@chromium.org designates 209.85.214.179 as permitted sender) smtp.mailfrom=keescook@chromium.org; dmarc=pass (policy=none) header.from=chromium.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1671062910; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=4/QZI1b9BuX09J6n+wRULrAcCHBLRMc57Wa6cWYocm8=; b=u04tbu6JqEx0ykphXIcXY4n2i2WhTqMTaXTR9tWGW2o6LY8ZuCBocxBU4ARROguO/CDE1n pL+VJ2aK90HigznIs6QRQYW/CG7mT2r+pYZ0puDp9yPK56YUBPD+FFIHzdbJpP/xjSOQIT qrlXi+Xh/IUiUmTewIS6oLMQrY+vYl0= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=Wzg4FSPk; spf=pass (imf11.hostedemail.com: domain of keescook@chromium.org designates 209.85.214.179 as permitted sender) smtp.mailfrom=keescook@chromium.org; dmarc=pass (policy=none) header.from=chromium.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1671062910; a=rsa-sha256; cv=none; b=ouhKXznLdQdlrIl3RtDq0Mvn9igC8LV6KLUKYg8C8EkQXg1AbA6PgxXTIt+iyS0diBgmdr Mds5JJBoTQyPAZELV/9avNQbPElfb/yaLJf4ztsdwxYb1NC2v/0QHR9b2CW9bAQFLlBOXo 6aucely86q6CUGuVaf5i/di9tOH7s98= Received: by mail-pl1-f179.google.com with SMTP id n4so1468298plp.1 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=WXzrc78e0ZVtUIruUp9sGr/e2Eo2v9+ZkpbsLXxoevSJoLgFTLlQhzVc2LpkbA4Ye3 so2U6eH138TYx8C5BSIyjaXtSoTaNktNl2yoooFK/q05HHf2NXgCvP0V18NBWAgCajpf oOSzxm3KJWMZSISAtk9dq207D4zllyzIS3iNVXvVK8TgiCX2Czqcqikfz8m8bTnjGbcR t+D4VJzdXQGuGt6NDklWJMAFSms0Yh1Z+h+QTbVAzNCBFJfELET5IcGRFfsQZtfb1/G8 KXivvfsqMqKT43x+wMZHu8o6ospmJxOxe5fkRvEGarlBbXLFxsfGe/V0j3PBUoBN8q3j BsJw== X-Gm-Message-State: ANoB5ple/iFmpMbqKpitnvyj52W/QS9riVgVpokuWUlIHQW8FCyKLY4r IUIynaoNf/g/ReMh9lZuKFOMqA== X-Google-Smtp-Source: AA0mqf5mW27dLgxQNaTm44+KabAsGNHUSGUXlQnLRIn9jXbgYMKGtUuoV8/lZ1AmsVgq54rAF6sJEA== 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-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 09DCA40003 X-Rspam-User: X-Stat-Signature: jxuen8kbphn76iubn3n6azpnk39crbew X-HE-Tag: 1671062909-349240 X-HE-Meta: U2FsdGVkX19IqNaRYscS4anqtHSSAVaA8lP3E0GT5swY9oWiI9U9LG2rea1F5EEsEYTJcJXwVZVcOsvUlZZaYXUdonf3Kb0CgrzB2QOqxQSoiFq+XJ11n2MNfzt6yBafVb5yf70nnN/0r/0wix1Gp8GrAoocYWRWFjtoaJQvKi0viq4Ooji8j/huDq1QC2WtFydmgZWZGLFLG6ZFLHXMr5qN8an96fc0WO8WOMQxHbnX6H5ugYEr+g7yc16ZYiMAAGbEXLHKzCF6QYKogLzQwR/NYl7bjThBhqLnw7QX1Y1qvwkuWrfAiHoNehhvmk9YMr3OMUEqFRLrM8lMLTdzehver0C06dQiepqwreoaQB89+gS4nPpVfv2xH2yeKWU0EhWKWo6SE4Z5OvxG5BUW34gVcGRETg4k48ySYWzaXWtSeF8HqrEw6KcpomRmz4MGCtDMtIGLNHSgV0GRUnWD8PKDok1CU14rK8skjFtQeA5Ydn4AUlpBmr+a4DVsy7b/rfeoWL87oyv7u2InWEf3MdVoD0lB0vesinK8IoEOz85Si+QM9ktu8QLkQ9ZD4z/6S65+2km47znTHXAxEfgXx/0yC4nq9HUnMqRySPp3swpIG8srwKOnjMsOydfQfbIVe7KMuNK1lqdtrdkW6KVxJjFEiF1aJaTEP83JH5oFOZgB8uKr4Nk4Dc6vDD/VPPpdeY3y4bUopZk7HoE0msoPf1SbKffWuR3NXWEOpzHoOfAP8XNJxeGyhvXtOTmDFHa1261QXur6GwiWLIYyHKijrPAjAvKP1vtBcayVlrtUKFbXiMbu5gnd2WkMUFuH8H7W6NJu0gQpLFG0cVT5W3ceT1XX31og0FD+nb9QmO8VPQHHfg7yNeq0NkJ8NyAy3eAI1RthlzeQtrY9B/9IUkEq/cN92cIyLZjbKCHfbb6OgoPx+36OwPbXotM4zJYuGh21b22iv213pgwq/8M+hr9 4chTxYtO CQw4+6dgvZPh7iqxOrXERI+LQ6Vjizbruhxqer3XjQtbdVzpA5u8yu55XhyZuNTNePZohrkjn3z6sj9kyBFnenkMlKBS5iY8bTL3o1jTnnDmoOlIMUY7PxIDEJKyBKrFGrSm0qj34iSXm5DAHUwSoUVUm1fjHTX33z8h50irx3fvxPhqJ8k5FPvN4LCNa/wSazS8RUwODApQikoGdfDdMbbpywQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000001, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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