Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp174084rwe; Tue, 23 Aug 2022 21:32:51 -0700 (PDT) X-Google-Smtp-Source: AA6agR7iyMwANbjtvLsoof5ELuY3QmJA51j2JbtZOPK9amwNK/nMEYY+nwHfT48wmjwXt54YC9zC X-Received: by 2002:a05:6402:c0b:b0:447:7cc3:1555 with SMTP id co11-20020a0564020c0b00b004477cc31555mr1037163edb.404.1661315571455; Tue, 23 Aug 2022 21:32:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661315571; cv=none; d=google.com; s=arc-20160816; b=PhyVbjwNQtftkT78PsuJKIW+zjvfc+ksLE8/HV+SL3lxl5WONuSkNk0Nd1hOnGrvym 5AJPL2RUi5/KnSK9B6CzcSlvt4cmk5NR0Cr7y/dPc/H+NYJi5+VmNP1JsDqrSQlCdwbW U7jt76CV2Mc8bgoEeREnKHLRMU6JN37jbLsGuviP95vKPmJX6FNVQ4yl87nY4GlSbBw8 iscIxD5mbJLHXlD8Ukc+o7ExSc0r8k7hWDYrVQB9Hn+7/bfYDq21tCXEAcTTLjQSQ8EY mcLSfXEs4vmtppZcrl3jU+yC+5hzpzxntnTNvN4Pe/gmHGMNR5y1/FDhZdW7+5WaFtRZ +ycQ== 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=1mJLK6hvchjehsHzEl3FcCuJd52Ags4MhBAkvBSrkO8=; b=MxO4tlun21MyScm/WD/ffMpr4LXJF7DikNdTvjAt+zXrxk8KF7AUnbFv0qAYY8dYx5 ft0MN4P+4YIyBlxBp22wRL7DnORiztCaPbm/uIRFdfMj1NPixXoggbPX++NCXZMnt5qj tVOXwMVs5cWh3kWptQyW5sTdXDkgHkLc4IfrR7tFsLlJ7ltvS1KfdKgr3ltBbdrGHp2u UfqOAWHLO+KRN9xKsYrzgVQS4KdZ4v2h6eE6OKz6/igdP3RS8WITsypHdwhj0n/eYcZp iWnviNc/hMp6WU6ezUfoRW/uMkIrSuKxzkb96uQtoxW+eBGJvV4EZH5wh4fBqWgLUTgY Es9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=V+BeboyB; 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 du17-20020a17090772d100b00718bf486a1csi1194895ejc.782.2022.08.23.21.32.25; Tue, 23 Aug 2022 21:32:51 -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=V+BeboyB; 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 S234401AbiHXDwt (ORCPT + 99 others); Tue, 23 Aug 2022 23:52:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36616 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234403AbiHXDwm (ORCPT ); Tue, 23 Aug 2022 23:52:42 -0400 Received: from mail-pf1-x42b.google.com (mail-pf1-x42b.google.com [IPv6:2607:f8b0:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A8208491F0 for ; Tue, 23 Aug 2022 20:52:41 -0700 (PDT) Received: by mail-pf1-x42b.google.com with SMTP id y127so12344003pfy.5 for ; Tue, 23 Aug 2022 20:52:41 -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; bh=1mJLK6hvchjehsHzEl3FcCuJd52Ags4MhBAkvBSrkO8=; b=V+BeboyB52pIWv5vpduP3TvkOHnga0om6vi5F3s495lrnJuoBjUVULAGmQLyDwLdDl GTRSmL4+VnRRqPfjqE11cqxzklZWYfwlDrsZt8GpPWrQrEA3TJQL/cfT6BxaSjjQDCVW NYXeP6Ak4AEYA0dliJ8FAFzCZcWBGNgHKeRzmqN9SyoOFdkIqbO/+eb4nfzskJo2IyXG L4ORtgiC81jxctyH9LqJtHRPkfDKgRrluePFneMaqI4pyvy1BuQKNPdrvDKevcBpKAHX 4bFM0A0+Ko3WZKDZNLTG0f3PgIdvmFtsgNxxtBBSMdffNoNXY4/Q8e54zCjmN6nPfKcK YDMA== 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; bh=1mJLK6hvchjehsHzEl3FcCuJd52Ags4MhBAkvBSrkO8=; b=rtd65GZc9f1kpS4sQnEMHcxhVcCiydz39Bf4R+AnG0OecrMM8iOTvNVF8Q2uuHRQ9/ ETnhjl9MwdAVH7HZhOuKk6txJq395ZUzk1LkM+uWe2W9Ya1uvxRGu9tvjtA+JOxn1aBu fPBr9yJxSLUPBfU5tsVoEswhmX7vnD+Dj5mETxRCfVPfjnZfVcaaVrvJhLuvVXzmTJqb qeh6vGqxGYtB2pSwBN1RfApQ4cNZV88SwAIHhMKdhj5N0yk6YJyfx4+lU0Q9+R0z5jfK DOGg6B4S5sGkLDzZtKzVUIAm9MGVNLDmTgg0REmkFHn5gwu+U5tgHpwy/6HzurarunQz HoFg== X-Gm-Message-State: ACgBeo3EdenYUvbmTWQAAzlBhy/y3vSOd0WkKe7j3rJCR3GSeW5AhMVC kXatQJv5hRl4RgegaAC86QRtHQcgcz8= X-Received: by 2002:a63:204d:0:b0:42a:5e9b:44b6 with SMTP id r13-20020a63204d000000b0042a5e9b44b6mr17366133pgm.372.1661313161070; Tue, 23 Aug 2022 20:52:41 -0700 (PDT) Received: from hyeyoo ([114.29.91.56]) by smtp.gmail.com with ESMTPSA id s2-20020a170902ea0200b0016ed20eacd2sm11420310plg.150.2022.08.23.20.52.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Aug 2022 20:52:39 -0700 (PDT) Date: Wed, 24 Aug 2022 12:52:34 +0900 From: Hyeonggon Yoo <42.hyeyoo@gmail.com> To: Vlastimil Babka Cc: Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , Roman Gushchin , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Marco Elver Subject: Re: [PATCH v4 17/17] mm/sl[au]b: check if large object is valid in __ksize() Message-ID: References: <20220817101826.236819-1-42.hyeyoo@gmail.com> <20220817101826.236819-18-42.hyeyoo@gmail.com> <66e25026-a86a-0157-3671-cf66eb53964c@suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <66e25026-a86a-0157-3671-cf66eb53964c@suse.cz> 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, T_SCC_BODY_TEXT_LINE 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 Tue, Aug 23, 2022 at 05:12:01PM +0200, Vlastimil Babka wrote: > On 8/17/22 12:18, Hyeonggon Yoo wrote: > > If address of large object is not beginning of folio or size of > > the folio is too small, it must be invalid. BUG() in such cases. > > > > Cc: Marco Elver > > Suggested-by: Vlastimil Babka > > Signed-off-by: Hyeonggon Yoo <42.hyeyoo@gmail.com> > > Reviewed-by: Vlastimil Babka > > --- > > mm/slab_common.c | 5 ++++- > > 1 file changed, 4 insertions(+), 1 deletion(-) > > > > diff --git a/mm/slab_common.c b/mm/slab_common.c > > index 9c273a5fb0d7..98d029212682 100644 > > --- a/mm/slab_common.c > > +++ b/mm/slab_common.c > > @@ -984,8 +984,11 @@ size_t __ksize(const void *object) > > > > folio = virt_to_folio(object); > > > > - if (unlikely(!folio_test_slab(folio))) > > + if (unlikely(!folio_test_slab(folio))) { > > + BUG_ON(folio_size(folio) <= KMALLOC_MAX_CACHE_SIZE); > > + BUG_ON(object != folio_address(folio)); > > return folio_size(folio); > > + } > > > > return slab_ksize(folio_slab(folio)->slab_cache); > > } > > In light of latest Linus' rant on BUG_ON() [1] I'm changing it to WARN_ON > and return 0, as it was in v3. > > [1] https://lore.kernel.org/all/CAHk-=wiEAH+ojSpAgx_Ep=NKPWHU8AdO3V56BXcCsU97oYJ1EA@mail.gmail.com/ Okay. I'm fine with that. > > > diff --git a/mm/slab_common.c b/mm/slab_common.c > index 98d029212682..a80c3a5e194d 100644 > --- a/mm/slab_common.c > +++ b/mm/slab_common.c > @@ -985,8 +985,10 @@ size_t __ksize(const void *object) > folio = virt_to_folio(object); > > if (unlikely(!folio_test_slab(folio))) { > - BUG_ON(folio_size(folio) <= KMALLOC_MAX_CACHE_SIZE); > - BUG_ON(object != folio_address(folio)); > + if (WARN_ON(folio_size(folio) <= KMALLOC_MAX_CACHE_SIZE)) > + return 0; > + if (WARN_ON(object != folio_address(folio))) > + return 0; > return folio_size(folio); > } > > -- Thanks, Hyeonggon