From patchwork Mon Aug 29 07:56:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Feng Tang X-Patchwork-Id: 12957489 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 41B92ECAAD2 for ; Mon, 29 Aug 2022 07:55:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CD73C94000B; Mon, 29 Aug 2022 03:55:56 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C865A940007; Mon, 29 Aug 2022 03:55:56 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B759894000B; Mon, 29 Aug 2022 03:55:56 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id A8CB3940007 for ; Mon, 29 Aug 2022 03:55:56 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 69D5E14069C for ; Mon, 29 Aug 2022 07:55:56 +0000 (UTC) X-FDA: 79851871512.03.4E7EF21 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by imf20.hostedemail.com (Postfix) with ESMTP id AEFA31C0041 for ; Mon, 29 Aug 2022 07:55:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1661759755; x=1693295755; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=jcnnNskazsBc3DHIiMPQsDf7lUlURK3M021eCeUP7pM=; b=OGcIyYRbXBOQQejgaaDTfoCuJJSngme/mry8Wzwg/caju5n9W3z8SguK X7zDPFtNKj+wftSQH3It4wQagJD3WbIAQwNvz40prKQo7eSiZ/oKxD8/D L96PWpwjYsISi3JsHbfpdYWKkD461oAO/Wps+oCtOm/YHPan+3miV/r6p GJGkOOhqO9lKqtzm0GnO2GTu7pllHRZFui8GS0+BcqhLiqjh8y/E/ZvT0 AiEPqvIC8iQo6nvQYxCxfZxLI3b7iD+BUIuhS0hxj7WFmDFAuaokTiugp 8UpXqz6mMl+KrKndQ6P2eNkHb+uxmGeEWGVBD1I5IX0V1pXLWFeSSe5fp Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10453"; a="296111522" X-IronPort-AV: E=Sophos;i="5.93,272,1654585200"; d="scan'208";a="296111522" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Aug 2022 00:55:55 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,272,1654585200"; d="scan'208";a="672283586" Received: from shbuild999.sh.intel.com ([10.239.147.181]) by fmsmga008.fm.intel.com with ESMTP; 29 Aug 2022 00:55:52 -0700 From: Feng Tang To: Andrew Morton , Vlastimil Babka , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Roman Gushchin , Hyeonggon Yoo <42.hyeyoo@gmail.com>, Dmitry Vyukov Cc: Dave Hansen , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Feng Tang , kernel test robot Subject: [PATCH v4 3/4] mm: kasan: Add free_meta size info in struct kasan_cache Date: Mon, 29 Aug 2022 15:56:17 +0800 Message-Id: <20220829075618.69069-4-feng.tang@intel.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20220829075618.69069-1-feng.tang@intel.com> References: <20220829075618.69069-1-feng.tang@intel.com> MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1661759756; a=rsa-sha256; cv=none; b=GWC3MdHhZL4On3IqPUz7Bmzx0iHVhYRYnmkFM005W4pSkwUCUVcc+jyJbRx0sjH4E/OatT JZ7dNcNtHVyHadTz4+z1zQ5B+7MG9Y5kwytiTId6SU7SRHUWxXbZ94QBc4YJqEQfGlPBmV ItYr+sQUyn2LQ/fvwxKU8/zBcy4dR20= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=none ("invalid DKIM record") header.d=intel.com header.s=Intel header.b=OGcIyYRb; spf=pass (imf20.hostedemail.com: domain of feng.tang@intel.com designates 134.134.136.65 as permitted sender) smtp.mailfrom=feng.tang@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1661759756; 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=J64Rhb1TYG6oR5L91PBe0TU5EH464UhjIRgwvau1hKg=; b=YWe3a/1kAoHyAOIdZfzomGXQsUQ8Y+oVqUDteKaFyDLzgub0h2GM3z3Xm2uFAo9nOlaskq 7OWbNmReBCXfeT1IjTTA4jHHpQhqjx80r5zObtsCLN4m9YLophVGFRT8j5y1BO7DIzoyAV aBGYt8wTIrxGPrIvGqRdbtZA4+EgnKE= X-Rspam-User: X-Rspamd-Queue-Id: AEFA31C0041 Authentication-Results: imf20.hostedemail.com; dkim=none ("invalid DKIM record") header.d=intel.com header.s=Intel header.b=OGcIyYRb; spf=pass (imf20.hostedemail.com: domain of feng.tang@intel.com designates 134.134.136.65 as permitted sender) smtp.mailfrom=feng.tang@intel.com; dmarc=pass (policy=none) header.from=intel.com X-Stat-Signature: x68sxo8cm1ei3scdutwusx6k73xfrdru X-Rspamd-Server: rspam07 X-HE-Tag: 1661759755-768184 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: When kasan is enabled for slab/slub, it may save kasan' free_meta data in the former part of slab object data area in slab object free path, which works fine. There is ongoing effort to extend slub's debug function which will redzone the latter part of kmalloc object area, and when both of the debug are enabled, there is possible conflict, especially when the kmalloc object has small size, as caught by 0Day bot [1] For better information for slab/slub, add free_meta's data size info 'kasan_cache', so that its users can take right action to avoid data conflict. [1]. https://lore.kernel.org/lkml/YuYm3dWwpZwH58Hu@xsang-OptiPlex-9020/ Reported-by: kernel test robot Signed-off-by: Feng Tang Acked-by: Dmitry Vyukov --- include/linux/kasan.h | 2 ++ mm/kasan/common.c | 2 ++ 2 files changed, 4 insertions(+) diff --git a/include/linux/kasan.h b/include/linux/kasan.h index b092277bf48d..293bdaa0ba09 100644 --- a/include/linux/kasan.h +++ b/include/linux/kasan.h @@ -100,6 +100,8 @@ static inline bool kasan_has_integrated_init(void) struct kasan_cache { int alloc_meta_offset; int free_meta_offset; + /* size of free_meta data saved in object's data area */ + int free_meta_size_in_object; bool is_kmalloc; }; diff --git a/mm/kasan/common.c b/mm/kasan/common.c index 69f583855c8b..762ae7a7793e 100644 --- a/mm/kasan/common.c +++ b/mm/kasan/common.c @@ -201,6 +201,8 @@ void __kasan_cache_create(struct kmem_cache *cache, unsigned int *size, cache->kasan_info.free_meta_offset = KASAN_NO_FREE_META; *size = ok_size; } + } else { + cache->kasan_info.free_meta_size_in_object = sizeof(struct kasan_free_meta); } /* Calculate size with optimal redzone. */