From patchwork Thu Aug 29 03:29:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Peng Fan (OSS)" X-Patchwork-Id: 13782412 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 34648C54FC6 for ; Thu, 29 Aug 2024 03:20:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B29BE6B00C8; Wed, 28 Aug 2024 23:20:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AD8E26B00C9; Wed, 28 Aug 2024 23:20:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 952C96B00CA; Wed, 28 Aug 2024 23:20:50 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 6D52A6B00C8 for ; Wed, 28 Aug 2024 23:20:50 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id E02711C4F85 for ; Thu, 29 Aug 2024 03:20:49 +0000 (UTC) X-FDA: 82503831018.03.9325C8C Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2046.outbound.protection.outlook.com [40.107.21.46]) by imf03.hostedemail.com (Postfix) with ESMTP id C879620015 for ; Thu, 29 Aug 2024 03:20:46 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=NXP1.onmicrosoft.com header.s=selector1-NXP1-onmicrosoft-com header.b=bA18HkAt; dmarc=pass (policy=none) header.from=nxp.com; spf=pass (imf03.hostedemail.com: domain of peng.fan@oss.nxp.com designates 40.107.21.46 as permitted sender) smtp.mailfrom=peng.fan@oss.nxp.com; arc=pass ("microsoft.com:s=arcselector10001:i=1") ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1724901626; a=rsa-sha256; cv=pass; b=dFc6Ez0BxDDwMeowhi9eBGlRk8HlQ9gHeFktK5cB2aGK83lJVW++Hj5e3uB8YOlQZrK789 jHdJ6mWPqLA0oi2YArukEol+0BE/6jXvSHVyi6rtzsjYMqy7nlLaln7l9O7K0e9YuTiR2H LgIlsMYLhc+EeByMwyanz3GXEWvK9nw= ARC-Authentication-Results: i=2; imf03.hostedemail.com; dkim=pass header.d=NXP1.onmicrosoft.com header.s=selector1-NXP1-onmicrosoft-com header.b=bA18HkAt; dmarc=pass (policy=none) header.from=nxp.com; spf=pass (imf03.hostedemail.com: domain of peng.fan@oss.nxp.com designates 40.107.21.46 as permitted sender) smtp.mailfrom=peng.fan@oss.nxp.com; arc=pass ("microsoft.com:s=arcselector10001:i=1") ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724901626; 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-type: content-transfer-encoding:content-transfer-encoding:in-reply-to: references:dkim-signature; bh=xNKmRDb7oPfYXiGt9ClVeyzklnTPZO4EuI7x17N4V88=; b=OskWH7erC/4UknYXjljq2FKCI331t4J1WDIUajkkcf++4NNdkehUwVH+2rkKjYL1L5HRUP g/35XmcVX9DWrfZv9SmwslFRE8vTHH2CLsdUUpPMC9eimZLoyWa7eFmsRm3X/CInI8ZgXu GmCN8u0GR7zAxZaMpDQFEb2Fhq8T2v0= ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=FRvf+gqDWDXonogjaCAtmaxdhHoYNOMiXnSyxnBjxuXItS3j/HQB51ioAFJyE2a2WTnJPEYk8OHLf+JTJEW7o2WGBBbnyFiagMiOVU/vmdzZ1m00ZDofgnXO397RkHX6OEgcG6x1b5PJOwheJ+pqCknpeS05k37zWE2mSCl42YyYY51NLiPQ6QnSqztrs7R6mBn6UYzaktBm7gK7Vl4e3lnT+lTkstq+hM0ufIiJAJ2nt5gpbCwDa/AB6wF38CW4WpO9zVRBphyG9MY7OcsLvF0wVf7x8QfX4M5wiHBqSQo47yjvSusw8cqCgWMuwzwCxTbdUx4v53dmc8nLzIuV4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=xNKmRDb7oPfYXiGt9ClVeyzklnTPZO4EuI7x17N4V88=; b=rHDKPS4lsZ/FAkPSmbglcOZzoaK1wcDtl6NWTUwu3gSsPesQf84MU+QYifUyq/bvxJlj7Ci8vTz+g5qHCcv33msObCiL1EijhmyFvXzImrIobxUojGje4zLPSpjnC4QKVSGed4WFEOW1ZuVh4r3PJqHQRJTOYZby8W+qErOXjHuQEdP0w8CQDiYyNxZwXQGK0Q+TMjhLoY8n/wSXTbzHDBKN1lxQY/xEp8COLNl3oU7W65+9sJH/Yn/WJLc6dhwAgwlLRG3V9LC56LalkmM1tyQfcyMKiwkv4mnY/KZnmsZ1LSQ85JReWYY4U4x7PZhoOd0yq41FfSSr3gGViyg66w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oss.nxp.com; dmarc=pass action=none header.from=oss.nxp.com; dkim=pass header.d=oss.nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=NXP1.onmicrosoft.com; s=selector1-NXP1-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=xNKmRDb7oPfYXiGt9ClVeyzklnTPZO4EuI7x17N4V88=; b=bA18HkAttxKV27CyIFFc5QGQYC36YNIziFO/tdxhuoSuQ1G2maX4k7WdHwGdbmDomu964N91C8XgwJlQC9tr1dRrK0Eda7RKe2pKMJw+gOKVFDTrHQbn5DEAgZdtILCpXpN1jmlCys8aSIJxhCD+ua4PGt0A2U1OxKSpFouYa75Zqa3unBbUnUquILMJO1kLcCsgyNx8pSAxjhiC2HGBWgiNzjAP/bZ1kCcdRxFTJ4DDyCNgg+Jxxj7psML+wfkX164CDVBT3KrRBF4l+NPQqX7TszcAiYHCHJYhEO1V2A//B9/f8kHEKPo4sUlTVPUVWyHJGvuSgygs+6vm6YaWeA== Received: from PAXPR04MB8459.eurprd04.prod.outlook.com (2603:10a6:102:1da::15) by PAXPR04MB8223.eurprd04.prod.outlook.com (2603:10a6:102:1c9::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7875.20; Thu, 29 Aug 2024 03:20:40 +0000 Received: from PAXPR04MB8459.eurprd04.prod.outlook.com ([fe80::165a:30a2:5835:9630]) by PAXPR04MB8459.eurprd04.prod.outlook.com ([fe80::165a:30a2:5835:9630%6]) with mapi id 15.20.7897.027; Thu, 29 Aug 2024 03:20:40 +0000 From: "Peng Fan (OSS)" To: Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , Vlastimil Babka , Roman Gushchin , Hyeonggon Yoo <42.hyeyoo@gmail.com>, Feng Tang , linux-mm@kvack.org (open list:SLAB ALLOCATOR), linux-kernel@vger.kernel.org (open list) Cc: Peng Fan Subject: [PATCH V2] mm, slub: avoid zeroing kmalloc redzone Date: Thu, 29 Aug 2024 11:29:11 +0800 Message-Id: <20240829032911.2801669-1-peng.fan@oss.nxp.com> X-Mailer: git-send-email 2.37.1 X-ClientProxiedBy: SI2PR04CA0012.apcprd04.prod.outlook.com (2603:1096:4:197::14) To PAXPR04MB8459.eurprd04.prod.outlook.com (2603:10a6:102:1da::15) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB8459:EE_|PAXPR04MB8223:EE_ X-MS-Office365-Filtering-Correlation-Id: 22a1eae8-712e-4f57-e0f5-08dcc7d98f34 X-MS-Exchange-SharedMailbox-RoutingAgent-Processed: True X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|52116014|366016|376014|7416014|1800799024|38350700014|921020; X-Microsoft-Antispam-Message-Info: CFZqJ4Y/PkjiALOCcyK+dyPF+9ywSshSrPpveYnx9DD2s880wIfi04BSZhs0XGPi1G0JFJgeQwFBGgLx9ZI4lqw3vmTwWvCCP86CSOSh88OOGXIRrtiBRi7CBMPKgbNDP7CjKL15gYEVd+HQ5VP/5oUQuySnzjUNJZKx0T/4X1VURhlfOscXRjCxPa3WldzSihSJILFwFcqXmbAYmcahVXaTlv8fa0mQ2QZ158B8bLpst6c7KrxScYJ4J6hQ8hqyVwdgHNjXxYIKgLCZGCkTQFc5do7uu24lPjYydXIZ3zcH5VObW8waDZlxR8lFIWp3LQXG/3jyNHOoOZqs2+CeS9BJU+7NmKCOmloAy771+ytZ5JqTja1OjH5HgIRTnqMQmYrdFkSgm2QfhU2CFWS8nAwfKBPB8xJo+rpquXKl6vMSNbBBIrx81GA8rvi3BHxLqGyg7vf/0DP7h1gnYLkGuDjDEvDG+XMGESQlv2ZcR4MqSlXx4XYS0hJxdrJIwBed3uNWyVNcPHK8gMiS+x7tsV7aACkrtb7ND1d+coQocHg01cFBNe8fo0JbVC3mKuHz2XbLJC59pdjZ4MsQ3jZmKCoz1hp3ytDuoBdmRQ9UUgUPyr+Qn+FKnVXuKCQz6BN4eIIPomX9/2ZaO7kuSaftgWU+/yCBgzJp1q+QxmLsI1AiR2VC8JcXdSi48tG7vmvQMhwq6wrfbXV3Qu3gAzwardznf3ywrfYauy4C3ohQ1v6/GENoOwkzV7qPMiCyBHkdES2ZXnWdCq43kGx6NVAxHLEbQp4X4ziHRWhv4QkvGp3YDV85gahJTtQbOoiS9FTz4NU6gAij4bKZR5FLOaJbOc30tbrK+qIh/s9c8rey9UJGLv2l0hqLEc1TpurrdDQ1b7S7Ka07ExIIiiuR/f16xQStPEADkwq5qOxHF5AhX+09zMnbA0Dfxy9WnZE83wfFOvofSk5Opif9fblCBVBB5F3YMEezQ80Aa8wHZJe5Zm9akTWP9OIRJL1Kk50rv+IpJE9Vg0THSTRXQyG6kdr2IFrc/M8tehayNUhWFH73l+nj/2P1MkwiK+GjylUC8CAT02y+5Jvaqt/iuvu2nxqo1mxM6/vsClYaD+MoIVmJ3jdu5pJqHX6PXWGEvKs3mVAVv1/o94NaAwNJWA0AkWXbxacXxVp+6Imgog9CWbfv0Bb+fUdqTuVn3b7HatH1flSkLVwQvCnjxjZs/HYcANPMsChPdjJ84IK/OTBe0yamXP6Dku6bq8Y1AuoSFoW/s4v75RgzcgGK6QXXWJfzqVByRcVJnMqsJSj+X/x2LvM1wfiMIm4/9P9u3JabqmCx03JHzDdkP7AM/GqF7G9jS2qcUHbYsLHTJ0G3zAHQAbUbsDfABdQeRpmeuocmCBaImZ+cNcW0qyTmP7veWhFHzKAMmXXc2KncnOGj9IPsQSBqd4M= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PAXPR04MB8459.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(52116014)(366016)(376014)(7416014)(1800799024)(38350700014)(921020);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Ca04lx4YD88WuZwlrpevsQwT6yReJsEKYunnhNs2fMcc8AR4guEPgUYZ/r2cnlxBNK3W8L/bsjSvQ1nvXkZ6SOjcBuvDFY7eblH8f1j8UMVEa3FhhcJW2GXc6aGqIbJUIUBmxsK3vKV1k1wJ9SMvqXt9rfHrRJENO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pwmYnwKNScWDfOl7r3tqDiCABKGVZDnFzI1gGl3FbPbDM6Nf5thGqorXUKrQNc6cC7XZ/KsyK+KpWxcdih+ZYnJyMuGNEDL4hPeMH7fVKjwT0I30GL8nWjn28mlK5nS98JHDSndUkRHaKvtcEemThzxh20MO/AUyG+0HnKiR1OqSsFjNgeNdCPw3p128LgszVqdGyHA42AaIxOyjLemaFF1WO4FmbDk6gh7lzw+qIeW3yz8BANMyyXyfapJMnWK2A5g9VFNB38rMxIw1bmmaYIE4db+Uznvx+zkAHvlJdi73hqHX+QKxnowlwPhu9ak878QHgsQU6JPnCPGX8k4k0opxVMDi35r1RzmMpo X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 22a1eae8-712e-4f57-e0f5-08dcc7d98f34 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB8459.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Aug 2024 03:20:40.7805 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: SPfO83ElTBB+KAU4IMHCNt/BJyF53xQ0fYR74brr3xkl+mKo4TJGtWbbcYKdMgVn99gN+ITGMCUAvyOEstPTAQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAXPR04MB8223 X-Rspam-User: X-Rspamd-Queue-Id: C879620015 X-Rspamd-Server: rspam01 X-Stat-Signature: qohpq6hpz85ciau9b8pooros7xdo33rd X-HE-Tag: 1724901646-515661 X-HE-Meta: U2FsdGVkX1/4Do5TEddzQMHd7FalqX5RJNa2CwjcfzZRkmse7Hb7I/UNKzx4F8FI2t88zg85JCSg5x1Ofk2pgQoqrA2qGkyoQ/z1iCN/NCI71WU6iacOMtIiHpDlLt3OQ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FHnx9D7P0oYclW43HsxTvES+PY3XANzG38I7fGrS3hM/MMDGq/yLIRcTwSYXb8nq6Jvq6CRW/qI3ALXCuIe+RrgYywnyxEBgaUGdhf/vgpTSIspURNOsHJOJ/N/c0WRtIVAH3JYOSYntv4/PI+AFzlc3mcPhfnjNtBBHgG4Jbw0x5+q+NCVf1StXyovVzT2nVCWM/fj+qKkv0ioUlnZaBCqMx0mDrUHKAZxgWNUgIY1sgzRDBIsRDwc6l8ZG2H0yHrTsDx0cCuDfuJxWOIO3V3HxBi8N8B2su30IhJ7IM5OB9neWN2/dtTcLuYQTp+qZRGF88mWMtaIQ+J8CBL2MZ1hik5e5 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: From: Peng Fan Since commit 946fa0dbf2d8 ("mm/slub: extend redzone check to extra allocated kmalloc space than requested"), setting orig_size treats the wasted space (object_size - orig_size) as a redzone. However with init_on_free=1 we clear the full object->size, including the redzone. Additionally we clear the object metadata, including the stored orig_size, making it zero, which makes check_object() treat the whole object as a redzone. These issues lead to the following BUG report with "slub_debug=FUZ init_on_free=1": [ 0.000000] ============================================================================= [ 0.000000] BUG kmalloc-8 (Not tainted): kmalloc Redzone overwritten [ 0.000000] ----------------------------------------------------------------------------- [ 0.000000] [ 0.000000] 0xffff000010032858-0xffff00001003285f @offset=2136. First byte 0x0 instead of 0xcc [ 0.000000] FIX kmalloc-8: Restoring kmalloc Redzone 0xffff000010032858-0xffff00001003285f=0xcc [ 0.000000] Slab 0xfffffdffc0400c80 objects=36 used=23 fp=0xffff000010032a18 flags=0x3fffe0000000200(workingset|node=0|zone=0|lastcpupid=0x1ffff) [ 0.000000] Object 0xffff000010032858 @offset=2136 fp=0xffff0000100328c8 [ 0.000000] [ 0.000000] Redzone ffff000010032850: cc cc cc cc cc cc cc cc ........ [ 0.000000] Object ffff000010032858: cc cc cc cc cc cc cc cc ........ [ 0.000000] Redzone ffff000010032860: cc cc cc cc cc cc cc cc ........ [ 0.000000] Padding ffff0000100328b4: 00 00 00 00 00 00 00 00 00 00 00 00 ............ [ 0.000000] CPU: 0 UID: 0 PID: 0 Comm: swapper/0 Not tainted 6.11.0-rc3-next-20240814-00004-g61844c55c3f4 #144 [ 0.000000] Hardware name: NXP i.MX95 19X19 board (DT) [ 0.000000] Call trace: [ 0.000000] dump_backtrace+0x90/0xe8 [ 0.000000] show_stack+0x18/0x24 [ 0.000000] dump_stack_lvl+0x74/0x8c [ 0.000000] dump_stack+0x18/0x24 [ 0.000000] print_trailer+0x150/0x218 [ 0.000000] check_object+0xe4/0x454 [ 0.000000] free_to_partial_list+0x2f8/0x5ec To address the issue, use orig_size to clear the used area. And restore the value of orig_size after clear the remaining area. When CONFIG_SLUB_DEBUG not defined, (get_orig_size()' directly returns s->object_size. So when using memset to init the area, the size can simply be orig_size, as orig_size returns object_size when CONFIG_SLUB_DEBUG not enabled. And orig_size can never be bigger than object_size. Fixes: 946fa0dbf2d8 ("mm/slub: extend redzone check to extra allocated kmalloc space than requested") Reviewed-by: Feng Tang Signed-off-by: Peng Fan Acked-by: David Rientjes --- V1->V2: Update commit log (Per Vlastimil) Move get_orig_size/set_orig_size out of CONFIG_SLUB_DEBUG (Per Vlastimil and Feng) Add R-b from Feng RFC->V1: Update commit log (Per Hyeonggon) Use orig_size to do memset(Per Hyeonggon) Add get_orig_size and set_orig_size when CONFIG_SLUB_DEBUG not enabled(kernel test robot) https://lore.kernel.org/all/20240819064115.385086-1-peng.fan@oss.nxp.com/ mm/slub.c | 100 +++++++++++++++++++++++++++++------------------------- 1 file changed, 53 insertions(+), 47 deletions(-) diff --git a/mm/slub.c b/mm/slub.c index 668ea1e998a4..d63f39a5a1f8 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -756,6 +756,50 @@ static inline bool slab_update_freelist(struct kmem_cache *s, struct slab *slab, return false; } +/* + * kmalloc caches has fixed sizes (mostly power of 2), and kmalloc() API + * family will round up the real request size to these fixed ones, so + * there could be an extra area than what is requested. Save the original + * request size in the meta data area, for better debug and sanity check. + */ +static inline void set_orig_size(struct kmem_cache *s, + void *object, unsigned int orig_size) +{ + void *p = kasan_reset_tag(object); + unsigned int kasan_meta_size; + + if (!slub_debug_orig_size(s)) + return; + + /* + * KASAN can save its free meta data inside of the object at offset 0. + * If this meta data size is larger than 'orig_size', it will overlap + * the data redzone in [orig_size+1, object_size]. Thus, we adjust + * 'orig_size' to be as at least as big as KASAN's meta data. + */ + kasan_meta_size = kasan_metadata_size(s, true); + if (kasan_meta_size > orig_size) + orig_size = kasan_meta_size; + + p += get_info_end(s); + p += sizeof(struct track) * 2; + + *(unsigned int *)p = orig_size; +} + +static inline unsigned int get_orig_size(struct kmem_cache *s, void *object) +{ + void *p = kasan_reset_tag(object); + + if (!slub_debug_orig_size(s)) + return s->object_size; + + p += get_info_end(s); + p += sizeof(struct track) * 2; + + return *(unsigned int *)p; +} + #ifdef CONFIG_SLUB_DEBUG static unsigned long object_map[BITS_TO_LONGS(MAX_OBJS_PER_PAGE)]; static DEFINE_SPINLOCK(object_map_lock); @@ -985,50 +1029,6 @@ static void print_slab_info(const struct slab *slab) &slab->__page_flags); } -/* - * kmalloc caches has fixed sizes (mostly power of 2), and kmalloc() API - * family will round up the real request size to these fixed ones, so - * there could be an extra area than what is requested. Save the original - * request size in the meta data area, for better debug and sanity check. - */ -static inline void set_orig_size(struct kmem_cache *s, - void *object, unsigned int orig_size) -{ - void *p = kasan_reset_tag(object); - unsigned int kasan_meta_size; - - if (!slub_debug_orig_size(s)) - return; - - /* - * KASAN can save its free meta data inside of the object at offset 0. - * If this meta data size is larger than 'orig_size', it will overlap - * the data redzone in [orig_size+1, object_size]. Thus, we adjust - * 'orig_size' to be as at least as big as KASAN's meta data. - */ - kasan_meta_size = kasan_metadata_size(s, true); - if (kasan_meta_size > orig_size) - orig_size = kasan_meta_size; - - p += get_info_end(s); - p += sizeof(struct track) * 2; - - *(unsigned int *)p = orig_size; -} - -static inline unsigned int get_orig_size(struct kmem_cache *s, void *object) -{ - void *p = kasan_reset_tag(object); - - if (!slub_debug_orig_size(s)) - return s->object_size; - - p += get_info_end(s); - p += sizeof(struct track) * 2; - - return *(unsigned int *)p; -} - void skip_orig_size_check(struct kmem_cache *s, const void *object) { set_orig_size(s, (void *)object, s->object_size); @@ -1894,7 +1894,6 @@ static inline void inc_slabs_node(struct kmem_cache *s, int node, int objects) {} static inline void dec_slabs_node(struct kmem_cache *s, int node, int objects) {} - #ifndef CONFIG_SLUB_TINY static bool freelist_corrupted(struct kmem_cache *s, struct slab *slab, void **freelist, void *nextfree) @@ -2286,14 +2285,21 @@ bool slab_free_hook(struct kmem_cache *s, void *x, bool init, */ if (unlikely(init)) { int rsize; - unsigned int inuse; + unsigned int inuse, orig_size; inuse = get_info_end(s); + orig_size = get_orig_size(s, x); if (!kasan_has_integrated_init()) - memset(kasan_reset_tag(x), 0, s->object_size); + memset(kasan_reset_tag(x), 0, orig_size); rsize = (s->flags & SLAB_RED_ZONE) ? s->red_left_pad : 0; memset((char *)kasan_reset_tag(x) + inuse, 0, s->size - inuse - rsize); + /* + * Restore orig_size, otherwize kmalloc redzone overwritten + * would be reported + */ + set_orig_size(s, x, orig_size); + } /* KASAN might put x into memory quarantine, delaying its reuse. */ return !kasan_slab_free(s, x, init, still_accessible);