From patchwork Wed Aug 17 10:18:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hyeonggon Yoo <42.hyeyoo@gmail.com> X-Patchwork-Id: 12945695 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 B79B2C25B08 for ; Wed, 17 Aug 2022 10:20:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5492E6B0073; Wed, 17 Aug 2022 06:20:16 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4F9616B0074; Wed, 17 Aug 2022 06:20:16 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3E8246B0075; Wed, 17 Aug 2022 06:20:16 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 312C96B0073 for ; Wed, 17 Aug 2022 06:20:16 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 154E1AAE99 for ; Wed, 17 Aug 2022 10:20:16 +0000 (UTC) X-FDA: 79808689632.26.96FD3D9 Received: from mail-pg1-f169.google.com (mail-pg1-f169.google.com [209.85.215.169]) by imf24.hostedemail.com (Postfix) with ESMTP id 1A7931801F2 for ; Wed, 17 Aug 2022 10:19:50 +0000 (UTC) Received: by mail-pg1-f169.google.com with SMTP id 24so11605059pgr.7 for ; Wed, 17 Aug 2022 03:19:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=QvbBlM64XGXvCYpSrw2ZhXubC7osA9SaKrvHemruWUk=; b=OH1i67TRQUnuhYunmmI/MYZkQu3kqwPcoWFksU+md4pWKAZnkbL8LMUnQFZcQ2ihXg AXvgKmdFw8N9HiH4T1CGwUKqhKiLDSXrAw1D6savzF8DUwAN1q0NeZNH18ESnyEIQGu6 nugZqGOPIbMKIQDiyvg9qiWA1W+EysZuIoPc58j95+BudKMg4WPJiSVfrxmz36ASlbSh Xd07i+oFEYQ7f2iWznifckbG5x6HlGnLRSUwyz0uFBT2C0TNca2HBDwbWCXuxm3Pel3N uxY6CHinDJ/cnbjrWvKy3JqwZ9dHWsFlPLb2AlhKDtCzlwsdULxFoAWm6UV0hO7fTKtB +wnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=QvbBlM64XGXvCYpSrw2ZhXubC7osA9SaKrvHemruWUk=; b=aUPb7D5gfu4uXopOjVwlobBa4ztw0GuUv3Xfd/GdIA+57WerxnRcOOCBD6Vb8mmLKt +9bZVwDz73R6kJ2OrpmmLTukQdwuA/z/CRe5vLU06H2vHQ41cn7b/a7NXyzRAH0I+Iph tyyhuHtN27c+95IKtppjN65zdc0PKvq2q9F6tyAhAfUR6nr7urjYooDpuDiRf0ygREFK 3TBifi08cn/fJcvHjutYDTxb4+P784zQ8Lasg6LPjOZNX0loNEAp9IPXefHDm0uA/ggp htgZqRGndmUGMaknG/OkTcIOfeBvGgAG5to13YFZ+AH5JkZSruWAnFTUdc3NRfQD2LLH cicg== X-Gm-Message-State: ACgBeo2V/2MkzGtC2lQxk/6eB3i6RhAS5/mLUfVyHEmm39/JmlKIz/a7 UibHzgVB6kLiyuVjIgR81FU= X-Google-Smtp-Source: AA6agR5BivBlhg3XB+mK1tMfAb8bN7Obm740H6tldqe9nQKKdLaKub/ufv6AC+sNXwisZ+Ihenb5GA== X-Received: by 2002:a05:6a00:1c53:b0:52d:d673:2241 with SMTP id s19-20020a056a001c5300b0052dd6732241mr24646290pfw.71.1660731590183; Wed, 17 Aug 2022 03:19:50 -0700 (PDT) Received: from hyeyoo.. ([114.29.91.56]) by smtp.gmail.com with ESMTPSA id d8-20020a170903230800b00172633fc236sm1071318plh.174.2022.08.17.03.19.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Aug 2022 03:19:49 -0700 (PDT) From: Hyeonggon Yoo <42.hyeyoo@gmail.com> To: Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , Vlastimil Babka , Roman Gushchin Cc: Hyeonggon Yoo <42.hyeyoo@gmail.com>, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Marco Elver Subject: [PATCH v4 17/17] mm/sl[au]b: check if large object is valid in __ksize() Date: Wed, 17 Aug 2022 19:18:26 +0900 Message-Id: <20220817101826.236819-18-42.hyeyoo@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220817101826.236819-1-42.hyeyoo@gmail.com> References: <20220817101826.236819-1-42.hyeyoo@gmail.com> MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1660731591; a=rsa-sha256; cv=none; b=xpzJSMfMckAi/lN01OvVmkHOqfHiZQxkVvdxrCXoC9MBOMq4dcFv9KtGiqogSc4TqvN6Yu qXwV8H9RoTv67ryUKZZsHs6r/LgFomDjmp6gDLDgXTOPumJGWuB/hd3h4v4rJJ+As4UAbF biS+GJnpNRrBtIMwi+57E1EvQMYI8mM= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=OH1i67TR; spf=pass (imf24.hostedemail.com: domain of 42.hyeyoo@gmail.com designates 209.85.215.169 as permitted sender) smtp.mailfrom=42.hyeyoo@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1660731591; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=QvbBlM64XGXvCYpSrw2ZhXubC7osA9SaKrvHemruWUk=; b=wC9SD3OVyV/mPhShxJBJyB8Io9qdXXp71ampARHwSnTfneqpHbY+LAcIVSQ1/NjwpevLHf RmOWUA0b/CP9qFu9W0kgm37tRNlaLhGxosg2o+pl6op16pR5Vnct9Z6nrfGwSv6qZuURoH JYiwTxV5/nr52mUsBYlmEwZv4xBqWaU= X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 1A7931801F2 X-Rspam-User: Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=OH1i67TR; spf=pass (imf24.hostedemail.com: domain of 42.hyeyoo@gmail.com designates 209.85.215.169 as permitted sender) smtp.mailfrom=42.hyeyoo@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Stat-Signature: nod57adw6q54kiapn1o79z3i6go8h1ud X-HE-Tag: 1660731590-294158 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: 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); }