Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp99483imw; Thu, 7 Jul 2022 22:19:39 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uS5USXfBGfvcgzxrZ00/Hw8Q8hTRpGuRwMbMzUulJJRODnllJMMLK5KYWxmDZ+2dHa6o/v X-Received: by 2002:a17:902:d588:b0:16b:fbd1:9f53 with SMTP id k8-20020a170902d58800b0016bfbd19f53mr1746359plh.156.1657257579398; Thu, 07 Jul 2022 22:19:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657257579; cv=none; d=google.com; s=arc-20160816; b=ziUuXgcaSUUqmoyWebHrPssWfEx+Erqb9+N0Fy+TnWIKuPMVsAUIW0k22TynBrg0Y+ Vzu7gdtJeD+kzxMV2ps5GJ1GYH2Mu1E7tFRrgLk7A1xeeQ/+q+7ARF9DOpqfPLUj7xd9 cJJkjsUDbhdFsVAV6Vnb4tDTFXYuhActOCS17Vzl8W+6q+t8tgce/l1Jo9DXspKXKjW4 A3yFXwop8IwKkyqAxKf3+lxsEB+k8irWLmCrx+Xcorb0+YRGtDo2RkhG111mivz60sLR eNjF2Kpy2r8d0TjonEZ1ka8cjKGcmxnDsRMvXAx2kjjtQF5oFszyQUH3nkPsxpbWhk9w kajQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=sz8usM5OOAxMSGMRGNk8MoEaRmhzBeAasBjyztwmQ0o=; b=MOg9k7ClK9bNq2uHO4K8B/n6QTq/fM0eCRspds123kyWrPK8Ku0SgdCGMlr/VckVy8 nKEc/g5Mq7JwNLGzIiQL8PcQyCboz+UL2IpxMaI6zlD7qFfB+3kOLKMfmT8r/08vyQme 4JxIhFoXvcpn/I2/t3tP9HcRJHLk4GrJI0jh+dTr5cmzw48QtyXYO7mkOgYIDGeN3S8W 5W7MKsc1KWTtVm5uZ7fefcn5cdnR74AqxRmMQYfoEEfSXWamf/BcGf9CpyjyyOhC0Pa4 VbAFX5pxOk4fE8QFBa+iqKYVHpGe6nrj7ovN62fxnaVFfX+ZGUdwBs+7R5KwmfnJEn9E sZgw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=XvQr0qdg; 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 jj15-20020a170903048f00b0016bf771178fsi1690367plb.456.2022.07.07.22.19.24; Thu, 07 Jul 2022 22:19:39 -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=XvQr0qdg; 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 S237225AbiGHEyo (ORCPT + 99 others); Fri, 8 Jul 2022 00:54:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55834 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237267AbiGHEyl (ORCPT ); Fri, 8 Jul 2022 00:54:41 -0400 Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0B11D76974 for ; Thu, 7 Jul 2022 21:54:39 -0700 (PDT) Received: by mail-wr1-x436.google.com with SMTP id n10so3653514wrc.4 for ; Thu, 07 Jul 2022 21:54:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=sz8usM5OOAxMSGMRGNk8MoEaRmhzBeAasBjyztwmQ0o=; b=XvQr0qdgMR+nOcAcTf+7xs8BktG18BYs/gyLp5C5uUsjKtaGS7EF9lRf5zMCPTk5BJ 91x/Spo8Cfl4CVSPbPoMfLrZsEwhY0cNHM2q7EZ0nlSFf2pbkNNGBgFJwDr4PWfiQA1R rjSqjpl0EY3iSCJAU48gfTIUWBgXCZlfQnTkkQe5IaGiy4iNSAVkSmARbuu5920d6StE Mu+9ay0uGrpKJNlbX9QXXUknZR2EeKcCJs4NUI/9GG+xW0j5zMKpqA9wT3lgzcNdk1P3 +DDWrQu8tOvaOqcdVi11eMbXfr8ZoiUe4Ta28ix+r6raRL7MH0DfN1S0WQseo23ZyBuK IaKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=sz8usM5OOAxMSGMRGNk8MoEaRmhzBeAasBjyztwmQ0o=; b=FujqogwediH9E53NV9vTQtgZHB5zqh7xxeiZiWOu69WLz7ddm4ZFDc73N10T640yD5 +xW7Xbstfac8GWeuymoIzFuCdg9PoIAeXXD/p6TFPxxABbQDJgQ6vAvnt5DJOnT9+Hl7 4NioMLjFHZ/wSViSk6DetM5ROa3B0Ur30b9kaspnoSGKqAq1x7lwJtHimfE6j0BeULK8 XZbNh1fOl6J28N6VeG/8w7mLzTE7Gxo6gsVONH9vp5bS2BPKcVgUHQG7MT12RkkAdDVK 321I0y/IjiNaSg1OErO6o5+MWhdmzzW7U0x4QgsffuasBBxAeVmwMIcPvASJIxAoRVof C3zg== X-Gm-Message-State: AJIora9xSPOaufFld/d9/SiaQnKB9H3W00boVNg81Glzb0c7VRwhvQW+ zoHuRsUvlGUELJyz6TtPQcE4T43+76DzSCnpsVGjtQ== X-Received: by 2002:adf:e804:0:b0:21d:6e85:7550 with SMTP id o4-20020adfe804000000b0021d6e857550mr1349414wrm.337.1657256077460; Thu, 07 Jul 2022 21:54:37 -0700 (PDT) MIME-Version: 1.0 References: <20220702040959.3232874-1-davidgow@google.com> <20220702040959.3232874-2-davidgow@google.com> In-Reply-To: From: David Gow Date: Fri, 8 Jul 2022 12:54:26 +0800 Message-ID: Subject: Re: [PATCH v5 2/4] module: panic: Taint the kernel when selftest modules load To: Nathan Chancellor Cc: Brendan Higgins , Andy Shevchenko , Jonathan Corbet , Andrew Morton , Kees Cook , Shuah Khan , Greg KH , Luis Chamberlain , Masahiro Yamada , "Guilherme G . Piccoli" , Sebastian Reichel , John Ogness , Joe Fradley , Daniel Latypov , KUnit Development , "open list:KERNEL SELFTEST FRAMEWORK" , "open list:DOCUMENTATION" , Linux Kernel Mailing List , Jani Nikula , Lucas De Marchi , Aaron Tomlin , linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, Michal Marek , Nick Desaulniers , Linux Kbuild mailing list Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_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 On Fri, Jul 8, 2022 at 8:40 AM Nathan Chancellor wrote: > > On Sat, Jul 02, 2022 at 12:09:57PM +0800, David Gow wrote: > > 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 > > --- > > 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) > > -- > > 2.37.0.rc0.161.g10f37bed90-goog > > > > > > Hi David, > > This change has landed in linux-next as commit e20729ede7ed ("module: > panic: taint the kernel when selftest modules load") and on all of my > test machines, I see this new message printed, even though as far as I > am aware, I am not loading any testing modules. For example, in QEMU, I > see: > > [ 0.596978] serio: loading test module taints kernel. > > and on my Honeycomb LX2, I see: > > [ 5.400861] fuse: loading test module taints kernel. > > It seems like the get_modinfo() check might be wrong? The following diff > resolves it for me, I can send a formal patch if necessary (although it > appears to have gone in via -mm so I assume Andrew can squash this in). > Whoops: this is definitely the wrong way round. Thanks very much for catching it! (I'd swapped it locally at some point to test, and must've accidentally committed it.) I've sent out v6 with this fixed (and a couple of other minor changes): https://lore.kernel.org/linux-kselftest/20220708044847.531566-2-davidgow@google.com/T/#u That being said, if just squashing your change below in is easier, I'm fine with that, too. (The other changes are minor enough that we could live without them and/or send them in separately.) Unless there are any objections, should Andrew update this patch in his tree, and we remove the series from the kunit tree? Cheers, -- David > > diff --git a/kernel/module/main.c b/kernel/module/main.c > index 730503561eb0..4f91e41b8bc9 100644 > --- a/kernel/module/main.c > +++ b/kernel/module/main.c > @@ -1988,7 +1988,7 @@ 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 (get_modinfo(info, "test")) { > if (!test_taint(TAINT_TEST)) > pr_warn_once("%s: loading test module taints kernel.\n", > mod->name);