From patchwork Wed Oct 30 13:32:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marc Dionne X-Patchwork-Id: 13856515 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 4221ED5CCAE for ; Wed, 30 Oct 2024 13:32:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C28AB8D0002; Wed, 30 Oct 2024 09:32:14 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BD8A98D0001; Wed, 30 Oct 2024 09:32:14 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A794F8D0002; Wed, 30 Oct 2024 09:32:14 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 866B28D0001 for ; Wed, 30 Oct 2024 09:32:14 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 1AB2BA0C9F for ; Wed, 30 Oct 2024 13:32:14 +0000 (UTC) X-FDA: 82730357136.29.CC0042A Received: from mail-qk1-f170.google.com (mail-qk1-f170.google.com [209.85.222.170]) by imf23.hostedemail.com (Postfix) with ESMTP id 93BA114001F for ; Wed, 30 Oct 2024 13:31:55 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Qemmb8bF; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf23.hostedemail.com: domain of marc.c.dionne@gmail.com designates 209.85.222.170 as permitted sender) smtp.mailfrom=marc.c.dionne@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1730295014; a=rsa-sha256; cv=none; b=5FwtEk8BPxDCOgrml9QsJN05B8+OSDkdv4K4EyA/isyUZqxVuYv/WvuiMgu6nS6NkRQa1p jKxM9pEYvCGI+Ud3vFYuAuCMqjHTfIgup2UDkFW5roD4Ysj8nNjl4FrJ9BupDvktlYZZNQ RKAmY6A3CA+0L7Eac+jJNphxlU7AfWw= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Qemmb8bF; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf23.hostedemail.com: domain of marc.c.dionne@gmail.com designates 209.85.222.170 as permitted sender) smtp.mailfrom=marc.c.dionne@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1730295014; 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:references:dkim-signature; bh=ns5nWhr0PT4Sc6/u0VDcTbhfTPo6/0aZkcTxVWdIZRo=; b=QGa7UxuyqVssVADsgxNOzN/x+VHalWNFhSrLfcmvVFhFVNfxBhmLHOoCYq3vLcsMOIuqTO T8eJheC4YVVZVyh9QWfSR7nbh+jVJ34lZ5VSWnYdwO2LlQgVn+KKppZIPKMB20r8Yf6Bf4 doTUl8QnQ1v8EJ5vxcxR1wVnQQ7DNII= Received: by mail-qk1-f170.google.com with SMTP id af79cd13be357-7b15eadee87so475780185a.2 for ; Wed, 30 Oct 2024 06:32:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730295131; x=1730899931; darn=kvack.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=ns5nWhr0PT4Sc6/u0VDcTbhfTPo6/0aZkcTxVWdIZRo=; b=Qemmb8bF+urHFLX3AdyJVHELuqglNl9ZvwUNFEySdxTm5TnUrNdNdb9CFTDE/9hlpA ibbEUrP4sFMLbcX6NUMebjI510CtOvlmQxB9K0x7YQm0uG/etoKbeoI/MoHJmRcG7+Qb qUMoFF5XQQjIaKDgabyAPo6L6tJPUYng/Ejcyo1FP1gE0xECB+CAZ6yr8PKx8OhYqS6P qGUHmhtBOV3NAdC0hp1zLkx8GIlRNRQrtFG/20QtItYcpYSZ/I9laAZCJAaFFSk8p/Es ccmTuI6ZqGgivCImQXeYVmRj5xN5bXl7VwDJMJ3hxJxrxraBMb20II5h4vhuuRINc5xg nLuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730295131; x=1730899931; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=ns5nWhr0PT4Sc6/u0VDcTbhfTPo6/0aZkcTxVWdIZRo=; b=GccB72+rv48Jp2DqjuvfWWxWNJBt1VAvLheTAP4FK9hBNEsJwCyaJs99vp6iI2Id9V d7B/EhKoFYu2rCnW/NfwbvJolYrHLyMqa8dMktjFKfQ9wg/G54DVMWddXILX9p9AVnti rpdMvTaj8sSJ8M+Y2IZ8QeAsL/EtoyGnfSC9LKbfV6yLlS+UtS3HLrtj1lCGOlRbzMYf MUoibGWdbAay9Pz3cuD0DoNfHwpT6ft1qi3/sf5AUeMg+PF09XWnaaLwvNgopmC1s01Z fCJJyPsLjpatGyC65euncq97nJFgvS5UMGdAA+8+eGKpL+sMl7Wg8Lo9XRlPmxz4jsmK SdzQ== X-Forwarded-Encrypted: i=1; AJvYcCW9u9dH/QYygrRbhHmUWVpifihni16p+LZChgpfTzGsoHPWf093o+YJH5OgM5OVjdes9cU0U7TrnQ==@kvack.org X-Gm-Message-State: AOJu0Yy8SWKDIKs0hCzw/Gbg9kpm3WK93/ImoqlMpAphGw6kr1TREzQP tfFa7IQ/Tqw1Rby+KouGMiQsMX7L2uiKwXiV+QfwiLoa0YzoHM+q X-Google-Smtp-Source: AGHT+IHDeLO3HDuzQWG5QFgMmTLs8z3uetA7y8Qy6YtIjbeSmpntV0NS1nysmvuJx6ZNotSlChVO1w== X-Received: by 2002:a05:620a:3182:b0:7b1:3754:7d82 with SMTP id af79cd13be357-7b193f74527mr2102137485a.66.1730295131265; Wed, 30 Oct 2024 06:32:11 -0700 (PDT) Received: from hemlock.fiveisland.rocks (dhcp-213-15-2-159.pbband.net. [159.2.15.213]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7b18d2aab9csm513495785a.61.2024.10.30.06.32.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Oct 2024 06:32:10 -0700 (PDT) From: Marc Dionne To: Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Vlastimil Babka , Marc Dionne Subject: [PATCH v3] tools/mm: Fix slabinfo crash when MAX_SLABS is exceeded Date: Wed, 30 Oct 2024 10:32:08 -0300 Message-ID: <20241030133208.41061-1-marc.c.dionne@gmail.com> X-Mailer: git-send-email 2.47.0 MIME-Version: 1.0 X-Rspamd-Queue-Id: 93BA114001F X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: zozuyt9mtyqm9hwzwbzwm9ogca858uoh X-HE-Tag: 1730295115-663684 X-HE-Meta: U2FsdGVkX1/lM9dtPeCaVXPz30dmmNimgnz5VbGT4smDfg7xDWT/X/CP6xfU/dTFYorFtXtQynm49mkfDis65dA/clVVBwGe9LL4mbC2PtZZWrNn+cQDplHe9jaEYkvytKTUXYd2aAj5X9N+rDeK052FbN1u/PQ817hH5F3nY0WBsmL9HscfojwDhRy+/823ULjHMV515L5/q0fZWLIUBvt6xQE6bjJRrNDw2ZGstw4S1NXiCsifkXYPyGZffjf/5DcJwzQ54rBIkPrx6f5sCtLHy5eMAyd81KwHx3CwWp2IkxtJjqL8Yg97HsO/LDT1KhZbfr3IcPPOYL0H0jY0Jw0azwp1RO8sDCMrveAjXw3HoTbXx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mtymdRcyzfB+EktaD3sbNrnL0MQrrA6xpw= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000032, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Marc Dionne The number of slabs can easily exceed the hard coded MAX_SLABS in the slabinfo tool, causing it to overwrite memory and crash. Increase the value of MAX_SLABS, and check if that has been exceeded for each new slab, instead of at the end when it's already too late. Also move the check for MAX_ALIASES into the loop body. Signed-off-by: Marc Dionne --- tools/mm/slabinfo.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tools/mm/slabinfo.c b/tools/mm/slabinfo.c index cfaeaea71042..bf770101929a 100644 --- a/tools/mm/slabinfo.c +++ b/tools/mm/slabinfo.c @@ -21,7 +21,7 @@ #include #include -#define MAX_SLABS 500 +#define MAX_SLABS 2000 #define MAX_ALIASES 500 #define MAX_NODES 1024 @@ -1240,6 +1240,8 @@ static void read_slab_dir(void) p--; alias->ref = strdup(p); alias++; + if (alias - aliasinfo == MAX_ALIASES) + fatal("Too many aliases\n"); break; case DT_DIR: if (chdir(de->d_name)) @@ -1301,6 +1303,8 @@ static void read_slab_dir(void) if (slab->name[0] == ':') alias_targets++; slab++; + if (slab - slabinfo == MAX_SLABS) + fatal("Too many slabs\n"); break; default : fatal("Unknown file type %lx\n", de->d_type); @@ -1310,10 +1314,6 @@ static void read_slab_dir(void) slabs = slab - slabinfo; actual_slabs = slabs; aliases = alias - aliasinfo; - if (slabs > MAX_SLABS) - fatal("Too many slabs\n"); - if (aliases > MAX_ALIASES) - fatal("Too many aliases\n"); } static void output_slabs(void)