Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp1315143pxb; Tue, 8 Feb 2022 14:28:49 -0800 (PST) X-Google-Smtp-Source: ABdhPJxmZtPKl9JyFWR3/tVcfJ1CH0nScwBhB9AoxCTrEWtpl22EG8P9eyHAcuxqu4cS0P/707WK X-Received: by 2002:a17:902:e294:: with SMTP id o20mr1591402plc.58.1644359329230; Tue, 08 Feb 2022 14:28:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644359329; cv=none; d=google.com; s=arc-20160816; b=yiafvEJ6iQoeG6WCoK/ZuaKQIw81LbDvXe/YiJekeycHmuXfV2UaLmT2Hk5zB0zTU6 D9Ip69jNW9kaHgJFCjOX/aTPx05gGubu1xRl13SBbXGvFAMl76uTqopf0kpzmxuWmzrO +1HCuGOb7kIfbCbCS3W0+l7qW8mpbZNzAHKHSa57bGL71ZtYrdoT8LxvlqYxdpDG11uH kpVg41UneP19t7cSgcrWZZFg9GDDYQWs/4MTTA/x3Cm750xowduU+cT62ZS0EMPY5TgQ cnuBkGTpVqD5m/EJz8dzpMTIWl4Xr3O6ai4b7cezQjK/PS7aafcUkVkbZ3e/H4Asgjpk fZDg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=NRVXz6k5qYgOdp2xZIUPWtH2m6FyLOF3PXWsoqOGl2A=; b=srF0tO4sH0GcyHYLuaTrKh7lEbWjunIpffxSZvenTPHnGFMJD2+O3FnBbRXX37qBX7 tkAf2fvo1W2ddROWQssT8EDnb1cWY5R9XnUYwh9BotFy7wGhpVrSVmT2mTiVqbW1XWvl lj7JcNmlTiInHZyzpGWIiJyWr9eJn8Yy/i5vXdiJLDj4pBR/kj4zHelcoZp/d04MEaDy 6CAOilNxCncl2kYbAD63g7JCkYtFjrX+uQLRWKuMwEb56GWY4GXWaEZHp8zTRkEPKgdy TY5UW9IIATEgMVilMHtwKttU3X6d+Tefl/YRQJVvmhx0SshnoVPSc0jTnzV7NZ3N6sFl h43A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=ZUjyopAN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i32si16308061pgi.668.2022.02.08.14.28.35; Tue, 08 Feb 2022 14:28:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=ZUjyopAN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1385050AbiBHShz (ORCPT + 99 others); Tue, 8 Feb 2022 13:37:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34198 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231149AbiBHShu (ORCPT ); Tue, 8 Feb 2022 13:37:50 -0500 Received: from out2.migadu.com (out2.migadu.com [IPv6:2001:41d0:2:aacc::]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 77D87C061576 for ; Tue, 8 Feb 2022 10:37:49 -0800 (PST) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1644345464; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=NRVXz6k5qYgOdp2xZIUPWtH2m6FyLOF3PXWsoqOGl2A=; b=ZUjyopANDHkE28JEx8nr2AFxm/cEBICwlMTv17KttWtGbSNoDnkbTzmL2FmwJ8ze6NWwEM OvFClwfXddJxwZTGFuL7akWh657ngPhBE8nkMNVppeoHiBgZtZBFmoB4BV3SFe/umYB+Jx TzoWc1cTazy49fpJW/hIF+ZAdJLt67U= From: andrey.konovalov@linux.dev To: Marco Elver , Andrew Morton Cc: Andrey Konovalov , Alexander Potapenko , Dmitry Vyukov , Andrey Ryabinin , kasan-dev@googlegroups.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov Subject: [PATCH] kasan: test: prevent cache merging in kmem_cache_double_destroy Date: Tue, 8 Feb 2022 19:37:36 +0100 Message-Id: <748bd5e0bad5266a4cac52ff25232bbc314b24f5.1644345308.git.andreyknvl@google.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: linux.dev X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Andrey Konovalov With HW_TAGS KASAN and kasan.stacktrace=off, the cache created in the kmem_cache_double_destroy() test might get merged with an existing one. Thus, the first kmem_cache_destroy() call won't actually destroy it but will only descrease the refcount. This causes the test to fail. Provide an empty contructor for the created cache to prevent the cache from getting merged. Fixes: f98f966cd750 ("kasan: test: add test case for double-kmem_cache_destroy()") Signed-off-by: Andrey Konovalov --- lib/test_kasan.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/test_kasan.c b/lib/test_kasan.c index 26a5c9007653..3b413f8c8a71 100644 --- a/lib/test_kasan.c +++ b/lib/test_kasan.c @@ -869,11 +869,14 @@ static void kmem_cache_invalid_free(struct kunit *test) kmem_cache_destroy(cache); } +static void empty_cache_ctor(void *object) { } + static void kmem_cache_double_destroy(struct kunit *test) { struct kmem_cache *cache; - cache = kmem_cache_create("test_cache", 200, 0, 0, NULL); + /* Provide a constructor to prevent cache merging. */ + cache = kmem_cache_create("test_cache", 200, 0, 0, empty_cache_ctor); KUNIT_ASSERT_NOT_ERR_OR_NULL(test, cache); kmem_cache_destroy(cache); KUNIT_EXPECT_KASAN_FAIL(test, kmem_cache_destroy(cache)); -- 2.25.1