From nobody Sun May 24 18:43:53 2026 Received: from m16.mail.163.com (m16.mail.163.com [117.135.210.4]) (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 EF4922248A5 for ; Sun, 24 May 2026 03:11:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=117.135.210.4 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779592314; cv=none; b=B0stNTnO70ur6Ep+vZFl+HpzWPQ2goiWokctaKE7JdZgZ+kJGLZbQJ6cmlJEiyXaVce3D2Cfz79e+WXdvhkhwy4UK5fHAT62fImYt7+QM14u9Ra1UHIakbpYlDL2Cy+cqOOSsohkX6gKUlkXVzE8CkElejtiirOUsXDVK4HwZw0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779592314; c=relaxed/simple; bh=SW5pBXER81J5qzLdntsWJFEM5pGmKGjAh0uxb2RjykA=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=NE/L7cc4tz/rT6dh+9MeIAawn3u1VZMpQODPRbfwPWHSUSEDhJ/xClPJtkCJDnGGuX533HN6CjiFonIGtATEmA+CEafOQORhF7LkbHo8n/w4o4+5pzcmRmk6MBgoKRAfkfdsIZormCoki1PjE61606pyXj/yJeWBDCuVAbzXGoM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b=a6ly8jQw; arc=none smtp.client-ip=117.135.210.4 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b="a6ly8jQw" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=Dy qmddIWKaGSpB/GUFD1AdFn79TKghn9LsBISCzCwis=; b=a6ly8jQwlmRAA2/YZo DdovHeYb7XrNMeVgkzaXGuDApKguyhQSZafVFPnZk4U33ucx4zK2+oGcHa9knPtt bOrduw5DATfcVGw7xOOIW3UD7bE6HsSyZGex4jjZ0OqzlsoIBlMD88qI4cU50GWr oFJ5l0MadEO2qlpbPc1IzE89Q= Received: from wang-MACHR-WX9.. (unknown []) by gzga-smtp-mtada-g1-2 (Coremail) with SMTP id _____wCHPxc9bBJqGzx0DA--.36645S2; Sun, 24 May 2026 11:10:54 +0800 (CST) From: Wang Wensheng To: ryabinin.a.a@gmail.com, glider@google.com, andreyknvl@gmail.com, dvyukov@google.com, vincenzo.frascino@arm.com, akpm@linux-foundation.org, kasan-dev@googlegroups.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: wsw9603@163.com Subject: [PATCH v2] kasan/test: only do kmalloc_double_kzfree for generic mode Date: Sun, 24 May 2026 11:10:53 +0800 Message-ID: <20260524031053.381776-1-wsw9603@163.com> X-Mailer: git-send-email 2.43.0 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 X-CM-TRANSID: _____wCHPxc9bBJqGzx0DA--.36645S2 X-Coremail-Antispam: 1Uf129KBjvJXoW7AryrXr1rCrWUGr1DArW8WFg_yoW8GFyfpr 95t34rJFnYyr1Sqr1UAF4v93yrAan7G3W0gasavws09Fy5Gw1Syrn2krWDZrWkZr4xZF4I v3Wqyr13Ww1DAw7anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0pi_-B_UUUUU= X-CM-SenderInfo: pzvzmliqt6il2tof0z/xtbC3gBKUmoSbEBzgQAA3g Content-Type: text/plain; charset="utf-8" kmalloc_double_kzfree() would corrupt kernel memory when the just freed memory were allocated by another thread before the second call to kfree_sensitive() and the new allocation tag happened to match the old one. This could not happen in GENERIC mode as it uses quarantine. Signed-off-by: Wang Wensheng Reviewed-by: Andrey Konovalov --- v1->v2: Update comment suggested by Andrey Konovalov. -- mm/kasan/kasan_test_c.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/mm/kasan/kasan_test_c.c b/mm/kasan/kasan_test_c.c index 32d06cbf6a31..3f4ed29178b3 100644 --- a/mm/kasan/kasan_test_c.c +++ b/mm/kasan/kasan_test_c.c @@ -874,6 +874,16 @@ static void kmalloc_double_kzfree(struct kunit *test) char *ptr; size_t size =3D 16; =20 + /* + * With the tag-based KASAN modes, if the memory happens to be + * reallocated between the two frees and the new allocation tag happens + * to match the old one, the second free will cause a memory corruption. + * Resolving https://bugzilla.kernel.org/show_bug.cgi?id=3D212177 would + * help to deal with this. With Generic KASAN, it's effectively + * impossible for the memory to get reallocated due to the quarantine. + */ + KASAN_TEST_NEEDS_CONFIG_ON(test, CONFIG_KASAN_GENERIC); + ptr =3D kmalloc(size, GFP_KERNEL); KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); =20 --=20 2.43.0