Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp1610938pxf; Fri, 19 Mar 2021 11:01:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJznh+RhQJhKUz2gZZt7EzRloKUQkaCE6q2aejAMsQqVDUQ7n7iFWZoRdMG2OCGZxnMVYi9O X-Received: by 2002:a17:906:3f8c:: with SMTP id b12mr5922213ejj.340.1616176870013; Fri, 19 Mar 2021 11:01:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616176870; cv=none; d=google.com; s=arc-20160816; b=QUtHxwrO1yogoD54rhuSJ/UFBnr9x2bSfZGYDB5+JLKA94hxuhcsM1Mt2cRLd4Dsrr JlJgHkaAbXFHf2oi1biAiexpMGXoGFylZKbLyOg2+RYAQKx/t0oVzMOq9rMsiwDnqk5Z S8MjxPR4h6YGNvqLlzWdsrQldrUfvKVbgXgGt/xmOS/hwcySj5yHdSHXtygNi1s41Lr0 NmRP0cc/X5RYR9VCXDuIg+PdAxQZ+rnGb4s58rF0lVlpC2QdfHy0xaYbjDFp4hiNfgQx TRBVsjh+Q4L+a4Y2CPMsnJYxmrf4kaMpHJGcNaOGzx9Jt/kDaLrQHvd8o5RYTrRd12HC 7NfA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=+q/3pbtU4KRBeCiClf1jVde3rqJff5tAE3G/yUO/twY=; b=XlqLzK8699tMH3jrlL+hft+BmYUWrTI7e/DF1CfW1bv2HbODDMWHTrR6e9/vy5Ndqi gbsjoL5wTk3dNWef/o2M2kumaV3SwyBKj9MXZhA7sNakMx7Weli8poKYVG66NvayFpXi zOiBkefYUO94jC30mx/nkq4tLvpqa6n5FhiKKGFlqFDKvmIK/pN2ZKDWYUt3OWIeJs4S oYGlMfwtDZUgqfH9eWp1Vx+TSNvnoshRw6Nh4fO1QDwL7035rIgKBQnxP5AZFPOau0z/ +a6s1BAmleIiEBIVS3RXJNJbttJajQT2Mi746qJ4C3Su9iheNgnHe/4GSA1SI2o/mOe8 RF5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Px46bBJ7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bc12si4813910edb.241.2021.03.19.11.00.46; Fri, 19 Mar 2021 11:01:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Px46bBJ7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230319AbhCSR5F (ORCPT + 99 others); Fri, 19 Mar 2021 13:57:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43638 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230321AbhCSR4e (ORCPT ); Fri, 19 Mar 2021 13:56:34 -0400 Received: from mail-pg1-x534.google.com (mail-pg1-x534.google.com [IPv6:2607:f8b0:4864:20::534]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B8CE6C061763 for ; Fri, 19 Mar 2021 10:56:34 -0700 (PDT) Received: by mail-pg1-x534.google.com with SMTP id m3so4190453pga.1 for ; Fri, 19 Mar 2021 10:56:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to; bh=+q/3pbtU4KRBeCiClf1jVde3rqJff5tAE3G/yUO/twY=; b=Px46bBJ7mvrljx8ek9g5SOvd1jKb2iflgcqeVZiVe5xUV+ssBoFXrkhepVOQKvAu0W wc544ZAyTrYKxp4eU7wneG31VhgV2pG4OO8vR/OUGy+eT4tlva1ClajEyl5BGBpqNmzG hunNRfv4R9KjhPsKcrcyZbynh9VC1EqLCPhJk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=+q/3pbtU4KRBeCiClf1jVde3rqJff5tAE3G/yUO/twY=; b=XlBeQqEK6JSN+qzacM7ehtLaL6bLU5hcxCzFkkjorY0z2S5gETMnxYDIYEVhaA4BK1 l0mS8+LmAdnV9ImXDZVITdUA47f8o4QY2uQ/vt8fwgU5xno/cvWSQ/YaCR+fHjTbYTlz n+Rnc88m8SjrU00ckCGp/30s8DFLQHBRF+/0/NMfyj7qSAJyFQbgzGWAem9lGbqd43GZ 0zGYgo7bEAdG5lr2QAgvYw8t1lh4GcJyD8k7z/nMGq0m1ebFceMLBOLF5b6WVy6vAcOI r9GFeDVgZ/cY/R/IAsdJfOmydINLctE3DEHuRknjd36JTN6ULuDnsrsL2eZK+Xnj365m xNsg== X-Gm-Message-State: AOAM531cBozNdBK16W2fG6YDysTSQMddBu5OkWQf3XQrAL+dv0pq9+VH nzystXlSjPF2qzqztoyMjAv62g== X-Received: by 2002:aa7:8493:0:b029:1ee:75b2:2865 with SMTP id u19-20020aa784930000b02901ee75b22865mr10002946pfn.61.1616176594196; Fri, 19 Mar 2021 10:56:34 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id t1sm6114696pfc.173.2021.03.19.10.56.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Mar 2021 10:56:33 -0700 (PDT) Date: Fri, 19 Mar 2021 10:56:32 -0700 From: Kees Cook To: =?iso-8859-1?Q?Micka=EBl_Sala=FCn?= Cc: James Morris , Jann Horn , "Serge E . Hallyn" , Al Viro , Andrew Morton , Andy Lutomirski , Anton Ivanov , Arnd Bergmann , Casey Schaufler , David Howells , Jeff Dike , Jonathan Corbet , Michael Kerrisk , Richard Weinberger , Shuah Khan , Vincent Dagonneau , kernel-hardening@lists.openwall.com, linux-api@vger.kernel.org, linux-arch@vger.kernel.org, linux-doc@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-security-module@vger.kernel.org, x86@kernel.org, =?iso-8859-1?Q?Micka=EBl_Sala=FCn?= Subject: Re: [PATCH v30 10/12] selftests/landlock: Add user space tests Message-ID: <202103191026.D936362B@keescook> References: <20210316204252.427806-1-mic@digikod.net> <20210316204252.427806-11-mic@digikod.net> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20210316204252.427806-11-mic@digikod.net> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Mar 16, 2021 at 09:42:50PM +0100, Micka?l Sala?n wrote: > From: Micka?l Sala?n > > Test all Landlock system calls, ptrace hooks semantic and filesystem > access-control with multiple layouts. > > Test coverage for security/landlock/ is 93.6% of lines. The code not > covered only deals with internal kernel errors (e.g. memory allocation) > and race conditions. > > Cc: James Morris > Cc: Jann Horn > Cc: Kees Cook > Cc: Serge E. Hallyn > Cc: Shuah Khan > Signed-off-by: Micka?l Sala?n > Reviewed-by: Vincent Dagonneau > Link: https://lore.kernel.org/r/20210316204252.427806-11-mic@digikod.net This is terrific. I love the coverage. How did you measure this, BTW? To increase it into memory allocation failures, have you tried allocation fault injection: https://www.kernel.org/doc/html/latest/fault-injection/fault-injection.html > [...] > +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; > + > + ASSERT_NE(NULL, buf); > + > + /* Checks copy_from_user(). */ > + ASSERT_EQ(-1, landlock_create_ruleset(ruleset_attr, 0, 0)); > + /* The size if less than sizeof(struct landlock_attr_enforce). */ > + ASSERT_EQ(EINVAL, errno); > + ASSERT_EQ(-1, landlock_create_ruleset(ruleset_attr, 1, 0)); > + ASSERT_EQ(EINVAL, errno); Almost everywhere you're using ASSERT instead of EXPECT. Is this correct (in the sense than as soon as an ASSERT fails the rest of the test is skipped)? I do see you using EXPECT is some places, but I figured I'd ask about the intention here. > +/* > + * TEST_F_FORK() is useful when a test drop privileges but the corresponding > + * FIXTURE_TEARDOWN() requires them (e.g. to remove files from a directory > + * where write actions are denied). For convenience, FIXTURE_TEARDOWN() is > + * also called when the test failed, but not when FIXTURE_SETUP() failed. For > + * this to be possible, we must not call abort() but instead exit smoothly > + * (hence the step print). > + */ Hm, interesting. I think this should be extracted into a separate patch and added to the test harness proper. Could this be solved with TEARDOWN being called on SETUP failure? > +#define TEST_F_FORK(fixture_name, test_name) \ > + static void fixture_name##_##test_name##_child( \ > + struct __test_metadata *_metadata, \ > + FIXTURE_DATA(fixture_name) *self, \ > + const FIXTURE_VARIANT(fixture_name) *variant); \ > + TEST_F(fixture_name, test_name) \ > + { \ > + int status; \ > + const pid_t child = fork(); \ > + if (child < 0) \ > + abort(); \ > + if (child == 0) { \ > + _metadata->no_print = 1; \ > + fixture_name##_##test_name##_child(_metadata, self, variant); \ > + if (_metadata->skip) \ > + _exit(255); \ > + if (_metadata->passed) \ > + _exit(0); \ > + _exit(_metadata->step); \ > + } \ > + if (child != waitpid(child, &status, 0)) \ > + abort(); \ > + if (WIFSIGNALED(status) || !WIFEXITED(status)) { \ > + _metadata->passed = 0; \ > + _metadata->step = 1; \ > + return; \ > + } \ > + switch (WEXITSTATUS(status)) { \ > + case 0: \ > + _metadata->passed = 1; \ > + break; \ > + case 255: \ > + _metadata->passed = 1; \ > + _metadata->skip = 1; \ > + break; \ > + default: \ > + _metadata->passed = 0; \ > + _metadata->step = WEXITSTATUS(status); \ > + break; \ > + } \ > + } \ This looks like a subset of __wait_for_test()? Could __TEST_F_IMPL() be updated instead to do this? (Though the fork overhead might not be great for everyone.) -- Kees Cook