From patchwork Fri Aug 23 06:24:15 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: 13774621 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 6D539C52D7C for ; Fri, 23 Aug 2024 06:15:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C5F868007F; Fri, 23 Aug 2024 02:15:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C0F248007E; Fri, 23 Aug 2024 02:15:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A3A8B8007F; Fri, 23 Aug 2024 02:15:43 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 81E4C8007E for ; Fri, 23 Aug 2024 02:15:43 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id E83441413E0 for ; Fri, 23 Aug 2024 06:15:42 +0000 (UTC) X-FDA: 82482498924.30.451556B Received: from EUR03-AM7-obe.outbound.protection.outlook.com (mail-am7eur03on2084.outbound.protection.outlook.com [40.107.105.84]) by imf05.hostedemail.com (Postfix) with ESMTP id F36B4100015 for ; Fri, 23 Aug 2024 06:15:38 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=NXP1.onmicrosoft.com header.s=selector1-NXP1-onmicrosoft-com header.b=uQTSByCU; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf05.hostedemail.com: domain of peng.fan@oss.nxp.com designates 40.107.105.84 as permitted sender) smtp.mailfrom=peng.fan@oss.nxp.com; dmarc=pass (policy=none) header.from=nxp.com ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724393657; 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=GwPworFSrTxprqkjrTZuERbwpCCyRNtbk54DCKDLpcs=; b=5is966KmteT8dJUK1z0H9ndnRBABQYIEqtm28hs+avHt7KEE0ICZy3iC+UheQiqg1iAULg 3Tzn26qF/kVAATcWkLDi9qX520WtgqhUwiOTIyGXRTq6rrxTb/TIaLdnH8MQWat3nr8WwS 3kfK5PdRUjlmgEt4uxexCqpYYTRAoKo= ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1724393657; a=rsa-sha256; cv=pass; b=h5AqiBjVSKOL2s/5Ec5opY+5NQtdhoI1iMwCqttF9JkrX3MjjRwW1LvdisNp+ynB48n+kD 4iuPbIGoJx/W79Zca3tF9qmVYctNTjys7UlTTLK0YukCk+a6WNE7Swb+kxSsZzKTEF+zK/ tILHWE00kon8t5HMvmf+nPEa3J/i76I= ARC-Authentication-Results: i=2; imf05.hostedemail.com; dkim=pass header.d=NXP1.onmicrosoft.com header.s=selector1-NXP1-onmicrosoft-com header.b=uQTSByCU; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf05.hostedemail.com: domain of peng.fan@oss.nxp.com designates 40.107.105.84 as permitted sender) smtp.mailfrom=peng.fan@oss.nxp.com; dmarc=pass (policy=none) header.from=nxp.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=vCTDQOlGIwt8ISZf1y12M2CPTtMYeHUflxFcXkgFEYlSHMyxczwHH76VOjC5w1CfoFRGP1uUQWQhm08IqGQTccoBovVRI+9xX/tEs50JZoUPpb1QTfirVxK+ajFVdHy0fN/PWMaYGNlxI+CEqg66cdBlQum7Jw31TALRuSeSecK7fVt39OZRQviaEdSihS8J0Y/RpW8io4BncLPTF0u9y0K8kH/N9mPTLUvDUXkftMvp+0NqQHRrn4xZgNjcT9kEfln2R/79PklBtM/8bj9CTW9VNSslgV9ylMCorIFytbifDTVfOqkb9cUQgdgeMxlz3tWaJ24ldsiw151LynEWOQ== 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=GwPworFSrTxprqkjrTZuERbwpCCyRNtbk54DCKDLpcs=; b=kNaEJi2y9cvTimW7/HkFadTMltS0f7oljooII2Sa0f62r+/LXbfdBl7ey9kbzrtog/MvP7MpMS5CPqkFz+KZTbMFb5g0Pd/f4At1sHtYh9MdlC6+ugW6PI+RMcXH4ZXFWxx+0XFzlPLgsayt0AFp5MVn2tnmmDDqEXwSLQu9Adp3YjPhJP7hbgdpdwtYSDvWVsxTVNX95m2TzKMan5YQtQ+N2RAwCPPVqT54kqgOMj1gTuTOOVFGqDQo0db3t2iDi+dhXAF36hfl3mWWuWnjIGyI7Bd030bYxuWpsBlwAoupc4uBFI4P4NBPb011mFvDeMiWwOQzr1WMsvKV+51wnQ== 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=GwPworFSrTxprqkjrTZuERbwpCCyRNtbk54DCKDLpcs=; b=uQTSByCU264MQPA6sMNM8A+tJ/eNc2NssTAqKTfKBHFn27i1/ZLjEmLyujJ4vkakoZG8b0mghVTk0JVk0GAcYkMx1VK/FH6OvgDY4zjdGlWEEYycJWHWaUHGKpHuacxQrtUKr5pSguLwQ51cqOX53VLUtGEBqusifs3W6NsFEDhfueql1CPrveiLUTJdj5Y2I/rdIXqDoe2T8xq57BsGkD5Xxo88J9srJ6FU1GbC/Bz/vwrrJhkYu8o0eg/4RAeWsoCwzNrfrQck9KFhRXnV9GV4ecv8Zx1Kjp59x7LRKlao1SyEALA0Lo4UoFsFEHdksqDEz17BuL9NuK+0okZYMg== Received: from PAXPR04MB8459.eurprd04.prod.outlook.com (2603:10a6:102:1da::15) by GV1PR04MB9053.eurprd04.prod.outlook.com (2603:10a6:150:1c::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7875.20; Fri, 23 Aug 2024 06:15:35 +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.014; Fri, 23 Aug 2024 06:15:35 +0000 From: "Peng Fan (OSS)" To: nicolas.bouchinet@clip-os.org, chengming.zhou@linux.dev, vbabka@suse.cz, Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , 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 V1] mm, slub: avoid zeroing kmalloc redzone Date: Fri, 23 Aug 2024 14:24:15 +0800 Message-Id: <20240823062415.3632189-1-peng.fan@oss.nxp.com> X-Mailer: git-send-email 2.37.1 X-ClientProxiedBy: SGAP274CA0004.SGPP274.PROD.OUTLOOK.COM (2603:1096:4:b6::16) 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_|GV1PR04MB9053:EE_ X-MS-Office365-Filtering-Correlation-Id: 71ae3e7d-5d85-46f6-d089-08dcc33affca 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|1800799024|7416014|52116014|376014|366016|921020|38350700014; X-Microsoft-Antispam-Message-Info: vIV3YMpXJOSSZxSmmF6FlpakCOmSG3SZEM5xeBapIxUzU7+IdjiseTRNu5ymqhio026Y7tsZliYveRaF+YSHtvbxdxGVO+frlZmhxNfibtBzN9OCe8tCxqhekoiHAXtPiPPSzR36YH2tK2QqcpQUYZKSqAZVxy0sSE7xfw3JDBwc4FlBL9+95Gs4REJr2nzikRVmyZhtWy3KiZFjttlIIA5GlZ5K26KZDyLvTdCSaUrxpE0cOMeVOubkfyByeEkMiFZux9CqFtZ7PQzeTl3w87qcsI8xjt57Iv31TlxbWleyK4cIvym2H0R85kbgXuDKc8raKkP7RpQb8gHxqm61eccAgGC6r0EV9qBwb+Dlh/O8spe8Itf2TF6Q+7JWm89IkE0yOjFAMuYGKKyJstLu49eUqhFdjnnTH8n162s3B+AEzyS1TLs6OYzY1uS4ZXd7YX0nH/UJA6gKbnbwTkSChsh8sIVPEV0RltYMfjqRej+hprW/MU3QX9pn0g0/8YfyXI5r/nsC5oYIvq8VrGKiRFwHT7f7pBcXxoY4yVIM4qBsFAlDNrgcHn9PeWpect1vMhyoH+ntk6R9gBmoh+K5UMgzvyk6vEa2zqXT/0/dREX6ezqurfs4DGiwXXZU9zniZWwgrQiQIM7vMxbgZco45vLxrjnAIUfXi0CSkhjn7iLTiD8V+UvXNzunBn1IbJ2n3irCIXoxN3x0AAgLtJekcjYA2HB7+2lN/ckC39Q/+iNoea2P4Jk4PkIy5U2/bWIEFiyt+c980lKTmXwfQ5+rhry9AVbSacwv13yRBQv3YrHz/ZoB45PzY4gRDVP0iCVfZ1c3rPxf3J0ZvErOBlFMyXaV2XEy6VQw7WX1luCS34YvCttjkSTM1NOpedIIHE9clSbmfGe5ZSpkEPHgPE69VfH4cVR2RNDjl+ta5cBZkvbtf04GGvLDo07PKPNhnb2qXrjpLPCQWR4ZhwxdISkNBDvLRL1rvy+FNvh7IIrUIMG1jVveTApie0OT77GJ5tY557eNlJlZFSQl78pGrCZ0bS+V0NM2XMzrzXs1QzTtwELo3sbQ627MCSKbboOa8U/C3VzUJp0uchGUgHonz17a9dJy/QuXerBgPS93Lqmp3S9rOqpCLAWsJNmPATmRRbkTwZrecqtmcC2lV4ygZgPWyQTL+GWWGY4KchntGK7g1awbdlZMkFWpN0xl/bC9Q8ybWwQ1kHzf/3Icejkw2ZRY7TvdD7zHYX73bKYexwQnN9lngOKH2OGUx/NAf/hSWoHsWqEUvBf4MqYVADg+g0gtituKG1Sw4Yo/hZdy/3g5ASEJ5OD/qlkgddhWSwiYFkeGatycpK3uDjbUWbd97qWlC7b1ibINJm9WqyfI/BGnFRpoeFIChGu8pL+LMaNO3Qwj6/EnGHO+xMh/3bclj6oSDDiLRzfSKDVKRBdeddt//XA= 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)(1800799024)(7416014)(52116014)(376014)(366016)(921020)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: V1kGHmor+wQyLlHQHcAjwg+5it9qoIjpd/nmBQDXpJOTImtjzhFJpCvQVnw/M3QXaBUGNBVajMhUmWfEPCe+eXttGXCM/+FphdBuYb5+gpX5f6a7zyRvIXuWTf9OqCqBBhZ6fb91Alv9u8aAHTe00DGoy7adl9Y+nNU/5temY0ULxazsiL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wY71n3RV4aEL0gZ1wiHrkh5xex4PZx7sDBQOx1D5NGw2OQbRsjZsSvdsXPLor+vA1zzr0ed6xmdBxQpZS6iJiiNNDrZ3Iayfk7qk/jALvP5Z9A1fydP6FPwESfTJhiYaKoXF6KiswkpHqBd0hhGS0AMT1MERpxFiNrqK2zlMGaiq5aEJck+8wPgDo40jk56PagalaB32Ct3rNcMPhsKTNkUfTInyvRi0qo8i/wUYe6zDbkn+l3D+H/sCyE6ZHM46pKUk3BEcojln1/CquI7VlXvIoLs3pslj37Qtm8CGk21gQgBArHUfKXwwcUgG0A06r27CY8urP0nWwKKa3ccyxxRPoTbQ84ayaFGDi3/B X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 71ae3e7d-5d85-46f6-d089-08dcc33affca X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB8459.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Aug 2024 06:15:34.9696 (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: 7RaDb2kIlN9HZoyOE7fqN1o099f5xsYUW4ZcbZx0G67uoLKTQ23kcUo1PnJg2hDl2hXD6YDB8GDBwVBk+98XXw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: GV1PR04MB9053 X-Stat-Signature: nmf7ddsssdyedmjgokxckjdthbxnh7wc X-Rspamd-Queue-Id: F36B4100015 X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1724393738-323175 X-HE-Meta: U2FsdGVkX1+8BCby6Yf5R7yXbRTd2Qti5zJtkeMfcfcbHdbpgCy9vQGmmKRZxGNP0yGqlDHWCwG2a7N7l8J6LbinLO9CjT4AmH/SHXDx9taj3zA3f0l/gPJ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Mj+CIW+Sa4ROBaOVB44z4eNJSJk2xtK+BaPV5gk8MjPouZ2gBPtN7l0jOgGQS4IckK+2G5ZqG742vQgFSbZk1oe26OrZPnftMHCkBRRL6wJpGndNqCd3JjmhXiQp/Jb/GB7zeVccVppVRhnNQsIbPy0A0WZpllJGPtQsnuBslBbfgLWnngqQHhhlm2IKd2QC+bUWXsSlIEOVpWSaFl+1mumsh9JNT4BJ9705qjeY3Su+Mw6zFuMZ3lvnfs5QYIE9SY+91SppDuTxS0tN583w8F+c9gnEeN6PyY3zgSrQ1pkIiZ30ANyohYJL6NP9TdGxBj+a69tsWByVdYgfk3Rn6tn/UU9Ll2loBlPCaGmeChjTExYK8wZ+ 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 With 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 redzones. But (in check_object()) when orig_size is set to zero, the entire object is perceived as a redzone. To a valid allocated kmalloc space, when init_on_free=1, the wasted space and the orig_size should not be cleared to 0, otherwise there will be kernel dump: [ 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") Signed-off-by: Peng Fan Reviewed-by: Feng Tang --- 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 | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/mm/slub.c b/mm/slub.c index 94f5a4143825..a5fbeb2835b1 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -1895,6 +1895,15 @@ static inline void inc_slabs_node(struct kmem_cache *s, int node, static inline void dec_slabs_node(struct kmem_cache *s, int node, int objects) {} +static inline unsigned int get_orig_size(struct kmem_cache *s, void *object) +{ + return s->object_size; +} + +static inline void set_orig_size(struct kmem_cache *s, void *object, + unsigned int orig_size) +{} + #ifndef CONFIG_SLUB_TINY static bool freelist_corrupted(struct kmem_cache *s, struct slab *slab, void **freelist, void *nextfree) @@ -2282,14 +2291,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);