From patchwork Fri Jun 7 08:40:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chengming Zhou X-Patchwork-Id: 13689485 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 ADAB9C27C53 for ; Fri, 7 Jun 2024 08:41:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1C85A6B0082; Fri, 7 Jun 2024 04:41:01 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 179C46B0085; Fri, 7 Jun 2024 04:41:01 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 01B3D6B00B3; Fri, 7 Jun 2024 04:41:00 -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 D74816B00B1 for ; Fri, 7 Jun 2024 04:41:00 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 653821411D8 for ; Fri, 7 Jun 2024 08:41:00 +0000 (UTC) X-FDA: 82203447480.06.4258A24 Received: from out-174.mta0.migadu.com (out-174.mta0.migadu.com [91.218.175.174]) by imf01.hostedemail.com (Postfix) with ESMTP id E88CF40017 for ; Fri, 7 Jun 2024 08:40:57 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=e9yKJrsJ; spf=pass (imf01.hostedemail.com: domain of chengming.zhou@linux.dev designates 91.218.175.174 as permitted sender) smtp.mailfrom=chengming.zhou@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1717749658; 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:in-reply-to:references:references:dkim-signature; bh=zl8yWyiipM81e8Qi1LyYy64GATjSdpFn6JGZvmprGhI=; b=iGFcr1DGWGDeq9ZOYQKk245c1dMEeZgItSaU1UGgqws1jPapu3Bo33f52JphimNhO5yN/X evep1n8/xOnGVw4mlc6uyXxrWhffJyudKd+IZz1eOdSbDtbFacJSGSFAbdAfgDUrJBt1hu hoOBQYR/G1LhflOP8JAgbLFaHIs+Pr0= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=e9yKJrsJ; spf=pass (imf01.hostedemail.com: domain of chengming.zhou@linux.dev designates 91.218.175.174 as permitted sender) smtp.mailfrom=chengming.zhou@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1717749658; a=rsa-sha256; cv=none; b=dUOYrnn6K791DF/S51zyW4LLlN5pYdAZJ751GcvSSKYuEeZJlSZP6nJZMJ8rfyfH7DsA+C Y0mkTHSeANUs6wjysWtmp3sWHGA6vZ8v28aenAqjXIxxDSQ2CXa9/wi7jk2em7tWoLHTMA IidG+g75EXmUb3vC+wZPtf0Umya9djA= X-Envelope-To: akpm@linux-foundation.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1717749656; h=from:from: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:in-reply-to:references:references; bh=zl8yWyiipM81e8Qi1LyYy64GATjSdpFn6JGZvmprGhI=; b=e9yKJrsJCyHtaE6gVXuVQZ6ME1Lqhp0vXYf9L7qHjqQAGh3lA2m35CXSJdRDlg51u2z+fz DZKQxelkJdemyDRYlVnekXq5f1oKkkhvCyqyoU8/3lhbDj6e3gmI9F7aSeBwYif1fA1uMC VB8TpBNhvx+5rjqXmLu5oO2tH5/6fBM= X-Envelope-To: cl@linux.com X-Envelope-To: linux-kernel@vger.kernel.org X-Envelope-To: penberg@kernel.org X-Envelope-To: vbabka@suse.cz X-Envelope-To: roman.gushchin@linux.dev X-Envelope-To: iamjoonsoo.kim@lge.com X-Envelope-To: 42.hyeyoo@gmail.com X-Envelope-To: rientjes@google.com X-Envelope-To: linux-mm@kvack.org X-Envelope-To: zhouchengming@bytedance.com X-Envelope-To: feng.tang@intel.com X-Envelope-To: chengming.zhou@linux.dev X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Chengming Zhou Date: Fri, 07 Jun 2024 16:40:13 +0800 Subject: [PATCH v3 2/3] slab: don't put freepointer outside of object if only orig_size MIME-Version: 1.0 Message-Id: <20240607-b4-slab-debug-v3-2-bb2a326c4ceb@linux.dev> References: <20240607-b4-slab-debug-v3-0-bb2a326c4ceb@linux.dev> In-Reply-To: <20240607-b4-slab-debug-v3-0-bb2a326c4ceb@linux.dev> To: Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , Vlastimil Babka , Roman Gushchin , Hyeonggon Yoo <42.hyeyoo@gmail.com>, Feng Tang Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, zhouchengming@bytedance.com, Chengming Zhou X-Developer-Signature: v=1; a=ed25519-sha256; t=1717749639; l=2058; i=chengming.zhou@linux.dev; s=20240508; h=from:subject:message-id; bh=bn0rvFBpWAZhns05Xqu0KeFYe1or4fDM7A08yx3Psto=; b=EuZ0xsakv2Ol3sPIh0H8VsgQnTrIw6dnox/41Kp96uAXgh1BW2zow6fYw1U6Rfy0z1KMEzF+T lLAWR3T1+rZBIqhuQg+F2qjIYANliGwimvM7/uSh7c6p94F5n11MfVY X-Developer-Key: i=chengming.zhou@linux.dev; a=ed25519; pk=kx40VUetZeR6MuiqrM7kPCcGakk1md0Az5qHwb6gBdU= X-Migadu-Flow: FLOW_OUT X-Rspam-User: X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: E88CF40017 X-Stat-Signature: 1xb8s9b49p3t6q9w44bfx1xygshfjk74 X-HE-Tag: 1717749657-499617 X-HE-Meta: U2FsdGVkX1/s0YBL0TY5p45uUltamRiIssvhQFdR4maNVkxUOwqkjsjKZGmGJIUgeNwo1CokoZQKQLGvdkV1p4mWnIi2BUqbE3TDvssOPoHf5JsaGJF7GtcqJM0nt37dSK9gQ+SqbvJwvLtOceAm1SR3RHJoVwGQOoBbJiBcOQcwNY4lKJAzjq2yOXpfVRS7NempTyYVsr4bpGXfRxIrTT8ATK2gY9FN5XVW1pUaw/1xJaT/jBdN1xpbzwDekxVPfK3xdByoOhD/lXdI7/yJD+MLbvsdYUsdbLbHU/YNIFg0cwRV96yhhOCC2HQ2HP4UGOEHd46I0A2ENy77JznZK7s0UO8p1H7ivrcIMBaducXGEQEQpCRDsoeuDwH/9UxTan8WDf8N0zGkOHVtodvW2oUYEOMKHOReZLKHFYl5ShynknWJdTYT6Kpqfk31m4V0S+hejHe4fXZql1KQI+P6bQte/TlG9fmptPKzv9tTSojQoT1/P0O96x6Txs1g0qM4yP+E5XAQ0xEUTrzD6kp8x0VtYcW27XYk5eIARNC0l2AeUni9exqef2ROz2my01aPC3m5a/eMPnsjrpHn7BhtjdcaDhL3Whbjpzno/YgGKf+w0PS1wKLRe560cGb7AP5+mv81wNZurgSpHxSGz0zf984MS4EXiU5kXBipbGpAhnn4rMtEpKbgYSHUddv8C1iAzB4KMAgkcAF+c8v+LUYRW52kd8nhlppU5M4Pb6jRM1jU/fOu6EV2Oj4s6XiutRbNDzq2Qp01uKaCH5zfnInD4kJw+15ec/I1ncBm3aSgQN5GcTDcnRowKTpVECBblUdzyP37qNQMiTtcRWdFWi7WNwq8mG2mxJQnsxIb4OKXT985Lvu6MlbbD1h+GVFo3ndAl8tC826dnZKKEpyI881dSyYJdnH/BCDJH0goun+EqKxMHLpzR3R/WGxY0lIurMa7NYD8HzKpNk7hhBsHue7 yx77yCCg cgEJp4vk0LqCAPqslq43eZWuQRXN2WbSyQL7f2pZiKybQjQH9pDkru2r52RW4IILACU+h9EAkvVxCqjs5iVwb6f7CdaEPss5ORyR0+4goiZVa/Sd/rFgKwbv2r8DDBs5NxPW0kAeChceBKudlmCWmVRGkJQdA2pGfpzr9eyxqFrL1KUhzuZXxa6aRLh433Zh48smttyA8MO7zo0xiT8d3H61yXh3wTpHAijI+Kxe6w4UkIMrxBICQ1FdCxoY6ODrS/qvoGspDMkP2gcc= 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: The commit 946fa0dbf2d8 ("mm/slub: extend redzone check to extra allocated kmalloc space than requested") will extend right redzone when allocating for orig_size < object_size. So we can't overlay the freepointer in the object space in this case. But the code looks like it forgot to check SLAB_RED_ZONE, since there won't be extended right redzone if only orig_size enabled. As we are here, make this complex conditional expressions a little prettier and add some comments about extending right redzone when slub_debug_orig_size() enabled. Reviewed-by: Feng Tang Reviewed-by: Vlastimil Babka Signed-off-by: Chengming Zhou --- mm/slub.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/mm/slub.c b/mm/slub.c index 45f89d4bb687..1551a0345650 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -5169,10 +5169,9 @@ static int calculate_sizes(struct kmem_cache *s) */ s->inuse = size; - if (slub_debug_orig_size(s) || - (flags & (SLAB_TYPESAFE_BY_RCU | SLAB_POISON)) || - ((flags & SLAB_RED_ZONE) && s->object_size < sizeof(void *)) || - s->ctor) { + if ((flags & (SLAB_TYPESAFE_BY_RCU | SLAB_POISON)) || s->ctor || + ((flags & SLAB_RED_ZONE) && + (s->object_size < sizeof(void *) || slub_debug_orig_size(s)))) { /* * Relocate free pointer after the object if it is not * permitted to overwrite the first word of the object on @@ -5180,7 +5179,9 @@ static int calculate_sizes(struct kmem_cache *s) * * This is the case if we do RCU, have a constructor or * destructor, are poisoning the objects, or are - * redzoning an object smaller than sizeof(void *). + * redzoning an object smaller than sizeof(void *) or are + * redzoning an object with slub_debug_orig_size() enabled, + * in which case the right redzone may be extended. * * The assumption that s->offset >= s->inuse means free * pointer is outside of the object is used in the