From patchwork Thu Feb 29 17:04:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Micka=C3=ABl_Sala=C3=BCn?= X-Patchwork-Id: 13577441 Received: from smtp-190d.mail.infomaniak.ch (smtp-190d.mail.infomaniak.ch [185.125.25.13]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 564684AEC4 for ; Thu, 29 Feb 2024 17:04:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.125.25.13 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709226276; cv=none; b=p/FiTZosBv87aVWg/sC1jrSZ3hlENWchweXOK1tR8bcetVelJmtJIu01gjZq9zdbRCaa1SDMVsQzorMyjvpiLPeBjFehfXqtONkw9IJ+D9Ks8YozPVWbTKuh67D7I6tZZ6jcQENgHO5E9w023PCMxEulx14CZF+AqrzsWM1o84k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709226276; c=relaxed/simple; bh=4wDdbt4I56G5n6LSUJ2u1jaEVBMsm/64WWZPbsYi9U0=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type; b=bQE7NajQSZBmp49NEGNSLgTBZuSy4twdNVOzq/qJfXvgSogv2Ic0tStrb1o6G/RgAtuPMt9HT4OAyxpXwbKdGLBrWsZqtT1kUvPBjZqvItwR+w5KIUd7dF60Q8CwlTnLSQ0tDPKR6b6IleACpsGm+lU90ezByRIqgN4eawk2Uuk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=digikod.net; spf=pass smtp.mailfrom=digikod.net; dkim=pass (1024-bit key) header.d=digikod.net header.i=@digikod.net header.b=nlVkoodR; arc=none smtp.client-ip=185.125.25.13 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=digikod.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=digikod.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=digikod.net header.i=@digikod.net header.b="nlVkoodR" Received: from smtp-4-0000.mail.infomaniak.ch (smtp-4-0000.mail.infomaniak.ch [10.7.10.107]) by smtp-4-3000.mail.infomaniak.ch (Postfix) with ESMTPS id 4TlyHp6JJMz5wk; Thu, 29 Feb 2024 18:04:22 +0100 (CET) Received: from unknown by smtp-4-0000.mail.infomaniak.ch (Postfix) with ESMTPA id 4TlyHm47S2zYBH; Thu, 29 Feb 2024 18:04:20 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=digikod.net; s=20191114; t=1709226262; bh=4wDdbt4I56G5n6LSUJ2u1jaEVBMsm/64WWZPbsYi9U0=; h=From:To:Cc:Subject:Date:From; b=nlVkoodRGG/+JH60co6QTYI+j/xS/kAvzRqTk/xdhkVfSSC5JtD7P7treNBKoqd0u U5gu49lO236cmDqZAiQi+oFIZbE1jszXjS2h0mslolmhNqIG4IKa/drMCKvMRTmYRX pKXV1VkrqQbG3nE+oEnjraDdG3Vrknapc8Mb93bc= From: =?utf-8?q?Micka=C3=ABl_Sala=C3=BCn?= To: Brendan Higgins , David Gow , Kees Cook , Rae Moar , Shuah Khan Cc: =?utf-8?q?Micka=C3=ABl_Sala=C3=BCn?= , Alan Maguire , Borislav Petkov , Dave Hansen , "H . Peter Anvin" , Ingo Molnar , James Morris , Luis Chamberlain , "Madhavan T . Venkataraman" , Marco Pagani , Paolo Bonzini , Sean Christopherson , Stephen Boyd , Thara Gopinath , Thomas Gleixner , Vitaly Kuznetsov , Wanpeng Li , Zahra Tarkhani , kvm@vger.kernel.org, linux-hardening@vger.kernel.org, linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org, linux-security-module@vger.kernel.org, linux-um@lists.infradead.org, x86@kernel.org Subject: [PATCH v1 0/8] Run KUnit tests late and handle faults Date: Thu, 29 Feb 2024 18:04:01 +0100 Message-ID: <20240229170409.365386-1-mic@digikod.net> Precedence: bulk X-Mailing-List: linux-security-module@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Infomaniak-Routing: alpha Hi, This patch series moves KUnit test execution at the very end of kernel initialization, just before launching the init process. This opens the way to test any kernel code in its normal state (i.e. fully initialized). This patch series also teaches KUnit to handle kthread faults as errors, and it brings a few related fixes and improvements. New tests check NULL pointer dereference and read-only memory, which wasn't possible before. This is useful to test current kernel self-protection mechanisms or future ones such as Heki: https://github.com/heki-linux Regards, Mickaël Salaün (8): kunit: Run tests when the kernel is fully setup kunit: Handle thread creation error kunit: Fix kthread reference kunit: Fix timeout message kunit: Handle test faults kunit: Fix KUNIT_SUCCESS() calls in iov_iter tests kunit: Print last test location on fault kunit: Add tests for faults include/kunit/test.h | 24 +++++- include/kunit/try-catch.h | 3 - init/main.c | 4 +- lib/bitfield_kunit.c | 8 +- lib/checksum_kunit.c | 2 +- lib/kunit/executor.c | 81 ++++++++++++++------ lib/kunit/kunit-example-test.c | 6 +- lib/kunit/kunit-test.c | 115 +++++++++++++++++++++++++++- lib/kunit/try-catch.c | 33 +++++--- lib/kunit_iov_iter.c | 70 ++++++++--------- tools/testing/kunit/kunit_kernel.py | 6 +- 11 files changed, 261 insertions(+), 91 deletions(-) base-commit: d206a76d7d2726f3b096037f2079ce0bd3ba329b