Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2658732pxa; Mon, 17 Aug 2020 15:45:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwnTqCJDAjY0Qnhiy+E27jhIDQ8Ag5Hj/RTjHWZI5RwItV/AiDI7vp2OBX2a1AtvUy0inVr X-Received: by 2002:a05:6402:2037:: with SMTP id ay23mr16729637edb.48.1597704353163; Mon, 17 Aug 2020 15:45:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597704353; cv=none; d=google.com; s=arc-20160816; b=yU0U7hsfWyJw2fZdIv4u8kvmTJMbNHfxAg6L3ZKN6Twpi/LY2yc+05kMf+lL8eISlK ME3M7cJnp4xt4qQ/moSDJAQ8TLdVD91vX1sRBuUjdzSZbzkkDciIoi88bmpsqW9L8Grp 4h3eHvclzwyWPiDJi73Rk5ZRU/cRPdgdIQBwlPoalvBJWGQjMhvkY+pmFs2NoLv34Q7w 7HMk9M+q4erdkV5t/8A1986/J1eVUATyN3+TU8l6HQTPGcLYFQh3VzAF5b9bLcQGNPwc o1BD7g5hPm9VJsLVDPIEUhKDgsjNdXxa2ZD2UNzKfuEZbNGvlKJbb1ggh+ymKacWKylE z0WQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=+Ktm1ipN0AvvpHuMupF1McXqj/3o5Q8H267zRYiR8AE=; b=H6DNivd6D7GlFPas0flSve2lKer+l0K2P3pztiGH0Ehgf26DafjbrKAKMyPOHG0iim MubiQjHiWZTzCpvbD2QMQYcne5y2GTN7JA+oaMWfwmJrI1kOUKrL09Kfn0ZwMoqiFf3q WgwJDsyJIZ/SgwiR2JtxilE8B/ep7kBTjgTIj337LhwbyBgzrDvQBbJsXWDu/tgk0Dmf 2/+/plT4YsxNG6V+5yUAVTChvL9zrtr/iT3UaQZ/tmTq+A3J6SXXdiLqeAmc9AFhIulU 0ovp/iBOCcc1g2hSSJUyKZZR2f4qhwfuon/Dd9pHl4FiF9AdV3TI1rLt2Tbm85v3kjdU 4J0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="NIQT6/GZ"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a22si11879987eju.634.2020.08.17.15.45.29; Mon, 17 Aug 2020 15:45:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="NIQT6/GZ"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387898AbgHQS7f (ORCPT + 99 others); Mon, 17 Aug 2020 14:59:35 -0400 Received: from mail.kernel.org ([198.145.29.99]:60628 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729273AbgHQPs2 (ORCPT ); Mon, 17 Aug 2020 11:48:28 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id DC6BC221E2; Mon, 17 Aug 2020 15:48:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597679307; bh=deTRSKqym2ESqM59ZVGraolv/F1PUNmemVxpu0kvG+Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NIQT6/GZ483//dAfhsbd6sZ7BHEsqiLWngSe2pXPeqA3jA4jtawvDL121Tl1dM9pw d7spue8JZfI+kq3DX7r4b8RgaBC07Yc/C3fCHFaHRrXnqjwJPzHCIdrk4iIy8nL0Pc /gWu/1nhW8kdB/GklHod+hvmFwqvnwQHQEP18gh0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kees Cook , Sasha Levin Subject: [PATCH 5.7 167/393] lkdtm: Make arch-specific tests always available Date: Mon, 17 Aug 2020 17:13:37 +0200 Message-Id: <20200817143827.721129529@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200817143819.579311991@linuxfoundation.org> References: <20200817143819.579311991@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Kees Cook [ Upstream commit ae56942c14740c2963222efdc36c667ab19555ef ] I'd like arch-specific tests to XFAIL when on a mismatched architecture so that we can more easily compare test coverage across all systems. Lacking kernel configs or CPU features count as a FAIL, not an XFAIL. Additionally fixes a build failure under 32-bit UML. Fixes: b09511c253e5 ("lkdtm: Add a DOUBLE_FAULT crash type on x86") Fixes: cea23efb4de2 ("lkdtm/bugs: Make double-fault test always available") Fixes: 6cb6982f42cb ("lkdtm: arm64: test kernel pointer authentication") Signed-off-by: Kees Cook Link: https://lore.kernel.org/r/20200625203704.317097-5-keescook@chromium.org Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/misc/lkdtm/bugs.c | 38 ++++++++++++++----------- drivers/misc/lkdtm/lkdtm.h | 2 -- tools/testing/selftests/lkdtm/tests.txt | 1 + 3 files changed, 22 insertions(+), 19 deletions(-) diff --git a/drivers/misc/lkdtm/bugs.c b/drivers/misc/lkdtm/bugs.c index e1b43f6155496..7913c9ff216c9 100644 --- a/drivers/misc/lkdtm/bugs.c +++ b/drivers/misc/lkdtm/bugs.c @@ -13,7 +13,7 @@ #include #include -#ifdef CONFIG_X86_32 +#if IS_ENABLED(CONFIG_X86_32) && !IS_ENABLED(CONFIG_UML) #include #endif @@ -418,7 +418,7 @@ void lkdtm_UNSET_SMEP(void) void lkdtm_DOUBLE_FAULT(void) { -#ifdef CONFIG_X86_32 +#if IS_ENABLED(CONFIG_X86_32) && !IS_ENABLED(CONFIG_UML) /* * Trigger #DF by setting the stack limit to zero. This clobbers * a GDT TLS slot, which is okay because the current task will die @@ -453,38 +453,42 @@ void lkdtm_DOUBLE_FAULT(void) #endif } -#ifdef CONFIG_ARM64_PTR_AUTH +#ifdef CONFIG_ARM64 static noinline void change_pac_parameters(void) { - /* Reset the keys of current task */ - ptrauth_thread_init_kernel(current); - ptrauth_thread_switch_kernel(current); + if (IS_ENABLED(CONFIG_ARM64_PTR_AUTH)) { + /* Reset the keys of current task */ + ptrauth_thread_init_kernel(current); + ptrauth_thread_switch_kernel(current); + } } +#endif -#define CORRUPT_PAC_ITERATE 10 noinline void lkdtm_CORRUPT_PAC(void) { +#ifdef CONFIG_ARM64 +#define CORRUPT_PAC_ITERATE 10 int i; + if (!IS_ENABLED(CONFIG_ARM64_PTR_AUTH)) + pr_err("FAIL: kernel not built with CONFIG_ARM64_PTR_AUTH\n"); + if (!system_supports_address_auth()) { - pr_err("FAIL: arm64 pointer authentication feature not present\n"); + pr_err("FAIL: CPU lacks pointer authentication feature\n"); return; } - pr_info("Change the PAC parameters to force function return failure\n"); + pr_info("changing PAC parameters to force function return failure...\n"); /* - * Pac is a hash value computed from input keys, return address and + * PAC is a hash value computed from input keys, return address and * stack pointer. As pac has fewer bits so there is a chance of * collision, so iterate few times to reduce the collision probability. */ for (i = 0; i < CORRUPT_PAC_ITERATE; i++) change_pac_parameters(); - pr_err("FAIL: %s test failed. Kernel may be unstable from here\n", __func__); -} -#else /* !CONFIG_ARM64_PTR_AUTH */ -noinline void lkdtm_CORRUPT_PAC(void) -{ - pr_err("FAIL: arm64 pointer authentication config disabled\n"); -} + pr_err("FAIL: survived PAC changes! Kernel may be unstable from here\n"); +#else + pr_err("XFAIL: this test is arm64-only\n"); #endif +} diff --git a/drivers/misc/lkdtm/lkdtm.h b/drivers/misc/lkdtm/lkdtm.h index 601a2156a0d48..8878538b2c132 100644 --- a/drivers/misc/lkdtm/lkdtm.h +++ b/drivers/misc/lkdtm/lkdtm.h @@ -31,9 +31,7 @@ void lkdtm_CORRUPT_USER_DS(void); void lkdtm_STACK_GUARD_PAGE_LEADING(void); void lkdtm_STACK_GUARD_PAGE_TRAILING(void); void lkdtm_UNSET_SMEP(void); -#ifdef CONFIG_X86_32 void lkdtm_DOUBLE_FAULT(void); -#endif void lkdtm_CORRUPT_PAC(void); /* lkdtm_heap.c */ diff --git a/tools/testing/selftests/lkdtm/tests.txt b/tools/testing/selftests/lkdtm/tests.txt index 92ca32143ae5f..9d266e79c6a27 100644 --- a/tools/testing/selftests/lkdtm/tests.txt +++ b/tools/testing/selftests/lkdtm/tests.txt @@ -14,6 +14,7 @@ STACK_GUARD_PAGE_LEADING STACK_GUARD_PAGE_TRAILING UNSET_SMEP CR4 bits went missing DOUBLE_FAULT +CORRUPT_PAC UNALIGNED_LOAD_STORE_WRITE #OVERWRITE_ALLOCATION Corrupts memory on failure #WRITE_AFTER_FREE Corrupts memory on failure -- 2.25.1