Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp179483pxb; Mon, 11 Apr 2022 22:23:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwSbLgpCYnIK/bYcBSsVPYntU6O5MR4z9lM97oxEXYlt2XhL9XuXxyVcjinblTefjKjmzP4 X-Received: by 2002:a05:6402:4396:b0:418:d776:14c1 with SMTP id o22-20020a056402439600b00418d77614c1mr37147072edc.127.1649741038280; Mon, 11 Apr 2022 22:23:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649741038; cv=none; d=google.com; s=arc-20160816; b=M2nkHs1crwQuz57hxsNC7bKBBHqrr6CYk3L7zNLsVYiATjWAmpSta35X3HpNNWZo9x KzU0+1TuZ8FgwGGOuVCZGGy9YDNqUGqYdnultZzpllBmQytO5jJgtCCNzqbR2TLtb2ha C/E6Gx7SCZDtq5IazoWGYm0yiA8veN3p/fHfqILoBEnXON1L2ZhMy7nZj/FEw8EwQPEV SN+o8U4diy8CBGniFGk4W7pWSqIB7laqD2c39TE+0nGYlrigm1nUH8PlIUtrJgOCwOAE oP1FN15HspNJHCf9sRrR2k+s+ZfDuFcftc13QRH9yTpSIXxG4U4DAB9m0i02dmkK9PMu nXgg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=mJxxC/APXTRl7kftAHP1mvug6on3AJS+uTWnEEHyKWg=; b=roG+B+QFF91Q1EFv75t7tpSC2w4B4arBOMGRjGhVf+FyulhPC3Gm1DqHBMqufRAHxC 731qZekmReffcXCvYvSICKTjDus/4aV8U0Ed7tLjZHDRWhZ4b6dc/6yPh8KXyivU32+q 7cecct+U5buAXRC/5EIUZSKSJ3xoxkiZD5Mct6V5pDHw3hoJZRSWCmTYLyJ6kkTbeuo3 cuGqw4HYRmCbhGm6Wjt9KOi9jzw7aPfD8nMahU6dC0BBg8yeofAPVwmGXXQGhWaD8afl VW9QjPRS+kZhNTt9JNZulx7sprT5M7+QloT2xV854Zgs8v1s7sEfkZpT4VsLgvFcQq5Z pocw== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id vz9-20020a17090704c900b006e4aae98be2si4754684ejb.892.2022.04.11.22.23.33; Mon, 11 Apr 2022 22:23:58 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349518AbiDKTQL (ORCPT + 99 others); Mon, 11 Apr 2022 15:16:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57562 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235610AbiDKTQK (ORCPT ); Mon, 11 Apr 2022 15:16:10 -0400 Received: from pegase2.c-s.fr (pegase2.c-s.fr [93.17.235.10]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E17301EECB for ; Mon, 11 Apr 2022 12:13:53 -0700 (PDT) Received: from localhost (mailhub3.si.c-s.fr [172.26.127.67]) by localhost (Postfix) with ESMTP id 4KcdnD30bpz9sV5; Mon, 11 Apr 2022 21:13:52 +0200 (CEST) X-Virus-Scanned: amavisd-new at c-s.fr Received: from pegase2.c-s.fr ([172.26.127.65]) by localhost (pegase2.c-s.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 5gGs-u6Ay1cu; Mon, 11 Apr 2022 21:13:52 +0200 (CEST) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase2.c-s.fr (Postfix) with ESMTP id 4KcdnD1pbGz9sV4; Mon, 11 Apr 2022 21:13:52 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 166C18B76E; Mon, 11 Apr 2022 21:13:52 +0200 (CEST) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id iGQeiEsNUe2J; Mon, 11 Apr 2022 21:13:51 +0200 (CEST) Received: from PO20335.IDSI0.si.c-s.fr (unknown [192.168.203.78]) by messagerie.si.c-s.fr (Postfix) with ESMTP id B1E3F8B763; Mon, 11 Apr 2022 21:13:51 +0200 (CEST) Received: from PO20335.IDSI0.si.c-s.fr (localhost [127.0.0.1]) by PO20335.IDSI0.si.c-s.fr (8.17.1/8.16.1) with ESMTPS id 23BJDeXM972781 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Mon, 11 Apr 2022 21:13:40 +0200 Received: (from chleroy@localhost) by PO20335.IDSI0.si.c-s.fr (8.17.1/8.17.1/Submit) id 23BJDdYn972780; Mon, 11 Apr 2022 21:13:39 +0200 X-Authentication-Warning: PO20335.IDSI0.si.c-s.fr: chleroy set sender to christophe.leroy@csgroup.eu using -f From: Christophe Leroy To: Kees Cook , Arnd Bergmann , Greg Kroah-Hartman Cc: Christophe Leroy , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v2] lkdtm/bugs: Don't expect thread termination without CONFIG_UBSAN_TRAP Date: Mon, 11 Apr 2022 21:13:39 +0200 Message-Id: <363b58690e907c677252467a94fe49444c80ea76.1649704381.git.christophe.leroy@csgroup.eu> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1649704418; l=2871; s=20211009; h=from:subject:message-id; bh=RLwexbMQAWzDpT+/wG8yGNeAAZhFmV03nOMJ5ww5lXc=; b=13GCUW2rr5U6kuQjAbew1WPESq+ym971NZs/YcOfavRAXzJpoV/hvf03fqbsNGKYiOPXls4d7RNV RiVKT4/NCCXrDGkOqCau+eo/aOKYCDmU2AGTGvPH4sLsO+cHZfj3 X-Developer-Key: i=christophe.leroy@csgroup.eu; a=ed25519; pk=HIzTzUj91asvincQGOFx6+ZF5AoUuP9GdOtQChs7Mm0= Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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 When you don't select CONFIG_UBSAN_TRAP, you get: # echo ARRAY_BOUNDS > /sys/kernel/debug/provoke-crash/DIRECT [ 102.265827] ================================================================================ [ 102.278433] UBSAN: array-index-out-of-bounds in drivers/misc/lkdtm/bugs.c:342:16 [ 102.287207] index 8 is out of range for type 'char [8]' [ 102.298722] ================================================================================ [ 102.313712] lkdtm: FAIL: survived array bounds overflow! [ 102.318770] lkdtm: Unexpected! This kernel (5.16.0-rc1-s3k-dev-01884-g720dcf79314a ppc) was built with CONFIG_UBSAN_BOUNDS=y It is not correct because when CONFIG_UBSAN_TRAP is not selected you can't expect array bounds overflow to kill the thread. Modify the logic so that when the kernel is built with CONFIG_UBSAN_BOUNDS but without CONFIG_UBSAN_TRAP, you get a warning about CONFIG_UBSAN_TRAP not been selected instead. This also require a fix of pr_expected_config(), otherwise the following error is encountered. CC drivers/misc/lkdtm/bugs.o drivers/misc/lkdtm/bugs.c: In function 'lkdtm_ARRAY_BOUNDS': drivers/misc/lkdtm/bugs.c:351:2: error: 'else' without a previous 'if' 351 | else | ^~~~ Fixes: c75be56e35b2 ("lkdtm/bugs: Add ARRAY_BOUNDS to selftests") Signed-off-by: Christophe Leroy --- v2: Fix pr_expected_config(), otherwise it can't be used in an if/else sequence. --- drivers/misc/lkdtm/bugs.c | 5 ++++- drivers/misc/lkdtm/lkdtm.h | 5 ++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/misc/lkdtm/bugs.c b/drivers/misc/lkdtm/bugs.c index f21854ac5cc2..0f4dd9621b75 100644 --- a/drivers/misc/lkdtm/bugs.c +++ b/drivers/misc/lkdtm/bugs.c @@ -346,7 +346,10 @@ void lkdtm_ARRAY_BOUNDS(void) kfree(not_checked); kfree(checked); pr_err("FAIL: survived array bounds overflow!\n"); - pr_expected_config(CONFIG_UBSAN_BOUNDS); + if (IS_ENABLED(CONFIG_UBSAN_BOUNDS)) + pr_expected_config(CONFIG_UBSAN_TRAP); + else + pr_expected_config(CONFIG_UBSAN_BOUNDS); } void lkdtm_CORRUPT_LIST_ADD(void) diff --git a/drivers/misc/lkdtm/lkdtm.h b/drivers/misc/lkdtm/lkdtm.h index f508096e8fd9..9c21a4ca0482 100644 --- a/drivers/misc/lkdtm/lkdtm.h +++ b/drivers/misc/lkdtm/lkdtm.h @@ -8,15 +8,14 @@ extern char *lkdtm_kernel_info; -#define pr_expected_config(kconfig) \ -{ \ +#define pr_expected_config(kconfig) do { \ if (IS_ENABLED(kconfig)) \ pr_err("Unexpected! This %s was built with " #kconfig "=y\n", \ lkdtm_kernel_info); \ else \ pr_warn("This is probably expected, since this %s was built *without* " #kconfig "=y\n", \ lkdtm_kernel_info); \ -} +} while (0) #ifndef MODULE int lkdtm_check_bool_cmdline(const char *param); -- 2.35.1