Received: by 2002:ab2:6d45:0:b0:1fb:d597:ff75 with SMTP id d5csp119734lqr; Wed, 5 Jun 2024 00:16:41 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVwTL0xU+hBgfKFQNxJRZyy0iNPYAfSLhKtfkC56Ee3rPbanOmIVJUuGYYJD7TkR9WaJS37ByDtx55HMu2OezDLVgge3ePad5aBXHHQkw== X-Google-Smtp-Source: AGHT+IHcx+PL5zFdrjBXI7zao8hJwBN3VjnhlPszppah/BrycdTUv9fsJ6TbjYf8d7IxbHs11dJx X-Received: by 2002:a05:620a:b19:b0:792:de8a:7b7b with SMTP id af79cd13be357-79523d4710amr175927085a.26.1717571800735; Wed, 05 Jun 2024 00:16:40 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717571800; cv=pass; d=google.com; s=arc-20160816; b=cWSVO0KNEgNxCnIr4gbRK/GihqvjG4/+Xy4xJ8rgkxvf/7I4Am3ePeH/wfl3R48iOE GGr9M/bdg4bKz7OcFg/OLv1E7Ry4zegwLfHrgBV3gzAh2xcrJ1SgAo6xOv0EbTWBVOuI s5P2YXMxHPAlO4zFdJeIL2dEulQbVFTgw3gKIwJNDSgU5+PkZZrvjghctgWtHI6YFwTu H8iBVIixT4jHlLb0SM3TFE3fCS4kT0dqfggXzkaiB5tYmmJqjjVHU9dfue1dGhZa3yFN u+8BScI9K2kcJZaZL40Y7I5L4L76CPGlSyCAb3s4aoOFabGYKm11AJBASV1FdESyqag+ CS5g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=lPq/L6362zO9SgmJGiWknKOMwYQmxGr9076aQ1KsSus=; fh=aAcHoaoscyWZDK/c0LWwA/7SqDW92Zbn0KNW0yzusYI=; b=eCSPNtk2cr9RJui8VmMjOqCMHlyLPzbMSEImYgilE48PGQRhev5IFmVXwOtAYHQsy1 UcjtB55dZ7jk7ZNzLaOvM4dZb9BhZLA/umoicW338/Tb5ki2F8f0A74CHI2ROEFEYKsz 2c3/GzTSnsYOk1BkxttnPehnAmJg+QQ2+aDQWXv5+DM3U53We/zbV0DkiMHFmyXG0SjH uWMky0dKhrlHkmGh0iNyKVBUHGF6CLJ3ehY+RAG1wNTXopat+6HgNCT/Ag4I99mJYFxr sqFky2h+pdAFMTMkxn+UPVmYr2IBLncMRmhQxx01I+yFKioKV8XFtyd49EbG4ar7V28O FDvA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b="fD/gfTPv"; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-201856-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-201856-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id af79cd13be357-794f32bd648si1397668885a.730.2024.06.05.00.16.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jun 2024 00:16:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-201856-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b="fD/gfTPv"; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-201856-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-201856-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 73FDB1C24AF8 for ; Wed, 5 Jun 2024 07:16:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 757003DAC19; Wed, 5 Jun 2024 07:15:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="fD/gfTPv" Received: from out-170.mta1.migadu.com (out-170.mta1.migadu.com [95.215.58.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0AF5321C190 for ; Wed, 5 Jun 2024 07:15:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.170 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717571722; cv=none; b=V9zDfgK1s14Z1ZjdpUQACLSvUMGSdzeVbJzMVEE3vuKu2bIOH8OM5/JtGivhc9U8I4DlblPR4OnmcTtlZdNLw7Qf0zAUH1W5iPVjLWxJzw1ZcTzmf7fJfUyaHHigoLuOY1WR8N/uyVgSs+CQfo3/9g6OARVdWatugyUvQlvUVdA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717571722; c=relaxed/simple; bh=MNPWcriUGn3mWR3ZY0iN2pkP7N14YS8clJZTFwJ05Yw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=mJBeLtzsfU/TSCa4IqTGkVrQhbsdHQ8L+fmvWx1/mOsJtrvinO8wDREr7Hnku15cKMYgOsIrtVYu9ZHCh38Q0QwIphUhYjL3qYGtUbkAMXwPLeCJvRfHKlGEPcqZrn6EbpiLYekkEkDBCPwJvowbcsnVtz2wtqlMAbc5sHLJXSw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=fD/gfTPv; arc=none smtp.client-ip=95.215.58.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=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 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit 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 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 --- 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 -- 2.45.1