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