From mboxrd@z Thu Jan 1 00:00:00 1970 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 F2A90C43334 for ; Wed, 13 Jul 2022 10:34:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 74CFE940127; Wed, 13 Jul 2022 06:34:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6FAE09400E5; Wed, 13 Jul 2022 06:34:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5C296940127; Wed, 13 Jul 2022 06:34:09 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 4A7DD9400E5 for ; Wed, 13 Jul 2022 06:34:09 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 1E16861178 for ; Wed, 13 Jul 2022 10:34:09 +0000 (UTC) X-FDA: 79681716618.29.29CAC54 Received: from mail-yb1-f175.google.com (mail-yb1-f175.google.com [209.85.219.175]) by imf10.hostedemail.com (Postfix) with ESMTP id CF030C009B for ; Wed, 13 Jul 2022 10:34:08 +0000 (UTC) Received: by mail-yb1-f175.google.com with SMTP id r3so18529417ybr.6 for ; Wed, 13 Jul 2022 03:34:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=PD3ohJ/EmhNYKgVuLh+1SqFmgLy6OdvncR7q74oGJgI=; b=SFkRptQv/fARrJEXyjgdl3GI/SNI8s22WPYtvUrVhQI7uqGJl1eG7kDJG9WCzpi/oS vbOs8s7fLxxgZipbGnE+yg2GJbqhEOAof8pKtlWJO3Nv40SHvj+Ok+9BDj4FJRxH7+p1 FNdVIuTsM+3E0KR+CwyzKwWY3lbJAsKTDJP9YJ17aKY0UajdUFkZGa5EkGCYtUUfm+jj UjFKgWFRFTer4Hkq1JP2TkX4prE8+mpUkTbipb78wRzGnvCjsX995BzgRk/BswHHsiS2 X5bDvWUo/+QLB8d2JenM7ZAiK6VfHNsNnB01WX5kJluNt0tuqVJCjSFBQlEplHVJk62w jBEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=PD3ohJ/EmhNYKgVuLh+1SqFmgLy6OdvncR7q74oGJgI=; b=jQ6CZUomChgMF/OSOg2wL2nHjsMlHTWgOVgM4iwnN2rtLHd4MdWyyKEU1cP8ZIhcGK O0njKgaZSYLhQomEHrO9L8qa2PiQPwniaJXLE63iQ9oM+RCqSzhCJxzKrbaLWbZAMsMy mtdcREeTs7JWTF/aTxvqpfV7yp80SYqD59O+mTfw9t0AgIT/0aEvEC71Y1BZiSE0Yf3f E07k8Alyv2/WOhVGvZ2NCF1lMiazKLxDbue31KrlQ0q+g0x8aKvN4Lp3XPYkn6JfxL/K TflSVmviZrSmWhTYJ5DSqhZladhisMiP+TdLhBbVYcErafnK29PLkLkkF0qYlli2I3yM tpmg== X-Gm-Message-State: AJIora8dsHg43yQ99jXKxl19MeDpIMki24VkppTo3a39Vwh9HsiZVMWL v1kutjP32IZiIucsLT0JbuzO6v8bIdwSNeJwHsuJ9w== X-Google-Smtp-Source: AGRyM1vA9+p0W0ZH+zrwNUqogn3p1vap0TQyU6ssDzvta9TdLjk0Bu4O0HaJelNrRS0933ZUZYhceElQHXKy5uIogzE= X-Received: by 2002:a25:abc5:0:b0:66e:3983:3ca7 with SMTP id v63-20020a25abc5000000b0066e39833ca7mr2939658ybi.168.1657708447835; Wed, 13 Jul 2022 03:34:07 -0700 (PDT) MIME-Version: 1.0 References: <20220712133946.307181-1-42.hyeyoo@gmail.com> <20220712133946.307181-17-42.hyeyoo@gmail.com> In-Reply-To: From: Marco Elver Date: Wed, 13 Jul 2022 12:33:31 +0200 Message-ID: Subject: Re: [PATCH 16/16] mm/sl[au]b: check if large object is valid in __ksize() To: Christoph Lameter Cc: Hyeonggon Yoo <42.hyeyoo@gmail.com>, 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 Content-Type: text/plain; charset="UTF-8" ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1657708448; a=rsa-sha256; cv=none; b=3YjmY8F+wHUfXx2cikLQ4ycqE7ktSVb+LTXHDKGbbmcCqnp9fI24Yxq6CM40s/OK9UvCWh 3aXnYi7FFF7v3juWJX59IoW0o0UNgQbu2/K8kLKeSTOwvfYoiUu2XEBTvsTig2TwUFQAN3 +x/rqn+Hc44389KCg1Q2ZI07YvapV4E= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=SFkRptQv; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf10.hostedemail.com: domain of elver@google.com designates 209.85.219.175 as permitted sender) smtp.mailfrom=elver@google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1657708448; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=PD3ohJ/EmhNYKgVuLh+1SqFmgLy6OdvncR7q74oGJgI=; b=FrMWb5t6XTxq82V6HNMvU2NLnTOL5lrHBECIFMkhbbqmL5uQDdWKyK+rKr83ftcoXw2Z4/ YynJOQbTtRCrsK2K5vGd8l5PzIU0KJVkZidAsfZqb7JaunBenXAi+K0mMF6H8C9/Cezp/O knCBZD+jz3WvtoMnxPnP+a1qHhZY5FM= X-Stat-Signature: dxreyj93mupoez6o3h36z68gokzy8k9b X-Rspamd-Queue-Id: CF030C009B Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=SFkRptQv; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf10.hostedemail.com: domain of elver@google.com designates 209.85.219.175 as permitted sender) smtp.mailfrom=elver@google.com X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1657708448-173535 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: On Wed, 13 Jul 2022 at 12:07, Christoph Lameter wrote: > > On Wed, 13 Jul 2022, Hyeonggon Yoo wrote: > > > > Why return 0 if there is an error and why bother the callers with these > > > checks. BUG()? > > > > I thought BUG should be used when there is no other solution. > > Spurios returns of 0 that the caller has to check for is a solution? It's never really been about the caller checking for 0, see below. > > > I guess this is an error since the order-0 page cannot come from slab > > > allocations. > > > > comment in ksize() says: > > "The caller must guarantee that objp points to a valid object > > previously allocated with either kmalloc() or kmem_cache_alloc()." > > > > It should not be used on order-0 page that is not allocated from slab. No? > > I guess we would need to check. Code could exist that does this. > > Getting a 0 size would be surprising too here. BUG()? Or WARN() and return > PAGE_SIZE. We shouldn't crash, so it should be WARN(), but also returning PAGE_SIZE is bad. The intuition behind returning 0 is to try and make the buggy code cause less harm to the rest of the kernel. >From [1]: > Similarly, if you are able to tell if the passed pointer is not a > valid object some other way, you can do something better - namely, > return 0. The intuition here is that the caller has a pointer to an > invalid object, and wants to use ksize() to determine its size, and > most likely access all those bytes. Arguably, at that point the kernel > is already in a degrading state. But we can try to not let things get > worse by having ksize() return 0, in the hopes that it will stop > corrupting more memory. It won't work in all cases, but should avoid > things like "s = ksize(obj); touch_all_bytes(obj, s)" where the size > bounds the memory accessed corrupting random memory. [1] https://lore.kernel.org/all/CANpmjNNYt9AG8RrGF0pq2dPbFc=vw2kaOnL2k5+8kfJeEMGuwg@mail.gmail.com/ Thanks, -- Marco