mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Kees Cook <keescook@chromium.org>
To: Daniel Latypov <dlatypov@google.com>
Cc: linux-hardening@vger.kernel.org, "Kees Cook" <kees@outflux.net>,
	"Andy Shevchenko" <andy@kernel.org>,
	"Cezary Rojewski" <cezary.rojewski@intel.com>,
	"Puyou Lu" <puyou.lu@gmail.com>,
	"Mark Brown" <broonie@kernel.org>,
	"Josh Poimboeuf" <jpoimboe@kernel.org>,
	"Peter Zijlstra" <peterz@infradead.org>,
	"Brendan Higgins" <brendan.higgins@linux.dev>,
	"David Gow" <davidgow@google.com>,
	"Andrew Morton" <akpm@linux-foundation.org>,
	"Nathan Chancellor" <nathan@kernel.org>,
	"Alexander Potapenko" <glider@google.com>,
	"Zhaoyang Huang" <zhaoyang.huang@unisoc.com>,
	"Randy Dunlap" <rdunlap@infradead.org>,
	"Geert Uytterhoeven" <geert+renesas@glider.be>,
	"Miguel Ojeda" <ojeda@kernel.org>,
	"Nick Desaulniers" <ndesaulniers@google.com>,
	"Liam Howlett" <liam.howlett@oracle.com>,
	"Vlastimil Babka" <vbabka@suse.cz>,
	"Dan Williams" <dan.j.williams@intel.com>,
	"Rasmus Villemoes" <linux@rasmusvillemoes.dk>,
	"Yury Norov" <yury.norov@gmail.com>,
	"Jason A. Donenfeld" <Jason@zx2c4.com>,
	"Sander Vanheule" <sander@svanheule.net>,
	"Eric Biggers" <ebiggers@google.com>,
	"Masami Hiramatsu (Google)" <mhiramat@kernel.org>,
	"Andrey Konovalov" <andreyknvl@gmail.com>,
	"Linus Walleij" <linus.walleij@linaro.org>,
	"José Expósito" <jose.exposito89@gmail.com>,
	linux-kernel@vger.kernel.org, kunit-dev@googlegroups.com
Subject: Re: [PATCH 2/9] fortify: Allow KUnit test to build without FORTIFY
Date: Thu, 6 Apr 2023 16:09:36 -0700	[thread overview]
Message-ID: <642f5130.170a0220.2a780.356a@mx.google.com> (raw)
In-Reply-To: <CAGS_qxpk8WsPjN702nhQcEsK4yzzXZCc5n5cTVMSpwnVhCHSvA@mail.gmail.com>

On Wed, Apr 05, 2023 at 06:22:25PM -0700, Daniel Latypov wrote:
> On Wed, Apr 5, 2023 at 5:08 PM Kees Cook <keescook@chromium.org> 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
> <test helpers, etc>
> #endif
> 
> But I have a suggestion below to simplify this a bit
> 
> >
> > Signed-off-by: Kees Cook <kees@outflux.net>
> > ---
> >  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

  reply	other threads:[~2023-04-06 23:09 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-06  0:01 [PATCH 0/9] fortify: Add KUnit tests for runtime overflows Kees Cook
2023-04-06  0:02 ` [PATCH 1/9] kunit: tool: Enable CONFIG_FORTIFY_SOURCE under UML Kees Cook
2023-04-06  3:10   ` Kees Cook
2023-04-06  0:02 ` [PATCH 2/9] fortify: Allow KUnit test to build without FORTIFY Kees Cook
2023-04-06  1:22   ` Daniel Latypov
2023-04-06 23:09     ` Kees Cook [this message]
2023-04-06  0:02 ` [PATCH 3/9] string: Add Kunit tests for strcat() family Kees Cook
2023-04-06  9:11   ` Alexander Potapenko
2023-04-06 23:07     ` Kees Cook
2023-04-12 12:34       ` Alexander Potapenko
2023-04-06  0:02 ` [PATCH 4/9] fortify: Add protection for strlcat() Kees Cook
2023-04-06 13:32   ` Miguel Ojeda
2023-04-06 22:58     ` Kees Cook
2023-04-06  0:02 ` [PATCH 5/9] fortify: strcat: Move definition to use fortified strlcat() Kees Cook
2023-04-06  0:02 ` [PATCH 6/9] fortify: Split reporting and avoid passing string pointer Kees Cook
2023-04-06 10:20   ` Andy Shevchenko
2023-04-06 22:57     ` Kees Cook
2023-04-07  8:34       ` Andy Shevchenko
2023-04-07 19:49         ` Kees Cook
2023-04-06 13:44   ` Miguel Ojeda
2023-04-06 22:54     ` Kees Cook
2023-04-06 15:23   ` Alexander Lobakin
2023-04-06 22:54     ` Kees Cook
2023-04-06  0:02 ` [PATCH 7/9] fortify: Provide KUnit counters for failure testing Kees Cook
2023-04-06  0:02 ` [PATCH 8/9] fortify: Add KUnit tests for runtime overflows Kees Cook
2023-04-06  0:02 ` [PATCH 9/9] fortify: Improve buffer overflow reporting Kees Cook

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=642f5130.170a0220.2a780.356a@mx.google.com \
    --to=keescook@chromium.org \
    --cc=Jason@zx2c4.com \
    --cc=akpm@linux-foundation.org \
    --cc=andreyknvl@gmail.com \
    --cc=andy@kernel.org \
    --cc=brendan.higgins@linux.dev \
    --cc=broonie@kernel.org \
    --cc=cezary.rojewski@intel.com \
    --cc=dan.j.williams@intel.com \
    --cc=davidgow@google.com \
    --cc=dlatypov@google.com \
    --cc=ebiggers@google.com \
    --cc=geert+renesas@glider.be \
    --cc=glider@google.com \
    --cc=jose.exposito89@gmail.com \
    --cc=jpoimboe@kernel.org \
    --cc=kees@outflux.net \
    --cc=kunit-dev@googlegroups.com \
    --cc=liam.howlett@oracle.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@rasmusvillemoes.dk \
    --cc=mhiramat@kernel.org \
    --cc=nathan@kernel.org \
    --cc=ndesaulniers@google.com \
    --cc=ojeda@kernel.org \
    --cc=peterz@infradead.org \
    --cc=puyou.lu@gmail.com \
    --cc=rdunlap@infradead.org \
    --cc=sander@svanheule.net \
    --cc=vbabka@suse.cz \
    --cc=yury.norov@gmail.com \
    --cc=zhaoyang.huang@unisoc.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome