From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=83.166.143.172 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796404064; b=Te194LP0JQKEP5XAcYQWVWNqvUiOtuUaqYbJoTMseM7bHWArSsL41B8fPeWPp+zfn1xI 6UuKgtVrrAignok0qxP7aM8jn5Bof3c8JWRaKxyiMuPnkngwhWkguxtn/15mGv7ThDsu2 KPZ/m2AyUm1vB6gLb5LSIsQK43Qg7XQrEd0eTKcWrxlbF4sLIc2Wrh5XI0MYubiHgFCOC mJGuMumlSUQTzOqGJiSDGBGAb990g00Ap9lPf6je6siqW+Bse2xG/y4LqNOBA68olDxOe zZm04axPtzZHhgwJRgrzyhvQsuvLbnqYWufv8HyFwgAX8fnhsFxgOdukVVIXnn4SKLw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796404064; h=DMARC-Filter:Received:DKIM-Signature:Received:Date:From:To:Cc: Subject:Message-ID:References:MIME-Version:Content-Type: Content-Disposition:Content-Transfer-Encoding:In-Reply-To: X-Infomaniak-Routing; bh=qXsq1T1Gb7Ph28Hv7WvHNis8r7ggf4HgwmooIMFCqSU=; b=GYnH4aBQfDZACla62YfU8AjCbMQ6T8Rq8IDYOrj+//a49Z7oEAyAe8tWVLI52XU89Vbq R3F727P/gFZrFuWnRY30vvckVXtaVoR83AHqSPbLwyCuzO6vZbb3oeTuRiKjHzDAZ0Bxr ia01QJMdUb9K487Kk2OMx/RNW61z54sjA/llEw0ZH4Ci+vdIRdGyRQgeFhLu5l3f9zgL7 v8TbTLlSr7HmtAqIbFDK77qTPrDvDvDZ9ShQuJj9HjRuQmCy6Y8bnS8yMDtkC0rM7VJTS 5VbKNQaG2pReevN7/K0UalOozxz0ueoGXBREKQXRj56ng0+zjTyv4DC+7FXxjaQ6fFw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none header.from=digikod.net; spf=pass smtp.mailfrom=digikod.net; dkim=pass header.d=digikod.net header.i=@digikod.net header.a=rsa-sha256 header.s=20191114 header.b=vXtLAHL+; arc=none smtp.remote-ip=83.166.143.172 Received: from smtp-8fac.mail.infomaniak.ch (smtp-8fac.mail.infomaniak.ch [83.166.143.172]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 12D48606A32D for ; Fri, 4 Dec 2026 17:07:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 12D48606A32D Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=digikod.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=digikod.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=digikod.net header.i=@digikod.net header.a=rsa-sha256 header.s=20191114 header.b=vXtLAHL+ Received: from smtp-3-0000.mail.infomaniak.ch (smtp-3-0000.mail.infomaniak.ch [10.4.36.107]) by smtp-3-3000.mail.infomaniak.ch (Postfix) with ESMTPS id 4jgybr3r71zs66; Fri, 4 Dec 2026 18:07:36 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=digikod.net; s=20191114; t=1796404056; bh=qXsq1T1Gb7Ph28Hv7WvHNis8r7ggf4HgwmooIMFCqSU=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=vXtLAHL+TTdzpk3G0dyb63JQvF82d6ne6WycjClh3PR6CBkQIn98tgBZoKn/hZb9U ScOeaT5pVGhwQxrnKKXQ8V46lUL0suwLx64I919i9QrtO0u0CFANnKXeL0LEKIr5aM mhgHzdSlKzSItT8HQCOBEmKBGny5wi7GlRXyu8pU= Received: from unknown by smtp-3-0000.mail.infomaniak.ch (Postfix) with ESMTPA id 4jgybq55jszrFD; Fri, 4 Dec 2026 18:07:35 +0100 (CET) Date: Fri, 4 Dec 2026 18:07:35 +0100 From: =?utf-8?Q?Micka=C3=ABl_Sala=C3=BCn?= To: =?utf-8?Q?G=C3=BCnther?= Noack Cc: =?utf-8?Q?G=C3=BCnther?= Noack , Shuah Khan , linux-security-module@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 11/27] selftests/landlock: Assert helper results that are used afterwards Message-ID: <20261204.IeToh1phai9E@digikod.net> References: <20261104-selftests-refactor-v2-0-c52f23f7ce33@gmail.com> <20261104-selftests-refactor-v2-11-c52f23f7ce33@gmail.com> X-Mailing-List: linux-security-module@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20261104-selftests-refactor-v2-11-c52f23f7ce33@gmail.com> X-Infomaniak-Routing: alpha On Wed, Nov 04, 2026 at 10:08:57PM +0100, Günther Noack wrote: > Some helpers check a result with EXPECT_*() and then use it: > cap_get_proc() in _init_caps() and _change_cap(), and > landlock_create_ruleset() in drop_access_rights(), create_domain() and > create_fs_domain(). On failure they pass NULL or -1 to the next calls, > which then fail with misleading messages. > > Use ASSERT_*() for these checks, as create_scoped_domain() already does. > > Signed-off-by: Günther Noack > --- > tools/testing/selftests/landlock/common.h | 6 +++--- > tools/testing/selftests/landlock/ptrace_test.c | 2 +- > tools/testing/selftests/landlock/scoped_abstract_unix_test.c | 2 +- > 3 files changed, 5 insertions(+), 5 deletions(-) > > diff --git a/tools/testing/selftests/landlock/common.h b/tools/testing/selftests/landlock/common.h > index 6c2aa913ff11..a662a68bee7b 100644 > --- a/tools/testing/selftests/landlock/common.h > +++ b/tools/testing/selftests/landlock/common.h > @@ -55,7 +55,7 @@ static void _init_caps(struct __test_metadata *const _metadata, bool drop_all) > EXPECT_EQ(0, cap_set_secbits(noroot)); > > cap_p = cap_get_proc(); > - EXPECT_NE(NULL, cap_p); > + ASSERT_NE(NULL, cap_p); > EXPECT_NE(-1, cap_clear(cap_p)); > if (!drop_all) { > EXPECT_NE(-1, cap_set_flag(cap_p, CAP_PERMITTED, > @@ -91,7 +91,7 @@ static void _change_cap(struct __test_metadata *const _metadata, > cap_t cap_p; > > cap_p = cap_get_proc(); > - EXPECT_NE(NULL, cap_p); > + ASSERT_NE(NULL, cap_p); If _change_cap() aborts during cleanup_layout(), we never reach audit_cleanup(). Could it return an error when cap_get_proc() fails, so teardown can still try to clean up audit state? Also, cap_stacking.two_layers can pass a negative FD to add_cap_rule() before checking it. Could you check the FD before adding the rule and keep the check for the FS-only branch? > EXPECT_NE(-1, cap_set_flag(cap_p, flag, 1, &cap, value)); > EXPECT_NE(-1, cap_set_proc(cap_p)) > { > @@ -227,7 +227,7 @@ drop_access_rights(struct __test_metadata *const _metadata, > > ruleset_fd = > landlock_create_ruleset(ruleset_attr, sizeof(*ruleset_attr), 0); > - EXPECT_LE(0, ruleset_fd) > + ASSERT_LE(0, ruleset_fd) > { > TH_LOG("Failed to create a ruleset: %s", strerror(errno)); > } > diff --git a/tools/testing/selftests/landlock/ptrace_test.c b/tools/testing/selftests/landlock/ptrace_test.c > index 10371c1830ad..b951889cd6ca 100644 > --- a/tools/testing/selftests/landlock/ptrace_test.c > +++ b/tools/testing/selftests/landlock/ptrace_test.c > @@ -37,7 +37,7 @@ static void create_domain(struct __test_metadata *const _metadata) > > ruleset_fd = > landlock_create_ruleset(&ruleset_attr, sizeof(ruleset_attr), 0); > - EXPECT_LE(0, ruleset_fd) > + ASSERT_LE(0, ruleset_fd) > { > TH_LOG("Failed to create a ruleset: %s", strerror(errno)); > } > diff --git a/tools/testing/selftests/landlock/scoped_abstract_unix_test.c b/tools/testing/selftests/landlock/scoped_abstract_unix_test.c > index 5e8224623780..55a1599819c8 100644 > --- a/tools/testing/selftests/landlock/scoped_abstract_unix_test.c > +++ b/tools/testing/selftests/landlock/scoped_abstract_unix_test.c > @@ -40,7 +40,7 @@ static void create_fs_domain(struct __test_metadata *const _metadata) > > ruleset_fd = > landlock_create_ruleset(&ruleset_attr, sizeof(ruleset_attr), 0); > - EXPECT_LE(0, ruleset_fd) > + ASSERT_LE(0, ruleset_fd) > { > TH_LOG("Failed to create a ruleset: %s", strerror(errno)); > } > > -- > 2.56.0 > >