Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp151432rwl; Thu, 6 Apr 2023 16:28:35 -0700 (PDT) X-Google-Smtp-Source: AKy350Y9lVmw7lYUWDQ2o4RaDwQXEPFPi9Ew9G3UjlG5aTZA4h6NWnksSzW6hjxS1A1aLDds0N+q X-Received: by 2002:a17:903:41d0:b0:19e:b2f3:e8c4 with SMTP id u16-20020a17090341d000b0019eb2f3e8c4mr873912ple.25.1680823715124; Thu, 06 Apr 2023 16:28:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680823715; cv=none; d=google.com; s=arc-20160816; b=sWZVlilGLy3BbOec6J+IE1yqpwzAdWtFcGefdNxSSny0BcjVDvdYxM6dHz15CdMtZ/ ce3E0jZYSXqb0BRFRKgIJYjx4j8yipGOBfDkpzsTlLsNHCC1Frb/9ned6ef1/lpp2M7C wuTf2/zS+MngI52p3ea/mGc/68c7AJefqLpASahUdqV6fAbgXFsu3jy99wXkuX4Wq9rF iaKtL/xyS4tA+2FfbAPjASQFfQy8oFcSHQ5LELaWLB9fmfl0I2DYUKRFIyEsXbVMtpzx xyqj0RDhKzD7paXFtG/J5zGD5S9/9MsmJl6eb78WZZMjn9UM5VJ22eSYxNBYmThIqTTj l2Lg== 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:subject:cc:to:from:date :message-id:dkim-signature; bh=yNpperMVoMjGe9P/2ZjLt4qAm5WmNOqgf9FRwnhU5yY=; b=byMZjnKgGiW4IZSd5kzWUFMw40zzcCZrspMnjI24ApuThtoCp/TU7nKNQqtPsGzGeG fEITkz/phCSS0D5hXvPSOiSwaiLpTGpZVE9/e9iT4inzaq7QV2u7hySUe9horeDoBAhu kNOzVgN4I+beR+XDsUFVkzl4PhRJZdUkubnbYtqD2BPnUxQVGbH2yXtRpfUiiyOPzqsv 6r3mvwkfwh+NJgu2gT0AYm6PJr1r86l7/EkmiMPZ3DcvZJjbYx50TQv7c3CbmwTBDTrK OUW4l1bD/aDt1VwnLlbalMKrMEc8yBECnHZqStZ21Aw/Fn8SkmoRiLbNzohbqeb2sGv1 2Htw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=BoVVuhpG; 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=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z1-20020a63e541000000b004fb9559b9a4si2178924pgj.741.2023.04.06.16.28.22; Thu, 06 Apr 2023 16:28:35 -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; dkim=pass header.i=@chromium.org header.s=google header.b=BoVVuhpG; 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=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239451AbjDFXJl (ORCPT + 99 others); Thu, 6 Apr 2023 19:09:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36114 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239411AbjDFXJj (ORCPT ); Thu, 6 Apr 2023 19:09:39 -0400 Received: from mail-pj1-x1032.google.com (mail-pj1-x1032.google.com [IPv6:2607:f8b0:4864:20::1032]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B4DDB9ECC for ; Thu, 6 Apr 2023 16:09:37 -0700 (PDT) Received: by mail-pj1-x1032.google.com with SMTP id d22-20020a17090a111600b0023d1b009f52so88065pja.2 for ; Thu, 06 Apr 2023 16:09:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1680822577; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:subject:cc:to:from:date:message-id:from:to :cc:subject:date:message-id:reply-to; bh=yNpperMVoMjGe9P/2ZjLt4qAm5WmNOqgf9FRwnhU5yY=; b=BoVVuhpGsaWDgIhUoJKJ8LMVbXoLy7l490DOcO7JCwh6ZAlgfwSRVAHgYUuknWbX1u sMMAKyFSTNzK8Zp9rf3/68Fo3YDv8qlzsKpJsf5+RHt0jLINxttU1+6vBvSAWgR5y/l+ YJqW1e/9kctB910imujLtuoqhv3RWB8RSpSfI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680822577; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:subject:cc:to:from:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=yNpperMVoMjGe9P/2ZjLt4qAm5WmNOqgf9FRwnhU5yY=; b=y3Qr6j/0RFYzVRCzOtJ0EgnJKjoXttoSjiIcLI83dW3FmMM4PlHqiB5L+uLpdsG3R8 t/UmxA2hsgoBiv1cB6ftTz3/Nxrr6i70CbaBZNjDBusAp5IqMpNB+2TL9q6bke/x7Qbo PYMRKm5vPRQjiBR0bQQQz4Ti4KUI5noyG1AyT9aLz7+fBcr4HdU7ChEkPFspxV8JcLJv UIc/Kw2jl26RxRh0ExhIXPhrPKiLiD6U3elobaPMtT4/sxtfl5nXWvnNH8BLEfbqX+1J CoCg+ceF/mZ79+ReaVb6QOSYMGfl/Qjl/JHuRBzy9lSwYBeoiYvX9jmw7u5sWF3Qu37O PALQ== X-Gm-Message-State: AAQBX9eI9y5dsIm7nFNPorehzycnP07f5tXQo7OZpP88N/xgLmST0vbn AP8RY0Ei8VuGj5XwfKSv9ebKew== X-Received: by 2002:a17:90b:17d1:b0:237:2edb:d4e3 with SMTP id me17-20020a17090b17d100b002372edbd4e3mr218072pjb.27.1680822577189; Thu, 06 Apr 2023 16:09:37 -0700 (PDT) Received: from www.outflux.net (198-0-35-241-static.hfc.comcastbusiness.net. [198.0.35.241]) by smtp.gmail.com with ESMTPSA id g8-20020a17090ace8800b00234e6d2de3dsm1627452pju.11.2023.04.06.16.09.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Apr 2023 16:09:36 -0700 (PDT) Message-ID: <642f5130.170a0220.2a780.356a@mx.google.com> X-Google-Original-Message-ID: <202304061608.@keescook> Date: Thu, 6 Apr 2023 16:09:36 -0700 From: Kees Cook To: Daniel Latypov Cc: linux-hardening@vger.kernel.org, Kees Cook , Andy Shevchenko , Cezary Rojewski , Puyou Lu , Mark Brown , Josh Poimboeuf , Peter Zijlstra , Brendan Higgins , David Gow , Andrew Morton , Nathan Chancellor , Alexander Potapenko , Zhaoyang Huang , Randy Dunlap , Geert Uytterhoeven , Miguel Ojeda , Nick Desaulniers , Liam Howlett , Vlastimil Babka , Dan Williams , Rasmus Villemoes , Yury Norov , "Jason A. Donenfeld" , Sander Vanheule , Eric Biggers , "Masami Hiramatsu (Google)" , Andrey Konovalov , Linus Walleij , =?iso-8859-1?Q?Jos=E9_Exp=F3sito?= , linux-kernel@vger.kernel.org, kunit-dev@googlegroups.com Subject: Re: [PATCH 2/9] fortify: Allow KUnit test to build without FORTIFY References: <20230405235832.never.487-kees@kernel.org> <20230406000212.3442647-2-keescook@chromium.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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 On Wed, Apr 05, 2023 at 06:22:25PM -0700, Daniel Latypov wrote: > On Wed, Apr 5, 2023 at 5:08 PM Kees Cook wrote: > > In order for CI systems to notice all the skipped tests related to > > CONFIG_FORTIFY_SOURCE, allow the FORTIFY_SOURCE KUnit tests to build > > with or without CONFIG_FORTIFY_SOURCE. > > Hmm, I wonder if this warrants a deeper discussion. > It's a lot easier to have tests get disabled by kconfig if their deps > aren't met. Yeah, I wasn't sure where to put the "kunit defconfig" settings. "default.config" didn't seem to actually work as I was expecting. The real "problem" I'm solving is that FORTIFY_SOURCE isn't in the standard defconfig. > If there's pressure to have them compiled and just get marked skipped, > that sounds like that could be annoying. > Esp. in the cases where more code needs to be put behind > > #ifdef CONFIG_MY_DEP > > #endif > > But I have a suggestion below to simplify this a bit > > > > > Signed-off-by: Kees Cook > > --- > > lib/Kconfig.debug | 2 +- > > lib/fortify_kunit.c | 15 +++++++++++++++ > > 2 files changed, 16 insertions(+), 1 deletion(-) > > > > diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug > > index c8b379e2e9ad..d48a5f4b471e 100644 > > --- a/lib/Kconfig.debug > > +++ b/lib/Kconfig.debug > > @@ -2614,7 +2614,7 @@ config STACKINIT_KUNIT_TEST > > > > config FORTIFY_KUNIT_TEST > > tristate "Test fortified str*() and mem*() function internals at runtime" if !KUNIT_ALL_TESTS > > - depends on KUNIT && FORTIFY_SOURCE > > + depends on KUNIT > > default KUNIT_ALL_TESTS > > help > > Builds unit tests for checking internals of FORTIFY_SOURCE as used > > diff --git a/lib/fortify_kunit.c b/lib/fortify_kunit.c > > index c8c33cbaae9e..d054fc20a7d5 100644 > > --- a/lib/fortify_kunit.c > > +++ b/lib/fortify_kunit.c > > @@ -25,8 +25,21 @@ static const char array_of_10[] = "this is 10"; > > static const char *ptr_of_11 = "this is 11!"; > > static char array_unknown[] = "compiler thinks I might change"; > > > > +/* Handle being built without CONFIG_FORTIFY_SOURCE */ > > +#ifndef __compiletime_strlen > > +# define __compiletime_strlen __builtin_strlen > > +#endif > > + > > +#define skip_without_fortify() \ > > +do { \ > > + if (!IS_ENABLED(CONFIG_FORTIFY_SOURCE)) \ > > + kunit_skip(test, "Not built with CONFIG_FORTIFY_SOURCE=y"); \ > > +} while (0) > > Note: you can add an `init` function to the suite and skip the tests there. > > static void fortify_init(struct kunit *test) { > if (!IS_ENABLED(CONFIG_FORTIFY_SOURCE)) > kunit_skip(test, "Not built with CONFIG_FORTIFY_SOURCE=y"); > } > > ... > static struct kunit_suite fortify_test_suite = { > .name = "fortify", > + .init = fortify_init, > .test_cases = fortify_test_cases, > }; > > That way we don't have to add it to each test case. Ah! Excellent. I didn't realize it would have that effect. I will do that. :) -- Kees Cook