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"); }