From mboxrd@z Thu Jan 1 00:00:00 1970 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 C41C3C32772 for ; Tue, 23 Aug 2022 21:20:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230225AbiHWVUJ (ORCPT ); Tue, 23 Aug 2022 17:20:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35662 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229533AbiHWVUG (ORCPT ); Tue, 23 Aug 2022 17:20:06 -0400 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DA44F53026 for ; Tue, 23 Aug 2022 14:20:04 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-33931a5c133so173568467b3.17 for ; Tue, 23 Aug 2022 14:20:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:mime-version:message-id:date:from:to:cc; bh=8VeZYoidRbxCrAGHLIxsjoWrKlcdP3ygGRJKvTGM14s=; b=sUPIwT+TKjogJoBV6i+R1coppPbUF2jIqnYJesgbisbTP/7RulqcH/pADy3obDIwqn V3qaBMquKA1unRavnFfL+bDjWHEmPa0njGLkzXOkZis6LmBig4WeqzX+4EE7rMXT90NV NdLg+cLKCLuT9McTFZPW0hfo5LT3pf11SzNHeUw+e3Jm34tiDHL90ra/kV+xHP0j/ZyK 9+MFtYY7hOnhrhLtvYQkhrq5iWy5bAuaqauIq3xLvcPxCbl1eU9/IicO6UYeEBT1FC4c CJj6znhOj5GOFovB3NWxHB51Jd9lWYsk2wF+fAUm8SjgqVx8u7KMhlZQZn8KFJpqw6YF +EgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:mime-version:message-id:date:x-gm-message-state :from:to:cc; bh=8VeZYoidRbxCrAGHLIxsjoWrKlcdP3ygGRJKvTGM14s=; b=fYG8aCHi0W8AnmQ/lqRLKH3El1mzW24B3SY9pp2yDpsBPF1cPxOrMvF7EsA/dv6vvH oagPzrUJPGUmGSfwFazlDmwxr9o1H6mI9Ur7NRTYHWSzwK3qWLGBOEO5ZkTc2lFuZzb/ pYQSgOSOC9nmorMk1HeGUhkBAvzZNsyCiU2UPj55784yYmycwIXHFWlHxtVb7+7GuoEA tD80hvb11xRysdYJJEwGLBPm0dM5xWzbW2Ld2/i074hGailp9g/c4Apx0M2LTtEnCGzd yz39IM8wo4Y3ZMDqDnyK/G6NDPVmh0VRqMXmEF16CT77uItWRVGhWUMZg0OYhYabNw5Q cAGQ== X-Gm-Message-State: ACgBeo38FbUhkOxUZRHU0ZnU1g0CsmvjFbFntOfK+UOzfvdukfDAWJaq ITDMn4K+N+cK8aCKH5O/dvy0UxBHxA== X-Google-Smtp-Source: AA6agR7dXbMe2QWC6NUqnUS2IDe3BcZnRXK37GUPMMJMhxQYn1ivPx7YVvo/EvE/LSCwIqKikSxMB896Ow== X-Received: from adelg-virt.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:d1f]) (user=adelg job=sendgmr) by 2002:a0d:f9c1:0:b0:33b:65f4:9506 with SMTP id j184-20020a0df9c1000000b0033b65f49506mr13422629ywf.227.1661289604176; Tue, 23 Aug 2022 14:20:04 -0700 (PDT) Date: Tue, 23 Aug 2022 21:19:58 +0000 Message-Id: <20220823211958.2519055-1-adelg@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.37.1.595.g718a3a8f04-goog Subject: [PATCH] selftests: Add a taint selftest From: Andrew Delgadilo To: Shuah Khan Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, dylanbhatch@google.com, sashalevin@google.com, gthelen@google.com, adelg@google.com Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Andrew Delgadillo When testing a kernel, one of the earliest signals one can get is if a kernel has become tainted. For example, an organization might be interested in mass testing commits on their hardware. An obvious first step would be to make sure every commit boots, and a next step would be to make sure there are no warnings/crashes/lockups, hence the utility of a taint test. Signed-off-by: Andrew Delgadillo --- tools/testing/selftests/core/Makefile | 1 + tools/testing/selftests/core/taint.sh | 28 +++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100755 tools/testing/selftests/core/taint.sh diff --git a/tools/testing/selftests/core/Makefile b/tools/testing/selftests/core/Makefile index f6f2d6f473c6a..695bdbfb02f90 100644 --- a/tools/testing/selftests/core/Makefile +++ b/tools/testing/selftests/core/Makefile @@ -2,6 +2,7 @@ CFLAGS += -g -I../../../../usr/include/ TEST_GEN_PROGS := close_range_test +TEST_PROGS := taint.sh include ../lib.mk diff --git a/tools/testing/selftests/core/taint.sh b/tools/testing/selftests/core/taint.sh new file mode 100755 index 0000000000000..661c2cb8cd9bf --- /dev/null +++ b/tools/testing/selftests/core/taint.sh @@ -0,0 +1,28 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 +set -oue pipefail + +# By default, we only want to check if our system has: +# - seen an oops or bug +# - a warning occurred +# - a lockup occurred +# The bit values for these, and more, can be found at +# Documentation/admin-guide/tainted-kernels.html +# This value can be overridden by passing a mask as the +# first positional argument. +taint_bitmask=$(( 128 + 512 + 16384 )) + +# If we have a positional argument, then override our +# default bitmask. +if [[ -n "${1-}" ]]; then + taint_bitmask=$1 +fi + +taint_bits=$(cat /proc/sys/kernel/tainted) + +result=$(( taint_bitmask & taint_bits )) +if [[ "$result" -ne 0 ]]; then + exit 1 +fi + +exit 0 -- 2.37.1.595.g718a3a8f04-goog