From patchwork Mon Aug 14 08:40:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aleksa Sarai X-Patchwork-Id: 13352565 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 5165CEB64DD for ; Mon, 14 Aug 2023 08:41:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E58A08E0001; Mon, 14 Aug 2023 04:41:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E07E5900003; Mon, 14 Aug 2023 04:41:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CA9FE8E0005; Mon, 14 Aug 2023 04:41:47 -0400 (EDT) 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 BB19C8E0001 for ; Mon, 14 Aug 2023 04:41:47 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 84F39C0B1D for ; Mon, 14 Aug 2023 08:41:47 +0000 (UTC) X-FDA: 81122067054.08.42AE994 Received: from mout-p-202.mailbox.org (mout-p-202.mailbox.org [80.241.56.172]) by imf15.hostedemail.com (Postfix) with ESMTP id 860E1A0004 for ; Mon, 14 Aug 2023 08:41:45 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=cyphar.com header.s=MBO0001 header.b=p1mH3+eN; spf=pass (imf15.hostedemail.com: domain of cyphar@cyphar.com designates 80.241.56.172 as permitted sender) smtp.mailfrom=cyphar@cyphar.com; dmarc=pass (policy=reject) header.from=cyphar.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692002505; a=rsa-sha256; cv=none; b=RsLyif+oPnrgo0W0zBr5OMl8f+vF5mJxMLUPeu3JCEIgosayirqhqXzKD8SP05Bi+fAgJk J1sJathNnbrFUrZ42WBKSPhi8QilJqTtCfCefGVLkk7u0bL0D6UYZCc+KVk5eNac2jS9ua fx7Ll1DK2Dp2GhQPhb8YQMi5q5Gy3Xc= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=cyphar.com header.s=MBO0001 header.b=p1mH3+eN; spf=pass (imf15.hostedemail.com: domain of cyphar@cyphar.com designates 80.241.56.172 as permitted sender) smtp.mailfrom=cyphar@cyphar.com; dmarc=pass (policy=reject) header.from=cyphar.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1692002505; 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=79RoJoR/fwEl868XiYEwCuZo1mWc1anAic2p8X8NglE=; b=p3ARRXIeb9yaou/+svn/oFByieVqx4+pwsOMx9Lrkh1h4TvUS0Z4cik6cQheV8LZZAY0JU FJ2GwvTEXA+gqiMHzic8O+cRyF7qrYJnxNaLa3cDwOwWkcZLokJ7BDUsRRpN12fP2xf+3K 2WOiGec8wzqMY2iOx+cruBLdlJF1BFE= Received: from smtp202.mailbox.org (smtp202.mailbox.org [IPv6:2001:67c:2050:b231:465::202]) (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-202.mailbox.org (Postfix) with ESMTPS id 4RPSYd70PJz9slh; Mon, 14 Aug 2023 10:41:41 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cyphar.com; s=MBO0001; t=1692002502; h=from:from: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; bh=79RoJoR/fwEl868XiYEwCuZo1mWc1anAic2p8X8NglE=; b=p1mH3+eN9eCVXdi/TxEUdL6OIDyTpQYTMvtKaZZl79SDtqiMak9oJhVRBoeaG94oNA8btJ PXKhAtBfpm7RHIgirGHwamL0Dqr5iJzMUBPRM7gjZR47hIhN/BQmCcoL7ufFIkmwRd7HqN mVSznBoc06lgSX95l1aKE8O5Iqd0oGrgrweoODmiJ5QxpRealAixDosNM60Yo40IYyHmgg UYfjbMmbOD9Hz5BIR3vTbMmxgQcmoaVDW7Tiy9rJ0hv/5isMvaFDnVF17zljfHsxF5j7Ls UyjsKXdyA9wOQ660D6kuX8HSkD2lACAmd416Q3kl9z/0UdxSYT4GZVOm+puhqA== From: Aleksa Sarai Date: Mon, 14 Aug 2023 18:40:59 +1000 Subject: [PATCH v2 3/5] memfd: improve userspace warnings for missing exec-related flags MIME-Version: 1.0 Message-Id: <20230814-memfd-vm-noexec-uapi-fixes-v2-3-7ff9e3e10ba6@cyphar.com> References: <20230814-memfd-vm-noexec-uapi-fixes-v2-0-7ff9e3e10ba6@cyphar.com> In-Reply-To: <20230814-memfd-vm-noexec-uapi-fixes-v2-0-7ff9e3e10ba6@cyphar.com> To: Andrew Morton , Shuah Khan , Jeff Xu , Kees Cook , Daniel Verkamp Cc: Christian Brauner , Dominique Martinet , stable@vger.kernel.org, linux-api@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-kselftest@vger.kernel.org, Aleksa Sarai X-Developer-Signature: v=1; a=openpgp-sha256; l=2138; i=cyphar@cyphar.com; h=from:subject:message-id; bh=RhSvSYmzoCDTkzH6eBS7S4EFPaKzfTKNkGx9zoaFDXg=; b=owGbwMvMwCWmMf3Xpe0vXfIZT6slMaTcfLHKkqnzauO+Q1m9W/cV6QoIafZdM/7bxXw//nBq8 PzZ8dumdpSyMIhxMciKKbJs8/MM3TR/8ZXkTyvZYOawMoEMYeDiFICJPFNl+F/zy9EjaynTW+l7 ofv84tUT6+bn3924QbCv9tcRc+nsOj5GhjfxJfaqHXPWTy+PW/w4KtRJ8Llqn1Da/fm3D9eIrua pYQcA X-Developer-Key: i=cyphar@cyphar.com; a=openpgp; fpr=C9C370B246B09F6DBCFC744C34401015D1D2D386 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 860E1A0004 X-Stat-Signature: y7sh7m1t1pxgio66qm7htxa7sfggadqm X-Rspam-User: X-HE-Tag: 1692002505-919138 X-HE-Meta: U2FsdGVkX18lwm0ldfkt1YPCABTfi+qdL7FBiJFB6jWufI/5ZBe5LuRJ4m9c4SB1zPNrito1+y+E9KCf2nbl71ogKGxUghLowo2N5wzZcVYh1Qg4Gj6a/EXwgQUclXS9YXeq8KPKMEaBiR0CglBBvXBeHJIhJhSzaDd/2bz04NUQB9sNbTRZSS6osmBFNJrWEDvQKpPiQnDwPYhmJ312EnOG2x/DCwCUnGPxCpuyAPE65yU8kuG5MRnm9DpJ1KZKJMXduj4MB9yIrV+hNT3wejro5C4r8lft4cDbRkF/w3JTUWrgQFhi63ZZ8K8HbQUR6UjzTcvWSasjap+ivT1zaiIBMICR3jtzaoYR65QrS6/ESV/qH4dGixAN+Y5Lg71lb6NWTMyl2B9mH7EnccheTLhDJcKm3beKRbNZrs6j/IOZTSC8zvQ5mFxaI5+frAYI0UsU7FxvtQfjtaLIMwQf7u7ASfO68237y1sAQBusHf8VJE4YG0wuob9fpNFCXqnjDcIUupG0/xqtDDgzP2mCrxz8vT5H1YlOpm6SZsFbTC+n1FEfs3jrzvSQCuJjHcadx++5/ofIhzpWLQtAvQlTGRoSpo+N5VX5QT/shrktg4HVpeURvXbw9vB9seWcLyCcc2cQa18WQrTYhibg7xC6t+MnSHYtEVuWzolRe9Hfn/LDm/Huao+wgq2LNqLHgAzdD4bYmSP7urH4p2F1O+gzfSvlCH4PwYrc6gbRmPkDyYw9jXglO0gnSxHE+Hv/pnpy5vb9eqhJbXL/wR/getSclLkuf0nFmxYmvbW3DWOICd6ply8/2/SLJrac7UVyE2RMYVz/p9GbQdQ22NApx63tEMKZD/+rhQMF9lWqe1Iub/nvADkUY7nhFaVzw3G5xhXxoIxi4Pup2J5Ef95LMKut1XwdPDdLZPQ0vevRWH2HCp+AOzs6zyPPBfqa8tUm1SWkxk6pm3pZgF0Q42qdjhc QH/AnC42 EoXDn53VcQoD7PaBgDPdLZXdoFuKGrUxNYJVKvfjQqOdxalX3/YLG8379rLA4lhPzejpuKs1O5e5/TgfmFQ5q9IDpXdopkII6PznhlCYqJvhmHdxQHJukv1FGp1neZx3fNW1FXSOhtlQIBGS4EuDKMaZRLVd858CuX+hv/GeOu72XOYOkm7o8+Gle6GE31E5wY+JnPpcM8ss+rzD9UjQEXpdo6Hke0vdaETE4jH1mnYon5bNz8Y0ALcsfQAa3e62lnJcnSZ35BqPywRlKdFubB0Z/gdIMZtl0P62gh7eowKFpWhrnvK/w6Mx7i0oAx+cjMYTlfzBZT8X1dmh1EKf+KP8bpYs4zXzNlNPAQFfXhW+k7ALkftVGymx9hQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: In order to incentivise userspace to switch to passing MFD_EXEC and MFD_NOEXEC_SEAL, we need to provide a warning on each attempt to call memfd_create() without the new flags. pr_warn_once() is not useful because on most systems the one warning is burned up during the boot process (on my system, systemd does this within the first second of boot) and thus userspace will in practice never see the warnings to push them to switch to the new flags. The original patchset[1] used pr_warn_ratelimited(), however there were concerns about the degree of spam in the kernel log[2,3]. The resulting inability to detect every case was flagged as an issue at the time[4]. While we could come up with an alternative rate-limiting scheme such as only outputting the message if vm.memfd_noexec has been modified, or only outputting the message once for a given task, these alternatives have downsides that don't make sense given how low-stakes a single kernel warning message is. Switching to pr_info_ratelimited() instead should be fine -- it's possible some monitoring tool will be unhappy with a stream of warning-level messages but there's already plenty of info-level message spam in dmesg. [1]: https://lore.kernel.org/20221215001205.51969-4-jeffxu@google.com/ [2]: https://lore.kernel.org/202212161233.85C9783FB@keescook/ [3]: https://lore.kernel.org/Y5yS8wCnuYGLHMj4@x1n/ [4]: https://lore.kernel.org/f185bb42-b29c-977e-312e-3349eea15383@linuxfoundation.org/ Cc: stable@vger.kernel.org # v6.3+ Fixes: 105ff5339f49 ("mm/memfd: add MFD_NOEXEC_SEAL and MFD_EXEC") Signed-off-by: Aleksa Sarai Reviewed-by: Christian Brauner --- mm/memfd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/memfd.c b/mm/memfd.c index d65485c762de..aa46521057ab 100644 --- a/mm/memfd.c +++ b/mm/memfd.c @@ -315,7 +315,7 @@ SYSCALL_DEFINE2(memfd_create, return -EINVAL; if (!(flags & (MFD_EXEC | MFD_NOEXEC_SEAL))) { - pr_warn_once( + pr_info_ratelimited( "%s[%d]: memfd_create() called without MFD_EXEC or MFD_NOEXEC_SEAL set\n", current->comm, task_pid_nr(current)); }