From nobody Wed Nov 27 04:45:45 2024 Received: from mail-ej1-f51.google.com (mail-ej1-f51.google.com [209.85.218.51]) (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 97A85231C9D; Sun, 13 Oct 2024 13:01:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728824518; cv=none; b=a46YefXba0y+0y+MWTXw4JXVlVONzumeN/2/piHrkbkT/iouNRjIkQCVCqdZM/xoil1/7zAgnYBULpl8ZyYO0hqq9ppJFGYbCSJFrjs5S+T24r6uIlgd6YhE59KXz6lyifH1MrT+DxYybdmAwZd5NhSocj5KCQq/PEzOSMoaqGs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728824518; c=relaxed/simple; bh=QXZEJoFSggOrdz5mMDrg+gJdJU7I21DSRG8B6ih233o=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=mTOYpuissYreh8f8ufIxQKbJBc9OCGIBZzUS+oqNDZ/6Hmn0uwp+7oeouSWI0T2RHpCiWEy+S87zgiJVkXdDnfQh2k5Pl5r7AHHlxMyimynFm+zOC60yg56hnFynWobedYXzH6wdA/h00b7iH2jguQ9C/OKszt0rqtpbTaAnMuI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=jMXT1pDr; arc=none smtp.client-ip=209.85.218.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="jMXT1pDr" Received: by mail-ej1-f51.google.com with SMTP id a640c23a62f3a-a99ffeea60bso78601866b.3; Sun, 13 Oct 2024 06:01:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1728824515; x=1729429315; 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=YUH0O52iG9NocMBQX2ifD6HnZr5R8mVmxmATQ3anrSs=; b=jMXT1pDrInGvE03fMxC9e9yqQ94T52UZa8WBZklD6GX9BgyCx5vOl/gxMern9zrB72 17yhjA0bFZ596sm17BptwNcp2gscXEd62rS822RywSc2SpwOZpjaswGftiErv69ClGU5 +8CoQwzB9m1JrLm+2gOCqbLqKVj8RIfIfxvjC7t1DtRI4+aCwGBhSOT5t0qA07evSA5r atTF4k0pE9UMCpJ1iCdFKGuhDonWCGyZRsDFACO6RDY/FloSUXUObz70+z0ffOygW79M w4zTayUlGBtTKWH+ZXtJGqm3IBlT7NEHOF4LumO9LejSrwbYuBtr8SsxMrVCMvtMn+hq 8agA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728824515; x=1729429315; 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=YUH0O52iG9NocMBQX2ifD6HnZr5R8mVmxmATQ3anrSs=; b=j95W7AIu4T1DWlh8jF36lv8QFo/L6eQK/8GDaRn8MIriqQHOZhD0gSr/t4Cq2mWlMZ 25mC/ziZlbYpzXzK7ju1PXpXq8OjiKlQgEU13l8n7QL8+3NOweb6lwN0yH6N/uMU1fq4 aKkdjcWjSkRVfqNvKxbkyZYuMm3oIXfBt66CAi33LDR6xR2C3N6sGvwsiGFeNu2Dqxyo bZipJYNAGJzQ2XL+wrmK0PY89KKDnPj33oRuh93ncOhmfB7Fer1RSCoNHlm2ZZXG1zHA tOEkLN3Sm3YL/HYoIPkMNek4Y7jCkFr4sNwI4WOuf+2RRp9q56t2rOYk+H3Zm0UQvQB6 WK7w== X-Forwarded-Encrypted: i=1; AJvYcCU3PDjR1whNeRxwcTENZ/UbkovWZyaD/641BVwIQP1q6Za/jGn7GxqjFa3g1haQAzfZPz+AgH2E2NSuSEAM@vger.kernel.org, AJvYcCVBeqY5gboZ3xG7mkh6xcfoq4bWc5vNNTEPaPTDQPW83FqgqThb7MDd3h74WeT4JcwRGRLgeJmln2kd@vger.kernel.org, AJvYcCWCPu4m8NS4Z7E0qk3x1rw94C7c+xwj2HJE50LhIci/WH3rGzp3dikIdueVulrx/clhIXZet5Lyeqo=@vger.kernel.org X-Gm-Message-State: AOJu0Yzj8wvuDIo/YfAYYsJnca1iwSB7V+xgm/zh/WKjg2hrBhybctLw pzhP/o5+f4ZwRl2rGSdxNFnX17y3ipM2j5jzG4pMZT91x8AT0t+g X-Google-Smtp-Source: AGHT+IF9TP9UXY7+Xn/KTanZ8SmeeHtdh4zwU64TMJUgxaxAT9yUrVHKBUO3RgLezRWQskcH3dLtjw== X-Received: by 2002:a17:907:2d8b:b0:a99:399f:cf2b with SMTP id a640c23a62f3a-a99b93ae7c8mr624523566b.12.1728824514634; Sun, 13 Oct 2024 06:01:54 -0700 (PDT) Received: from work.. (2.133.25.254.dynamic.telecom.kz. [2.133.25.254]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9a0d9de967sm19209666b.139.2024.10.13.06.01.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 13 Oct 2024 06:01:54 -0700 (PDT) From: Sabyrzhan Tasbolatov To: andreyknvl@gmail.com Cc: akpm@linux-foundation.org, dvyukov@google.com, glider@google.com, kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, ryabinin.a.a@gmail.com, snovitoll@gmail.com, vincenzo.frascino@arm.com, elver@google.com, corbet@lwn.net, alexs@kernel.org, siyanteng@loongson.cn, 2023002089@link.tyut.edu.cn, workflows@vger.kernel.org, linux-doc@vger.kernel.org Subject: [PATCH v2 1/3] kasan: move checks to do_strncpy_from_user Date: Sun, 13 Oct 2024 18:02:09 +0500 Message-Id: <20241013130211.3067196-2-snovitoll@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241013130211.3067196-1-snovitoll@gmail.com> References: <20241013130211.3067196-1-snovitoll@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Since in the commit 2865baf54077("x86: support user address masking instead of non-speculative conditional") do_strncpy_from_user() is called from multiple places, we should sanitize the kernel *dst memory and size which were done in strncpy_from_user() previously. Fixes: 2865baf54077 ("x86: support user address masking instead of non-spec= ulative conditional") Signed-off-by: Sabyrzhan Tasbolatov Reviewed-by: Andrey Konovalov --- lib/strncpy_from_user.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c index 989a12a6787..f36ad821176 100644 --- a/lib/strncpy_from_user.c +++ b/lib/strncpy_from_user.c @@ -31,6 +31,9 @@ static __always_inline long do_strncpy_from_user(char *ds= t, const char __user *s const struct word_at_a_time constants =3D WORD_AT_A_TIME_CONSTANTS; unsigned long res =3D 0; =20 + kasan_check_write(dst, count); + check_object_size(dst, count, false); + if (IS_UNALIGNED(src, dst)) goto byte_at_a_time; =20 @@ -142,8 +145,6 @@ long strncpy_from_user(char *dst, const char __user *sr= c, long count) if (max > count) max =3D count; =20 - kasan_check_write(dst, count); - check_object_size(dst, count, false); if (user_read_access_begin(src, max)) { retval =3D do_strncpy_from_user(dst, src, count, max); user_read_access_end(); --=20 2.34.1 From nobody Wed Nov 27 04:45:45 2024 Received: from mail-ej1-f54.google.com (mail-ej1-f54.google.com [209.85.218.54]) (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 6C4B213B2A2; Sun, 13 Oct 2024 13:02:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728824544; cv=none; b=oCf9xlDCC6kXzF/26zMBrvlk7fUJEn1ZO6zEjkNVv1lXJlLf2WONxlAEWjDKw9fIW9BMonBU1p8OkIvauY2ypgjhL4hDYmwky+sQ3xzzXHuy65qVHGaVj0xDwR5YF4T/Z7XyiIQbPrZuq3luPBiVHvUQ0hzccUOLfrNQtraNRvc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728824544; c=relaxed/simple; bh=48nguJIJIqrt68cC26/V2bcL81sYU6GUZ0U14Det/uM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=rbrapwZPSQxX3qQPX/kbihQILA6HgXn1aKUEm+KhU5j10DHqqQYAAUu93S0B66e1zhbHCBX3AjdcSg32Cap/MAqpDE7sIBjQcTNADcdKxeFDPe/ylQRN3SoepdcoIAdEMMS94yn10kTsza9//DjQlZDdPec3vxpDyp0P7ZT+nZQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=hUMSCvkC; arc=none smtp.client-ip=209.85.218.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="hUMSCvkC" Received: by mail-ej1-f54.google.com with SMTP id a640c23a62f3a-a9944c4d5d4so498675566b.0; Sun, 13 Oct 2024 06:02:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1728824541; x=1729429341; 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=EOio8S+6KOqaUEgqnfvfmeW8wlYXV0IlIhkZKQFgu/c=; b=hUMSCvkCfDggaX1y5ll14eyZkgwOj7mIqbTR8ZMq98Y7xBPLAW+i8VvFSD5JBkL+1b geMNAmoC2ZdSqzoUkReBaJJdxqNC9hm838/wMUGzmh7AFFx0pLxkOLBdJ38O+DFSv49x mFluDuPqCGUAg9IpNqNYbNTejiE2AM5iDPJCWpNHSsPgQLJRDa+9MDaqkFer7/Rf4CF7 3+MrCHvEmnxlOU/r/k+al42YXxK4YzPG7O/XUrcL4mWtUjKNPkwtZpUJ+Z8zsV0Ofbwg VInrB/t2yBbqC4ibP5TH8zEkArsYBfIehIOXB35ymo0a0FmTPmW4G29iUdHQvWeCP4Fx DvAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728824541; x=1729429341; 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=EOio8S+6KOqaUEgqnfvfmeW8wlYXV0IlIhkZKQFgu/c=; b=CiPPlNgJ/efJ906YT1ukWSxgEamMa4hNnfyliHmdhoaTnP0zKBQMV8Rxx/rlpXj3X3 4Sn+hydGgHzu+BFFjcY6hM6njIfW4UJwhnqQzEpHmNbRvMDXeVnxdy1LsEB0OBIMlBiO +x6p9XUZxAytd65WMbDulNwUTXem+HBW92EOTmBSk1xLsr6wGJee2L5W2lWQlo4kTyOZ QhJagPYj4Iu3oa3QeQCLlLx5hdCcj5lUUVE4iixtdwKel/236XaH3xrs6niMNys47eLS PAXbLXptesBPKOcAFJgtwsjFzUJH2vgplgaLk0Szzqa/CCH4VMkRadJG0qGmD4PsHxmM GGwg== X-Forwarded-Encrypted: i=1; AJvYcCUM57Ljje3NPK0rSo1PHXzG0K7NaLn2WWDZ+/dkQagKAuhnfC3o6nPzrrAQuObF9FXGmXlvxWOKf9k=@vger.kernel.org, AJvYcCVGG9nCwOo8bJiH0itXMn9Z+bDe/QI1f+7ybMXrUbXPs90o/azAfZ2DW3nTrKyAi4CkAz9Om7gRcfhGrhAm@vger.kernel.org, AJvYcCVYXrJAXopohFDO7p13tg7e+GdjPUDGRwBj9+C7DcZB5XTFruIeHuWzlVoGnEeZovMsRGTJP8TnSdK2@vger.kernel.org X-Gm-Message-State: AOJu0YzGiDmYHhMtloO7+vQ1oSqD2BoWceUa9ZdHjVZHJfqAwgzHPoV6 i7zV6p2n7w3yd/Co/A+6WHUG7wL/5mabRR7KppoT6gsmOQYzL7fr X-Google-Smtp-Source: AGHT+IGa72/I5E1R4rZXYJgY/jp96XXQXIIaDV5rRLP1ox3QbO7ExR6jmFn8fxtaiWDpevEMJRVjBQ== X-Received: by 2002:a17:907:ea3:b0:a99:4e8c:e5c9 with SMTP id a640c23a62f3a-a99b937b7famr780021966b.20.1728824540497; Sun, 13 Oct 2024 06:02:20 -0700 (PDT) Received: from work.. (2.133.25.254.dynamic.telecom.kz. [2.133.25.254]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9a0d9de967sm19209666b.139.2024.10.13.06.02.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 13 Oct 2024 06:02:19 -0700 (PDT) From: Sabyrzhan Tasbolatov To: andreyknvl@gmail.com Cc: akpm@linux-foundation.org, dvyukov@google.com, glider@google.com, kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, ryabinin.a.a@gmail.com, snovitoll@gmail.com, vincenzo.frascino@arm.com, elver@google.com, corbet@lwn.net, alexs@kernel.org, siyanteng@loongson.cn, 2023002089@link.tyut.edu.cn, workflows@vger.kernel.org, linux-doc@vger.kernel.org Subject: [PATCH v2 2/3] kasan: migrate copy_user_test to kunit Date: Sun, 13 Oct 2024 18:02:10 +0500 Message-Id: <20241013130211.3067196-3-snovitoll@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241013130211.3067196-1-snovitoll@gmail.com> References: <20241013130211.3067196-1-snovitoll@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Migrate the copy_user_test to the KUnit framework to verify out-of-bound detection via KASAN reports in copy_from_user(), copy_to_user() and their static functions. This is the last migrated test in kasan_test_module.c, therefore delete the file. Signed-off-by: Sabyrzhan Tasbolatov --- mm/kasan/Makefile | 2 - mm/kasan/kasan_test_c.c | 39 +++++++++++++++++ mm/kasan/kasan_test_module.c | 81 ------------------------------------ 3 files changed, 39 insertions(+), 83 deletions(-) delete mode 100644 mm/kasan/kasan_test_module.c diff --git a/mm/kasan/Makefile b/mm/kasan/Makefile index b88543e5c0c..1a958e7c8a4 100644 --- a/mm/kasan/Makefile +++ b/mm/kasan/Makefile @@ -46,7 +46,6 @@ endif =20 CFLAGS_kasan_test_c.o :=3D $(CFLAGS_KASAN_TEST) RUSTFLAGS_kasan_test_rust.o :=3D $(RUSTFLAGS_KASAN) -CFLAGS_kasan_test_module.o :=3D $(CFLAGS_KASAN_TEST) =20 obj-y :=3D common.o report.o obj-$(CONFIG_KASAN_GENERIC) +=3D init.o generic.o report_generic.o shadow.= o quarantine.o @@ -59,4 +58,3 @@ ifdef CONFIG_RUST endif =20 obj-$(CONFIG_KASAN_KUNIT_TEST) +=3D kasan_test.o -obj-$(CONFIG_KASAN_MODULE_TEST) +=3D kasan_test_module.o diff --git a/mm/kasan/kasan_test_c.c b/mm/kasan/kasan_test_c.c index a181e4780d9..e71a16d0dfb 100644 --- a/mm/kasan/kasan_test_c.c +++ b/mm/kasan/kasan_test_c.c @@ -1954,6 +1954,44 @@ static void rust_uaf(struct kunit *test) KUNIT_EXPECT_KASAN_FAIL(test, kasan_test_rust_uaf()); } =20 +static void copy_user_test_oob(struct kunit *test) +{ + char *kmem; + char __user *usermem; + unsigned long useraddr; + size_t size =3D 128 - KASAN_GRANULE_SIZE; + int __maybe_unused unused; + + kmem =3D kunit_kmalloc(test, size, GFP_KERNEL); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, kmem); + + useraddr =3D kunit_vm_mmap(test, NULL, 0, PAGE_SIZE, + PROT_READ | PROT_WRITE | PROT_EXEC, + MAP_ANONYMOUS | MAP_PRIVATE, 0); + KUNIT_ASSERT_NE_MSG(test, useraddr, 0, + "Could not create userspace mm"); + KUNIT_ASSERT_LT_MSG(test, useraddr, (unsigned long)TASK_SIZE, + "Failed to allocate user memory"); + + OPTIMIZER_HIDE_VAR(size); + usermem =3D (char __user *)useraddr; + + KUNIT_EXPECT_KASAN_FAIL(test, + unused =3D copy_from_user(kmem, usermem, size + 1)); + KUNIT_EXPECT_KASAN_FAIL(test, + unused =3D copy_to_user(usermem, kmem, size + 1)); + KUNIT_EXPECT_KASAN_FAIL(test, + unused =3D __copy_from_user(kmem, usermem, size + 1)); + KUNIT_EXPECT_KASAN_FAIL(test, + unused =3D __copy_to_user(usermem, kmem, size + 1)); + KUNIT_EXPECT_KASAN_FAIL(test, + unused =3D __copy_from_user_inatomic(kmem, usermem, size + 1)); + KUNIT_EXPECT_KASAN_FAIL(test, + unused =3D __copy_to_user_inatomic(usermem, kmem, size + 1)); + KUNIT_EXPECT_KASAN_FAIL(test, + unused =3D strncpy_from_user(kmem, usermem, size + 1)); +} + static struct kunit_case kasan_kunit_test_cases[] =3D { KUNIT_CASE(kmalloc_oob_right), KUNIT_CASE(kmalloc_oob_left), @@ -2028,6 +2066,7 @@ static struct kunit_case kasan_kunit_test_cases[] =3D= { KUNIT_CASE(match_all_ptr_tag), KUNIT_CASE(match_all_mem_tag), KUNIT_CASE(rust_uaf), + KUNIT_CASE(copy_user_test_oob), {} }; =20 diff --git a/mm/kasan/kasan_test_module.c b/mm/kasan/kasan_test_module.c deleted file mode 100644 index 27ec22767e4..00000000000 --- a/mm/kasan/kasan_test_module.c +++ /dev/null @@ -1,81 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * - * Copyright (c) 2014 Samsung Electronics Co., Ltd. - * Author: Andrey Ryabinin - */ - -#define pr_fmt(fmt) "kasan: test: " fmt - -#include -#include -#include -#include -#include - -#include "kasan.h" - -static noinline void __init copy_user_test(void) -{ - char *kmem; - char __user *usermem; - size_t size =3D 128 - KASAN_GRANULE_SIZE; - int __maybe_unused unused; - - kmem =3D kmalloc(size, GFP_KERNEL); - if (!kmem) - return; - - usermem =3D (char __user *)vm_mmap(NULL, 0, PAGE_SIZE, - PROT_READ | PROT_WRITE | PROT_EXEC, - MAP_ANONYMOUS | MAP_PRIVATE, 0); - if (IS_ERR(usermem)) { - pr_err("Failed to allocate user memory\n"); - kfree(kmem); - return; - } - - OPTIMIZER_HIDE_VAR(size); - - pr_info("out-of-bounds in copy_from_user()\n"); - unused =3D copy_from_user(kmem, usermem, size + 1); - - pr_info("out-of-bounds in copy_to_user()\n"); - unused =3D copy_to_user(usermem, kmem, size + 1); - - pr_info("out-of-bounds in __copy_from_user()\n"); - unused =3D __copy_from_user(kmem, usermem, size + 1); - - pr_info("out-of-bounds in __copy_to_user()\n"); - unused =3D __copy_to_user(usermem, kmem, size + 1); - - pr_info("out-of-bounds in __copy_from_user_inatomic()\n"); - unused =3D __copy_from_user_inatomic(kmem, usermem, size + 1); - - pr_info("out-of-bounds in __copy_to_user_inatomic()\n"); - unused =3D __copy_to_user_inatomic(usermem, kmem, size + 1); - - pr_info("out-of-bounds in strncpy_from_user()\n"); - unused =3D strncpy_from_user(kmem, usermem, size + 1); - - vm_munmap((unsigned long)usermem, PAGE_SIZE); - kfree(kmem); -} - -static int __init kasan_test_module_init(void) -{ - /* - * Temporarily enable multi-shot mode. Otherwise, KASAN would only - * report the first detected bug and panic the kernel if panic_on_warn - * is enabled. - */ - bool multishot =3D kasan_save_enable_multi_shot(); - - copy_user_test(); - - kasan_restore_multi_shot(multishot); - return -EAGAIN; -} - -module_init(kasan_test_module_init); -MODULE_LICENSE("GPL"); --=20 2.34.1 From nobody Wed Nov 27 04:45:45 2024 Received: from mail-ej1-f41.google.com (mail-ej1-f41.google.com [209.85.218.41]) (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 D6D721459FD; Sun, 13 Oct 2024 13:02:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728824549; cv=none; b=JVHsmL1pGwAAMQbYf7mGW20d6ekuKTM+JDP5mL+Xj6ih8UUOMeY1ZVtMqYwt5LOnf6DXlUxf3QCsEzgoRB4ltEQoilOxLFw3BZc1IJUjH7XeR/+LhXHnIpz7V0QjLUoBrAGNsPaO7rONDQzEuUNW4DT3WJdS7boE5xlBTFWjmb4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728824549; c=relaxed/simple; bh=lDXbQwkkaPxMIXDbVLFhS8GkBnxi0Gxz701uf9q5oR0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=PV41K+BSggQHJlvIayy5mhYW/oLP5bH121xkEVDMppT1m0CcOQRYEK26Y3sGUqnw8cK7jqJL0ZhK6lfoHoa7uHITgAl17ZZEmUE9uarw+Id1e41zKe/pDKCS3d1kzALLs5DZMa52QytCwpRraERicE9UgpO9lgHZyZDRWGqJoWM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=b/BUkZK4; arc=none smtp.client-ip=209.85.218.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="b/BUkZK4" Received: by mail-ej1-f41.google.com with SMTP id a640c23a62f3a-a99d1b7b5f5so215858466b.0; Sun, 13 Oct 2024 06:02:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1728824545; x=1729429345; 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=pqumvoIyJhkt9W5HwjJwb/i/n9g4P9IeX/TAEyTfGvM=; b=b/BUkZK48/1tjKmhKbxa3pf2eFusTmWi+/ggr+ycX3LrgBu5Dmez48b6LAEQj7qp6O s66bw+GtXZcjypAfcSPMy5aF0rPMybEDAsNs0tkcnT6ZT06096JBAPo033mmv4XRncru xNok1Ido4Y1Jo4+zxGKfo+EuOH2TFJuMB7r4sGpqzZJ+S8VL0LftVsHllFFh0UDgcWQ2 ow2H0dVN8OHtxl7EPxkEM/UJOaZwEDogTpYPO4H0vzntWu3WF/4FCu8hqr4Z+p8/urxS eFYqUyfBK72oN6WYhek0G1yiDYbnUtIBzJNTfzCO+Mm4peAOepq456PKiJw8y0X67LYH m9kg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728824545; x=1729429345; 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=pqumvoIyJhkt9W5HwjJwb/i/n9g4P9IeX/TAEyTfGvM=; b=CsU01Pqup+EIexYF7pZxtpYUjcosfXFSbC7PMgaOLfj2HareUj3O5Nv/WtWbX4gvt9 0FXO3AZGACQVz2a2uuRhK+CzXPw9zBsg6aL4vkC6biMJUKMcyDbmiY12E41QVXfk25l8 8Ek5PGaPGa0QkJcnK3N0SFlnPJ7kxWfJmXm+vqNT6JYp8qPYeJ1JrMzPGPmqLk+Scr/J 1FNpl0jgaqVGNS2sqJa+d2JjP3VhyLC0pgVWjhMChuMYEd9M8KzzTssi519Ujev6GJcE bssxs/Rls+t5m2tPEUhF0wNuZ+4TTjdhbO6Fxx9qC2rwcolnBXemHsw1U6neifwuMZL9 49Lg== X-Forwarded-Encrypted: i=1; AJvYcCUbSRbx04pAJgztGNlicNhbTxTCXnTdQSpxFamgIw5T4RhEtz5Z+8J+JQXD4pgz7kv0j9CmondNHma5a1ll@vger.kernel.org, AJvYcCUmVcay2c84AsBh+QIGLTWS0HyN6737xnMZecBKHKzHFljBeYYChScKS21GF3ub8jZpcg3OF3RZAN/X@vger.kernel.org, AJvYcCWpfOADCvWzSCA7EBvNyJhnGnsUCMPQmSLvxl76d6LXPr+Bmg9xWnovLhuFk4/50EfL9ifaeltrHnU=@vger.kernel.org X-Gm-Message-State: AOJu0YzbPrILH2PVYCqKVoeeJ4Cru70nwdg2+cJ5zHvGxdc3q9QvhUeS ML2rCDggdHtNvFNHY3bc+ssi8FiQxULHZZh9LRVaDw+/ImX29N8S X-Google-Smtp-Source: AGHT+IH3hBQZELCO27froLhmQMniGAn0bBg1HgfDg+xB1ADD1RL5C7wQdwmHKKqPnxl1b745khWtcw== X-Received: by 2002:a17:907:9723:b0:a99:ef41:33db with SMTP id a640c23a62f3a-a99ef4137ebmr460504966b.19.1728824544896; Sun, 13 Oct 2024 06:02:24 -0700 (PDT) Received: from work.. (2.133.25.254.dynamic.telecom.kz. [2.133.25.254]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9a0d9de967sm19209666b.139.2024.10.13.06.02.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 13 Oct 2024 06:02:24 -0700 (PDT) From: Sabyrzhan Tasbolatov To: andreyknvl@gmail.com Cc: akpm@linux-foundation.org, dvyukov@google.com, glider@google.com, kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, ryabinin.a.a@gmail.com, snovitoll@gmail.com, vincenzo.frascino@arm.com, elver@google.com, corbet@lwn.net, alexs@kernel.org, siyanteng@loongson.cn, 2023002089@link.tyut.edu.cn, workflows@vger.kernel.org, linux-doc@vger.kernel.org Subject: [PATCH v2 3/3] kasan: delete CONFIG_KASAN_MODULE_TEST Date: Sun, 13 Oct 2024 18:02:11 +0500 Message-Id: <20241013130211.3067196-4-snovitoll@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241013130211.3067196-1-snovitoll@gmail.com> References: <20241013130211.3067196-1-snovitoll@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Since we've migrated all tests to the KUnit framework, we can delete CONFIG_KASAN_MODULE_TEST and mentioning of it in the documentation as well. I've used the online translator to modify the non-English documentation. Signed-off-by: Sabyrzhan Tasbolatov --- Documentation/dev-tools/kasan.rst | 9 ++------- Documentation/translations/zh_CN/dev-tools/kasan.rst | 6 +----- Documentation/translations/zh_TW/dev-tools/kasan.rst | 6 +----- lib/Kconfig.kasan | 7 ------- mm/kasan/kasan.h | 2 +- mm/kasan/report.c | 2 +- 6 files changed, 6 insertions(+), 26 deletions(-) diff --git a/Documentation/dev-tools/kasan.rst b/Documentation/dev-tools/ka= san.rst index d7de44f5339..52fdd6b5ef6 100644 --- a/Documentation/dev-tools/kasan.rst +++ b/Documentation/dev-tools/kasan.rst @@ -511,17 +511,12 @@ Tests ~~~~~ =20 There are KASAN tests that allow verifying that KASAN works and can detect -certain types of memory corruptions. The tests consist of two parts: +certain types of memory corruptions. =20 -1. Tests that are integrated with the KUnit Test Framework. Enabled with +Tests that are integrated with the KUnit Test Framework. Enabled with ``CONFIG_KASAN_KUNIT_TEST``. These tests can be run and partially verified automatically in a few different ways; see the instructions below. =20 -2. Tests that are currently incompatible with KUnit. Enabled with -``CONFIG_KASAN_MODULE_TEST`` and can only be run as a module. These tests = can -only be verified manually by loading the kernel module and inspecting the -kernel log for KASAN reports. - Each KUnit-compatible KASAN test prints one of multiple KASAN reports if an error is detected. Then the test prints its number and status. =20 diff --git a/Documentation/translations/zh_CN/dev-tools/kasan.rst b/Documen= tation/translations/zh_CN/dev-tools/kasan.rst index 4491ad2830e..f968d262be1 100644 --- a/Documentation/translations/zh_CN/dev-tools/kasan.rst +++ b/Documentation/translations/zh_CN/dev-tools/kasan.rst @@ -422,14 +422,10 @@ KASAN=E8=BF=9E=E6=8E=A5=E5=88=B0vmap=E5=9F=BA=E7=A1= =80=E6=9E=B6=E6=9E=84=E4=BB=A5=E6=87=92=E6=B8=85=E7=90=86=E6=9C=AA=E4=BD=BF= =E7=94=A8=E7=9A=84=E5=BD=B1=E5=AD=90=E5=86=85=E5=AD=98=E3=80=82 ~~~~ =20 =E6=9C=89=E4=B8=80=E4=BA=9BKASAN=E6=B5=8B=E8=AF=95=E5=8F=AF=E4=BB=A5=E9=AA= =8C=E8=AF=81KASAN=E6=98=AF=E5=90=A6=E6=AD=A3=E5=B8=B8=E5=B7=A5=E4=BD=9C=E5= =B9=B6=E5=8F=AF=E4=BB=A5=E6=A3=80=E6=B5=8B=E6=9F=90=E4=BA=9B=E7=B1=BB=E5=9E= =8B=E7=9A=84=E5=86=85=E5=AD=98=E6=8D=9F=E5=9D=8F=E3=80=82 -=E6=B5=8B=E8=AF=95=E7=94=B1=E4=B8=A4=E9=83=A8=E5=88=86=E7=BB=84=E6=88=90: =20 -1. =E4=B8=8EKUnit=E6=B5=8B=E8=AF=95=E6=A1=86=E6=9E=B6=E9=9B=86=E6=88=90=E7= =9A=84=E6=B5=8B=E8=AF=95=E3=80=82=E4=BD=BF=E7=94=A8 ``CONFIG_KASAN_KUNIT_TE= ST`` =E5=90=AF=E7=94=A8=E3=80=82 +=E4=B8=8EKUnit=E6=B5=8B=E8=AF=95=E6=A1=86=E6=9E=B6=E9=9B=86=E6=88=90=E7=9A= =84=E6=B5=8B=E8=AF=95=E3=80=82=E4=BD=BF=E7=94=A8 ``CONFIG_KASAN_KUNIT_TEST`= ` =E5=90=AF=E7=94=A8=E3=80=82 =E8=BF=99=E4=BA=9B=E6=B5=8B=E8=AF=95=E5=8F=AF=E4=BB=A5=E9=80=9A=E8=BF=87= =E5=87=A0=E7=A7=8D=E4=B8=8D=E5=90=8C=E7=9A=84=E6=96=B9=E5=BC=8F=E8=87=AA=E5= =8A=A8=E8=BF=90=E8=A1=8C=E5=92=8C=E9=83=A8=E5=88=86=E9=AA=8C=E8=AF=81=EF=BC= =9B=E8=AF=B7=E5=8F=82=E9=98=85=E4=B8=8B=E9=9D=A2=E7=9A=84=E8=AF=B4=E6=98=8E= =E3=80=82 =20 -2. =E4=B8=8EKUnit=E4=B8=8D=E5=85=BC=E5=AE=B9=E7=9A=84=E6=B5=8B=E8=AF=95=E3= =80=82=E4=BD=BF=E7=94=A8 ``CONFIG_KASAN_MODULE_TEST`` =E5=90=AF=E7=94=A8=E5= =B9=B6=E4=B8=94=E5=8F=AA=E8=83=BD=E4=BD=9C=E4=B8=BA=E6=A8=A1=E5=9D=97 -=E8=BF=90=E8=A1=8C=E3=80=82=E8=BF=99=E4=BA=9B=E6=B5=8B=E8=AF=95=E5=8F=AA= =E8=83=BD=E9=80=9A=E8=BF=87=E5=8A=A0=E8=BD=BD=E5=86=85=E6=A0=B8=E6=A8=A1=E5= =9D=97=E5=B9=B6=E6=A3=80=E6=9F=A5=E5=86=85=E6=A0=B8=E6=97=A5=E5=BF=97=E4=BB= =A5=E8=8E=B7=E5=8F=96KASAN=E6=8A=A5=E5=91=8A=E6=9D=A5=E6=89=8B=E5=8A=A8=E9= =AA=8C=E8=AF=81=E3=80=82 - =E5=A6=82=E6=9E=9C=E6=A3=80=E6=B5=8B=E5=88=B0=E9=94=99=E8=AF=AF=EF=BC=8C= =E6=AF=8F=E4=B8=AAKUnit=E5=85=BC=E5=AE=B9=E7=9A=84KASAN=E6=B5=8B=E8=AF=95= =E9=83=BD=E4=BC=9A=E6=89=93=E5=8D=B0=E5=A4=9A=E4=B8=AAKASAN=E6=8A=A5=E5=91= =8A=E4=B9=8B=E4=B8=80=EF=BC=8C=E7=84=B6=E5=90=8E=E6=B5=8B=E8=AF=95=E6=89=93= =E5=8D=B0 =E5=85=B6=E7=BC=96=E5=8F=B7=E5=92=8C=E7=8A=B6=E6=80=81=E3=80=82 =20 diff --git a/Documentation/translations/zh_TW/dev-tools/kasan.rst b/Documen= tation/translations/zh_TW/dev-tools/kasan.rst index ed342e67d8e..19457860486 100644 --- a/Documentation/translations/zh_TW/dev-tools/kasan.rst +++ b/Documentation/translations/zh_TW/dev-tools/kasan.rst @@ -404,14 +404,10 @@ KASAN=E9=80=A3=E6=8E=A5=E5=88=B0vmap=E5=9F=BA=E7=A4= =8E=E6=9E=B6=E6=A7=8B=E4=BB=A5=E6=87=B6=E6=B8=85=E7=90=86=E6=9C=AA=E4=BD=BF= =E7=94=A8=E7=9A=84=E5=BD=B1=E5=AD=90=E5=85=A7=E5=AD=98=E3=80=82 ~~~~ =20 =E6=9C=89=E4=B8=80=E4=BA=9BKASAN=E6=B8=AC=E8=A9=A6=E5=8F=AF=E4=BB=A5=E9=A9= =97=E8=AD=89KASAN=E6=98=AF=E5=90=A6=E6=AD=A3=E5=B8=B8=E5=B7=A5=E4=BD=9C=E4= =B8=A6=E5=8F=AF=E4=BB=A5=E6=AA=A2=E6=B8=AC=E6=9F=90=E4=BA=9B=E9=A1=9E=E5=9E= =8B=E7=9A=84=E5=85=A7=E5=AD=98=E6=90=8D=E5=A3=9E=E3=80=82 -=E6=B8=AC=E8=A9=A6=E7=94=B1=E5=85=A9=E9=83=A8=E5=88=86=E7=B5=84=E6=88=90: =20 -1. =E8=88=87KUnit=E6=B8=AC=E8=A9=A6=E6=A1=86=E6=9E=B6=E9=9B=86=E6=88=90=E7= =9A=84=E6=B8=AC=E8=A9=A6=E3=80=82=E4=BD=BF=E7=94=A8 ``CONFIG_KASAN_KUNIT_TE= ST`` =E5=95=93=E7=94=A8=E3=80=82 +=E8=88=87KUnit=E6=B8=AC=E8=A9=A6=E6=A1=86=E6=9E=B6=E9=9B=86=E6=88=90=E7=9A= =84=E6=B8=AC=E8=A9=A6=E3=80=82=E4=BD=BF=E7=94=A8 ``CONFIG_KASAN_KUNIT_TEST`= ` =E5=95=93=E7=94=A8=E3=80=82 =E9=80=99=E4=BA=9B=E6=B8=AC=E8=A9=A6=E5=8F=AF=E4=BB=A5=E9=80=9A=E9=81=8E= =E5=B9=BE=E7=A8=AE=E4=B8=8D=E5=90=8C=E7=9A=84=E6=96=B9=E5=BC=8F=E8=87=AA=E5= =8B=95=E9=81=8B=E8=A1=8C=E5=92=8C=E9=83=A8=E5=88=86=E9=A9=97=E8=AD=89=EF=BC= =9B=E8=AB=8B=E5=8F=83=E9=96=B1=E4=B8=8B=E9=9D=A2=E7=9A=84=E8=AA=AA=E6=98=8E= =E3=80=82 =20 -2. =E8=88=87KUnit=E4=B8=8D=E5=85=BC=E5=AE=B9=E7=9A=84=E6=B8=AC=E8=A9=A6=E3= =80=82=E4=BD=BF=E7=94=A8 ``CONFIG_KASAN_MODULE_TEST`` =E5=95=93=E7=94=A8=E4= =B8=A6=E4=B8=94=E5=8F=AA=E8=83=BD=E4=BD=9C=E7=88=B2=E6=A8=A1=E5=A1=8A -=E9=81=8B=E8=A1=8C=E3=80=82=E9=80=99=E4=BA=9B=E6=B8=AC=E8=A9=A6=E5=8F=AA= =E8=83=BD=E9=80=9A=E9=81=8E=E5=8A=A0=E8=BC=89=E5=85=A7=E6=A0=B8=E6=A8=A1=E5= =A1=8A=E4=B8=A6=E6=AA=A2=E6=9F=A5=E5=85=A7=E6=A0=B8=E6=97=A5=E8=AA=8C=E4=BB= =A5=E7=8D=B2=E5=8F=96KASAN=E5=A0=B1=E5=91=8A=E4=BE=86=E6=89=8B=E5=8B=95=E9= =A9=97=E8=AD=89=E3=80=82 - =E5=A6=82=E6=9E=9C=E6=AA=A2=E6=B8=AC=E5=88=B0=E9=8C=AF=E8=AA=A4=EF=BC=8C= =E6=AF=8F=E5=80=8BKUnit=E5=85=BC=E5=AE=B9=E7=9A=84KASAN=E6=B8=AC=E8=A9=A6= =E9=83=BD=E6=9C=83=E6=89=93=E5=8D=B0=E5=A4=9A=E5=80=8BKASAN=E5=A0=B1=E5=91= =8A=E4=B9=8B=E4=B8=80=EF=BC=8C=E7=84=B6=E5=BE=8C=E6=B8=AC=E8=A9=A6=E6=89=93= =E5=8D=B0 =E5=85=B6=E7=B7=A8=E8=99=9F=E5=92=8C=E7=8B=80=E6=85=8B=E3=80=82 =20 diff --git a/lib/Kconfig.kasan b/lib/Kconfig.kasan index 98016e137b7..f82889a830f 100644 --- a/lib/Kconfig.kasan +++ b/lib/Kconfig.kasan @@ -195,13 +195,6 @@ config KASAN_KUNIT_TEST For more information on KUnit and unit tests in general, please refer to the KUnit documentation in Documentation/dev-tools/kunit/. =20 -config KASAN_MODULE_TEST - tristate "KUnit-incompatible tests of KASAN bug detection capabilities" - depends on m && KASAN && !KASAN_HW_TAGS - help - A part of the KASAN test suite that is not integrated with KUnit. - Incompatible with Hardware Tag-Based KASAN. - config KASAN_EXTRA_INFO bool "Record and report more information" depends on KASAN diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h index f438a6cdc96..b7e4b81421b 100644 --- a/mm/kasan/kasan.h +++ b/mm/kasan/kasan.h @@ -568,7 +568,7 @@ static inline void kasan_kunit_test_suite_end(void) { } =20 #endif /* CONFIG_KASAN_KUNIT_TEST */ =20 -#if IS_ENABLED(CONFIG_KASAN_KUNIT_TEST) || IS_ENABLED(CONFIG_KASAN_MODULE_= TEST) +#if IS_ENABLED(CONFIG_KASAN_KUNIT_TEST) =20 bool kasan_save_enable_multi_shot(void); void kasan_restore_multi_shot(bool enabled); diff --git a/mm/kasan/report.c b/mm/kasan/report.c index b48c768acc8..3e48668c3e4 100644 --- a/mm/kasan/report.c +++ b/mm/kasan/report.c @@ -132,7 +132,7 @@ static bool report_enabled(void) return !test_and_set_bit(KASAN_BIT_REPORTED, &kasan_flags); } =20 -#if IS_ENABLED(CONFIG_KASAN_KUNIT_TEST) || IS_ENABLED(CONFIG_KASAN_MODULE_= TEST) +#if IS_ENABLED(CONFIG_KASAN_KUNIT_TEST) =20 bool kasan_save_enable_multi_shot(void) { --=20 2.34.1