From patchwork Tue Sep 13 06:54: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: 12974477 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 3563AC54EE9 for ; Tue, 13 Sep 2022 06:55:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C831A6B0073; Tue, 13 Sep 2022 02:54:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C3168940008; Tue, 13 Sep 2022 02:54:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AF9BA940007; Tue, 13 Sep 2022 02:54:59 -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 A00E86B0073 for ; Tue, 13 Sep 2022 02:54:59 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 7B32F1608BA for ; Tue, 13 Sep 2022 06:54:59 +0000 (UTC) X-FDA: 79906149918.18.D02ECD2 Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by imf11.hostedemail.com (Postfix) with ESMTP id CAC5940091 for ; Tue, 13 Sep 2022 06:54:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1663052098; x=1694588098; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=DytKD4r9+X/L41exc0OVKMw7LZ0hR4YVrRBK5Geu9bo=; b=IoR8MGtQ6sN3mUy9jWov3JLEXeQdhItD2wIiQCy5NyG8gsWVO6ldg3vx rMfDaJf1Spg2tmT2vnAu2u3626tP/+hIRbtjbfFvtqyPKb2w46whY5Ls9 Iu43CI2f/6HLU7aOl9BGTAtO6OwMZNermMkoVkHCN1eS2XEYcbucSnTVK D448JFaySJ55MU4N9tLasuckSMTAWkfpf+bo+8DIsX7nN7j7HC5XDwWut iMcMjEp4xceq6FJiyTrNwth5Jtt+TtDxOHWG/Xy5QS/sjefkgJxoXPZxK SFZ87oGRZ+6nLu2Ykh4DCf+oe1+PfzphFaanqDdBXP31HFtDeEvjnyIvi Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10468"; a="285079409" X-IronPort-AV: E=Sophos;i="5.93,312,1654585200"; d="scan'208";a="285079409" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Sep 2022 23:54:58 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,312,1654585200"; d="scan'208";a="861440734" Received: from feng-clx.sh.intel.com ([10.238.200.228]) by fmsmga006.fm.intel.com with ESMTP; 12 Sep 2022 23:54:54 -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 , Andrey Konovalov Cc: Dave Hansen , linux-mm@kvack.org, linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com, Feng Tang , kernel test robot Subject: [PATCH v6 3/4] mm: kasan: Add free_meta size info in struct kasan_cache Date: Tue, 13 Sep 2022 14:54:22 +0800 Message-Id: <20220913065423.520159-4-feng.tang@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220913065423.520159-1-feng.tang@intel.com> References: <20220913065423.520159-1-feng.tang@intel.com> MIME-Version: 1.0 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1663052099; 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=w4DAXzPXkCbDYCXb48OkMTjrkf0UJXQmQ3pLbnSy+bk=; b=3vumt5mXMtggIc59dxdgctkR2Ypm/oup6jysrbV83q4HB4sfhX4wTvJMGTPKe+naF8cQpX NGLg11sDQ3cmfdBwZCp11qiVdWz6Rt7+qdMB1hwwfxT3PpWn9onr5jevM/+OxuWisGmaH0 7kRSXnACrPo5uOwQyPHqMLBDBUakU+8= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=none ("invalid DKIM record") header.d=intel.com header.s=Intel header.b=IoR8MGtQ; spf=pass (imf11.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=1663052099; a=rsa-sha256; cv=none; b=gFV+POF8mDV4dMF9ox2CQqisyIU4NUEO+iGNwRTtt2kFAlQ9cLeRc/aGP2D8uGsS+grbER u4WXwA8+QwMUxRzpT8DsQBXxuaHpjOD3+dASKeYyxYBt+lDXKwxghPgeOmmvTVgokj2wo1 9AuFz+Gz2dpjdNh5NTc4JlbLZeEbtbE= X-Rspamd-Queue-Id: CAC5940091 X-Rspam-User: Authentication-Results: imf11.hostedemail.com; dkim=none ("invalid DKIM record") header.d=intel.com header.s=Intel header.b=IoR8MGtQ; spf=pass (imf11.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-Rspamd-Server: rspam02 X-Stat-Signature: g57a5j765mqwowayp8fo9ezyr8eiki58 X-HE-Tag: 1663052098-724201 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's 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 Reviewed-by: Andrey Konovalov Reported-by: kernel test robot Signed-off-by: Feng Tang Reviewed-by: Andrey Konovalov --- 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..49af9513e8ed 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; bool is_kmalloc; }; diff --git a/mm/kasan/common.c b/mm/kasan/common.c index 69f583855c8b..0cb867e92524 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 = sizeof(struct kasan_free_meta); } /* Calculate size with optimal redzone. */