Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp53577rdb; Fri, 16 Feb 2024 20:53:49 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCX/HTNg1jmV3tcPIB2NEuw0UYJNDOF6MkD4Oh7PahTuV8nhKxh1YtsnRGpANFKt8AISFbboI84Bu7711rtUN7ET6OojMw/8Q/W4LhakjA== X-Google-Smtp-Source: AGHT+IHaMQO/poMjqUHgPxCE67n74EC7mWIvxRj9Ln2YOEDUuJ5wPM66J1Sd/9JhIE+L7tYwb7fV X-Received: by 2002:a05:6402:3608:b0:561:edfe:7a58 with SMTP id el8-20020a056402360800b00561edfe7a58mr8441723edb.2.1708145629378; Fri, 16 Feb 2024 20:53:49 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708145629; cv=pass; d=google.com; s=arc-20160816; b=yTKx40Mz8b1pq/NUtxyqGHdz+cDV55JLaVfEh2L1rspXsNOJA6mAWu93MUYY8IjdHz iSJdE7OeLkw8sYzpwyiyJfhdeOYDml6PJNU5P3xlDACYbZaDDIhQUG1vzRjeL/YKw6m/ cZovJSWOFRFiyqaqwEJeYXQgpg+h9HLYqywSOx6BlMnZzfNxHfizJ1rp2AObFGW6YF59 54zSsX9fbSyt55o/AI9uMF1THVwoy36qVNax31+EaTdApmbjljEzWYH3tTdkXYipZSXD g3vKyaJ5KpDPduvDbdyLOc3iJMaFW6CxDBGcQcg/15Bpxeoue0NAanD4uWEThO/FO9GP zjFQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=7qdAfjTcONjZuFbVJIFLeD6GXhLkNJkyoK1rJKpx18g=; fh=XmuWYzTKbePbeHBLfp2ftXtPXA3jp0TNkhxHDjC/hr0=; b=gHlnsHrAx1wxBlxuxgV171y9MP+HzOou8ZR2J0g5HqqwGHuzJ9JIxyv4Dw1tu6wvEa haI6VvABKGxL9Xc21UR0FDGZfdjTzloNuMVQ0yBnOu3FulapBnmOu8GVqTCVG53WpcMd bh8HcILIp+1J39P1038xSdg6hRHwwL36iRlfic26V9ME8Z7QnS3Awtfqj611hYDTThrO sUJzQMcmuhhbvrLmQJQ3GBljRkZZiVMhuWZVdLEtZEdyeNUsf9omtVEZckaGw2kOsxyC CH6hZpVoBCmYGPW4Lq9yNSBnrnW1BRcgR5tUHy2nc8waXVSc2VRjJkcWe7rWpxhd6moQ XFOg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=AsKyh1i7; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-69683-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69683-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id g8-20020aa7d1c8000000b00563ef6e3994si572976edp.5.2024.02.16.20.53.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 20:53:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-69683-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=AsKyh1i7; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-69683-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69683-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 00D851F223A6 for ; Sat, 17 Feb 2024 04:53:49 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6CC391C6AE; Sat, 17 Feb 2024 04:53:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="AsKyh1i7" Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F25DF1C292 for ; Sat, 17 Feb 2024 04:53:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.176 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708145619; cv=none; b=EHmGqgwjvLq+waBCGf5vZM7UYDUETGEOtjA6Cb5fey+fbIkbGdmA55vYTL5UMLjKNngiu4tx872EvRQA83wM5uI2c70lA7u82Vd/p+kbBDjLHrL8XMVyVfikzBLS5bvNujtwwZTi/CfwPadh4VttQIfjU+qZtNGWpq4zTy8KCaE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708145619; c=relaxed/simple; bh=kuoh45Evnx5JyHfck+cgZ7vm+rNwO3DEfwaBM/CzXtM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=cFXRKU0xBqMfwEhArIe11NLEozt6LRKIaDHx2VLlk2Q5koTwQpblxb4DrwwCSGTTDfxIPll8FPFWUP282AwtJACGcvHbplFJk1dN4xEHNqmH7ZKLKkSOpvOe9/PL6AVtjK2Y545+ZmGFBntRKinUUfTz95TvIl9z05eZThJHR54= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=AsKyh1i7; arc=none smtp.client-ip=209.85.214.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-1d94b222a3aso26934955ad.2 for ; Fri, 16 Feb 2024 20:53:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1708145617; x=1708750417; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=7qdAfjTcONjZuFbVJIFLeD6GXhLkNJkyoK1rJKpx18g=; b=AsKyh1i7gSiAco917JNW/VbpJGqDbRvPapj4xwCbAVEXUgv6Kx5YoLEKMgnpw5bjUZ jV4ziR78LhoSc2RsaRabVjHVK155ztqZz8uFLrAqoIpEnjNN+jwT+ywFBQDmZzCc6MDS wxq9lPFjEGNh8pKxLbSq+SZNrMXh/3aefHB/Y= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708145617; x=1708750417; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7qdAfjTcONjZuFbVJIFLeD6GXhLkNJkyoK1rJKpx18g=; b=kF1N8Gzuii0Ppskq66EImmqgNyxWXndfmOCG9LJoLXxz5aA+awWZIQ0rNgkf4BgfnH KLi9tB09u2HdQ9GA301tPBNcxShcUoQ37fzPY8CmvzANlHwW9eun86Mj+lB2Gw+E7Gs8 YGZDMggSGkfWGBZkRd8weiUt/uzBmf7KzwJ7PMoPjY+gRUAJyNYSYpG4O5NJLyDJ7Jbm Vz9J4xhVNNjd9pC+Re8M1IZzs2D5G3Aquq4ef7puYG1z/J3Y02f+XoUcLrz58XPfgwRM 0N2dMyWYS+pc9SyFA9J/NeWqSMJVBuhv8dTUaAVSHgRyeNVGAcGjV0D1og++NYmZB+WI vQ0w== X-Forwarded-Encrypted: i=1; AJvYcCXwydd++XM2hUc8j1Rdz83+0IKU7/tzumrpSiY66iTgBJ+SSpn81zTurpaozb8qpLhJB3kgaAi2QCqs5h3PQFhTmUwqFbI/jNf1apQd X-Gm-Message-State: AOJu0YzsZDZhMpoShsq9CXF1cNhdccFD1013p/6NSG5VMCUm+WnR312F WkzgWzi7dxOs4A2a8JXGWUdIV/BHGVp46ZYuzqTIkIVhGSNBkvRxjfB66KwunQ== X-Received: by 2002:a17:902:d2c2:b0:1db:2d82:e803 with SMTP id n2-20020a170902d2c200b001db2d82e803mr8044720plc.20.1708145617246; Fri, 16 Feb 2024 20:53:37 -0800 (PST) Received: from www.outflux.net ([198.0.35.241]) by smtp.gmail.com with ESMTPSA id w12-20020a170902d3cc00b001db398d13ecsm621742plb.258.2024.02.16.20.53.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 20:53:36 -0800 (PST) From: Kees Cook To: linux-hardening@vger.kernel.org Cc: Kees Cook , Alexander Lobakin , Andy Shevchenko , Cezary Rojewski , Puyou Lu , Mark Brown , Brendan Higgins , David Gow , Nick Desaulniers , linux-kernel@vger.kernel.org, kunit-dev@googlegroups.com Subject: [PATCH v3 2/5] fortify: Allow KUnit test to build without FORTIFY Date: Fri, 16 Feb 2024 20:48:25 -0800 Message-Id: <20240217045335.1526675-2-keescook@chromium.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240217043535.make.664-kees@kernel.org> References: <20240217043535.make.664-kees@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2099; i=keescook@chromium.org; h=from:subject; bh=kuoh45Evnx5JyHfck+cgZ7vm+rNwO3DEfwaBM/CzXtM=; b=owEBbQKS/ZANAwAKAYly9N/cbcAmAcsmYgBl0DqcqxsshKhN+XVitP/aPp0wIqPepQH/G0HTU LaFc4bmVtyJAjMEAAEKAB0WIQSlw/aPIp3WD3I+bhOJcvTf3G3AJgUCZdA6nAAKCRCJcvTf3G3A JsyxD/9NuT75fNho8Z/IYQI3bIaDR5+SVoHtJn460dJU895HRVECqQDQK0FH10OwLUPmtsWRNLO e3AY4jCBlmVXEUvk312YO4mVGGKOwIrKn4qRGfuwrYIg6di0KWySPoUJlJmKuEeC0crqblr2VCm 9KdKwIM8rpCcWtVDnfpUdTHtEJDp4t8GB8jwnp3gJQbOgexoO1iHwV6eOQy6pJvdEFaPzv+pcqx 5b9SD2CIjBFPyY1unxleXUEbKZC7kOkSzcCyEQvAK7UgB7cH+7EhKyaXlPyVrou72mOJUhDHKv0 bR/kWpMi+iQ2zUIfTpl8jZIQpcxJZ8b3WsTN7mAG5xtpTnVjdzSbfazkWiTpY1AjGy2nUpuOqSD jhc8Tw8shjxmcmN6hgY9NfC5PQXVrg1frUMWiNR9fTlaSRIYSp9hlixNzCmHGFCFYKhEuWxYoXv gPFCLy8MEGfoUv28zY/TcahYUe338xs7yYeK5Ew7IVFHYtiX7psKu+eOT6oz8C6vQOZ/RmRYMVP K6DOuJygGnjnC1XgOib+KqdhTQCJ0KznSI24Z9g/U2hPwJrn8fdDa3LmXFsTE4+riDIDI3RbkmT CNmNkScyxcDWDUVFXft/0/JEVwtdhsW/xoLpBw8DTPLFlqaFywHieC3G4G808zoLZnhnI8lTLHN 6/YCwtjCopS6SAw== X-Developer-Key: i=keescook@chromium.org; a=openpgp; fpr=A5C3F68F229DD60F723E6E138972F4DFDC6DC026 Content-Transfer-Encoding: 8bit In order for CI systems to notice all the skipped tests related to CONFIG_FORTIFY_SOURCE, allow the FORTIFY_SOURCE KUnit tests to build with or without CONFIG_FORTIFY_SOURCE. Signed-off-by: Kees Cook --- Cc: linux-hardening@vger.kernel.org --- lib/Kconfig.debug | 2 +- lib/fortify_kunit.c | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index 975a07f9f1cc..4e2febe3b568 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug @@ -2748,7 +2748,7 @@ config STACKINIT_KUNIT_TEST config FORTIFY_KUNIT_TEST tristate "Test fortified str*() and mem*() function internals at runtime" if !KUNIT_ALL_TESTS - depends on KUNIT && FORTIFY_SOURCE + depends on KUNIT default KUNIT_ALL_TESTS help Builds unit tests for checking internals of FORTIFY_SOURCE as used diff --git a/lib/fortify_kunit.c b/lib/fortify_kunit.c index 2e4fedc81621..7a88b5dd3d27 100644 --- a/lib/fortify_kunit.c +++ b/lib/fortify_kunit.c @@ -22,6 +22,11 @@ #include #include +/* Handle being built without CONFIG_FORTIFY_SOURCE */ +#ifndef __compiletime_strlen +# define __compiletime_strlen __builtin_strlen +#endif + static const char array_of_10[] = "this is 10"; static const char *ptr_of_11 = "this is 11!"; static char array_unknown[] = "compiler thinks I might change"; @@ -308,6 +313,14 @@ DEFINE_ALLOC_SIZE_TEST_PAIR(kvmalloc) } while (0) DEFINE_ALLOC_SIZE_TEST_PAIR(devm_kmalloc) +static int fortify_test_init(struct kunit *test) +{ + if (!IS_ENABLED(CONFIG_FORTIFY_SOURCE)) + kunit_skip(test, "Not built with CONFIG_FORTIFY_SOURCE=y"); + + return 0; +} + static struct kunit_case fortify_test_cases[] = { KUNIT_CASE(known_sizes_test), KUNIT_CASE(control_flow_split_test), @@ -324,6 +337,7 @@ static struct kunit_case fortify_test_cases[] = { static struct kunit_suite fortify_test_suite = { .name = "fortify", + .init = fortify_test_init, .test_cases = fortify_test_cases, }; -- 2.34.1