From patchwork Wed Sep 7 07:10:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Feng Tang X-Patchwork-Id: 12968511 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 B2A4CC54EE9 for ; Wed, 7 Sep 2022 07:11:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2ECC86B0075; Wed, 7 Sep 2022 03:11:02 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 29C7F8D0003; Wed, 7 Sep 2022 03:11:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 13D898D0002; Wed, 7 Sep 2022 03:11:02 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 037D16B0075 for ; Wed, 7 Sep 2022 03:11:02 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id A97B8A9B86 for ; Wed, 7 Sep 2022 07:11:01 +0000 (UTC) X-FDA: 79884417522.17.B967D7A Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by imf19.hostedemail.com (Postfix) with ESMTP id 126DF1A005A for ; Wed, 7 Sep 2022 07:11:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1662534661; x=1694070661; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=LdKHrxAxXDqYHfPB0sEWH2wdDk/FqQuOHbbJB314/Vc=; b=jVHHsOXbfJp0cn0XmtcQkttSYuR8bm60c2SUUgXcKLUP2O4oOIA/zhJn kZtig43knLQwvL2aAEvGKsOzyNhOym+44O4wyNnvaBO9MzVmpZzG42VMW TD4mVhQQehbBcMIJaxgHTX7C7dkuct/p5uEBgrYrbR0158OPcKMiaESvt kcWo+i/lDf0jndPkDVD6MuPs/XURAswSP95qbGVpkskJbhyyMJIj+Htl0 zXVbXp9samgk3RNa/W3knd5Q3hbMMqZh2T2tQKuqcRbJnJ/GDedGgSV1s sbWQzbS/5UOwM3SoAwTPhUs/JUjw9eNcu5H88lLe/tOXch4bzzSAj+JEJ A==; X-IronPort-AV: E=McAfee;i="6500,9779,10462"; a="283798284" X-IronPort-AV: E=Sophos;i="5.93,296,1654585200"; d="scan'208";a="283798284" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Sep 2022 00:11:00 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,296,1654585200"; d="scan'208";a="676053451" Received: from feng-clx.sh.intel.com ([10.238.200.228]) by fmsmga008.fm.intel.com with ESMTP; 07 Sep 2022 00:10:57 -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 , Jonathan Corbet Cc: Dave Hansen , linux-mm@kvack.org, linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com, Feng Tang , kernel test robot Subject: [PATCH v5 3/4] mm: kasan: Add free_meta size info in struct kasan_cache Date: Wed, 7 Sep 2022 15:10:22 +0800 Message-Id: <20220907071023.3838692-4-feng.tang@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220907071023.3838692-1-feng.tang@intel.com> References: <20220907071023.3838692-1-feng.tang@intel.com> MIME-Version: 1.0 ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=none ("invalid DKIM record") header.d=intel.com header.s=Intel header.b=jVHHsOXb; spf=pass (imf19.hostedemail.com: domain of feng.tang@intel.com designates 134.134.136.20 as permitted sender) smtp.mailfrom=feng.tang@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1662534661; a=rsa-sha256; cv=none; b=YccooC/9gikQJe7Cqs+EUy9YnEDcHdLyElqzzJA01wdXgfvWrpEfGfpOmETxsC7JZHDH/2 yi6oVR8CpQ8+7SE78WCUJxBDuL3VacPBIx10R2wOB7lyOLF3zmZt6vWON1p2yk1DqQ9aUH YVU5qL8IjfsCJVxoyQd6gdLOKjC1Ge4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1662534661; 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=C2AvDIQQEePpY2JC2J8eigLe6k04A+oww6op+x2ryEw=; b=YEaZ4F9KmrVCqrz06hBgO4+93p4aRcJY/FJKCQx0Si+NOFXFYFa0K54SdEj2gX2ZPwCEUe cKbUW/Iaud4BQeElu7kItYlLuYPYW9iFBNVZ4TZVCx48i5cxh4i9Hjwemshx/tDxpjhIUL Qz41HryDAEG+1WQymah1yxnuUQlxN/Q= Authentication-Results: imf19.hostedemail.com; dkim=none ("invalid DKIM record") header.d=intel.com header.s=Intel header.b=jVHHsOXb; spf=pass (imf19.hostedemail.com: domain of feng.tang@intel.com designates 134.134.136.20 as permitted sender) smtp.mailfrom=feng.tang@intel.com; dmarc=pass (policy=none) header.from=intel.com X-Stat-Signature: kitseeemdsi7q5s1zdh9fzbcpc897op6 X-Rspamd-Queue-Id: 126DF1A005A X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1662534660-492107 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 into 'struct 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. */