Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp4495905imw; Tue, 12 Jul 2022 08:57:31 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tABMWah9q7gARfNbbaXNmJHqz8SZga6VwH+yWDkZWs3sz6FihayrIDTRGAget0VC/qayXr X-Received: by 2002:a63:5302:0:b0:412:219:928f with SMTP id h2-20020a635302000000b004120219928fmr20877118pgb.425.1657641451697; Tue, 12 Jul 2022 08:57:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657641451; cv=none; d=google.com; s=arc-20160816; b=ca3eMc1AlYON5IVH7lBc2cSII07n9ofRcOk57YlGJaZaNw2X1fS7KtJk01YBQAYIMy A2xK+l67da6bFoUH1QlZLba0RrkJxNL5UbSkk1XAASNubK3Os5NR9LNPqSvMYd9rr62u wP9lBMVLd+XqQhwJ9sKK9Jpd6iLZKbBJx4FG2FKD3Tz6DizwXKyLTQl7McUp4wYOiqze 51VUH/j/y5pHmu/DsmrD8kAielrWNGdyrRcdyotWvnQ8QWYDvTupZx62GkCSv8IMQMYL lDvA1C4kOUugNr9BQw9GMhfXdYl9bEdu9IlAE9g+4iIIp9yKbjrid8cGRzcEoHcnyHlN Bkug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:references:message-id :in-reply-to:subject:cc:to:from:date:dkim-signature; bh=qfeMTdLRpBSxU4Hu6dNMkTOU1oQkYZnE3ARvzgVICDA=; b=dE24vcZYNxyVV+9ma5Pt5ya5vv39unSEe3d0/gRgybXhewaQIMCCdr5FiIM7N5wRnK 1sjfmI56IbZCIgO45pR9MkFT9ZJ5eMzc1NGRdJmh624yD5rs8cM0cvznm2gy2D6jwubh nBZUDz9D5zObHm0VAUzQx/P3IUBlGqQQeRuaKc7lgAnaYbtTB79Hwpt5TZBYu6UIMbL8 vn5SYwVrn4ebu51mxpAPWsjI3qry4a+1O3l1jtjjUv2VvfTFh96u0REYTllJW7XSMT8h sJYRmgQjbbW4nWb5hLHZ4OFIIIeF0GQXUltUQ5iFgVtPJFQNJTC+pZuAz8NXgbZrBWLc 1sbQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gentwo.de header.s=default header.b="Xj/GN/J6"; 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=NONE dis=NONE) header.from=gentwo.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id kk10-20020a17090b4a0a00b001ece52e835bsi21488694pjb.2.2022.07.12.08.57.12; Tue, 12 Jul 2022 08:57:31 -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=@gentwo.de header.s=default header.b="Xj/GN/J6"; 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=NONE dis=NONE) header.from=gentwo.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232790AbiGLPS7 (ORCPT + 99 others); Tue, 12 Jul 2022 11:18:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51092 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233416AbiGLPSf (ORCPT ); Tue, 12 Jul 2022 11:18:35 -0400 Received: from gentwo.de (gentwo.de [IPv6:2a02:c206:2048:5042::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7D1B528E1C for ; Tue, 12 Jul 2022 08:13:49 -0700 (PDT) Received: by gentwo.de (Postfix, from userid 1001) id B8AE0B00422; Tue, 12 Jul 2022 17:13:44 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gentwo.de; s=default; t=1657638824; bh=7+H5sOVkN3QxHU6DQU93Nr8Rzf1W/u/tyJLdV84maC4=; h=Date:From:To:cc:Subject:In-Reply-To:References:From; b=Xj/GN/J6jJvlJrzAyTYFvqxapzZWR96npANp8WILastYr1yA6AZofEFMiv0vdCtXD geCh8MPf7MLjcbnU0dWUgWYTBhC6kBakj1/XnLfI9qT0E6AiiU8tr4VHGIQ5GmvxRg t+F/h14WJW+QqpvD7NiLVNcqK6RBEO8F8yLCdYu8sGJnNhgP7MoPFqvZRfm7TZI8o4 oxSJJ3eHrQa+oK2MHqcybzm3eIZ83WTdJaTro0WTbw+lSPpl59S0L4l0CW1EcfdPrU aPa4aRoXX985c/dKImmvDelc80KgvwmYtjuB/hfMb0gzBaxtfk6xl5UuuP4d0bVsCJ 3CMrv8AUiZ+8A== Received: from localhost (localhost [127.0.0.1]) by gentwo.de (Postfix) with ESMTP id B7EBEB0026E; Tue, 12 Jul 2022 17:13:44 +0200 (CEST) Date: Tue, 12 Jul 2022 17:13:44 +0200 (CEST) From: Christoph Lameter To: Hyeonggon Yoo <42.hyeyoo@gmail.com> cc: Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , Vlastimil Babka , Roman Gushchin , Joe Perches , Vasily Averin , Matthew WilCox , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH 16/16] mm/sl[au]b: check if large object is valid in __ksize() In-Reply-To: <20220712133946.307181-17-42.hyeyoo@gmail.com> Message-ID: References: <20220712133946.307181-1-42.hyeyoo@gmail.com> <20220712133946.307181-17-42.hyeyoo@gmail.com> User-Agent: Alpine 2.22 (DEB 394 2020-01-19) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham 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, 12 Jul 2022, Hyeonggon Yoo wrote: > __ksize() returns size of objects allocated from slab allocator. > When invalid object is passed to __ksize(), returning zero > prevents further memory corruption and makes caller be able to > check if there is an error. > > If address of large object is not beginning of folio or size of > the folio is too small, it must be invalid. Return zero in such cases. Why return 0 if there is an error and why bother the callers with these checks. BUG()? > diff --git a/mm/slab_common.c b/mm/slab_common.c > index 1f8db7959366..0d6cbe9d7ad0 100644 > --- a/mm/slab_common.c > +++ b/mm/slab_common.c > @@ -1013,8 +1013,12 @@ size_t __ksize(const void *object) > > folio = virt_to_folio(object); > > - if (unlikely(!folio_test_slab(folio))) > + if (unlikely(!folio_test_slab(folio))) { > + if (WARN_ON(object != folio_address(folio) || > + folio_size(folio) <= KMALLOC_MAX_CACHE_SIZE)) Hmmm... This may change things a bit. Before this patch it was possible to determine the storage size of order-0 pages using ksize(). Now this returns 0? I guess this is an error since the order-0 page cannot come from slab allocations.