From patchwork Wed Jul 5 06:33:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Xu X-Patchwork-Id: 13301699 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 4F42EEB64DD for ; Wed, 5 Jul 2023 06:33:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6C57B6B0071; Wed, 5 Jul 2023 02:33:23 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 675CF6B0072; Wed, 5 Jul 2023 02:33:23 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 53D5F8D0001; Wed, 5 Jul 2023 02:33:23 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 408FE6B0071 for ; Wed, 5 Jul 2023 02:33:23 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id ED8221C83EF for ; Wed, 5 Jul 2023 06:33:22 +0000 (UTC) X-FDA: 80976591444.19.BE071A9 Received: from mail-vk1-f171.google.com (mail-vk1-f171.google.com [209.85.221.171]) by imf02.hostedemail.com (Postfix) with ESMTP id 25D3280014 for ; Wed, 5 Jul 2023 06:33:20 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=bFlmbiX7; dmarc=pass (policy=none) header.from=chromium.org; spf=pass (imf02.hostedemail.com: domain of jeffxu@chromium.org designates 209.85.221.171 as permitted sender) smtp.mailfrom=jeffxu@chromium.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1688538801; a=rsa-sha256; cv=none; b=Xaa1O+hg9iKRi7xaeezxy+KtYWVjklb1s4c9jG5g5mrQyAo/+ow6Nd52ehK8QXeTw5fqK0 309NN0hJXXuvqWWpffILXpwaJHqE6de2YosQ/2m/6X1PGlIMCCkQW2hRoGvZdtdmP137hP upqSgat6l1nmONqlGa6/00l6Wf2MRN0= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=bFlmbiX7; dmarc=pass (policy=none) header.from=chromium.org; spf=pass (imf02.hostedemail.com: domain of jeffxu@chromium.org designates 209.85.221.171 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=1688538801; 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=W+MSmdpLaQYcYfYw7xJr5lmjiO0vLCrOZIxlLos01I4=; b=tl/waQtZNRsv5Pdt77AKxPwORgVvGzzwfOLmHpxHVMjf7DFoX6WCdDP8gJVSd6329dn4PQ v5CKH7jRaLXyqKDfsYA2EAhH2ioUTpIc8DNuk+n4yOFgh8veUAGcu1/+NhBzObNqNXnvCj HBWjRSQwbfOMFlTjIbTwayTe7cY6ucU= Received: by mail-vk1-f171.google.com with SMTP id 71dfb90a1353d-47e793ccdc7so150125e0c.1 for ; Tue, 04 Jul 2023 23:33:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1688538800; x=1691130800; 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=W+MSmdpLaQYcYfYw7xJr5lmjiO0vLCrOZIxlLos01I4=; b=bFlmbiX7I0IMNBN+awjy44Gd2HHxolAdFzcioJ6vbbxbKEhkdrQChkaBrAG9TgBfKT x0Z2gtzkhzO55v/fQhqA0JPCBoHFOFGB4fsAyofg2LzDmXjriBm2FqrokpTc7btoXEHH bLA19vYllamBMyiqrr9cjjjuZUbPI0WKT4WEE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688538800; x=1691130800; 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=W+MSmdpLaQYcYfYw7xJr5lmjiO0vLCrOZIxlLos01I4=; b=YUTIN9Wc6+uGAL6Fof+dMrmMVYKauyPL+XlqtOyXvinoTafOAKq9ytfRN2AHjKrClF piuX/5FUxDqgGQFLi5cjrEYnGCZLpWFdv75YeC2F7/gUm0yUzj2e7HEVwTqge1ChkJWL Cap7auofYqZgP4DU9w52Aag0+vOEzpU9jlng5WvXLlCe362P19r3SeQBQI7Z0NfpHXCE By8EZmub5lryOVRS5HiHvMRnXoxxBjuumYFlP5gu8WyyAL8hPTgmyz0upZjo+QI6F7oX CbTOXneMV19IWeM1JCrP55XKPtRFGP7zF9aYF3wmiFmi77EqJhtbR4HL+3xcz/YkW4QK ikXg== X-Gm-Message-State: ABy/qLbEkB6zYXwwPhMv+vPFJvZ4EXchmexD6NZeRXg5JH1tobh9DaWP TwjtiJY4eJHvzqIIXEacRmOujQ== X-Google-Smtp-Source: APBJJlFcgKaSPJKkbCoS2vIlhS3WYafUAvQl5v36URdmF0hDQjm/PTL88mvcn7PB87UgQocXD3sayA== X-Received: by 2002:a05:6122:2af:b0:46e:6af4:3333 with SMTP id 15-20020a05612202af00b0046e6af43333mr6858407vkq.5.1688538800100; Tue, 04 Jul 2023 23:33:20 -0700 (PDT) Received: from localhost (183.43.230.35.bc.googleusercontent.com. [35.230.43.183]) by smtp.gmail.com with UTF8SMTPSA id bj2-20020a17090b088200b002633fa95ac2sm633631pjb.13.2023.07.04.23.33.19 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 04 Jul 2023 23:33:19 -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, kernel test robot Subject: [PATCH v2 1/2] mm/memfd: sysctl: fix MEMFD_NOEXEC_SCOPE_NOEXEC_ENFORCED Date: Wed, 5 Jul 2023 06:33:14 +0000 Message-ID: <20230705063315.3680666-2-jeffxu@google.com> X-Mailer: git-send-email 2.41.0.255.g8b1d071c50-goog In-Reply-To: <20230705063315.3680666-1-jeffxu@google.com> References: <20230705063315.3680666-1-jeffxu@google.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 25D3280014 X-Stat-Signature: 9b89qyo6gcyto8hqfbn9uhm1wiuoifzn X-HE-Tag: 1688538800-342070 X-HE-Meta: U2FsdGVkX19E1QFWZlC98QIkMWEl2LNMo2Wknnqx9GFbqMV1g2ONf9y0mvheBXjtW43Hn6NCB+vPX3XnZx15ArEuZpeLb9crLBstnonrnyawtZ2m+s6vYkxnzFiVcVh7cLl3+0s7K4f26vo7LDVNovBHf9RaP4gsKUvtBFuxMX8QuKQUo9BuBb6+gPcNrdYvm5CZuSFiHWB0j/W838SJM8bVFSxzGBCxrS8Vn4k8cA7fxUqIDCDLtFj4gnj+jHJfnZXXqFUwvKNrrfoShYaDldybyLUwqTPe6VIwjIhU7rkCaOr1Yirgrqi1fySBjzOpH9z2AXC3F6jp8aeog0/mqrDl1FWs/BQSzYRSRZpYmz/E/AW5BnNVIHNDTbj48PHjjES+U14+XIgg418HkXKvVPQYUuEuPvnBlF4k+WSil501IpKSlyYA80cPEh0gy1VVD2lijCv00XzVa8/AUjGzL3qi2NKXMzj3UIMeyFo4++3pVRhDX24Be52cC+mDNf4XT4sioS+zSotLwSkRlqPZO9FFbX6+84WwyoeGSU2dghFQSCj8eSo0pij1W+pg2LGsCmqZCG9K9ew5vZAuHOZ6c+7KTKQebPCnk3X9NIt+3lu6nPYb3hmDiFmGkHIAfhsIH2r34u55+jOu2f/f0VP1I3es4pCyCFVTKDQg8A+918Fjgahc1FfYmsZfo7GMygoWl1cwf3Eskibl7kt9HqrXj3EMDRS5JkpDelpq41t66kavVsjVb/46V57lSrrt0sSDM5taLDVxLEoeDpcgc4zKwfrkwDrZPx/BjlOWOo+gERK2XH4jmcMnHWG6sg0Nt1wN6FXYTZqY+93q5vt9UZZzOoX8ZysTWBXmmtt2gieNf4eQNtLAuclbX47buGjwejUvYFQPH4TXWvpa1tedTJRgVLnThFa9iQD4Y5u85WmdazvGzdcjrxg2zMKgBZ6Zqr3KS2oFvhywrBIq9q8C2JU UW+wx+w2 I2wHYJR88hmltXbxHwegk9LRIYJ0ddrJhly0Nv7VTlyclaW5MN4vc79a6vBtIfvAWXyga9AG2x8AIhyncM8XROXARPcy2YQ2zVtZm1Zi3z9VGeFWJH9e6YZr3NfZb3WsixGwqcBjVV7GSqggTUEsvXCaUZIPz8KEjlvxAOcQNIh5C7bbFw3zaBn/yEN/COnRjAd7uBgcKl3K5vzDrAuRbUrctDRXrhaS85ENaqwHzgdqFKrq3LfdSrpjnJTEIw6FFfUtEXk245woL2yU0thx84J4s9ptSwPlB5XCm6QUqs1PxJct+TAvr0GS0pfHJxeBz4g4v9kxNQq7VAc97WaKhF4TuKgK4DsymYXNRIhm9x0p9xFPKBU3zwpOyGTn8COTYr2Z8zI8Z7a7el0k/16APe4oUxtrhAqxe08GJikMI16rjjhGR5xgsdT5iQoiQHENwMC0NDQCKszu/pvPjW/l+WZ3+KU2k1ATafmiW1Ifv6PG/WkjqEfrupsQb7vOgWNiNS30yWsbNqW1f7Py7tdk6J2Qe+HpcT9oy2h3aDF++eHo9FQjhfy2l2NNm8YRfSZFlLR+q 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" Fixes: 105ff5339f49 ("mm/memfd: add MFD_NOEXEC_SEAL and MFD_EXEC") Reported-by: Dominique Martinet Closes: https://lore.kernel.org/linux-mm/CABi2SkXUX_QqTQ10Yx9bBUGpN1wByOi_=gZU6WEy5a8MaQY3Jw@mail.gmail.com/T/ Reported-by: kernel test robot Closes: https://lore.kernel.org/oe-kbuild-all/202306301351.kkbSegQW-lkp@intel.com/ Signed-off-by: Jeff Xu --- mm/memfd.c | 57 +++++++++++++++++++++++++++++++----------------------- 1 file changed, 33 insertions(+), 24 deletions(-) diff --git a/mm/memfd.c b/mm/memfd.c index e763e76f1106..0bdbd2335af7 100644 --- a/mm/memfd.c +++ b/mm/memfd.c @@ -268,6 +268,36 @@ 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 check_sysctl_memfd_noexec(unsigned int *flags) +{ +#ifdef CONFIG_SYSCTL + char comm[TASK_COMM_LEN]; + int sysctl = MEMFD_NOEXEC_SCOPE_EXEC; + struct pid_namespace *ns; + + ns = task_active_pid_ns(current); + if (ns) + sysctl = ns->memfd_noexec_scope; + + if (!(*flags & (MFD_EXEC | MFD_NOEXEC_SEAL))) { + if (sysctl == MEMFD_NOEXEC_SCOPE_NOEXEC_SEAL) + *flags |= MFD_NOEXEC_SEAL; + else + *flags |= MFD_EXEC; + } + + 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; + } +#endif + + return 0; +} + SYSCALL_DEFINE2(memfd_create, const char __user *, uname, unsigned int, flags) @@ -294,35 +324,14 @@ 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: - 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 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 (check_sysctl_memfd_noexec(&flags) < 0) + return -EACCES; + /* length includes terminating zero */ len = strnlen_user(uname, MFD_NAME_MAX_LEN + 1); if (len <= 0) From patchwork Wed Jul 5 06:33:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Xu X-Patchwork-Id: 13301701 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 ADDFAC001DF for ; Wed, 5 Jul 2023 06:33:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B0C6B6B0074; Wed, 5 Jul 2023 02:33:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A94DC6B0075; Wed, 5 Jul 2023 02:33:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8E73A6B0078; Wed, 5 Jul 2023 02:33:24 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 812746B0074 for ; Wed, 5 Jul 2023 02:33:24 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 4436BA00E6 for ; Wed, 5 Jul 2023 06:33:24 +0000 (UTC) X-FDA: 80976591528.12.4374FE2 Received: from mail-oa1-f46.google.com (mail-oa1-f46.google.com [209.85.160.46]) by imf02.hostedemail.com (Postfix) with ESMTP id 593EE8000A for ; Wed, 5 Jul 2023 06:33:22 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=YwXhEKM0; dmarc=pass (policy=none) header.from=chromium.org; spf=pass (imf02.hostedemail.com: domain of jeffxu@chromium.org designates 209.85.160.46 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=1688538802; 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=OtlHSYlk61uE8OQ84nuywDVrRHfSI4oOT81ysMvjyFA=; b=IafukSU0Ov8IU9ds4b+ko4KIALEQWkTNweQCyiwHTh9kqqfT6iRf3NZy9tkhuBMyx0wbxA NoAsP5Lkx16SxZZ3LceSFcJFExzDxvpBak5dmE8JKHnSWu1lHQBe9WOGFpRgjE2esN1ODY mbPUIPKyx60oh/2GSxt0/1/sR2e4h94= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=YwXhEKM0; dmarc=pass (policy=none) header.from=chromium.org; spf=pass (imf02.hostedemail.com: domain of jeffxu@chromium.org designates 209.85.160.46 as permitted sender) smtp.mailfrom=jeffxu@chromium.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1688538802; a=rsa-sha256; cv=none; b=pPH6I+uNaJRfxwtYzYoMp7Ts8sFtAmRPv0kJR3ZsBwcFG0YSGxiXqxUQMPTMpqckF024Si Vrud9aWpBfVNMUAjPErVofUDRbZ69uMR4paNd7USgoxlE/iDRs+cAn3Iu8bANW6+FhLopX j+1+DU8zBj6XGeorqgl/H/Ocx8RvxUo= Received: by mail-oa1-f46.google.com with SMTP id 586e51a60fabf-1b03ec2015fso5563562fac.3 for ; Tue, 04 Jul 2023 23:33:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1688538801; x=1691130801; 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=OtlHSYlk61uE8OQ84nuywDVrRHfSI4oOT81ysMvjyFA=; b=YwXhEKM0bu8FLh1wIz59SqsCgWkobp8aMDaj1CHNsuATyIC4RfmsCuv+E2a0nBcO3E WDTMK08X82N1aLjr5w800Rmi5KkdfuSXoG5l/ZsyDV8RgeW0Y9gk8RsRABpvUrPPItNC oAJPB8tv5xMpX8RQvRgMYbfppt/cgVN4dJ6u4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688538801; x=1691130801; 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=OtlHSYlk61uE8OQ84nuywDVrRHfSI4oOT81ysMvjyFA=; b=ggpLa2qY7NnANDI5fNmVpFjFc75NitSbVYRGplnH2M0+AjpQpW/LQBO13ADqwIYN8B /o0f/5yr1AeiayHNidmW/dR2+IGQfVC8FxVmjAvoTy/NM0sNgnWJ3NxPGZ7cJqiIqzKr ZUqJkOsL7b/9xBYFmVtZ2URRJBQTAA3LBQ5H6u2urAJB7+5hjFsNewk6LTRwh3KK2/HJ KMuYEQpqetu/2ZF7j6BiIVur0CjZrW5W1RXUOB4Qetlej142WuL0kWA0ewjCyURd7CGE uMNbVmSFxJ00+/Wb75F82RBPg8h/kkEe4H5u2SjvI/1K/qDrkOTKt7GPBRejagIrRNBj fQQA== X-Gm-Message-State: ABy/qLajhiDuBZZBj3xOFHfUvFDrF4YyQtv11+QtZ+R12E3xwTAoWeYd VAToMiZtrm1Dt8FxA/YEDB0ktg== X-Google-Smtp-Source: APBJJlGWMaUVY0TTBQBklTknGLh3stDvEgk0pSskAi32YTtDZEDoFGMo+Ddm6TezqBzUtzqDD1VujQ== X-Received: by 2002:a05:6870:ac9a:b0:1ad:4d4:34c5 with SMTP id ns26-20020a056870ac9a00b001ad04d434c5mr17360781oab.39.1688538801499; Tue, 04 Jul 2023 23:33:21 -0700 (PDT) Received: from localhost (183.43.230.35.bc.googleusercontent.com. [35.230.43.183]) by smtp.gmail.com with UTF8SMTPSA id h18-20020a63f912000000b0051b36aee4f6sm17145711pgi.83.2023.07.04.23.33.20 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 04 Jul 2023 23:33:20 -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 v2 2/2] selftests/memfd: sysctl: fix MEMFD_NOEXEC_SCOPE_NOEXEC_ENFORCED Date: Wed, 5 Jul 2023 06:33:15 +0000 Message-ID: <20230705063315.3680666-3-jeffxu@google.com> X-Mailer: git-send-email 2.41.0.255.g8b1d071c50-goog In-Reply-To: <20230705063315.3680666-1-jeffxu@google.com> References: <20230705063315.3680666-1-jeffxu@google.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 593EE8000A X-Stat-Signature: remxr6c3yhyg5ituakopgnzh4bg4aqos X-HE-Tag: 1688538802-837537 X-HE-Meta: U2FsdGVkX19PNAWnZF7iN7L1fHxO48kpGc0CfPfVJygCCcMYqB4uthxMIJpBrUNHo1i+saZAYOtUUVxRR8LlzKijr7DD/Ak8Tv6UZ3QVT/XASrJXwVmTv93Ubu+ixkKOo0SM5JPr7SdfZbM0fnIQWLdmgr+HPGrxJ8WCaagACmiONWqmTW4e6XBny/+TAdcynN8IJrWB2eycoUNarp0MPsg+YG8tBlCBWwnClMPlFWu8iOM4Pyl6kw+sTTDV48GblCWpO3anjLY7I30vyAzgZFpHY6QV2xJhNsCgnzf25teWv0FVHOj7+Hk41j8DsNGR7KzmVibrRZtstlNgecKqI5+oXxJ4xuWdnYH9nS4uror42mkmOLnjt5QeW0haHCY4pUqiqI3lB30KsHShsNabSo52vi2mRooMI+k9ebG/YFQ0GrkM6aeAPmz4lfeXPoXyauaiGW0X0xUXU/boKo43DHSYFH7JWQQCOZtmB8wCcoxsb/6TaijTD73miaen5GdlYGbDGStsePiuKPHNQzBvIwvI/eHslbr9KdwPdQFuGEEZ/rvnNI8kRRAwBkmO7B/PaMg1J68QFSUk7MbCKVelmRjcxm1WNN/4043PO4nW3XuEfCz5CwGNc+b8FZQxOSMmKWx/75/JaXoO4yVC1m56r8uc0+PTBkULoFEry/CJSj6Q1jEyAdf0COrgivyk346gP7Ag2Vy8UKhQGNc+hHUa8NxsUegomxVE4dam3x5gWa9JZVW9iolq2PtIZw8CBQOnU2Bs7fmBAgeZhmDVKI/mhkjNYU4MWKA7RefWE3hhdaeem9l4QUPeZcnuOSJs0qVxJ9tvd5tNVULKV8W5cuweU+s+PdwNHO30sO72dmwc7b01LFWYZeGvWXDLYTRMAsGizWlHBczlxUUNojsYOLBUcc/3goKg58Rti59z239Og45Mn7U5F5tLj+mZBlEdbY0s+PyAIbmIJ62g6lJIGzn xQK8PWDQ sqEnEeuu5qxjj7GVCAwgrr0tcrxpPWGY6DUdDU/XAzXe3pGVBdoeTXzp4UYGqd6NiIMF77OYYj3NZgu7tlr9oqvE84j3Pal0fAap605JjA/AUONeMPDyRnVjDPRF0Eq4uAH04Liw+UJDX/edV0RBn8JmZofHJEpMAN5G8VXZZWMRp+eU4CsxXG8YbZddYAxxeMl3+2/R4Qs+FywLnqI6fmvR71nAaT9ji0iLhhGfCUJlH8KMYtwR6deH12K066NceG46dcO1UQXR3BGxpNf50gnby2jDuBUWjZT+32rdDvOyIdPDzu70j2vu/LhptsA/NaV17Oa/MrpTTklFRD2EgxbMpmQdFddHKBRNekul6sRqndNDEFW1J/HR8iXdYAuMeiHW/RKB5Hzr0MS0SmTSfzfx1jaiD+w2I8QntVGz73I6j23k2Y+6Fm0PSyWTMkQCENHcpm4q3tfSoM2hW4ELZQnq2heQQ6ShPjWweWUKZ90rOH0akjgzqQe/ZYAzLzRJPiP0KiImHEf305mf18VISqUWmMV1pUugnRJSN19gAFfHR5EjNmR/XPFoD2hcEUSxhW+1Ye1/lUhJVJ6v/GNkdtZk/Xg== 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. Reported-by: Dominique Martinet Closes: https://lore.kernel.org/linux-mm/CABi2SkXUX_QqTQ10Yx9bBUGpN1wByOi_=gZU6WEy5a8MaQY3Jw@mail.gmail.com/T/ 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"); }