Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp4716032iob; Sun, 8 May 2022 23:03:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJygFYX91kWUpgAekx6PlJzjz4Rh58e83JgrvKflGhJfo9VsRVkTayDm3UteWVjHx4+oLX+n X-Received: by 2002:a63:f710:0:b0:3c6:3561:42a5 with SMTP id x16-20020a63f710000000b003c6356142a5mr11773593pgh.295.1652076211238; Sun, 08 May 2022 23:03:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652076211; cv=none; d=google.com; s=arc-20160816; b=bUDurjANyMV9fsBdyaTZw394g6XfuI0s5imn8UDO+O2a/anRSNyEn5MTrsIANiwHtF 3DVcjdOhXFX+YyITazKHIdciohp5W8YuooVQR8GIaOymaekC7VZ7fgwi5RaN2MKxX1Eh QOzAZpnXxX0i5fUPHbPKfw7Cw8RJAhQLs3e10pVhQbs44EbfvHVbjuCJmBO7LT8byGWV rg8+a7RQ7NhgCFrShFzkvumk8HVTlFiaW5Z2yp95/z8CmX+9qbOPa7bU2NGLLPm1yclc 2FEf0cJkjvegYhBg+hsYyLCg+RT8cmVXwtVqdt7vp3oXzgthVz+vaH/EtPcgFNFWXNHY k3kg== 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 :dkim-signature; bh=vr0qRQV81rSwP/pbzhoy2ebIpl58CF34EPrIyi89cao=; b=m4i2hbzgltwiE4Q/fn9I6MWkQR3cDMSqtzEDE04W8T/pKew/K2AAeG/uxftkOob/oh WpA+du64XBGqVZedKgGa8yHFzjrpx6tKn7pXTRMNsFgkxijH45hA9DN28TiRZ7GSWp2T jgBqF2KqOWOmi1q7vsbFeUjfKm/A5lTjQ5CNnHff2GYDn2Bs8ySXHLq09rI1U4aCBUEC rsov2L/kV6kW0FTeiqFNBRDA/AmuiH1OOHM63WNe/ayTe19WbxdqbV2t1tz5CeFp38we 66jevua4So2CSi2OP/PlPtScTbmj/vjjid8pfH/u+pnrQ+rW/KiK5kyE0AOlXN/sSDSm yE1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@digikod.net header.s=20191114 header.b="mB7DYV/S"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id t7-20020a170902b20700b0015d133dea93si10057099plr.581.2022.05.08.23.03.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 May 2022 23:03:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@digikod.net header.s=20191114 header.b="mB7DYV/S"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 3B32016F907; Sun, 8 May 2022 23:03:22 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1443523AbiEFQLV (ORCPT + 99 others); Fri, 6 May 2022 12:11:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43148 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1443446AbiEFQKt (ORCPT ); Fri, 6 May 2022 12:10:49 -0400 Received: from smtp-bc0d.mail.infomaniak.ch (smtp-bc0d.mail.infomaniak.ch [45.157.188.13]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A3984DF71 for ; Fri, 6 May 2022 09:07:05 -0700 (PDT) Received: from smtp-2-0000.mail.infomaniak.ch (unknown [10.5.36.107]) by smtp-2-3000.mail.infomaniak.ch (Postfix) with ESMTPS id 4KvwS81Q89zMqpn1; Fri, 6 May 2022 18:07:04 +0200 (CEST) Received: from localhost (unknown [23.97.221.149]) by smtp-2-0000.mail.infomaniak.ch (Postfix) with ESMTPA id 4KvwS76b8czlhSM9; Fri, 6 May 2022 18:07:03 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=digikod.net; s=20191114; t=1651853224; bh=02n97EaILIuqTsXFx/oybn/WrgtfMPsX5MAhsYFLVdg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mB7DYV/SYQehyM22hGE2FaNyE+qytirrVLYuOtA5/fmNG0tvMKL0uif/XtLt46KL+ qHRWNjpk5l4uTjLOaCMbVlf3BrBO22WfN+zWuHa0tCo+ZjfUUVEMqP+/UVF4dMfEm8 u7gBJc2rs1hhrslip4BwNssnXAtdCN+Q8g0+Ur3U= From: =?UTF-8?q?Micka=C3=ABl=20Sala=C3=BCn?= To: James Morris , "Serge E . Hallyn" Cc: =?UTF-8?q?Micka=C3=ABl=20Sala=C3=BCn?= , Jann Horn , Kees Cook , Konstantin Meskhidze , Nathan Chancellor , Nick Desaulniers , Paul Moore , Shuah Khan , linux-api@vger.kernel.org, linux-kernel@vger.kernel.org, linux-security-module@vger.kernel.org Subject: [PATCH v2 10/10] selftests/landlock: Test landlock_create_ruleset(2) argument check ordering Date: Fri, 6 May 2022 18:08:20 +0200 Message-Id: <20220506160820.524344-11-mic@digikod.net> In-Reply-To: <20220506160820.524344-1-mic@digikod.net> References: <20220506160820.524344-1-mic@digikod.net> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 Add inval_create_ruleset_arguments, extension of inval_create_ruleset_flags, to also check error ordering for landlock_create_ruleset(2). This is similar to the previous commit checking landlock_add_rule(2). Test coverage for security/landlock is 94.4% of 504 lines accorging to gcc/gcov-11. Signed-off-by: Mickaël Salaün Link: https://lore.kernel.org/r/20220506160820.524344-11-mic@digikod.net --- Changes since v1: * New patch. --- tools/testing/selftests/landlock/base_test.c | 21 +++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/landlock/base_test.c b/tools/testing/selftests/landlock/base_test.c index 21fb33581419..35f64832b869 100644 --- a/tools/testing/selftests/landlock/base_test.c +++ b/tools/testing/selftests/landlock/base_test.c @@ -97,14 +97,17 @@ TEST(abi_version) ASSERT_EQ(EINVAL, errno); } -TEST(inval_create_ruleset_flags) +/* Tests ordering of syscall argument checks. */ +TEST(create_ruleset_checks_ordering) { const int last_flag = LANDLOCK_CREATE_RULESET_VERSION; const int invalid_flag = last_flag << 1; + int ruleset_fd; const struct landlock_ruleset_attr ruleset_attr = { .handled_access_fs = LANDLOCK_ACCESS_FS_READ_FILE, }; + /* Checks priority for invalid flags. */ ASSERT_EQ(-1, landlock_create_ruleset(NULL, 0, invalid_flag)); ASSERT_EQ(EINVAL, errno); @@ -119,6 +122,22 @@ TEST(inval_create_ruleset_flags) landlock_create_ruleset(&ruleset_attr, sizeof(ruleset_attr), invalid_flag)); ASSERT_EQ(EINVAL, errno); + + /* Checks too big ruleset_attr size. */ + ASSERT_EQ(-1, landlock_create_ruleset(&ruleset_attr, -1, 0)); + ASSERT_EQ(E2BIG, errno); + + /* Checks too small ruleset_attr size. */ + ASSERT_EQ(-1, landlock_create_ruleset(&ruleset_attr, 0, 0)); + ASSERT_EQ(EINVAL, errno); + ASSERT_EQ(-1, landlock_create_ruleset(&ruleset_attr, 1, 0)); + ASSERT_EQ(EINVAL, errno); + + /* Checks valid call. */ + ruleset_fd = + landlock_create_ruleset(&ruleset_attr, sizeof(ruleset_attr), 0); + ASSERT_LE(0, ruleset_fd); + ASSERT_EQ(0, close(ruleset_fd)); } /* Tests ordering of syscall argument checks. */ -- 2.35.1