Received: by 2002:a05:6358:51dd:b0:131:369:b2a3 with SMTP id 29csp34065rwl; Wed, 9 Aug 2023 10:29:02 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFAfe7rRva20gqGqORwxpyfQqOjEG13xtmMBuyKIujn69fcnKLkFH3eFXx30nrfXFBfFeFb X-Received: by 2002:a17:903:248:b0:1b8:2c6f:3248 with SMTP id j8-20020a170903024800b001b82c6f3248mr3940086plh.39.1691602142103; Wed, 09 Aug 2023 10:29:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691602142; cv=none; d=google.com; s=arc-20160816; b=GfB6xkim6LZaTICnEvEarcDSdLsVQUQ2HFYbfU7hhspGCD/n2kKB5O+JbWdajz4JpT fMtXKaJJz6pN6ZlnZr8Hq7+3Gra9FKtg8vibHpwZ04D3/uBlBV+U+HTWB44Lf/9Yh6ps yRoz8ojs/hfDnEPtM3jpjBTekmw8BCud2CjRgzQ3Yr1c2NlHCmNrPmdvYUX6ykTr0Civ pXNzzYRcCtwArZ2Rex+umDWiiXTvxkzkunSPqZRL4hsVkFtvCTbjacgrZ1g07Ns3OM4L 5YcodbyurrJSgTtZp/+CQbUVkcht2i7Vxxk/uzme8e5eaXMs9sXkjE8IrXWjsJ/stFBE ZGqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=r+vqNHxA1FhnNEYjItzn12SRHUd3Tf4TNfxKvTMxuTg=; fh=nE/UqZX6qzpWLzz9CgtzS7bs+n+xzJ8NCqsu+2HYlgM=; b=1K/T4m13WIZs9GE48Q/9Npquq+p16pvd62cEMJFiO9c9oDycec5fgQXNXqYujApffz 9C++QJdlnxYw3WW4wy+ZHX54r9geUdb547tzCXG9YsUvy3rVEUhycR7iPEAQEf0fS051 L0Z5KH4mWmYdRHNgoinUlCqc0wbBqnTX/HfUXKEgPaOtyt2R38NZQ9wx72nDFoEvM5Oq cgwoji40sRz/Sw53zDiGSkGeUnf2VNzRI5DAWlPFLcG+DnGsaGKBsz3+RoSfXbrv3vC8 rfO4QPvOiSkJjC+OgrX/mfPcSppHFEUg0y0oA2AjHSceTZULv3iUV7uB1QVumZvTcEte 5uHw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t1-20020a1709027fc100b001bbaa5e95fdsi9486365plb.102.2023.08.09.10.28.49; Wed, 09 Aug 2023 10:29:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232702AbjHIREt (ORCPT + 99 others); Wed, 9 Aug 2023 13:04:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46234 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232461AbjHIREo (ORCPT ); Wed, 9 Aug 2023 13:04:44 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 4CE0E2107; Wed, 9 Aug 2023 10:04:44 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 5F5F6139F; Wed, 9 Aug 2023 10:05:26 -0700 (PDT) Received: from donnerap.arm.com (donnerap.manchester.arm.com [10.32.100.58]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 310843F59C; Wed, 9 Aug 2023 10:04:43 -0700 (PDT) From: Andre Przywara To: =?UTF-8?q?Micka=C3=ABl=20Sala=C3=BCn?= , Shuah Khan Cc: linux-security-module@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/2] selftests: landlock: skip all tests without landlock syscall Date: Wed, 9 Aug 2023 18:04:35 +0100 Message-Id: <20230809170435.1312162-3-andre.przywara@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230809170435.1312162-1-andre.przywara@arm.com> References: <20230809170435.1312162-1-andre.przywara@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org "landlock" is a relatively new syscall, and most defconfigs do not enable it (yet). On systems without this syscall available, the selftests fail at the moment, instead of being skipped. Check the availability of the landlock system call before executing each test, and skip the rest of the tests if we get an ENOSYS back. Signed-off-by: Andre Przywara --- tools/testing/selftests/landlock/base_test.c | 27 ++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/tools/testing/selftests/landlock/base_test.c b/tools/testing/selftests/landlock/base_test.c index 1e3b6de57e80e..c539cec775fba 100644 --- a/tools/testing/selftests/landlock/base_test.c +++ b/tools/testing/selftests/landlock/base_test.c @@ -21,12 +21,20 @@ #define O_PATH 010000000 #endif +static bool has_syscall(void) +{ + return landlock_create_ruleset(NULL, 0, 0) == -1 && errno != ENOSYS; +} + TEST(inconsistent_attr) { const long page_size = sysconf(_SC_PAGESIZE); char *const buf = malloc(page_size + 1); struct landlock_ruleset_attr *const ruleset_attr = (void *)buf; + if (!has_syscall()) + SKIP(return, "landlock syscall not available"); + ASSERT_NE(NULL, buf); /* Checks copy_from_user(). */ @@ -75,6 +83,10 @@ TEST(abi_version) const struct landlock_ruleset_attr ruleset_attr = { .handled_access_fs = LANDLOCK_ACCESS_FS_READ_FILE, }; + + if (!has_syscall()) + SKIP(return, "landlock syscall not available"); + ASSERT_NE(0, landlock_create_ruleset(NULL, 0, LANDLOCK_CREATE_RULESET_VERSION)); @@ -107,6 +119,9 @@ TEST(create_ruleset_checks_ordering) .handled_access_fs = LANDLOCK_ACCESS_FS_READ_FILE, }; + if (!has_syscall()) + SKIP(return, "landlock syscall not available"); + /* Checks priority for invalid flags. */ ASSERT_EQ(-1, landlock_create_ruleset(NULL, 0, invalid_flag)); ASSERT_EQ(EINVAL, errno); @@ -153,6 +168,9 @@ TEST(add_rule_checks_ordering) const int ruleset_fd = landlock_create_ruleset(&ruleset_attr, sizeof(ruleset_attr), 0); + if (!has_syscall()) + SKIP(return, "landlock syscall not available"); + ASSERT_LE(0, ruleset_fd); /* Checks invalid flags. */ @@ -200,6 +218,9 @@ TEST(restrict_self_checks_ordering) const int ruleset_fd = landlock_create_ruleset(&ruleset_attr, sizeof(ruleset_attr), 0); + if (!has_syscall()) + SKIP(return, "landlock syscall not available"); + ASSERT_LE(0, ruleset_fd); path_beneath_attr.parent_fd = open("/tmp", O_PATH | O_NOFOLLOW | O_DIRECTORY | O_CLOEXEC); @@ -240,6 +261,9 @@ TEST(ruleset_fd_io) int ruleset_fd; char buf; + if (!has_syscall()) + SKIP(return, "landlock syscall not available"); + drop_caps(_metadata); ruleset_fd = landlock_create_ruleset(&ruleset_attr, sizeof(ruleset_attr), 0); @@ -267,6 +291,9 @@ TEST(ruleset_fd_transfer) pid_t child; int status; + if (!has_syscall()) + SKIP(return, "landlock syscall not available"); + drop_caps(_metadata); /* Creates a test ruleset with a simple rule. */ -- 2.25.1