Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp178988iob; Mon, 2 May 2022 16:24:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzt0DUR4rda/i/Cb65PgEYNCTK7E4TTv4xF0+Tq/81WbuJZBq69RethFLwEOQpVTxL6b3Bo X-Received: by 2002:a17:903:22c7:b0:15d:1c51:5bf4 with SMTP id y7-20020a17090322c700b0015d1c515bf4mr14399456plg.54.1651533857176; Mon, 02 May 2022 16:24:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651533857; cv=none; d=google.com; s=arc-20160816; b=J+HOb/LDQVPUHQd9KVu3UN1TwNWZC1WMuzIY7h0kqO20EuNdbncifaifTJTYlQK5Xc o/CCEcV9BAbjqJQo2QWfjwP2KACZKc6hxaXHpuovkFafIiikgejB8qobcdhte4hsLBpu vRjn5esAnly9QFduGQIBzuzUYCpuzjqlixxgX2MKRMq6bhNeMJtm/3miBbKbi48drKK+ uPj3KzwMXrDDhP9VzS8oPMUMDTGEmAS3LfTAukaQjm0es2BCIt8kyAZLylmxASeBpms4 75jhDF89piD5j0XBPm1K0uaeFCx6tYgEfc2GuDmKF8DNPm77xCNpC97loHZoxzyvIloY E8wQ== 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-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=805KELMticLJmPeBeSATD3TOM/bK/tzLYYAmcSpcc/E=; b=a5czepV3I5Lfgr90ePo8tzLvw/Quz/MutwEL/MBavVMhX8hCoaZwjlnuLCg31n0oPi RhFGNX6pev0r6VbB4elI761KrZWRhV5ThmyZUQakizbJMNCMYlGMEoZw/9ggLYDxlJai vd6eLD3dvmz90aTR52axW/PD52bMDh2J6tj7lLYpMfI+305IiYxyplGtgVaGquDs//nE MNsRxAgPzvs9T6ywwDRE5iZwE66d66cJyL9pa0YWfgNp2QkceAGIhoGrAEFADQV13JRV hyuJVw5lgmzJg+5a5EVGr89ZujHCo0FDZIYf8+FNlDObaqGYt6S1uOxDINBU27/AYQhu gppg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="zV/Ee37r"; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id h16-20020a056a001a5000b004f784a59a59si2677805pfv.0.2022.05.02.16.24.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 May 2022 16:24:17 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="zV/Ee37r"; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B19992B199; Mon, 2 May 2022 16:24:03 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235929AbiD2HMb (ORCPT + 99 others); Fri, 29 Apr 2022 03:12:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54432 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232023AbiD2HM3 (ORCPT ); Fri, 29 Apr 2022 03:12:29 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 54098BF958; Fri, 29 Apr 2022 00:09:12 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id E452861FAC; Fri, 29 Apr 2022 07:09:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BE2F5C385A7; Fri, 29 Apr 2022 07:09:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1651216151; bh=pPnNA7l+RPM/P9eQGjg00BuTyqTQsPsqQezFfVprvwo=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=zV/Ee37rg7nWJC6Gzw0dbhxcCqPFx7CIi0FPv8U8J/QH5RIlLqvhRitsSrxPPxkAt H+xZ8whaRKX/4IaX7ua4ADZQkmlPWxyWMK3cC1JGZZs2wpapFl+TSC+etpK4hapghA HkRQMn42GSiZwHQAWGBqNnhQgZZYCgk7S8gEov4M= Date: Fri, 29 Apr 2022 09:09:08 +0200 From: Greg KH To: David Gow Cc: Brendan Higgins , Andy Shevchenko , Jonathan Corbet , Andrew Morton , Kees Cook , Shuah Khan , "Guilherme G . Piccoli" , Luis Chamberlain , Sebastian Reichel , John Ogness , Joe Fradley , Daniel Latypov , kunit-dev@googlegroups.com, linux-kselftest@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] kunit: Taint kernel if any tests run Message-ID: References: <20220429043913.626647-1-davidgow@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220429043913.626647-1-davidgow@google.com> X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, 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=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 Fri, Apr 29, 2022 at 12:39:14PM +0800, David Gow wrote: > KUnit tests are not supposed to run on production systems: they may do > deliberately illegal things to trigger errors, and have security > implications (assertions will often deliberately leak kernel addresses). > > Add a new taint type, TAINT_KUNIT to signal that a KUnit test has been > run. This will be printed as 'N' (for kuNit, as K, U and T were already > taken). > > This should discourage people from running KUnit tests on production > systems, and to make it easier to tell if tests have been run > accidentally (by loading the wrong configuration, etc.) > > Signed-off-by: David Gow > --- > > This is something I'd been thinking about for a while, and it came up > again, so I'm finally giving it a go. > > Two notes: > - I decided to add a new type of taint, as none of the existing ones > really seemed to fit. We could live with considering KUnit tests as > TAINT_WARN or TAINT_CRAP or something otherwise, but neither are quite > right. > - The taint_flags table gives a couple of checkpatch.pl errors around > bracket placement. I've kept the new entry consistent with what's > there rather than reformatting the whole table, but be prepared for > complaints about spaces. > > Thoughts? > -- David > > --- > Documentation/admin-guide/tainted-kernels.rst | 1 + > include/linux/panic.h | 3 ++- > kernel/panic.c | 1 + > lib/kunit/test.c | 4 ++++ > 4 files changed, 8 insertions(+), 1 deletion(-) > > diff --git a/Documentation/admin-guide/tainted-kernels.rst b/Documentation/admin-guide/tainted-kernels.rst > index ceeed7b0798d..8f18fc4659d4 100644 > --- a/Documentation/admin-guide/tainted-kernels.rst > +++ b/Documentation/admin-guide/tainted-kernels.rst > @@ -100,6 +100,7 @@ Bit Log Number Reason that got the kernel tainted > 15 _/K 32768 kernel has been live patched > 16 _/X 65536 auxiliary taint, defined for and used by distros > 17 _/T 131072 kernel was built with the struct randomization plugin > + 18 _/N 262144 a KUnit test has been run > === === ====== ======================================================== > > Note: The character ``_`` is representing a blank in this table to make reading > diff --git a/include/linux/panic.h b/include/linux/panic.h > index f5844908a089..1d316c26bf27 100644 > --- a/include/linux/panic.h > +++ b/include/linux/panic.h > @@ -74,7 +74,8 @@ static inline void set_arch_panic_timeout(int timeout, int arch_default_timeout) > #define TAINT_LIVEPATCH 15 > #define TAINT_AUX 16 > #define TAINT_RANDSTRUCT 17 > -#define TAINT_FLAGS_COUNT 18 > +#define TAINT_KUNIT 18 > +#define TAINT_FLAGS_COUNT 19 > #define TAINT_FLAGS_MAX ((1UL << TAINT_FLAGS_COUNT) - 1) > > struct taint_flag { > diff --git a/kernel/panic.c b/kernel/panic.c > index eb4dfb932c85..b24ca63ed738 100644 > --- a/kernel/panic.c > +++ b/kernel/panic.c > @@ -404,6 +404,7 @@ const struct taint_flag taint_flags[TAINT_FLAGS_COUNT] = { > [ TAINT_LIVEPATCH ] = { 'K', ' ', true }, > [ TAINT_AUX ] = { 'X', ' ', true }, > [ TAINT_RANDSTRUCT ] = { 'T', ' ', true }, > + [ TAINT_KUNIT ] = { 'N', ' ', false }, As kunit tests can be in modules, shouldn't this be "true" here? Overall, I like it, makes sense to me. The "N" will take some getting used to, and I have no idea why "T" was for "struct randomization", that would have allowed you to use "T" instead. Oh well. thanks, greg k-h