From patchwork Wed Oct 16 13:18:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sabyrzhan Tasbolatov X-Patchwork-Id: 13838464 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0267CD1AD53 for ; Wed, 16 Oct 2024 13:18:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 890346B0088; Wed, 16 Oct 2024 09:18:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 83E986B0089; Wed, 16 Oct 2024 09:18:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 72D716B008A; Wed, 16 Oct 2024 09:18:17 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 547336B0088 for ; Wed, 16 Oct 2024 09:18:17 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 51EC31A024E for ; Wed, 16 Oct 2024 13:17:59 +0000 (UTC) X-FDA: 82679518782.12.D4882B0 Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) by imf06.hostedemail.com (Postfix) with ESMTP id D147E18000A for ; Wed, 16 Oct 2024 13:18:08 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=ZGjaNVSU; spf=pass (imf06.hostedemail.com: domain of snovitoll@gmail.com designates 209.85.128.45 as permitted sender) smtp.mailfrom=snovitoll@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1729084550; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=vp8mlzCFerHZwOQsdYQzAEyYccT5PlBtmx7TKcs3NbQ=; b=zJmo7fo/XjYSsNcP8yTWZ7ySwCZoewpYPdmKy0/i4fKnkEcUC+Ia6l7aZdKvObO3oWLoDM U2FJu6+tLeARKk6CW9g+DtdsNDk5xdRR/lhCP+1fyf2te4Sxb7j+hf8faKUG8oG8ejxTXY 3N8kbP494ZWmccm3TEdW5MMo9CxpFHY= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1729084550; a=rsa-sha256; cv=none; b=Lc1gjhVCbGkkTkewoXwz8cdJwu4EVZ0Va0hrqoKFyCxZuCfpODNUOFUgruT0+3IxqgIyN3 O0Lvg7Zm775UtFlsQr5VlMtze60ImaimnPmqm9iexTat1GjaiyTXZpV4SJYCssJ88mZ77E zbij7s8mvpTsIEqH0HLDJXfvRTBke1g= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=ZGjaNVSU; spf=pass (imf06.hostedemail.com: domain of snovitoll@gmail.com designates 209.85.128.45 as permitted sender) smtp.mailfrom=snovitoll@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-4311ae6426aso45617565e9.2 for ; Wed, 16 Oct 2024 06:18:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729084694; x=1729689494; darn=kvack.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=vp8mlzCFerHZwOQsdYQzAEyYccT5PlBtmx7TKcs3NbQ=; b=ZGjaNVSU1PKhGJsty5dfyQYLuVyer4QhlJzTkhZa8P3nFqMhALcUSbcKqNb5NU9ZSU shN5T1mq7WYg7q3vnqCgImZNzTX53a67kaLvAKEgEzmNoRRb6voh2CkT841vEVstFb3A rwLkTYE0TaQ3mSzm31116efB+8cSeyu3JzJhCdi5j4A6m4Z6T8qmaQhtGHxnIJXtEiWp ATzQxljgujFLYHONvvU2F/eG8ff7V/8gB47FiqLgDf0mbWQj4L9bcWWbJeAqAugdFxfm i0Mkzqy4Fj7sRWlj2mT3ptq2d663HKS7rkrcuKPzv1zyJasR7t8bDvd6+tOvCmMn9/xO aa5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729084694; x=1729689494; 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=vp8mlzCFerHZwOQsdYQzAEyYccT5PlBtmx7TKcs3NbQ=; b=IxbDBKneRbfGFjSZqwpft1MijmwmShCQ8CZN1ZWP7s4lx1JOLY5MCKZ6NWsDEQtLFx S0T2bMq1RJM3kfnZkhZlDgfoY5yLsLzGarbvd7ZUIsTNuJf0uFkhUD92M6sqI9RXJp5t DOmiGklqYdCk7YSKYOHASW7rJftUmjG0MXEqmwZ8traH+ae4dBc50PsT0f+w9W9E8bFN TXv5HIUiHkB1kxV7PNcAJ4jcqZXb+uaNku4zO9j3d1YUIElb/tqHWdtHhNWJo1DVxuhX Dym+DVkVEMdp80WmnLnllW12PvAjfzkYJKf0o0vBKXhn0L5wMDyrBxG/5VFokRt1pkg/ Zleg== X-Forwarded-Encrypted: i=1; AJvYcCUYJGd248jHraP7JYcBpiXvpeAwK/cYfdQzF7wcDNpYpPBT7j19rnSvY/vRRAqTBoKbi37TeCb7rw==@kvack.org X-Gm-Message-State: AOJu0Yy/e8vT8g3MmFeCR51S9HaQcNO131uyna32NEbSSY2WDRu7Sx2r nTafMTQpgq5f3DinXzCFNQ85acy2SMwM/Cm85haAb0B81mRNFpt1 X-Google-Smtp-Source: AGHT+IEPh2uD/e424mZy3TzaSgh1zMe8F8B2stIBFMZzi9dKTninoOvYVP/vLIQdZEOFtDvCeX2T8g== X-Received: by 2002:a05:600c:4514:b0:426:60b8:d8ba with SMTP id 5b1f17b1804b1-4314a362525mr29799615e9.28.1729084693271; Wed, 16 Oct 2024 06:18:13 -0700 (PDT) Received: from work.. (2.133.25.254.dynamic.telecom.kz. [2.133.25.254]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4313f5698aesm49612825e9.11.2024.10.16.06.18.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Oct 2024 06:18:12 -0700 (PDT) From: Sabyrzhan Tasbolatov To: andreyknvl@gmail.com Cc: 2023002089@link.tyut.edu.cn, akpm@linux-foundation.org, alexs@kernel.org, corbet@lwn.net, dvyukov@google.com, elver@google.com, glider@google.com, kasan-dev@googlegroups.com, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, ryabinin.a.a@gmail.com, siyanteng@loongson.cn, snovitoll@gmail.com, vincenzo.frascino@arm.com, workflows@vger.kernel.org Subject: [PATCH v4 1/3] kasan: move checks to do_strncpy_from_user Date: Wed, 16 Oct 2024 18:18:00 +0500 Message-Id: <20241016131802.3115788-2-snovitoll@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241016131802.3115788-1-snovitoll@gmail.com> References: <20241016131802.3115788-1-snovitoll@gmail.com> MIME-Version: 1.0 X-Stat-Signature: xfkkdr7tkqjg1ogsge4yxwp3ns5g9sot X-Rspamd-Queue-Id: D147E18000A X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1729084688-650673 X-HE-Meta: U2FsdGVkX18hSCDu6gTSrPpgxl5WdoxSOiBPEPtJF+AUW/Ka8BOVOGv7K8E4x8fqGxGZUKI/9XrAYV4xNYpro48ovFW2A8Nv3DE99jwZbY93WUos3WxcfbChB7tsJHGv3STyd6R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mjrgIwTasjkmt0TtANwYriGptHo16S14NGY8fMvsh4J2zvtqSzUFEKu4h5MP8jJvCfGn/VneLSwKSx4eytr2GpaiA4HyOeLj6XwHjqjiHD2PQUMtN3h9qXHBQlyTw8n2OqzidEj13BNXxkTIOS48kUZ9czyg++ko3YhhP/jkkoaXSoNv8bwk8FB3Xjuk4F6dEk4KmsIcM8CAj3SxynLka4Hjbcp5XiUl+E7BigITe0CiRz71VsxzZzXS6oYV+7SEMmPuPRR3c/vHyxUIRjJmhCRwcsk/1IgIqw== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000538, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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-speculative conditional") Reviewed-by: Andrey Konovalov Signed-off-by: Sabyrzhan Tasbolatov --- 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..6dc234913dd 100644 --- a/lib/strncpy_from_user.c +++ b/lib/strncpy_from_user.c @@ -120,6 +120,9 @@ long strncpy_from_user(char *dst, const char __user *src, long count) if (unlikely(count <= 0)) return 0; + kasan_check_write(dst, count); + check_object_size(dst, count, false); + if (can_do_masked_user_access()) { long retval; @@ -142,8 +145,6 @@ long strncpy_from_user(char *dst, const char __user *src, long count) if (max > count) max = count; - kasan_check_write(dst, count); - check_object_size(dst, count, false); if (user_read_access_begin(src, max)) { retval = do_strncpy_from_user(dst, src, count, max); user_read_access_end(); From patchwork Wed Oct 16 13:18:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sabyrzhan Tasbolatov X-Patchwork-Id: 13838465 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 77F12D1AD55 for ; Wed, 16 Oct 2024 13:18:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0ED916B008A; Wed, 16 Oct 2024 09:18:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 09DBA6B008C; Wed, 16 Oct 2024 09:18:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EA8AE6B0092; Wed, 16 Oct 2024 09:18:21 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id CCBD86B008A for ; Wed, 16 Oct 2024 09:18:21 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 2AC35A0251 for ; Wed, 16 Oct 2024 13:18:03 +0000 (UTC) X-FDA: 82679518950.23.95B8304 Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53]) by imf13.hostedemail.com (Postfix) with ESMTP id 7C36C20002 for ; Wed, 16 Oct 2024 13:18:10 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=B50aAktn; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf13.hostedemail.com: domain of snovitoll@gmail.com designates 209.85.128.53 as permitted sender) smtp.mailfrom=snovitoll@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1729084666; a=rsa-sha256; cv=none; b=SV/wmPjblvX2lRepiu2FnTwmPH6vdMvyXDj7NSQWLzSYp41TaVkzkn8CG1cIJR77ie6cDw Yhu2+g6le1Km/Yj79TmDRBHOCr5vNv/AwRAIg5tQnPlxOxQjacSZd0/7LOZxGKSJs4mzBe aeIitM9+/lWg0jA0dhlqjclKQPOk81Q= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=B50aAktn; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf13.hostedemail.com: domain of snovitoll@gmail.com designates 209.85.128.53 as permitted sender) smtp.mailfrom=snovitoll@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1729084666; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=/8xPPGnp2eNdFzyDsH77udpuxb5hGHHiKYVsaBBQcww=; b=CUXZk1z0JNB9S0Ip5rr+TNajHG6IasXkrD/X6fc8lvSYJMs4VJ7Ncnu/vPKCiB4Xc/7s7z xSrct22+ZQFmYsGgBXw+sYwW0HCoixvhdVCXc7sCcFW93XCLCFI8H63d1FGBkohvoEES9E zX8bzSQXLNrl/xdhMWEd7It4pX3n10I= Received: by mail-wm1-f53.google.com with SMTP id 5b1f17b1804b1-431548bd1b4so3783155e9.3 for ; Wed, 16 Oct 2024 06:18:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729084698; x=1729689498; darn=kvack.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=/8xPPGnp2eNdFzyDsH77udpuxb5hGHHiKYVsaBBQcww=; b=B50aAktnoifaJs9Ev1X8GglGhfhbqB2IPSREb/9xXHzmfNj/8Qs59U5utb7rYgsKmr AEfxm0tb5gG0rKqVCW3EkhsWgqmUk7kWk/zrIQ7Srw2/6ZDj7er/4boQIzRQF1UBYe2s P5znzwBYcdOcnUFk5QeChm6Qk3J+nSpUw1iZUSy+8kA3l1bOSI4XUhhXsudFg/g7JsEz q1TZ0VLLWwre2sA+L5hmeMMxNhRCh8IcBeTR6YKwdAFB7eEyHctzXJWkPpmclpdThjZA JdU6wzJkH2h498rRTbOjVKixxypx37J5k1p8xCPPKXPq0XAR2NWNzf9zjSSyO4fS4Gf8 c8QA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729084698; x=1729689498; 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=/8xPPGnp2eNdFzyDsH77udpuxb5hGHHiKYVsaBBQcww=; b=rLCN6yuTOgxOSSnIiNf1cQnA4d3cvbgMfEOwnW9ga0ag6i/C6V9OOwip7TSlDEMlCl HDldVW3G0q1HMAgwpwLdLsSxpZbgTmaZC7v0BRNJhH1x63Z6INnOkeGCcKCHjH4jcYDh Qmu74UV7NGh5I9ld8XxpzkOkZJ1E9jA8JcCGP3oYNA+OdgFD1e1/DwbXRc7XbhFGG+z6 2FDhYGgOmdODPLqheXcexQpX8utJhrTaiRfzrjhTp2uswWhgWu1FGho7om+aAr01Lgj/ wHZdC5KfpOnT6iAHRg/uA/b6CgStJhIf2gxaWTlff65jtG4ImLq20E5FINWxppUim11s 8cOw== X-Forwarded-Encrypted: i=1; AJvYcCX+vUF9I6e3XEKA0guEoyEj793q8gNWSauu7cz4Y5eNyor6jB6Xyvwz8iwSMnxU9J0z7ISYW8VQCw==@kvack.org X-Gm-Message-State: AOJu0YzPDDZd0aZ3OHOZFIll27rh3iT0xpnxpvMH4KbWMkQoV//Bw2va v+lxHL9oqYsxztD8BjhZKukymyeSpJHWdljWPcQFSKd04g0TBVSe X-Google-Smtp-Source: AGHT+IH3FuLlFjmqTs3wizKlwLXV6vFTExlSBMXK4B6QAGh74FnpgDABFCIjNm+jC+pHYvNYiZORlg== X-Received: by 2002:a05:600c:4fd3:b0:431:5503:43ca with SMTP id 5b1f17b1804b1-43155035333mr7296085e9.28.1729084697677; Wed, 16 Oct 2024 06:18:17 -0700 (PDT) Received: from work.. (2.133.25.254.dynamic.telecom.kz. [2.133.25.254]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4313f5698aesm49612825e9.11.2024.10.16.06.18.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Oct 2024 06:18:17 -0700 (PDT) From: Sabyrzhan Tasbolatov To: andreyknvl@gmail.com Cc: 2023002089@link.tyut.edu.cn, akpm@linux-foundation.org, alexs@kernel.org, corbet@lwn.net, dvyukov@google.com, elver@google.com, glider@google.com, kasan-dev@googlegroups.com, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, ryabinin.a.a@gmail.com, siyanteng@loongson.cn, snovitoll@gmail.com, vincenzo.frascino@arm.com, workflows@vger.kernel.org Subject: [PATCH v4 2/3] kasan: migrate copy_user_test to kunit Date: Wed, 16 Oct 2024 18:18:01 +0500 Message-Id: <20241016131802.3115788-3-snovitoll@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241016131802.3115788-1-snovitoll@gmail.com> References: <20241016131802.3115788-1-snovitoll@gmail.com> MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: 8ys6sjpes1b4xuz5jt6oupdc71wnrqs7 X-Rspamd-Queue-Id: 7C36C20002 X-Rspamd-Server: rspam02 X-HE-Tag: 1729084690-598289 X-HE-Meta: U2FsdGVkX1+PfswsPczRb87F8HO9pmrxDJX9ibul+1JAqp7oCwfgoZcCDxDJjqNAlkdEk81CP2wN/td/uKlVRZR+ZPMzClNrttgEAeJlowYZKicMp1Fk3103wZF6YCuEKLMW5TCs/p/hFF6P7px/fpbP/P4IQvvS83R5U2fjTyrP7Jt4dCwU4xLxmjaqaeSAzDATSCR7cMBzd3w8plUbXDrV6hDwyfkgtxs4d0r++DxY0793QGWnjD9pXv/utEnA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rmKka1SKtnLdUg7W6IzWdVhjRldeXh786wlmUQXxiTGCmh+u2ga7DJMLw5L3eY7o0dNOGEvu21BWAPQfn4Mp6+fCqI3FdMdZC8jwlftMMb8x0kJCBieJKMGiE5VuZJSJCyFMFlTby9JjkwSBmGVrAkJcUNEJnCrnVUM9DW/tSXU= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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. Reviewed-by: Andrey Konovalov Signed-off-by: Sabyrzhan Tasbolatov --- Changes v2 -> v3: - added a long string in usermem for strncpy_from_user. Suggested by Andrey. --- mm/kasan/Makefile | 2 - mm/kasan/kasan_test_c.c | 47 +++++++++++++++++++++ mm/kasan/kasan_test_module.c | 81 ------------------------------------ 3 files changed, 47 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 CFLAGS_kasan_test_c.o := $(CFLAGS_KASAN_TEST) RUSTFLAGS_kasan_test_rust.o := $(RUSTFLAGS_KASAN) -CFLAGS_kasan_test_module.o := $(CFLAGS_KASAN_TEST) obj-y := common.o report.o obj-$(CONFIG_KASAN_GENERIC) += init.o generic.o report_generic.o shadow.o quarantine.o @@ -59,4 +58,3 @@ ifdef CONFIG_RUST endif obj-$(CONFIG_KASAN_KUNIT_TEST) += kasan_test.o -obj-$(CONFIG_KASAN_MODULE_TEST) += kasan_test_module.o diff --git a/mm/kasan/kasan_test_c.c b/mm/kasan/kasan_test_c.c index a181e4780d9..382bc64e42d 100644 --- a/mm/kasan/kasan_test_c.c +++ b/mm/kasan/kasan_test_c.c @@ -1954,6 +1954,52 @@ static void rust_uaf(struct kunit *test) KUNIT_EXPECT_KASAN_FAIL(test, kasan_test_rust_uaf()); } +static void copy_user_test_oob(struct kunit *test) +{ + char *kmem; + char __user *usermem; + unsigned long useraddr; + size_t size = 128 - KASAN_GRANULE_SIZE; + int __maybe_unused unused; + + kmem = kunit_kmalloc(test, size, GFP_KERNEL); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, kmem); + + useraddr = 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 = (char __user *)useraddr; + + KUNIT_EXPECT_KASAN_FAIL(test, + unused = copy_from_user(kmem, usermem, size + 1)); + KUNIT_EXPECT_KASAN_FAIL(test, + unused = copy_to_user(usermem, kmem, size + 1)); + KUNIT_EXPECT_KASAN_FAIL(test, + unused = __copy_from_user(kmem, usermem, size + 1)); + KUNIT_EXPECT_KASAN_FAIL(test, + unused = __copy_to_user(usermem, kmem, size + 1)); + KUNIT_EXPECT_KASAN_FAIL(test, + unused = __copy_from_user_inatomic(kmem, usermem, size + 1)); + KUNIT_EXPECT_KASAN_FAIL(test, + unused = __copy_to_user_inatomic(usermem, kmem, size + 1)); + + /* + * Prepare a long string in usermem to avoid the strncpy_from_user test + * bailing out on '\0' before it reaches out-of-bounds. + */ + memset(kmem, 'a', size); + KUNIT_EXPECT_EQ(test, copy_to_user(usermem, kmem, size), 0); + + KUNIT_EXPECT_KASAN_FAIL(test, + unused = strncpy_from_user(kmem, usermem, size + 1)); +} + static struct kunit_case kasan_kunit_test_cases[] = { KUNIT_CASE(kmalloc_oob_right), KUNIT_CASE(kmalloc_oob_left), @@ -2028,6 +2074,7 @@ static struct kunit_case kasan_kunit_test_cases[] = { KUNIT_CASE(match_all_ptr_tag), KUNIT_CASE(match_all_mem_tag), KUNIT_CASE(rust_uaf), + KUNIT_CASE(copy_user_test_oob), {} }; 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 = 128 - KASAN_GRANULE_SIZE; - int __maybe_unused unused; - - kmem = kmalloc(size, GFP_KERNEL); - if (!kmem) - return; - - usermem = (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 = copy_from_user(kmem, usermem, size + 1); - - pr_info("out-of-bounds in copy_to_user()\n"); - unused = copy_to_user(usermem, kmem, size + 1); - - pr_info("out-of-bounds in __copy_from_user()\n"); - unused = __copy_from_user(kmem, usermem, size + 1); - - pr_info("out-of-bounds in __copy_to_user()\n"); - unused = __copy_to_user(usermem, kmem, size + 1); - - pr_info("out-of-bounds in __copy_from_user_inatomic()\n"); - unused = __copy_from_user_inatomic(kmem, usermem, size + 1); - - pr_info("out-of-bounds in __copy_to_user_inatomic()\n"); - unused = __copy_to_user_inatomic(usermem, kmem, size + 1); - - pr_info("out-of-bounds in strncpy_from_user()\n"); - unused = 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 = kasan_save_enable_multi_shot(); - - copy_user_test(); - - kasan_restore_multi_shot(multishot); - return -EAGAIN; -} - -module_init(kasan_test_module_init); -MODULE_LICENSE("GPL"); From patchwork Wed Oct 16 13:18:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Sabyrzhan Tasbolatov X-Patchwork-Id: 13838466 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1E4C8D1AD55 for ; Wed, 16 Oct 2024 13:18:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7A5AD6B0092; Wed, 16 Oct 2024 09:18:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7551A6B0093; Wed, 16 Oct 2024 09:18:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5CE276B0095; Wed, 16 Oct 2024 09:18:26 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 3CB876B0092 for ; Wed, 16 Oct 2024 09:18:26 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 07F3712016D for ; Wed, 16 Oct 2024 13:18:17 +0000 (UTC) X-FDA: 82679519076.06.1E8B2E2 Received: from mail-wr1-f46.google.com (mail-wr1-f46.google.com [209.85.221.46]) by imf23.hostedemail.com (Postfix) with ESMTP id 86588140015 for ; Wed, 16 Oct 2024 13:18:18 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="ZWL/cTRq"; spf=pass (imf23.hostedemail.com: domain of snovitoll@gmail.com designates 209.85.221.46 as permitted sender) smtp.mailfrom=snovitoll@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1729084559; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=JGMf0QveJLuqNVGuhCQVRHmO+zBayTHS2lF5VIrEUbY=; b=Gg26KstXDytvmyWUJaBVyHu+bMxyzJUede5AH2OEWJNNVF23HgBfs3F1bYPXQJEzCpSS+t a6mUcAqLBPSIdFYKIo2bsOvOHO/goNV9uB7hzdF/b8nK38UGA5XwgTQbT9+c2UbCcCj8KU 9mUQFB/cj7YS7vClVOLJpyZZLwEjjvY= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1729084559; a=rsa-sha256; cv=none; b=VM/rKLOCJNP2c4tkdDerxgq8cABMp4kvoNGD1UqzOIB3C4rg/Nz3d4K6YFwG0RccdtCkbz pkNJkeUDv66q27SqeYyLXRpsBQJmfDmPaZyZAeWaJgv1qPUDdP4GbXqjmS/zXlspPzfLFf 6IWx/Gob+s+mW3PhGvuppSc0PsxjzDo= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="ZWL/cTRq"; spf=pass (imf23.hostedemail.com: domain of snovitoll@gmail.com designates 209.85.221.46 as permitted sender) smtp.mailfrom=snovitoll@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-wr1-f46.google.com with SMTP id ffacd0b85a97d-37d462c91a9so4229647f8f.2 for ; Wed, 16 Oct 2024 06:18:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729084702; x=1729689502; darn=kvack.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=JGMf0QveJLuqNVGuhCQVRHmO+zBayTHS2lF5VIrEUbY=; b=ZWL/cTRqxaSmtp1dDy6e8C58/mhCjdNT2SvNSqEAFYNvHUinbPmpEQjCSizqgYCDTI 85Txpcr3XBXXzFeTmqmWycapNGweesgUP92EQyaWKOmEwguyr5V1msKINbU2QJNYK/xN nO7uSOEax1sYYSBjrd80He5j0ROWTUr2F6X6vsfRQPWkYTWrT1AGwZHF0VCKKsrFxhK/ YyZUZBa25FsXmdIEhFOiS0DlvR23dN28WwwMoBOuj6Uu8x7FZLPOR+6dzEiBci3R22fn ALW6H9Fl4coCTd7Jmi6cPkDUv+ycr50EhbBj1o3YpAxsr7BgLl3cV6UaH7UTgkOQ6/u4 wlwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729084702; x=1729689502; 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=JGMf0QveJLuqNVGuhCQVRHmO+zBayTHS2lF5VIrEUbY=; b=HG02RWSPlK5igaTmnga+u8bH9w0/nay8gDgWT9axCdxbKRKmeJaCWL0tvWcQFPexXH DTb5+XGuO61vabfXjPOzXCepfsTHarcRTqVwUjzit6GppIh6cnc/MP3A7Ug2hQU0EnOo tIdTW4IF4zKDC/mWkWdeizvfiO/O9S0yuS78k1RuiP2xTnxI/cUTL3egPrwItZV4JQQX hynl9jTUFT6fJX+JDtncN+lnrPpf4Y4ceI4HWpdb1pQUa0ON7dES8iSREczNZVbKjNRH +2QjHgofy5IL06RzBnLTGGiwgN+soES/KXY0w9YOv9SfBhhSa6OuRrbAdKdWjSoACy12 ZFig== X-Forwarded-Encrypted: i=1; AJvYcCUXNXIhRZR96K0owFw4KqGy4B+JSpdvigPVAvXFWXu23iaKYOT0c5Sps1zHFBnYTSdn6tFGuyo+BQ==@kvack.org X-Gm-Message-State: AOJu0YycUKpbfbByH+sj+EK6tS8phAjeOMSay3FxUPFhfu0YDWXyOZ6b 37X91OBaYAlnBC2JeOkuYFSu6hrVmnvNQzmqHbgU9vhLUuqruoHH X-Google-Smtp-Source: AGHT+IEnqE33zAEZ4Osvb5YV0WmK6TiqgW5ppvcNvuX+PIESYEVsFYkFYZLCq1hdV0OqDyWWM/vbiw== X-Received: by 2002:a5d:6109:0:b0:37d:3999:7b4 with SMTP id ffacd0b85a97d-37d5519cbb6mr11646512f8f.17.1729084702303; Wed, 16 Oct 2024 06:18:22 -0700 (PDT) Received: from work.. (2.133.25.254.dynamic.telecom.kz. [2.133.25.254]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4313f5698aesm49612825e9.11.2024.10.16.06.18.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Oct 2024 06:18:21 -0700 (PDT) From: Sabyrzhan Tasbolatov To: andreyknvl@gmail.com Cc: 2023002089@link.tyut.edu.cn, akpm@linux-foundation.org, alexs@kernel.org, corbet@lwn.net, dvyukov@google.com, elver@google.com, glider@google.com, kasan-dev@googlegroups.com, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, ryabinin.a.a@gmail.com, siyanteng@loongson.cn, snovitoll@gmail.com, vincenzo.frascino@arm.com, workflows@vger.kernel.org Subject: [PATCH v4 3/3] kasan: delete CONFIG_KASAN_MODULE_TEST Date: Wed, 16 Oct 2024 18:18:02 +0500 Message-Id: <20241016131802.3115788-4-snovitoll@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241016131802.3115788-1-snovitoll@gmail.com> References: <20241016131802.3115788-1-snovitoll@gmail.com> MIME-Version: 1.0 X-Stat-Signature: w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jJYRWZHS wrYDtTaD F0m28tGd2gYutPnNrCTdBwEl5e5g+jYS7nyWN2rRe65AJVNvbQJwb9iD/pOB4czYgYy/LkPUIFuXAtpgnu2Sfi6ciFNBu/M4cTpgkyxNi4SG5yDcUzc5JJZc/hyjMoMUTnYdLO5wtOQW2BmLU+Yyszcfqboe2aMvPYi9x8i5DMZA4expmghL8deBRv9UvVqEOWzVqiT6ZYrZr7tUNbbRB8HIr7HaYwvpS069N93xS1hmvIKEPNMyc+Mp1bYsr7Mr2setrIZFPAk6ksDtU380n47uizn9EYcjgwgwyCJPmfjLy70Fo7WObli9berCYJ+v8A85LQyIYvCRzFVlBUSn2HZ/GRUROG6FW+bsjx8CrBA7SMxt9RO4at41hrmVV+hYLTljfZ9HF5Yx61E/fy0M5aImvSYvXtspgcVIT1GhGKBu++IpnqUBwBxvF7OxtSmwX2jcWwS1zcoGzk9zqgHXxOeNcMQ8VWDh3wKKY6lnpu4EHa0aqRJw7ZhhKRHML1I3SvfvGpPprLniN2Zr8mbgtsDRsJQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.001719, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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. Reviewed-by: Andrey Konovalov Signed-off-by: Sabyrzhan Tasbolatov --- Changes v2 -> v3: - applied Andrey's patch to modify further kasan.rst. --- Documentation/dev-tools/kasan.rst | 23 ++++++++----------- .../translations/zh_CN/dev-tools/kasan.rst | 20 +++++++--------- .../translations/zh_TW/dev-tools/kasan.rst | 21 ++++++++--------- lib/Kconfig.kasan | 7 ------ mm/kasan/kasan.h | 2 +- mm/kasan/report.c | 2 +- 6 files changed, 28 insertions(+), 47 deletions(-) diff --git a/Documentation/dev-tools/kasan.rst b/Documentation/dev-tools/kasan.rst index d7de44f5339..0a1418ab72f 100644 --- a/Documentation/dev-tools/kasan.rst +++ b/Documentation/dev-tools/kasan.rst @@ -511,19 +511,14 @@ Tests ~~~~~ 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. -1. Tests that are integrated with the KUnit Test Framework. Enabled with -``CONFIG_KASAN_KUNIT_TEST``. These tests can be run and partially verified +All KASAN tests are integrated with the KUnit Test Framework and can be enabled +via ``CONFIG_KASAN_KUNIT_TEST``. The tests can be run and partially verified automatically in a few different ways; see the instructions below. -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. +Each KASAN test prints one of multiple KASAN reports if an error is detected. +Then the test prints its number and status. When a test passes:: @@ -550,16 +545,16 @@ Or, if one of the tests failed:: not ok 1 - kasan -There are a few ways to run KUnit-compatible KASAN tests. +There are a few ways to run the KASAN tests. 1. Loadable module - With ``CONFIG_KUNIT`` enabled, KASAN-KUnit tests can be built as a loadable - module and run by loading ``kasan_test.ko`` with ``insmod`` or ``modprobe``. + With ``CONFIG_KUNIT`` enabled, the tests can be built as a loadable module + and run by loading ``kasan_test.ko`` with ``insmod`` or ``modprobe``. 2. Built-In - With ``CONFIG_KUNIT`` built-in, KASAN-KUnit tests can be built-in as well. + With ``CONFIG_KUNIT`` built-in, the tests can be built-in as well. In this case, the tests will run at boot as a late-init call. 3. Using kunit_tool diff --git a/Documentation/translations/zh_CN/dev-tools/kasan.rst b/Documentation/translations/zh_CN/dev-tools/kasan.rst index 4491ad2830e..fd2e3afbdfa 100644 --- a/Documentation/translations/zh_CN/dev-tools/kasan.rst +++ b/Documentation/translations/zh_CN/dev-tools/kasan.rst @@ -422,16 +422,12 @@ KASAN连接到vmap基础架构以懒清理未使用的影子内存。 ~~~~ 有一些KASAN测试可以验证KASAN是否正常工作并可以检测某些类型的内存损坏。 -测试由两部分组成: -1. 与KUnit测试框架集成的测试。使用 ``CONFIG_KASAN_KUNIT_TEST`` 启用。 -这些测试可以通过几种不同的方式自动运行和部分验证;请参阅下面的说明。 +所有 KASAN 测试都与 KUnit 测试框架集成,可通过 ``CONFIG_KASAN_KUNIT_TEST`` 启用。 +测试可以通过几种不同的方式自动运行和部分验证;请参阅以下说明。 -2. 与KUnit不兼容的测试。使用 ``CONFIG_KASAN_MODULE_TEST`` 启用并且只能作为模块 -运行。这些测试只能通过加载内核模块并检查内核日志以获取KASAN报告来手动验证。 - -如果检测到错误,每个KUnit兼容的KASAN测试都会打印多个KASAN报告之一,然后测试打印 -其编号和状态。 +如果检测到错误,每个 KASAN 测试都会打印多份 KASAN 报告中的一份。 +然后测试会打印其编号和状态。 当测试通过:: @@ -458,16 +454,16 @@ KASAN连接到vmap基础架构以懒清理未使用的影子内存。 not ok 1 - kasan -有几种方法可以运行与KUnit兼容的KASAN测试。 +有几种方法可以运行 KASAN 测试。 1. 可加载模块 - 启用 ``CONFIG_KUNIT`` 后,KASAN-KUnit测试可以构建为可加载模块,并通过使用 - ``insmod`` 或 ``modprobe`` 加载 ``kasan_test.ko`` 来运行。 + 启用 ``CONFIG_KUNIT`` 后,可以将测试构建为可加载模块 + 并通过使用 ``insmod`` 或 ``modprobe`` 加载 ``kasan_test.ko`` 来运行。 2. 内置 - 通过内置 ``CONFIG_KUNIT`` ,也可以内置KASAN-KUnit测试。在这种情况下, + 通过内置 ``CONFIG_KUNIT``,测试也可以内置。 测试将在启动时作为后期初始化调用运行。 3. 使用kunit_tool diff --git a/Documentation/translations/zh_TW/dev-tools/kasan.rst b/Documentation/translations/zh_TW/dev-tools/kasan.rst index ed342e67d8e..35b7fd18aa4 100644 --- a/Documentation/translations/zh_TW/dev-tools/kasan.rst +++ b/Documentation/translations/zh_TW/dev-tools/kasan.rst @@ -404,16 +404,13 @@ KASAN連接到vmap基礎架構以懶清理未使用的影子內存。 ~~~~ 有一些KASAN測試可以驗證KASAN是否正常工作並可以檢測某些類型的內存損壞。 -測試由兩部分組成: -1. 與KUnit測試框架集成的測試。使用 ``CONFIG_KASAN_KUNIT_TEST`` 啓用。 -這些測試可以通過幾種不同的方式自動運行和部分驗證;請參閱下面的說明。 +所有 KASAN 測試均與 KUnit 測試框架集成,並且可以啟用 +透過 ``CONFIG_KASAN_KUNIT_TEST``。可以運行測試並進行部分驗證 + 以幾種不同的方式自動進行;請參閱下面的說明。 -2. 與KUnit不兼容的測試。使用 ``CONFIG_KASAN_MODULE_TEST`` 啓用並且只能作爲模塊 -運行。這些測試只能通過加載內核模塊並檢查內核日誌以獲取KASAN報告來手動驗證。 - -如果檢測到錯誤,每個KUnit兼容的KASAN測試都會打印多個KASAN報告之一,然後測試打印 -其編號和狀態。 +如果偵測到錯誤,每個 KASAN 測試都會列印多個 KASAN 報告之一。 +然後測試列印其編號和狀態。 當測試通過:: @@ -440,16 +437,16 @@ KASAN連接到vmap基礎架構以懶清理未使用的影子內存。 not ok 1 - kasan -有幾種方法可以運行與KUnit兼容的KASAN測試。 +有幾種方法可以執行 KASAN 測試。 1. 可加載模塊 - 啓用 ``CONFIG_KUNIT`` 後,KASAN-KUnit測試可以構建爲可加載模塊,並通過使用 - ``insmod`` 或 ``modprobe`` 加載 ``kasan_test.ko`` 來運行。 + 啟用 ``CONFIG_KUNIT`` 後,測試可以建置為可載入模組 + 並且透過使用 ``insmod`` 或 ``modprobe`` 來載入 ``kasan_test.ko`` 來運作。 2. 內置 - 通過內置 ``CONFIG_KUNIT`` ,也可以內置KASAN-KUnit測試。在這種情況下, + 透過內建 ``CONFIG_KUNIT``,測試也可以內建。 測試將在啓動時作爲後期初始化調用運行。 3. 使用kunit_tool 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/. -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) { } #endif /* CONFIG_KASAN_KUNIT_TEST */ -#if IS_ENABLED(CONFIG_KASAN_KUNIT_TEST) || IS_ENABLED(CONFIG_KASAN_MODULE_TEST) +#if IS_ENABLED(CONFIG_KASAN_KUNIT_TEST) 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); } -#if IS_ENABLED(CONFIG_KASAN_KUNIT_TEST) || IS_ENABLED(CONFIG_KASAN_MODULE_TEST) +#if IS_ENABLED(CONFIG_KASAN_KUNIT_TEST) bool kasan_save_enable_multi_shot(void) {