From patchwork Sat Jul 2 04:09:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Gow X-Patchwork-Id: 12903892 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 64A14CCA47B for ; Sat, 2 Jul 2022 04:10:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232011AbiGBEKO (ORCPT ); Sat, 2 Jul 2022 00:10:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49036 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231866AbiGBEKL (ORCPT ); Sat, 2 Jul 2022 00:10:11 -0400 Received: from mail-pg1-x54a.google.com (mail-pg1-x54a.google.com [IPv6:2607:f8b0:4864:20::54a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7749430560 for ; Fri, 1 Jul 2022 21:10:10 -0700 (PDT) Received: by mail-pg1-x54a.google.com with SMTP id o22-20020a637316000000b0040d238478aeso2054875pgc.2 for ; Fri, 01 Jul 2022 21:10:10 -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=2l3RLFgAAfB5gJrS1WFhkf1GPwe6iqzG1+pocvCkvn8=; b=n85fmgV8YL13NHOXAmDkw3hynV0Gh5QmNiSYsQm9jCdqtwslpAV93ZkYc8QzXG/8ep v9U2XDzaCoZBQ8BppCGZehEzLXTSKwGi+Zpi4ojVgQAxgVqVHZXNO0duA3b4gAoTMt80 +sHwKmRZxha0fJjw+Qztxf8qBWq1NZ/3BSsSp0HINUSML2vIsTS0UIbfMcbG+aeYsgD4 sPJ6AgB6kCdT7jUGinD6jUuhntlOLxQ0Be12GKo/Ra20XkoVtDN1yGG6N6aadBczZ4dQ WsL/dZ1TVlt+6M9D6Oeoci3tRrtxwPx+1Ii+kKcRy9o4ydGTIlLMjK0kgyXLl4CcWRNI 2q1Q== 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=2l3RLFgAAfB5gJrS1WFhkf1GPwe6iqzG1+pocvCkvn8=; b=Y+ApDlNcjxeUCMUQR+FH2dL+hxagsYHFfQpw80YWrN/hmKNOaLAZRx3sV5c3pid5cT 65vmo31zrO0Ar1/PiPk6/vbZD8MtxBiEbTT94FF84yjBVh93UlcSwAqYXRE6aPPkOXUw EQURo3JHIpmThIpK7dyKqLvRyFswjyzMUPj9fY/u5v25v1F6H57NiXkam70G7ojKbAyM LZ3Rp9j6/Z4qXLQZWFM2tSmcoIwrEZs4HziiUEzyghQ4EX+nBPhsppYAo7KjFc+DlFMo 2NqaqxYDXD8VzNiWLYSve1YXeclT5i6IKAsa7FGSv06OKqGp4JitdOUMymbmz7MOwvNV 6bYg== X-Gm-Message-State: AJIora9w0hUESbB/8mMx5hwqIL71aCdtSAN9k2QeIaYYYVlkjmsyzAlD XAB9Wvw6oRjvpCSC6qlN/2XufA7bIy6gOQ== X-Google-Smtp-Source: AGRyM1t57UbR+SZZR/NQAR1HDFq+gH9joW4fT50YArEFanjs2sHJOJuDfSxR47/JHfZFnFLUaBY6Az3aScZMCg== X-Received: from slicestar.c.googlers.com ([fda3:e722:ac3:cc00:4f:4b78:c0a8:20a1]) (user=davidgow job=sendgmr) by 2002:a17:902:e5cd:b0:16a:6f96:eb9 with SMTP id u13-20020a170902e5cd00b0016a6f960eb9mr23833900plf.69.1656735009687; Fri, 01 Jul 2022 21:10:09 -0700 (PDT) Date: Sat, 2 Jul 2022 12:09:57 +0800 In-Reply-To: <20220702040959.3232874-1-davidgow@google.com> Message-Id: <20220702040959.3232874-2-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 2/4] module: panic: Taint the kernel when selftest modules load 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 Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org Taint the kernel with TAINT_TEST whenever a test module loads, by adding a new "TEST" module property, and setting it for all modules in the tools/testing directory. This property can also be set manually, for tests which live outside the tools/testing directory with: MODULE_INFO(test, "Y"); Reviewed-by: Luis Chamberlain Signed-off-by: David Gow Reviewed-by: Aaron Tomlin Acked-by: Brendan Higgins --- kernel/module/main.c | 7 +++++++ scripts/mod/modpost.c | 3 +++ 2 files changed, 10 insertions(+) diff --git a/kernel/module/main.c b/kernel/module/main.c index fed58d30725d..730503561eb0 100644 --- a/kernel/module/main.c +++ b/kernel/module/main.c @@ -1988,6 +1988,13 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags) /* Set up license info based on the info section */ set_license(mod, get_modinfo(info, "license")); + if (!get_modinfo(info, "test")) { + if (!test_taint(TAINT_TEST)) + pr_warn_once("%s: loading test module taints kernel.\n", + mod->name); + add_taint_module(mod, TAINT_TEST, LOCKDEP_STILL_OK); + } + return 0; } diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index 29d5a841e215..5937212b4433 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c @@ -2191,6 +2191,9 @@ static void add_header(struct buffer *b, struct module *mod) if (strstarts(mod->name, "drivers/staging")) buf_printf(b, "\nMODULE_INFO(staging, \"Y\");\n"); + + if (strstarts(mod->name, "tools/testing")) + buf_printf(b, "\nMODULE_INFO(test, \"Y\");\n"); } static void add_exported_symbols(struct buffer *buf, struct module *mod)