Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp5147131rwb; Wed, 21 Sep 2022 03:59:21 -0700 (PDT) X-Google-Smtp-Source: AMsMyM456xUUanBySO6xKdA2vUXHweTOdDSKg7N5Am9u7dWpYTx0Hp5Z1kOS6ltJwn2+W4TSxYx5 X-Received: by 2002:a17:906:7950:b0:782:e99:a3aa with SMTP id l16-20020a170906795000b007820e99a3aamr2133269ejo.186.1663757961367; Wed, 21 Sep 2022 03:59:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663757961; cv=none; d=google.com; s=arc-20160816; b=kFaxWh+BP2GG/ATufN5n6Lj4P1Qm3DnlxQPncDsbiajLrNOTK292hu2+XiNI6By6GW xWthDmSAr7666XeD+SxEqHqUiRlW+wfo7WQk2HluEbfp7V2mRVHh+NfzUhnoyH3+VlK6 85LShWAXCGrIrsagMLaGM7wI9KMrbmx7INdOmowkNIumYEiv13FSjUF8Cx6YE7R8HEib 4v3IHmC8V4HDDCiJkvdr42QQsQNnqVJtGZIsTCRnsynxSjYdBxrMg88mZJMetrETUadX jFkF/O1O2Ou9hfaheNvgUQoT0nvl2zhc1xHoAydEUTwUcOhitjTqSHKY/8uqktHx+Cc7 8j4w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=qPdyqdgroowolFN4GRnR79RabeBW8kqO40WJAOflFYI=; b=qrd8NVz1WgaqsRMmakOVhbaSoeedyskKRN8X9Hd9sxuMdIDlrWiKINZaepqGWwgMiX HsbuX8tocTu7EBHioxMtaLbXraUvh3MbTgLFLKPAgxNg1CCIfA//LOB0u3Z8NXTx/WKE DQY4nVxZAdgzG4S+6GwwtpLbHW+UKermYaZ4fHZ94qiKJ+l40Dr6mkCQpcyeGmCfEH6y 1bd+77j2dIZt2x0ECVzL6kC7603Imrd5rycl3E7Eu6nPrtKyK3b7TCC9eTYpL/RncgZM jaJh+tvBhUA1MEFFo8kptug4uxziZWI706EyIYKGO/RPOGguA1O/PyNL6DFU/B+SRAz+ 1/BA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=O81iPm+K; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e13-20020a170906844d00b0077b2ad71224si1912414ejy.136.2022.09.21.03.58.54; Wed, 21 Sep 2022 03:59:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=O81iPm+K; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229669AbiIUKrB (ORCPT + 99 others); Wed, 21 Sep 2022 06:47:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57492 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229789AbiIUKq5 (ORCPT ); Wed, 21 Sep 2022 06:46:57 -0400 Received: from mail-pf1-x429.google.com (mail-pf1-x429.google.com [IPv6:2607:f8b0:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 987A98B2F8 for ; Wed, 21 Sep 2022 03:46:47 -0700 (PDT) Received: by mail-pf1-x429.google.com with SMTP id y136so5531071pfb.3 for ; Wed, 21 Sep 2022 03:46:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date; bh=qPdyqdgroowolFN4GRnR79RabeBW8kqO40WJAOflFYI=; b=O81iPm+KUz5n9Y8uAC2zjGZla7XVQmkzEOm+8edHWalNrZUz2eZdWyF7bBpZmuJZli 3v4Wus4yyKi5JVSuqwCBkmdFzb0dhMvdJDCdmmeup8WVa7jHBcCyNwgZPFPIp93UVhse Tg4fSHP5CX/FREA0YFM29slTnoaqB8ljpXeAl6J+GhgjPEMoV1RSIs7Y4A4H5qvj3kXL OgnxvoaOUOBOZZmf+483h5p6A1s8JMqm3q0rVId2I9T7aBEAKyAGZ2BsUo+sToN97gSB +QHR3PXnHlxrGIlWA8ZrP00n9e6WsmvfqPBROvlilmHpqbdXJR6rh6BFc5cDtqzfqKkP 77Rw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date; bh=qPdyqdgroowolFN4GRnR79RabeBW8kqO40WJAOflFYI=; b=pBsMJeKN48v8oiNHoP4ilUyZq2lJvraBh4OkRwbpTj8NqUg3VJvdMch/D7lW320EF4 POAQt4f7Tb7fnvTDyLvlPzPvnfMJ2s2/JpAEJ53B9kjZcmH8zrbtZ32B1BjX/t9xwY7P zHcOh17bqdoEkGH7bSB4fDz+EtFv0cDBPKCv7/Z6esNO7Y+4GVcWNlCOXTKRZx+FnV3B zSI+KAcc8s6AlJU27erk9DOUf2GGxkZ/6/A6n7xF0mmBD+imX2P6pNreQbgkHmdW8Ace Sk9p48maUEGcdBVgZMwsUfqnS8GrWhHNHBlH4/OItcnogsOp8kIQLmFEuIBElECzxsMj GJ7w== X-Gm-Message-State: ACrzQf1lKSQ8I7nQ3KTolE119aTOorqr5qOfAVQ1c4NBgYBh55RRhCVV EOgaPEsHZa40+KE2eHSHumQ= X-Received: by 2002:a65:6544:0:b0:439:b319:2422 with SMTP id a4-20020a656544000000b00439b3192422mr24100903pgw.114.1663757206906; Wed, 21 Sep 2022 03:46:46 -0700 (PDT) Received: from hyeyoo ([114.29.91.56]) by smtp.gmail.com with ESMTPSA id b15-20020a170902d50f00b00174c235e1fdsm1677504plg.199.2022.09.21.03.46.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Sep 2022 03:46:45 -0700 (PDT) Date: Wed, 21 Sep 2022 19:46:39 +0900 From: Hyeonggon Yoo <42.hyeyoo@gmail.com> To: Chao Yu Cc: Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , Vlastimil Babka , Roman Gushchin , Hugh Dickins , Chao Yu , Christophe JAILLET , Christoph Lameter , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] mm/slub: clean up create_unique_id() Message-ID: References: <20220918092146.4060783-1-chao@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220918092146.4060783-1-chao@kernel.org> X-Spam-Status: No, score=-0.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HK_RANDOM_ENVFROM, HK_RANDOM_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Sep 18, 2022 at 05:21:46PM +0800, Chao Yu wrote: > From: Chao Yu > > As Christophe JAILLET suggested: > > In create_unique_id(), > > "looks that ID_STR_LENGTH could even be reduced to 32 or 16. > > The 2nd BUG_ON at the end of the function could certainly be just > removed as well or remplaced by a: > if (p > name + ID_STR_LENGTH - 1) { > kfree(name); > return -E; > } > " > > According to above suggestion, let's do below cleanups: > 1. reduce ID_STR_LENGTH to 32, as the buffer size should be enough; > 2. remove BUG_ON() and return error if check condition is true. > > Link: https://lore.kernel.org/linux-mm/2025305d-16db-abdf-6cd3-1fb93371c2b4@wanadoo.fr/ > Suggested-by: Christophe JAILLET > Fixes: 81819f0fc828 ("SLUB core") > Signed-off-by: Chao Yu > --- > mm/slub.c | 7 +++++-- > 1 file changed, 5 insertions(+), 2 deletions(-) > > diff --git a/mm/slub.c b/mm/slub.c > index 5ba6db62a5ab..a045c1ca8772 100644 > --- a/mm/slub.c > +++ b/mm/slub.c > @@ -5883,7 +5883,7 @@ static inline struct kset *cache_kset(struct kmem_cache *s) > return slab_kset; > } > > -#define ID_STR_LENGTH 64 > +#define ID_STR_LENGTH 32 > > /* Create a unique string id for a slab cache: > * > @@ -5919,7 +5919,10 @@ static char *create_unique_id(struct kmem_cache *s) > *p++ = '-'; > p += sprintf(p, "%07u", s->size); > > - BUG_ON(p > name + ID_STR_LENGTH - 1); > + if (p > name + ID_STR_LENGTH - 1) { > + kfree(name); > + return ERR_PTR(-EINVAL); > + } > return name; IIUC 16 bytes will be still safe ;) Anyway, for either size: Looks good to me, Reviewed-by: Hyeonggon Yoo <42.hyeyoo@gmail.com> Thanks! > } > > -- > 2.25.1 > -- Thanks, Hyeonggon