Received: by 2002:ac0:cd04:0:0:0:0:0 with SMTP id w4csp491794imn; Fri, 1 Jul 2022 21:47:02 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vaFjAF8UTpPt4x36JwzFDDGBa1cuPTaiVx8WVc8iqRaQ5QFc48NS3ffJfUl+I++uzzyrEh X-Received: by 2002:a17:902:8e86:b0:168:d6d6:660f with SMTP id bg6-20020a1709028e8600b00168d6d6660fmr23883768plb.35.1656737222648; Fri, 01 Jul 2022 21:47:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656737222; cv=none; d=google.com; s=arc-20160816; b=JGwpExc95m7OW3AKP6xxYXNoJJTBBG5a+P081y0z3xza3+jlguDm6vquR8JnrPsDgv j8myI1544kwKEHfBekdw7JEdPYP8ngC7apa16pJzqKUEfMfbbUFlxJpJ4unIpWDcbjEH Gbm/x6HEVY9HM+BZXhOc/Z81pLdYME6F/nhCAfcq+5fJsQvfJPo1ppHm5J2+bggF2YHL /g5oDGNPmbrjp7mKQ6I/1LwVQa8o9Lx4vyqrvEgwrEn56jnwbQfPcvLw9/rAvZLrKu9c aSikgGH6I4ZeNK/Rdfvj8bkiCz4Fl2N/r0U3zChQKTXB/JCAETrKuh94uAwpNr6FO3/2 tNwA== 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:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=PtLO6IdA/ejKq3y5cNTb8tv3Fwaz8VhRhGcv2qLEc+w=; b=LBJCp7m3Jse46eREI/3qowJX3LGbrE57XJIYDX6flCiZ0UFBoub26dBzfQljiIQbJP TOYZ5zAak5c0CeL/mHilz2t7me+/i1LYKzPbhu++8c/+QCZhl3On+Gi3SH53W1wnuukv i+hrHhmXJx+72engtxKqnCpvuhGhSQNQBaFpwEC/Iravf0aYxFppdOcer49MgDTBE6Le cPkZDWvIcPVufoH5Dd0bRdY5aLOXo1a11BNS4pmdLQZoqMuvU6ZDSd3Nk3nkmDjhtLHD HblZ+qwW257pkp5BfhKhfF6Ckv/FRJN7UVNori4iYVTTCpjt8PSxxnCu3iVtF5enKE9D PECg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=PBmdJc1M; 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 a38-20020a056a001d2600b005254e98b56csi1075701pfx.153.2022.07.01.21.46.50; Fri, 01 Jul 2022 21:47:02 -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=PBmdJc1M; 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 S232119AbiGBEKc (ORCPT + 99 others); Sat, 2 Jul 2022 00:10:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49172 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231753AbiGBEKT (ORCPT ); Sat, 2 Jul 2022 00:10:19 -0400 Received: from mail-pj1-x104a.google.com (mail-pj1-x104a.google.com [IPv6:2607:f8b0:4864:20::104a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3471D31201 for ; Fri, 1 Jul 2022 21:10:15 -0700 (PDT) Received: by mail-pj1-x104a.google.com with SMTP id u1-20020a17090a450100b001ef1c4c2844so1934238pjg.4 for ; Fri, 01 Jul 2022 21:10:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=PtLO6IdA/ejKq3y5cNTb8tv3Fwaz8VhRhGcv2qLEc+w=; b=PBmdJc1M/oHFNfRQca5cVRdely/fXH+p63r8m9g1bKicCm/1KfuNbC+U1Nj38uk30x zm/qFkQte1xbHx99xZBbYpJXEqePj0P+z1QGO1x+Egflz6Y5DMcTZrPWHt6jF1Z0Kw4C 8Lp6x5tx3ttTzKiEMICNgbMkzEYcIO9Amnet/pYwMMf9tsXFxfE54ey+EW1sKUy3yX9o Mq2j8XCIL4MmEUQwe63f+4JY3uc/LGTMqUnKBk6+Jub5l045zizu6On17vVXZCORYDvp O1ME/T3feTZNJs8dZi0S2xVT8jYCSSNyZ1nz9X8ZVvC0PwYrh83cdzhQDiMNLjjnORB+ ZcFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=PtLO6IdA/ejKq3y5cNTb8tv3Fwaz8VhRhGcv2qLEc+w=; b=3oWYvw1FxrEvN6Ptq1u49Iw4dXI2nnUBBUGkF4oA83E1Wbb3A1R/kWYR7C9QvyZNpR w6zzn599WPM6qYMtw6MC3R8hMILqCqvSXtYkfcpl4YQy3/4SAA+PxrGjpwJuqWiC7C+y OoSLjzWsVlXzo5FULp+2x6ak5c5qEkpWjMP5rsmpIUlfuaoZWyqTv22b7c1y6lISl8vI 4Szm4b4Zq6YynY58zLyUAsBb1TCovWeru/5GBmndkrKKUedJ+7eViNHsHZTn4528mpj7 KPPX84YAkH4oQoC879N4TkPuu4cdu/fZvQ2TFz3U/fTaGByy232pu3QQbJzox77j3lij 2dcg== X-Gm-Message-State: AJIora+z3q5SLuyB1VCfnmQ9XQOKK5BmOLASjlDGphUmb7woYpMyJvCV oauEgbXaqIxTjbVSqLRbQm+xOgclgJ2pWA== X-Received: from slicestar.c.googlers.com ([fda3:e722:ac3:cc00:4f:4b78:c0a8:20a1]) (user=davidgow job=sendgmr) by 2002:a05:6a00:2295:b0:525:6c57:8dea with SMTP id f21-20020a056a00229500b005256c578deamr23491809pfe.62.1656735014424; Fri, 01 Jul 2022 21:10:14 -0700 (PDT) Date: Sat, 2 Jul 2022 12:09:58 +0800 In-Reply-To: <20220702040959.3232874-1-davidgow@google.com> Message-Id: <20220702040959.3232874-3-davidgow@google.com> Mime-Version: 1.0 References: <20220702040959.3232874-1-davidgow@google.com> X-Mailer: git-send-email 2.37.0.rc0.161.g10f37bed90-goog Subject: [PATCH v5 3/4] kunit: Taint the kernel when KUnit tests are run From: David Gow To: Brendan Higgins , Andy Shevchenko , Jonathan Corbet , Andrew Morton , Kees Cook , Shuah Khan , Greg KH , Luis Chamberlain , Masahiro Yamada Cc: David Gow , "Guilherme G . Piccoli" , 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, Jani Nikula , Lucas De Marchi , Aaron Tomlin , linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, Michal Marek , Nick Desaulniers , linux-kbuild@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,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL 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 Make KUnit trigger the new TAINT_TEST taint when any KUnit test is run. Due to KUnit tests not being intended to run on production systems, and potentially causing problems (or security issues like leaking kernel addresses), the kernel's state should not be considered safe for production use after KUnit tests are run. This both marks KUnit modules as test modules using MODULE_INFO() and manually taints the kernel when tests are run (which catches builtin tests). Acked-by: Luis Chamberlain Tested-by: Daniel Latypov Reviewed-by: Brendan Higgins Signed-off-by: David Gow --- include/kunit/test.h | 3 ++- lib/kunit/test.c | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/include/kunit/test.h b/include/kunit/test.h index 8ffcd7de9607..ccae848720dc 100644 --- a/include/kunit/test.h +++ b/include/kunit/test.h @@ -277,7 +277,8 @@ static inline int kunit_run_all_tests(void) { \ return __kunit_test_suites_exit(__suites); \ } \ - module_exit(kunit_test_suites_exit) + module_exit(kunit_test_suites_exit) \ + MODULE_INFO(test, "Y"); #else #define kunit_test_suites_for_module(__suites) #endif /* MODULE */ diff --git a/lib/kunit/test.c b/lib/kunit/test.c index a5053a07409f..8b11552dc215 100644 --- a/lib/kunit/test.c +++ b/lib/kunit/test.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include @@ -501,6 +502,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_TEST, LOCKDEP_STILL_OK); + if (suite->suite_init) { suite->suite_init_err = suite->suite_init(suite); if (suite->suite_init_err) { -- 2.37.0.rc0.161.g10f37bed90-goog