From patchwork Wed Jun 5 07:13:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chengming Zhou X-Patchwork-Id: 13686254 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 D982CC25B76 for ; Wed, 5 Jun 2024 07:15:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 694536B00A0; Wed, 5 Jun 2024 03:15:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 61F336B00A1; Wed, 5 Jun 2024 03:15:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4BDCA6B00A2; Wed, 5 Jun 2024 03:15:25 -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 2EA856B00A0 for ; Wed, 5 Jun 2024 03:15:25 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id E4910121197 for ; Wed, 5 Jun 2024 07:15:24 +0000 (UTC) X-FDA: 82195974168.13.3E8CD32 Received: from out-187.mta1.migadu.com (out-187.mta1.migadu.com [95.215.58.187]) by imf06.hostedemail.com (Postfix) with ESMTP id 82BD018000F for ; Wed, 5 Jun 2024 07:15:22 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b="fD/gfTPv"; spf=pass (imf06.hostedemail.com: domain of chengming.zhou@linux.dev designates 95.215.58.187 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=1717571722; 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=lPq/L6362zO9SgmJGiWknKOMwYQmxGr9076aQ1KsSus=; b=5U/V6D/lyDQyPMo7TmF77IZezpE8ND9rvQAE5K5kKBZrAImoP2x1yYm0Of+mCFktiTcyTL 4lPsCVcH0uUb3sjbU6060KeCRbgdFUsFwoJ+FGUIpT01KsM0ERl7Bn5jwxPG1+UDuzR94i NZrXlD9YFB3r/0PCLxwSL8C1A2dNO8w= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1717571722; a=rsa-sha256; cv=none; b=kgwJU6NsxY+3JAKJcS8imXbh2H5sRlFncu4J8Wh0aiXrM7WQ/XjXUpF/YTHbpNScwJ3quX t9bqlJ2vs2Jnba+iu6hBKU8B5VvplXPgUiV2D03ZBSbA2XhB9OqhDke1O65S807AJQGudY AJlmBNar/M79o0HnFQNYdYwL64Igmrw= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b="fD/gfTPv"; spf=pass (imf06.hostedemail.com: domain of chengming.zhou@linux.dev designates 95.215.58.187 as permitted sender) smtp.mailfrom=chengming.zhou@linux.dev; dmarc=pass (policy=none) header.from=linux.dev X-Envelope-To: linux-mm@kvack.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1717571718; 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=lPq/L6362zO9SgmJGiWknKOMwYQmxGr9076aQ1KsSus=; b=fD/gfTPvByekqdPzbiQjtEmLUAWXvovHbJ2ABuWxUjXekFVDifvCZ/KC/eGVUL2r73UWM2 BToI9v2Umvq9kMjCwaLswi1i1LdYrCqFycgwbmsbcjOS9iNqcMuQOjTEA00kCo56W4/xe0 TBDiewQOm6Ov6ROZbaCG024Ktj+JAVw= X-Envelope-To: penberg@kernel.org X-Envelope-To: roman.gushchin@linux.dev X-Envelope-To: feng.tang@intel.com X-Envelope-To: zhouchengming@bytedance.com X-Envelope-To: rientjes@google.com X-Envelope-To: linux-kernel@vger.kernel.org X-Envelope-To: akpm@linux-foundation.org X-Envelope-To: iamjoonsoo.kim@lge.com X-Envelope-To: vbabka@suse.cz X-Envelope-To: chengming.zhou@linux.dev X-Envelope-To: cl@linux.com X-Envelope-To: 42.hyeyoo@gmail.com X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Chengming Zhou Date: Wed, 05 Jun 2024 15:13:55 +0800 Subject: [PATCH v2 2/3] slab: don't put freepointer outside of object if only orig_size MIME-Version: 1.0 Message-Id: <20240605-b4-slab-debug-v2-2-c535b9cd361c@linux.dev> References: <20240605-b4-slab-debug-v2-0-c535b9cd361c@linux.dev> In-Reply-To: <20240605-b4-slab-debug-v2-0-c535b9cd361c@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=1717571706; l=2011; i=chengming.zhou@linux.dev; s=20240508; h=from:subject:message-id; bh=MNPWcriUGn3mWR3ZY0iN2pkP7N14YS8clJZTFwJ05Yw=; b=JB87AMt4zBO1QCf3L4tRwQF9EA4xx2dZLiX0nJN+Hd6lO7YDGPItst49BP1FaILquk6qB3pCC OPGGuLZwQkWCl0tN4tMtmzN0tCz5DSTScx5I6gNc8W5wzQjDtYx7ySh X-Developer-Key: i=chengming.zhou@linux.dev; a=ed25519; pk=kx40VUetZeR6MuiqrM7kPCcGakk1md0Az5qHwb6gBdU= X-Migadu-Flow: FLOW_OUT X-Rspam-User: X-Stat-Signature: tyuyg8jn9mgrzq8cfags11w3r7nqqhbe X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 82BD018000F X-HE-Tag: 1717571722-430102 X-HE-Meta: U2FsdGVkX19haMPM07F1jeI/yV6wwrvhJOGn496koIWwPm8Ftv0oWZciTYxJ491QldAdXJPwYjQhCOrqD18FnCyAd4vROwA0VB9mp2LPsbPQ0K4allMX/63moFXHou4Pa+nMcaWofPGIQiqrkRug0wCIuN8nf1IsAeWqK+As7cyts6bWoeqX9FAnHQNfPUms3+J/ltg3RAbTvC585hjOR8kxmA3uO5DSqifQQ2H0Goc4z7yFO6KQeIBxm/qipwhiw2EBE4rlXnWuyHe4Pj1myJzKs8hMuv7vkaOlk76+FveqRmHI0kLdvR5ZbFEb+4t4VSDzjMQyIP5xu/RwXo9AC5QnPOl118CV/mn1aW08I4+v0FzinZf8h4U5+TLm4EsHTrHzawAvO0+SULiXiZ3jBtaLfGYWVauVyqRItMzyY3iNtUbxfzaGPAG0U7fdGzw5Cgbp/jx+D5zBGPGTzL33odauqhLyrp655p9wJnb51dHu7R+ZTrSSZ2seQuRwhzHofThDZWw1Gnqp633zWPf6BzBF/3zXv5JLzPGQlQC8ahAXf8DMdhm25QUIxHfLDYvIirpTYBcILRx4/oL71tdkzxYVKsg+FwjJhlP8/Jl4alF6HGfG4Q3SoAbCEHa6kyDSaokhqZFDp5YGOAwuPzhe3P0d6RMguNWxRA+a4jsEvuG8coszHzMaZSs2aAcQbsZE6DxLKjPlKlUGnoWUYoyBJQbPCRkkGmmncoPzaYxhLYOIqS18Dd+BnPhy3JH6zUkLB5yQ3aVV2hNiB07tYvXhd7B7c37Dl30piwo0BnuZsmr+1u1U6h8As5yAoepy6CJ2OPw1Xvj1IoGYpNny7emhNJQ/c4ANBVaA/OQhElDRgzoOfTZ0FetjK84JxhJChedz2n0vOZcVk/a40623Wd0SNjsTFDOIvC0iUqUGzfvGQBFxVRLVBVLIDF7TRh/a+1+QlFIg/I5oMf1seVbBD8T R1ueJVNc g5QQO6+QKZV4JXHI1qex3uYJG937w/uTOfI/H8p257FzjBC5yReWVpuaPsVTpn5L9Ft1U5TS84VAT1vhxnnwJ7NHB3SLotHABodTJRcJLWiUqYYfSIoOhv1KplAle6YHDu4CpJqp/EEJHRLIqq4XyWVxU6Bha56xEZvoMiLmAMhNf03MeAeeDlakr7GizerFfa9qiIqq8Zismp3wucNYQ4SKvu1dY4dlNFZPm65tMVYGMtyvb6WzTYPVKTf6R4KtFa3wlAUHRdYeoXeY= 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 Signed-off-by: Chengming Zhou Reviewed-by: Vlastimil Babka --- mm/slub.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/mm/slub.c b/mm/slub.c index 7fbd5ce4320a..704c662227e6 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -5152,10 +5152,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 @@ -5163,7 +5162,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