From patchwork Thu Jul 13 14:33:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aleksa Sarai X-Patchwork-Id: 13312297 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 8FF37C0015E for ; Thu, 13 Jul 2023 14:34:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2EAE890002B; Thu, 13 Jul 2023 10:34:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2A57E90001C; Thu, 13 Jul 2023 10:34:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 18BB190002B; Thu, 13 Jul 2023 10:34:37 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 0BE8A90001C for ; Thu, 13 Jul 2023 10:34:37 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 6DC1DA02DA for ; Thu, 13 Jul 2023 14:34:36 +0000 (UTC) X-FDA: 81006834552.01.D464BA3 Received: from mout-p-102.mailbox.org (mout-p-102.mailbox.org [80.241.56.152]) by imf12.hostedemail.com (Postfix) with ESMTP id 700F540009 for ; Thu, 13 Jul 2023 14:34:34 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=cyphar.com header.s=MBO0001 header.b=qUOa4YG3; dmarc=pass (policy=reject) header.from=cyphar.com; spf=pass (imf12.hostedemail.com: domain of cyphar@cyphar.com designates 80.241.56.152 as permitted sender) smtp.mailfrom=cyphar@cyphar.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1689258874; 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-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=lAa7dqvmH+q9XR/GIeI3noqFo+Lf1ym1g3+Ai+iNMRQ=; b=OQbSuNpl8ue0XvBEERVOoCZUsMneLevaerctvuPpAfcH/mnykxmZi0wtSkCNyWLTmDBfgk 1w6lCG89q6YoxQ0+wrwuqrXeoeZ/BElMKl8zp8IhZvOaJlLYQLwHVMo9YgR/9YDbq5icUm QL0CQTypR8GpEkdldP8UQbbYC4lgdmU= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=cyphar.com header.s=MBO0001 header.b=qUOa4YG3; dmarc=pass (policy=reject) header.from=cyphar.com; spf=pass (imf12.hostedemail.com: domain of cyphar@cyphar.com designates 80.241.56.152 as permitted sender) smtp.mailfrom=cyphar@cyphar.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1689258874; a=rsa-sha256; cv=none; b=2e7WkqXRAZR02NT8Y7h/FBSwKuAVLQgae4IhfHgaBZuzKzwGM3D+KXUqfIEPTKMETz+Eyv m8RsGgZtlgPRcqPaYWAOAsIMzIV18edGtLIB4NNRWejK/xsg90GxIS0SBHEFKNJdhsYqil 2qnftej7UNsmXeplqV8sA1fEkfGxPZY= Received: from smtp2.mailbox.org (smtp2.mailbox.org [IPv6:2001:67c:2050:b231:465::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-102.mailbox.org (Postfix) with ESMTPS id 4R1xvT1mlmz9sTq; Thu, 13 Jul 2023 16:34:29 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cyphar.com; s=MBO0001; t=1689258869; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=lAa7dqvmH+q9XR/GIeI3noqFo+Lf1ym1g3+Ai+iNMRQ=; b=qUOa4YG376HPdtUX9J+UbKWx9u11F5Z+gXjdV/pSgA3GrtUNyKbuBsGccuriE0RNBmfVr+ GGOwyythmmKSi+L/FK9I5Xfwh+tZbGylpGRJ/1cm5pERnc6LMAeEPpwpR6KLaC0OhbZSv2 6rJ1jlIq3X/d812rYImFbjE2RDymOwNm7QF88DLJdMNYMuk/2J4cLmQsdhgX02yxqAOt1c ijb7fHSC4E1HLhOcAVnFqttvDhPqcQJ24eo2dt4A3ylYV5aKQjeVdRVPW+oG7VtYUJnFu6 C5F3iL4cZcSmSItYWfGBI4d4eP3wCC2JJhzSbBLQPUXrV09d206nmsfo9aygdA== From: Aleksa Sarai To: Andrew Morton , Shuah Khan , Jeff Xu , Kees Cook , Aleksa Sarai , Daniel Verkamp , Luis Chamberlain , YueHaibing Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [RFC PATCH 0/3] memfd: cleanups for vm.memfd_noexec Date: Fri, 14 Jul 2023 00:33:45 +1000 Message-ID: <20230713143406.14342-1-cyphar@cyphar.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 700F540009 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: axjksc9fk1cnn3bmzr9c5phero6mdwhw X-HE-Tag: 1689258874-60208 X-HE-Meta: U2FsdGVkX1+usjL1C+lw5xhqTJYaVPeI0a1Regm6/76enfbkUHf0LbyRNu4BuA7BGNNww4gMJecbcnUOQ7rBQubkgbJ6WmLT42NQUn55pV+1lKwgG5akN/4TCkW62NOOuSnAOAC/zlQ3bnbUlwynW1rYcOIgvJ66q2NL0I/UWnRZJ+Avd2H5JCb0VYdqlfycZlXtmC/3F2fpEbnCw36xgs2Xir1/nbrqRc0Q1tBwRoICHMI4naotPEsEmt2UpJgVm3RRF1wFoauR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ests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: It seems that the most critical issue with vm.memfd_noexec=2 (the fact that passing MFD_EXEC would bypass it entirely[1]) has been fixed in Andrew's tree[2], but there are still some outstanding issues that need to be addressed: * The dmesg warnings are pr_warn_once, which on most systems means that they will be used up by systemd or some other boot process and userspace developers will never see it. The original patch posted to the ML used pr_warn_ratelimited but the merged patch had it changed (with a comment about it being "per review"), but given that the current warnings are useless, pr_warn_ratelimited makes far more sense. * vm.memfd_noexec=2 shouldn't reject old-style memfd_create(2) syscalls because it will make it far to difficult to ever migrate. Instead it should imply MFD_EXEC. * The racheting mechanism for vm.memfd_noexec doesn't make sense as a security mechanism because a CAP_SYS_ADMIN capable user can create executable binaries in a hidden tmpfs very easily, not to mention the many other things they can do. * The memfd selftests would not exit with a non-zero error code when certain tests that ran in a forked process (specifically the ones related to MFD_EXEC and MFD_NOEXEC_SEAL) failed. (This patchset is based on top of Jeff Xu's patches[2] fixing the MFD_EXEC bug in vm.memfd_noexec=2.) [1]: https://lore.kernel.org/all/ZJwcsU0vI-nzgOB_@codewreck.org/ [2]: https://lore.kernel.org/all/20230705063315.3680666-1-jeffxu@google.com/ Aleksa Sarai (3): memfd: cleanups for vm.memfd_noexec handling memfd: remove racheting feature from vm.memfd_noexec selftests: memfd: error out test process when child test fails include/linux/pid_namespace.h | 16 +++------ kernel/pid_sysctl.h | 7 ---- mm/memfd.c | 32 +++++++---------- tools/testing/selftests/memfd/memfd_test.c | 41 ++++++++++++++++++---- 4 files changed, 51 insertions(+), 45 deletions(-)