From patchwork Fri Jun 30 03:17:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Xu X-Patchwork-Id: 13297531 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 46358EB64D9 for ; Fri, 30 Jun 2023 03:17:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A94888D0003; Thu, 29 Jun 2023 23:17:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A44458D0001; Thu, 29 Jun 2023 23:17:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 90DF08D0003; Thu, 29 Jun 2023 23:17:32 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 82F5C8D0001 for ; Thu, 29 Jun 2023 23:17:32 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 477BF120D2C for ; Fri, 30 Jun 2023 03:17:32 +0000 (UTC) X-FDA: 80957953944.06.1BE4087 Received: from mail-ot1-f53.google.com (mail-ot1-f53.google.com [209.85.210.53]) by imf21.hostedemail.com (Postfix) with ESMTP id 7DBCA1C0010 for ; Fri, 30 Jun 2023 03:17:30 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=Hhds97GU; dmarc=pass (policy=none) header.from=chromium.org; spf=pass (imf21.hostedemail.com: domain of jeffxu@chromium.org designates 209.85.210.53 as permitted sender) smtp.mailfrom=jeffxu@chromium.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1688095050; 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:in-reply-to:references:references:dkim-signature; bh=53ZMdGhNmZ+BOpMUbgSFLyEDTkK0ZHteXsorexZvGcc=; b=vrf5cUjqBK4UgTEtff8Nx8SfyVTm8D4AM+tgSIGhWapWGkBV0esbq7+C9Jpo8DjlBwOXoJ dvuvdcEv/aYz1Vx7LYy/1ORNrForR+w5p3LRxjEdW0t1p0OX3i1TQ1rA+MAFrdpgqC2PC7 IH0JcGB3VRWJKWrRE9YJJlI9A4p8HiY= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=Hhds97GU; dmarc=pass (policy=none) header.from=chromium.org; spf=pass (imf21.hostedemail.com: domain of jeffxu@chromium.org designates 209.85.210.53 as permitted sender) smtp.mailfrom=jeffxu@chromium.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1688095050; a=rsa-sha256; cv=none; b=uKn6NnnTGDrVEY+MU8/RICOZiqLWmITTXDII3noN9SLqZigphnwe8DoJlob3WV0tPkrSNB IEqRqTOXSBWX4YgC//zs/eYJOJz/OHF+8X/FIMFcdkY9KHEedsr/m/94aiA7FxVDI1wNZw NPDmOn0tps89nn5yQUbDMOoWTyGjjqc= Received: by mail-ot1-f53.google.com with SMTP id 46e09a7af769-6b708b97418so1147345a34.3 for ; Thu, 29 Jun 2023 20:17:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1688095049; x=1690687049; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=53ZMdGhNmZ+BOpMUbgSFLyEDTkK0ZHteXsorexZvGcc=; b=Hhds97GUYBeppbOwT50AZutzB1nVVfNLRInAfnNP58IkESH6yufdJYjjXoko1dy9G+ 7Ur8NWUwfJrbcpQSpTt286069+coFcb6LHT+Hpu/39T4cIbHcx3ohwZzEN7MljiB4mGX nGNyBGTlMBhsV2p04QbZotAIplV3r6a4qLE4w= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688095049; x=1690687049; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=53ZMdGhNmZ+BOpMUbgSFLyEDTkK0ZHteXsorexZvGcc=; b=LP1KuO7LzMX0LoeUkPlXnwPXVwN6Fdm6dS+mcugamWYC1Vo4gxOz1mTc4XO4TB+5n6 IziShM4Yf5MWz80faU3BHCjnGpH/RSD2+WDt9FZkRj58/+VRcGKGjLYFtn3MnYfWQzdY 5KQeCFdrY1P1PeQAahBeiNqJN8O/qvA3EIJnKjlfv7GtRCNmpNaqUVZrCB+JILZl72n2 zXVHVodH44gEoIb6JiYFWIx3q+l80Fy0LzRLrkXNpSswXt7BH/yLk12b1lxW4h3U+Jj/ NUFcGvqgEn82bR3wkIjsS99LJsVyaXG4fsbHeKk6Fx1R74wWrtMzaUs1yrqxxLiYRwEH Yl7w== X-Gm-Message-State: AC+VfDyX5TSLOOINXX7JyJUmcVPYTSJkWL3axeTMpQ5P9l20h0UcygfL VqP9fZ9GpsNhElQPrwEoo1nwBw== X-Google-Smtp-Source: ACHHUZ7w0MIcW5kZcKcCzQ5+ZTjH6ysBlmgQ4PxTyUtw8h8Kk3p3zrfxkxjd+Odq2hqr4KUnUW6Icw== X-Received: by 2002:a05:6808:1921:b0:3a3:7e8f:2f2a with SMTP id bf33-20020a056808192100b003a37e8f2f2amr1773186oib.11.1688095049673; Thu, 29 Jun 2023 20:17:29 -0700 (PDT) Received: from localhost (183.43.230.35.bc.googleusercontent.com. [35.230.43.183]) by smtp.gmail.com with UTF8SMTPSA id x24-20020aa784d8000000b0065438394fa4sm1622577pfn.90.2023.06.29.20.17.29 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 29 Jun 2023 20:17:29 -0700 (PDT) From: jeffxu@chromium.org To: skhan@linuxfoundation.org, keescook@chromium.org Cc: akpm@linux-foundation.org, dmitry.torokhov@gmail.com, dverkamp@chromium.org, asmadeus@codewreck.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, linux-security-module@vger.kernel.org Subject: [PATCH v1 1/2] mm/memfd: sysctl: fix MEMFD_NOEXEC_SCOPE_NOEXEC_ENFORCED Date: Fri, 30 Jun 2023 03:17:19 +0000 Message-ID: <20230630031721.623955-2-jeffxu@google.com> X-Mailer: git-send-email 2.41.0.255.g8b1d071c50-goog In-Reply-To: <20230630031721.623955-1-jeffxu@google.com> References: <20230630031721.623955-1-jeffxu@google.com> MIME-Version: 1.0 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 7DBCA1C0010 X-Stat-Signature: 6bea7n434rw3yuai1t8xn96czjfcf9wg X-Rspam-User: X-HE-Tag: 1688095050-797420 X-HE-Meta: U2FsdGVkX18x+FIjCBdF8RU/k1cyNcoRHhgl5iN9q/+kpXE7PdJO1fqePEwY9r7ak7XEGzgTED6r06REuGsBXAK4bmZZFGcC3D+NtjFmi1lYLfHJCI11Uk61Wo7br4aqDnOMUCdC3jmDIMs0J8PMUxb0RDlf4kYUiL/rApdGaKRaZ+MjJalvkM5w35jZFYl0VqNbRnkq8cw4m4iEEIHwgPoLnziKvfJjLcsVF60VBGegL1N5mBSiO6APF/Fyk1PClVMrva2PvPhoiBGnI10tNj4vsZYbyCI2cbplNK9Kpv3PZkEtsEZRqq6cJ8wW0A44EJJzYEFp6PvoKAzvj1Lvh2Sff0eb7dnAFkZTGilubNx3/a/zGK9Jg7KMtnUOQf3siTLAxyyULkcbunThzrN2PRdlYXgHdhE/yG5HnqJYNCj/RPNI5EFC5PQB/OYXAM8IlnfGBe4ECt4+PdaGR1MymXID7Z8by7xP2QI6+IT6yemoYboUpggz27Cv7Y5s1JiTh2mRw+j0ceAcp17QFxxkdSZVuorXpyVOJyJJeVJm2glpRAD9I/xHdu4jsxXPC99R1sDgDi2hTthZpCHzfkwIQlfB7D/C40jgS8aQVHVAfOf/cXW7nyGIqNdfzUGM7pXnltW2Jyt0/A3OxdQxZ+egrc25OCKG8VmqHeWA9Db2+Tp0RlWvNfhU378p1nfFRKSJgeTAhPlJxTREcuxOV/cFasq6z3GwFlcm8ABI0ayUwEXnexObxDDgoKVjugdObCxksUg5XDzE3SM/ZSwii6HCiwIhyhhhQNiquq78FVg4En3srS+KAOZxREc3YpB8GYnQAGrsyXH8/aIXmMigHbG/7klb53tCUf+W2NVmtX4UyN98tBR1OG9DkUS2pvM2W6Y9JN8tfm+0ZN0NLrJtYdGJgPxEVKW2e+vhzitlLB3MnEE5bMAoVLiuffVkEFASMR0Rt6gBQml5HuYPId/VFBI PQhBlEq1 wjMdoBWzGd5Ag1sD73/Ziy0S3PuIKo+UHIfZkyX3V6+LBKXqsMb9hmHZVJpi7OtZs4ywvRItLmfm9Mb5UDsIzuyAftBOpICAUPo8S2cOm5pIrxiN3CFLZIMdYaYp+FNJvJfCJiK4rgQtazlYXbP2q1fpI4w0Rh7GfxTBMWhGUsYTa/2A/uBlL8VnmweHcvSwtPncNo9VWvbrsf4uqNCPDTCZVNSAlF6IVoNqfYxtdnwnpHmMqNyrtAegPvnxSo5nByJWnFuwyF9NDvtXOb6BfhIhXK3q+qRB+L3Vm994O3lM1hc2vsoQxu80yT9kGhLxd1hFMkdN1UWSMho7s1kEr2mU86jHadOJNyGjnIm4jOBZe1Dejb87OP/81qY1DMrWtClM/GSR4bgTfWSoH36U+8G6exGyTE1dVSHXFFjXbPUPr7hXWcStNar/mWeq9L1ZdPoXrLmQ47tlTh7kBhZMZ0XsnMknf8tSTNU45hLX+fFK1NzfZ/ROiVcCwtFYIUptVjTyJTM8ueAeT2R6oSTbxDuBe6oA72VIB4CX/ 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: From: Jeff Xu When vm.memfd_noexec is 2 (MEMFD_NOEXEC_SCOPE_NOEXEC_ENFORCED), memfd_create(.., MFD_EXEC) should fail. This complies with how MEMFD_NOEXEC_SCOPE_NOEXEC_ENFORCED is defined - "memfd_create() without MFD_NOEXEC_SEAL will be rejected" Link:https://lore.kernel.org/linux-mm/CABi2SkXUX_QqTQ10Yx9bBUGpN1wByOi_=gZU6WEy5a8MaQY3Jw@mail.gmail.com/T/ Fixes: 105ff5339f49 ("mm/memfd: add MFD_NOEXEC_SEAL and MFD_EXEC") Reported-by: Dominique Martinet Signed-off-by: Jeff Xu --- mm/memfd.c | 48 +++++++++++++++++++++++++----------------------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/mm/memfd.c b/mm/memfd.c index e763e76f1106..812750298e8a 100644 --- a/mm/memfd.c +++ b/mm/memfd.c @@ -268,6 +268,19 @@ long memfd_fcntl(struct file *file, unsigned int cmd, unsigned int arg) #define MFD_ALL_FLAGS (MFD_CLOEXEC | MFD_ALLOW_SEALING | MFD_HUGETLB | MFD_NOEXEC_SEAL | MFD_EXEC) +static int sysctl_memfd_noexec(void) +{ + int sysctl = MEMFD_NOEXEC_SCOPE_EXEC; +#ifdef CONFIG_SYSCTL + struct pid_namespace *ns; + + ns = task_active_pid_ns(current); + if (ns) + sysctl = ns->memfd_noexec_scope; +#endif + return sysctl; +} + SYSCALL_DEFINE2(memfd_create, const char __user *, uname, unsigned int, flags) @@ -278,6 +291,7 @@ SYSCALL_DEFINE2(memfd_create, int fd, error; char *name; long len; + int sysctl = sysctl_memfd_noexec(); if (!(flags & MFD_HUGETLB)) { if (flags & ~(unsigned int)MFD_ALL_FLAGS) @@ -294,35 +308,23 @@ SYSCALL_DEFINE2(memfd_create, return -EINVAL; if (!(flags & (MFD_EXEC | MFD_NOEXEC_SEAL))) { -#ifdef CONFIG_SYSCTL - int sysctl = MEMFD_NOEXEC_SCOPE_EXEC; - struct pid_namespace *ns; - - ns = task_active_pid_ns(current); - if (ns) - sysctl = ns->memfd_noexec_scope; - - switch (sysctl) { - case MEMFD_NOEXEC_SCOPE_EXEC: - flags |= MFD_EXEC; - break; - case MEMFD_NOEXEC_SCOPE_NOEXEC_SEAL: + if (sysctl == MEMFD_NOEXEC_SCOPE_NOEXEC_SEAL) flags |= MFD_NOEXEC_SEAL; - break; - default: - pr_warn_once( - "memfd_create(): MFD_NOEXEC_SEAL is enforced, pid=%d '%s'\n", - task_pid_nr(current), get_task_comm(comm, current)); - return -EINVAL; - } -#else - flags |= MFD_EXEC; -#endif + else + flags |= MFD_EXEC; + pr_warn_once( "memfd_create() without MFD_EXEC nor MFD_NOEXEC_SEAL, pid=%d '%s'\n", task_pid_nr(current), get_task_comm(comm, current)); } + if (flags & MFD_EXEC && sysctl >= MEMFD_NOEXEC_SCOPE_NOEXEC_ENFORCED) { + pr_warn_once( + "memfd_create(): MFD_NOEXEC_SEAL is enforced, pid=%d '%s'\n", + task_pid_nr(current), get_task_comm(comm, current)); + return -EACCES; + } + /* length includes terminating zero */ len = strnlen_user(uname, MFD_NAME_MAX_LEN + 1); if (len <= 0) From patchwork Fri Jun 30 03:17:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Xu X-Patchwork-Id: 13297532 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 3C901EB64D9 for ; Fri, 30 Jun 2023 03:17:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9353A8D0005; Thu, 29 Jun 2023 23:17:35 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8E64F8D0001; Thu, 29 Jun 2023 23:17:35 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7AE178D0005; Thu, 29 Jun 2023 23:17:35 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 6B3B58D0001 for ; Thu, 29 Jun 2023 23:17:35 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 4D0661A04F2 for ; Fri, 30 Jun 2023 03:17:35 +0000 (UTC) X-FDA: 80957954070.22.A7A5BC6 Received: from mail-oo1-f50.google.com (mail-oo1-f50.google.com [209.85.161.50]) by imf16.hostedemail.com (Postfix) with ESMTP id 806F0180012 for ; Fri, 30 Jun 2023 03:17:33 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=HeDRz1ER; dmarc=pass (policy=none) header.from=chromium.org; spf=pass (imf16.hostedemail.com: domain of jeffxu@chromium.org designates 209.85.161.50 as permitted sender) smtp.mailfrom=jeffxu@chromium.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1688095053; 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:in-reply-to:references:references:dkim-signature; bh=KZoSuQHQ27DM/d6b7OOglRkF4w/BysG+jSVaxzCus5g=; b=6x4/0AX/y/4nkvfdE3Zb/Xc9biz8XvQdAZbwoeRpabCXCib8OIxQ0EEednVYCdUMB3jyd3 iccd4u42kgdu6QGz12K24l6SNf7BY3/yvAFBT3sUiaKaVH/OBKRjEMlsLiHVqmYUZFHZH6 Tx+dt4w+4f6Y2bVL8/WjkIpUjdA9UwQ= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=HeDRz1ER; dmarc=pass (policy=none) header.from=chromium.org; spf=pass (imf16.hostedemail.com: domain of jeffxu@chromium.org designates 209.85.161.50 as permitted sender) smtp.mailfrom=jeffxu@chromium.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1688095053; a=rsa-sha256; cv=none; b=ZXqvvsv/sZVynSz4OYoCHtLxMjd0ftDMjlwwbh6XuALrQkMtgv5rrS1fhFwgNb/tA6bDLH ufDQm8QvCarMwJyv0piAIxDUWQNMzCsu69NstF0Bn00pmgz7cgY0UynFxj2RZ/voPHdYE6 yZ607T9WomI8ZaoPABX1spfLS00hURA= Received: by mail-oo1-f50.google.com with SMTP id 006d021491bc7-565a8d9d832so958326eaf.1 for ; Thu, 29 Jun 2023 20:17:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1688095052; x=1690687052; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=KZoSuQHQ27DM/d6b7OOglRkF4w/BysG+jSVaxzCus5g=; b=HeDRz1ERohiy6m7ihytJYCLaW66pr6T/yVt3YJJVg+ByWiKq4yaXI4f/SVp6flkL+e MUFr8LdBari+Ig036YI4Hq83c5hmfUGZoLtXb3P2kvkgdyi+f132IV8Ci/c9QnPKnrFC QTiFkcVn8WpLZV0/xbD4SyhXu+ltOEWK6gsGQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688095052; x=1690687052; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=KZoSuQHQ27DM/d6b7OOglRkF4w/BysG+jSVaxzCus5g=; b=MFgRUb+l8AYuWI2VKUY1Hx+X59zGV4P9FQsw9wMxHphP+VF0XBOkQFJ1kEZ2owEHFa XleQrJ55MCEaLtowOxRqftb+kkAOqOY8CMQ1lCJ6/7cZ0sBwlOxQm5/eEUj1fISJQzC7 Y9s2/W8r2G40qgrXj7qlBl9fvJRoeyUsj+Ez6fl3eycsoWSYH0wPusNzpJaTqLrzcULk lJOkF1k+yvv5mypM5o6OeUyw21T6MrKW/SS5424jXk2sDIHo/mnuD8uTqZM9J+boai3A XjWpzcX41KUuei/512p+VhZqZNrHf+42oGZwwUrxopV5VNivwZu6HtGd8N4P0ZB4+ry9 sAxQ== X-Gm-Message-State: AC+VfDwnttitVQHuRvQz5TDtEijl9je0ICT9FqNq0lqjWb3hUDutF4kv yLvdS9nwUG/v8TjKwar7kf0Dbw== X-Google-Smtp-Source: ACHHUZ5ieji9f9FFgUwk0QNqn8Z7w6bi8Vxc4p96KvUt1caQq7AD4bSuKudaVKFZdPoLr4vL1DK+jw== X-Received: by 2002:a05:6808:d4e:b0:3a3:7e8d:b0b with SMTP id w14-20020a0568080d4e00b003a37e8d0b0bmr1648172oik.22.1688095052740; Thu, 29 Jun 2023 20:17:32 -0700 (PDT) Received: from localhost (183.43.230.35.bc.googleusercontent.com. [35.230.43.183]) by smtp.gmail.com with UTF8SMTPSA id y12-20020a655b4c000000b0055adf339c35sm6407088pgr.31.2023.06.29.20.17.32 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 29 Jun 2023 20:17:32 -0700 (PDT) From: jeffxu@chromium.org To: skhan@linuxfoundation.org, keescook@chromium.org Cc: akpm@linux-foundation.org, dmitry.torokhov@gmail.com, dverkamp@chromium.org, asmadeus@codewreck.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, linux-security-module@vger.kernel.org Subject: [PATCH v1 2/2] selftests/memfd: sysctl: fix MEMFD_NOEXEC_SCOPE_NOEXEC_ENFORCED Date: Fri, 30 Jun 2023 03:17:20 +0000 Message-ID: <20230630031721.623955-3-jeffxu@google.com> X-Mailer: git-send-email 2.41.0.255.g8b1d071c50-goog In-Reply-To: <20230630031721.623955-1-jeffxu@google.com> References: <20230630031721.623955-1-jeffxu@google.com> MIME-Version: 1.0 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 806F0180012 X-Stat-Signature: 51ibfp4y4xyg7dim4coa1yzzsdstgird X-Rspam-User: X-HE-Tag: 1688095053-260780 X-HE-Meta: U2FsdGVkX19z8HPHEB4bEO99KqtYmUPxW+EM2myZjlc2F9+TUiWe8HFUWhvFbbhWNIp9G5/hYY4lze3GzPdU9Sz4YIpk60/3mWO37+3MGxZjVsZ2zxiZJPqHmLCqkGAPFomxJ0B6RURCSzQGjGnJqqJeC2sMD0yRHW92lTbMCVprYPhuC/LqNKcEvUt7M/2xmmPf8jXk6nl2MdlwPHQcZd0LSMaO+1GpSrXcwNpxM5a/Uk5gbPOw1plp6NTHtBZc386L/tEBd66iKulqkzQDL/8KzhzZcfL7NvpEK7cmVrxWQKzR6GSvB6zdP1mn0p7fAjqc/f149CEba/0E3SKCi+NtoAutqMg1dHSCnxS43I4+gJe4UtY36FgNNZjw/NH72ZLBobTnmEKXjtrRxHDStxm0UpEnuLzpnkpIuKhfCSBmDZKlmJor4nTDE7cIDSIVnNLnI+RSUGSz7OPSr59ODJFsvh4iRVxjcWu78YLun1ilXX71PqjYXr0TA+ns0nV+IqO8wkWHiT/VinGjg06lPUmkHZla2f3CUnbNvYM/UGIEnFPU2eBzShbFG6byvtDYe6r4upfUeIffcWLAb3w8xckn9BLBUxIJInCxdViNNRO1hYrIKsbRD9wW7f0XYI7bFB6rTXiPfYZQpcJCDxxsFmUXnkrf4MyiaJ3gpHvC82NyJT6iVcK8C9LZh+coC8HgY/kNA8KChfnsMlTsco7BavIY05tCuiTHAJ9IboJXMNh3H6FubfLPkZBdfdtsWm5YIObqVWOFFVpq39jU4c89bMdGKVNCIJVQs4FLXAEpWgT2h/g5klP7wwrvD9VxCVbVzTVuwceWB2o/IVevAuCexASP66I2Jno3JwcMWnQ3AG72SWArJ1pzc8YOKXvdwFJfpDgsuAOlSl+OY+IKoOHY06vw8CgDIbBWcWJVBXbvkMo2+d0FPaNbEPaPSIUEeNxHPfAvUmExa7ZTtb/3lCs I/9BOUyH w8F+JhFDA/qT9rowOqX0fysUa+847JM3qUfLYxsiqFZwniG6u+QHLYkxORK9DezXV+VzplHcjxVg0mT4FmNG3QX2IbW9sy1SZNUkvzUXLO/ZrYBGwXjwvJWXoZnjlq7NDpaS6alGm6q0kauob/ITO2Bh5ytMbLFBaYbiwmyY/t04K0pzTFur1LWW0VTAAaBNzfPnveC5zkc52RPMRn1z8lPzI9wwkwlluwikBlNrfHVa2Z9HNjEPdUahyLL0YARn3DHc8jDAzjleqfoBYb1GL94NvFMtyxZJsKX3/pQE/rjgBaP4D6qPtzY7rEKW4I0EPunB14sf8IfHpvcxuQZHSr+lEu9JiunOm704UaXZQ1jpSxNULysb2E9sWZ8vqHxtKNDdb3wicJm0Po9X8Y2PXhpZ6kA== 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: From: Jeff Xu Add selftest for sysctl vm.memfd_noexec is 2 (MEMFD_NOEXEC_SCOPE_NOEXEC_ENFORCED) memfd_create(.., MFD_EXEC) should fail in this case. Signed-off-by: Jeff Xu --- tools/testing/selftests/memfd/memfd_test.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tools/testing/selftests/memfd/memfd_test.c b/tools/testing/selftests/memfd/memfd_test.c index dba0e8ba002f..dbdd9ec5e397 100644 --- a/tools/testing/selftests/memfd/memfd_test.c +++ b/tools/testing/selftests/memfd/memfd_test.c @@ -1147,6 +1147,11 @@ static void test_sysctl_child(void) sysctl_assert_write("2"); mfd_fail_new("kern_memfd_sysctl_2", MFD_CLOEXEC | MFD_ALLOW_SEALING); + mfd_fail_new("kern_memfd_sysctl_2_MFD_EXEC", + MFD_CLOEXEC | MFD_EXEC); + fd = mfd_assert_new("", 0, MFD_NOEXEC_SEAL); + close(fd); + sysctl_fail_write("0"); sysctl_fail_write("1"); }