From patchwork Wed Oct 16 15:41:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Feng Tang X-Patchwork-Id: 13838600 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 10A09D2A529 for ; Wed, 16 Oct 2024 15:42:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 929276B008C; Wed, 16 Oct 2024 11:42:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8D9976B0092; Wed, 16 Oct 2024 11:42:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 77CF16B0093; Wed, 16 Oct 2024 11:42:04 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 4EBF16B008C for ; Wed, 16 Oct 2024 11:42:04 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id C4598C05B8 for ; Wed, 16 Oct 2024 15:41:52 +0000 (UTC) X-FDA: 82679880948.08.F324F05 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.10]) by imf27.hostedemail.com (Postfix) with ESMTP id A2D924000E for ; Wed, 16 Oct 2024 15:41:52 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=Ub8EXjkf; spf=pass (imf27.hostedemail.com: domain of feng.tang@intel.com designates 198.175.65.10 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=1729093248; 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=g4wtmCSOL20OH1846ssdNZijDKNqe+VpFdtBicgceqw=; b=jN9NqUA9s33g0us4qyj5GTRkm0EARj4CfANzu+LMdMxDtKHuVC1GnzXHmJEoAtgYrNEfrx raIh1qECNrJEPYQxKoc0coI9BGgXbT/3DAXFo0CGanaMYa771T1Grvc4lDS6Vvo10gJGur DUEY19zb6e77isMY9cxHFW+eeFmyfM4= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=Ub8EXjkf; spf=pass (imf27.hostedemail.com: domain of feng.tang@intel.com designates 198.175.65.10 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=1729093248; a=rsa-sha256; cv=none; b=xsPBOk2d3YvOSTFo5fIIz1vwujn3tOO8yi82nQSTnzW7x6t0PxbWicnG/5gp3SW25xOxnx h+23HD8INaM7/m6Ly0waiWJzjqdPH3FYWrNalgwc6NhJoDAmJ7CIzUhVpqxWnVCJSmJAtl cY704aBornik/OO6laXQrTEGK2KXKog= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1729093321; x=1760629321; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=1yohiX8Mia2wqWhVgM9lhouT0M30SjIN3hnB+Hq2y3E=; b=Ub8EXjkfy0zoiUfR4IL2j6LuO2K/NIcQskBfFi9G71uMIEV8nP2o4kkY 5HpQ9qjyqu6eqtoZvYdptPiVpKvaY90mJUeyQh6N1z79YtcbOGsaHwuQh 8Yl2vWAlFaoNCpqBk30bUJh+NNjhxgD8b2Y+RaKBi0iHK3c9DcePgZzmd 8nmVpArYT+DqEmkeXQVQ8n+mCfL02qI0G+SjIl2AlPRPG0OGgBwGv8K1X M3lGunRt16VLDRbIChIKv+dDt3NSOVcVzUQwDj6/yMsHdjJc/hxZ6FQrz I4EGp8YWH7aVe39taDis7/HvG/MQF3hpe61aWxZXGGohkz89+v1tYV/m+ Q==; X-CSE-ConnectionGUID: CD92HxzGTGKOKl9e2x9ZvQ== X-CSE-MsgGUID: hqJ99KywQWeOCR9wSSCHyw== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="46021350" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="46021350" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by orvoesa102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Oct 2024 08:42:01 -0700 X-CSE-ConnectionGUID: +cn8A2teRjqp+D+KyviP2Q== X-CSE-MsgGUID: 8UoO9yu/TrqGqxq22dttoQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,208,1725346800"; d="scan'208";a="109018906" Received: from feng-clx.sh.intel.com ([10.239.159.50]) by fmviesa001.fm.intel.com with ESMTP; 16 Oct 2024 08:41:57 -0700 From: Feng Tang To: Vlastimil Babka , Andrew Morton , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Roman Gushchin , Hyeonggon Yoo <42.hyeyoo@gmail.com>, Andrey Konovalov , Marco Elver , Alexander Potapenko , Dmitry Vyukov , Danilo Krummrich , Narasimhan.V@amd.com Cc: linux-mm@kvack.org, kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, Feng Tang Subject: [PATCH v3 1/3] mm/slub: Consider kfence case for get_orig_size() Date: Wed, 16 Oct 2024 23:41:50 +0800 Message-Id: <20241016154152.1376492-2-feng.tang@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241016154152.1376492-1-feng.tang@intel.com> References: <20241016154152.1376492-1-feng.tang@intel.com> MIME-Version: 1.0 X-Rspamd-Server: rspam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vb8WtJ+kFLFB jTEFU/ag Vz6cSJvD2Zv8XS9a9wvJgyRqqhf5a6MKn/ryG2b9oI6cFxuo8lVKjZGo1ie3bNS/IPduM/8QOyplY+/XIenCmjof8VmP+MozF//N2Q/vfd2AcNNuRVPHjuJ7rHsKX19xZgs45Xz1AoqIYSxLLxnZSt48sfJbcagLpomN4euen9ef0kDCBLWILxXIgRdUYABQkDFvHTMeXqJB0y5BPg/+KSzf3BBetej42pbcdK3HWLVLQCU4JNXMG466Xv5Xc78L/l6kMol71doiVOOR/65rC+n7mZ/+Uedu0k8u5+Zt4fEyeCDo= 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: List-Subscribe: List-Unsubscribe: When 'orig_size' of kmalloc object is enabled by debug option, it should either contains the actual requested size or the cache's 'object_size'. But it's not true if that object is a kfence-allocated one, and the data at 'orig_size' offset of metadata could be zero or other values. This is not a big issue for current 'orig_size' usage, as init_object() and check_object() during alloc/free process will be skipped for kfence addresses. But it could cause trouble for other usage in future. Use the existing kfence helper kfence_ksize() which can return the real original request size. Signed-off-by: Feng Tang Reviewed-by: Hyeonggon Yoo <42.hyeyoo@gmail.com> --- mm/slub.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mm/slub.c b/mm/slub.c index af9a80071fe0..1d348899f7a3 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -768,6 +768,9 @@ static inline unsigned int get_orig_size(struct kmem_cache *s, void *object) { void *p = kasan_reset_tag(object); + if (is_kfence_address(object)) + return kfence_ksize(object); + if (!slub_debug_orig_size(s)) return s->object_size;