Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp1287505iob; Fri, 29 Apr 2022 01:51:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzt4p3JEre7EfpcJIsFkXZtPWyelKKhNhKoDDTbnkx2/jOMCt6Yqt4H24C3QwceRCNC9ukU X-Received: by 2002:a17:902:bc86:b0:151:ec83:4a8b with SMTP id bb6-20020a170902bc8600b00151ec834a8bmr37101033plb.69.1651222283283; Fri, 29 Apr 2022 01:51:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651222283; cv=none; d=google.com; s=arc-20160816; b=rjTLtn89AHCpe3pv7usU6a8rhIFLHQ3CS2IN2zhwKqyk7M5nPzRbCS6lC70hW1R2gG 9ehPk+Jp3vFqbJCe6Mayxi4UgB+M798pIA5NwOjT4+Rr3vLEUuad6MW/SJZSFzPla3lL U0QKb/xoj74IvfXO+DBw3X5hDZUW7SvsffhD4FrdeMOsEpLCDnB1acFVl5mHpWrsvDR2 fy0owCFaRMCbMXnwfUV6y13DqQb0wfKUQI1cr5CfweJ/z3IzMZsa4irZzqOA+IMtCbXQ mZMmgN6HC5btANmvsvb2QCUNn2UEDfq6PQzNoIiFhtyVUlGvXDtYW/nrGNxfpEvgcS+C dv9g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:mime-version:message-id:date :dkim-signature; bh=7pAm/LDFHoDLOVuIZx6NOUlnYoOG6z2KtSbentQNohQ=; b=UvL0395mAe5xDZw6gr2T7ub/ik0b/I3KG+vu7o50vhLYiXeX0nbZsx4Pt80TiYxOzZ oOTI7m2QgTvkCWt2ZoasSsr98rsv2Nt4+Eh2vfSawJccrA2aDBwrynso6uxxdluROp4Y eok3J6SWLbg1+nNf8+NdgWHiT7PNeADrHGK1lbyrbzdDHy37xZFbOFdP4SSi3QJcNi1b 3nAs3rpeREpLxMdMfEafby4uJijtD1bafzEba5eQdJ0IGQ/OGkoKQPdJde6oUdIgnpK2 BjrWoQq9aWJUZ9HY8VPj+K+EZZQawByvO+FJNqCaItjm4pzE6XDczfoXi1gddhHtKQ7D U8oA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=lOJ6ndqu; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q23-20020a656a97000000b003c1a429260fsi2411608pgu.791.2022.04.29.01.51.08; Fri, 29 Apr 2022 01:51:23 -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=@google.com header.s=20210112 header.b=lOJ6ndqu; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237515AbiD2EnZ (ORCPT + 99 others); Fri, 29 Apr 2022 00:43:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49538 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230133AbiD2EnX (ORCPT ); Fri, 29 Apr 2022 00:43:23 -0400 Received: from mail-pg1-x549.google.com (mail-pg1-x549.google.com [IPv6:2607:f8b0:4864:20::549]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ECBBE15FE2 for ; Thu, 28 Apr 2022 21:40:03 -0700 (PDT) Received: by mail-pg1-x549.google.com with SMTP id b198-20020a6334cf000000b003ab23ccd0cbso3369691pga.14 for ; Thu, 28 Apr 2022 21:40:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:message-id:mime-version:subject:from:to:cc; bh=7pAm/LDFHoDLOVuIZx6NOUlnYoOG6z2KtSbentQNohQ=; b=lOJ6ndqujbkQ9y8YtiKLh1NmKtjsaaYLb7DNBKdzwM6kNdDJymwTB229+sHcII9IGm ZgijMD9LB65oEfpnzDUuw7gMa1qtR6k7S2ZlegTaofUACUzwpv8vlppdU55LGRFu3xOo DTTGaB92cV5r20Fkg0e2H9E3kthvAOiLTkz3TfcnrbdLxtSzKUl/QUaAPl9Nlyd9d+NP hlFSo4WvNXsXYW96S52BZhtTswOFsceMy/Pzv0U02tJAyQ7NxtUhQdPT8MVsYrL7qi8C lrvnil194+31LqgOEWw4WdQqbFQ3bkGTAw/oDIyQ1CcH4F+XIZe5J159ZKBObnviPkrs Yh9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=7pAm/LDFHoDLOVuIZx6NOUlnYoOG6z2KtSbentQNohQ=; b=4GWPS4XZc4IwGYU3VXTleeWlJCT1Nc/fgK2M1FVbuYffnsmFL+CdldaPDQlOtk/Jgd nc28UP0vBfsbdnvdAlzRsP9T/SHSC00Zx8/V7fD/wE/zE/M2JdWya3c+J5+n39rvcpdH C0hTwyceibqmE2qyyeD7HfFLFyRiYtmeV6SxVNoQcM3saRiztIiFueRGL+OKvKeWZdUb Lq5PsDUTNK8Yi3esjPIrLcDLUKvcOQz6U4KlDVsDAlZ0KZ40xquchfmdRFPtvs19w/n2 b6lD89jKBPxR3rMHggIcYYgGjrLjbLKhIvulmCOcjZyLmeOsnzxAy6j5Lfr12MBRoGa4 VzsA== X-Gm-Message-State: AOAM532QzIxqzcIkOAI68McTr0yOcOJvWziwrd36gONxCnn8c6bU64j4 TrcAiLTHAzRxsYT2lDMMU4aNXliNz4yyRw== X-Received: from slicestar.c.googlers.com ([fda3:e722:ac3:cc00:4f:4b78:c0a8:20a1]) (user=davidgow job=sendgmr) by 2002:a17:902:ce02:b0:151:a86d:dc2b with SMTP id k2-20020a170902ce0200b00151a86ddc2bmr37514527plg.57.1651207203378; Thu, 28 Apr 2022 21:40:03 -0700 (PDT) Date: Fri, 29 Apr 2022 12:39:14 +0800 Message-Id: <20220429043913.626647-1-davidgow@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.36.0.464.gb9c8b46e94-goog Subject: [PATCH] kunit: Taint kernel if any tests run From: David Gow To: Brendan Higgins , Andy Shevchenko , Jonathan Corbet , Andrew Morton , Kees Cook , Shuah Khan Cc: David Gow , "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 Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=ham 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 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 }, }; /** diff --git a/lib/kunit/test.c b/lib/kunit/test.c index 0f66c13d126e..ea8e9162445d 100644 --- a/lib/kunit/test.c +++ b/lib/kunit/test.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include @@ -498,6 +499,9 @@ int kunit_run_tests(struct kunit_suite *suite) struct kunit_result_stats suite_stats = { 0 }; struct kunit_result_stats total_stats = { 0 }; + /* Taint the kernel so we know we've run tests. */ + add_taint(TAINT_KUNIT, LOCKDEP_STILL_OK); + kunit_print_subtest_start(suite); kunit_suite_for_each_test_case(suite, test_case) { -- 2.36.0.464.gb9c8b46e94-goog