From patchwork Fri May 13 08:32:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Gow X-Patchwork-Id: 12848479 X-Patchwork-Delegate: brendanhiggins@google.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 71251C433EF for ; Fri, 13 May 2022 08:32:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378296AbiEMIck (ORCPT ); Fri, 13 May 2022 04:32:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33192 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1378303AbiEMIce (ORCPT ); Fri, 13 May 2022 04:32:34 -0400 Received: from mail-pj1-x1049.google.com (mail-pj1-x1049.google.com [IPv6:2607:f8b0:4864:20::1049]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 56FB564BD0 for ; Fri, 13 May 2022 01:32:32 -0700 (PDT) Received: by mail-pj1-x1049.google.com with SMTP id h23-20020a17090a051700b001dc9132f2e6so3704755pjh.6 for ; Fri, 13 May 2022 01:32:32 -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=0ybWbXGPDsdksfVbXJMzQ1kLilXdTLhR2XM1EfoNTaQ=; b=mDbxxzGMPRe66EbTeOC0DGcg92DtfgZjKodWRekjDNOouMcdlsxRTubPmRzKzEg//+ NCtUoa0kB6dTGI5dBm+INXN2ngqEyVFZVXDa1xF8ystd1DFn7NF/874SjcTIb3v1qTDL UymPtLbOczNqc1qU+w3EfujQ9VYJzaSa2Qnvmnf/lzLYCpJn4fZi+optc113jKzHURNo Icw7XTBDwAPWE0plpyLnMfuriavPbm//BT2ukq/OrV6jT80TPt0YfRKsZBzv9Q1B6pqz vgtX3KGFCOlzV8Ozs/+RNXW5okVxVEvqN77emPfFAivLiAuMxWkThJEtfhfN9RcB3J/t lPcA== 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=0ybWbXGPDsdksfVbXJMzQ1kLilXdTLhR2XM1EfoNTaQ=; b=tNX5wVmfxUYszHGJa6ObsqCSs8T5E3bBSL95G/+dN5s4v85MlC8qRceYkPZ5Jh//B6 lTjWwjnHjsMBPVxVtjGxhXylVSdiafl2527Ok5gE5hwjE7o6UBWmsXHUC2pdgyM8hGXR C3hLDzD8d5XwX8Hte3DHAWsHQKZt8LpH4YfswzB1gFfxnb+mUBsKldpmWp4rdrKMuest sDof8TWb+0Uichar25j/RiC+Ro4mzbPYWMLF9Tfx80Bm2jxlsMbasVqjTHKeMAIrR/CS Bu1stK2gzEVjTg9GSIp18+U+fAOL6YHgxSEf6mpsFYcguDhOmrywg/KNk3AfXk6G4PvK HSFg== X-Gm-Message-State: AOAM530NujQQK8+F6Kyg+Yk37XEstrj3a13fGtWbVEeFxUwFvD6+8tS1 YRFUKk8mmtrovn2Fp+Wa/kgW2pN7dmDXtQ== X-Google-Smtp-Source: ABdhPJwfM5WbnpLP6WV99kx1KJIHYyM2xlBrsLZ0h+Pzul4XBI2zEL0Co3qEuGI3DWYVY6zO3MyaEFEHAAIkrg== X-Received: from slicestar.c.googlers.com ([fda3:e722:ac3:cc00:4f:4b78:c0a8:20a1]) (user=davidgow job=sendgmr) by 2002:a17:903:248:b0:155:ecb7:dfaf with SMTP id j8-20020a170903024800b00155ecb7dfafmr3832462plh.84.1652430751562; Fri, 13 May 2022 01:32:31 -0700 (PDT) Date: Fri, 13 May 2022 16:32:12 +0800 In-Reply-To: <20220429043913.626647-1-davidgow@google.com> Message-Id: <20220513083212.3537869-2-davidgow@google.com> Mime-Version: 1.0 References: <20220429043913.626647-1-davidgow@google.com> X-Mailer: git-send-email 2.36.0.550.gb090851708-goog Subject: [PATCH v3 2/3] 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 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 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@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. Signed-off-by: David Gow Acked-by: Luis Chamberlain Tested-by: Daniel Latypov Reviewed-by: Brendan Higgins --- lib/kunit/test.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/kunit/test.c b/lib/kunit/test.c index 0f66c13d126e..2b808117bd4a 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_TEST, LOCKDEP_STILL_OK); + kunit_print_subtest_start(suite); kunit_suite_for_each_test_case(suite, test_case) {