From patchwork Tue Jul 30 20:39:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrii Nakryiko X-Patchwork-Id: 13747867 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 92223C3DA7F for ; Tue, 30 Jul 2024 20:39:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9A5B56B0095; Tue, 30 Jul 2024 16:39:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9576D6B0096; Tue, 30 Jul 2024 16:39:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7F7396B0098; Tue, 30 Jul 2024 16:39:34 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 606CD6B0095 for ; Tue, 30 Jul 2024 16:39:34 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 106FBA048A for ; Tue, 30 Jul 2024 20:39:34 +0000 (UTC) X-FDA: 82397584668.11.5EB0D34 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf23.hostedemail.com (Postfix) with ESMTP id 00C6614003D for ; Tue, 30 Jul 2024 20:39:31 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=dXX4rvyZ; spf=pass (imf23.hostedemail.com: domain of andrii@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=andrii@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1722371929; 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=yf8fXbkWts3gtNZ55HimmuRr/D74w/nooI3+u4YlS38=; b=QqM6z1le32TRjKQfGwtIsuwQ2h2D70EMn3oPD/PLY4neFphFzHokmVbDPRaJQ+DDkBiuzq ceOaBUUcCGPYSepqKd2JF38VfvyDqTIWpMCl03rjnWvdAJwGpj0MMrC6TxMaauJXf1y/pL 8bRdnV1cYH2nqqdj6iq3KsvtT5gUDVc= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=dXX4rvyZ; spf=pass (imf23.hostedemail.com: domain of andrii@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=andrii@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1722371929; a=rsa-sha256; cv=none; b=gBwlmFAx1zVEkw49YZwYEFxxMsrV8VD0cusFLA76fhvULwnUh6COsobixX0Fn3pzCaGbZt pBx0bh/q7kqNMleM4ESMxv5Ovd5m4s2qGLMyq0VJr9CS7X7k0NGH7hmnZZXKCtdusBl7em Anlo/BM/57i4I+Q+NgzqrBKq/akk3LI= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 2A70062064; Tue, 30 Jul 2024 20:39:31 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A714AC4AF0B; Tue, 30 Jul 2024 20:39:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722371970; bh=GUqeiOWs92MpwBboJ0qXM//0rJO16RNb6rfoIYo9S10=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dXX4rvyZw8450YmvvFwxvviqZXlbtriu8fEHWqrGOUv1XfLApBmyxINQfj3YnY0Bl vZWFVhW9Pq0NMHeRUxsR9VcbZfoK/UrZPdI2aHrEsPKQud1c08aTblq8cSsNZ/ZzZL F6eGgBHvXSiJamEzY85jPZVCALN/Nm3XGIkz2anGpISmD/uJOEk0UTHKNx2hgEyUdU +JmjVyH5xwmx+DgwSZLtMhGRgkD7gC+2AMGhTPqnlp6NPOy2t/Q3Z09Db8/HQwKD0+ s+oMsmE63soYP23u6u0EA5vhTbhD6KBNbMBjoAPVsojUIRe4twSJIp+2SMRakWpSrj VqvWJDTkt2X4g== From: Andrii Nakryiko To: bpf@vger.kernel.org Cc: linux-mm@kvack.org, akpm@linux-foundation.org, adobriyan@gmail.com, shakeel.butt@linux.dev, hannes@cmpxchg.org, ak@linux.intel.com, osandov@osandov.com, song@kernel.org, jannh@google.com, Andrii Nakryiko Subject: [PATCH v3 bpf-next 04/10] lib/buildid: remove single-page limit for PHDR search Date: Tue, 30 Jul 2024 13:39:08 -0700 Message-ID: <20240730203914.1182569-5-andrii@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240730203914.1182569-1-andrii@kernel.org> References: <20240730203914.1182569-1-andrii@kernel.org> MIME-Version: 1.0 X-Stat-Signature: w8fzrz6ppsfbiftd87i6x1mszaaeg3jt X-Rspam-User: X-Rspamd-Queue-Id: 00C6614003D X-Rspamd-Server: rspam02 X-HE-Tag: 1722371971-208904 X-HE-Meta: U2FsdGVkX18y4cfUY9h85aVHiZKnLKEZ2wBBGqGksKTfXShADSQnGecSJeycPfrG0PtrCrzIbEpo3pjjL0O5TpsvzJM0RJ/fc78t4tG//nIGwzMXm836VTAsvEkmTIcklv5B+afH5p5dkXUm9NIFkBeVf3eSkQbAa4tOf3SiPuTNu+UesCm8E5ZuE4LOT3zQ4/KPwV3viKklRk5wXA3KJWByNY5YIeOsl2zNIDCe62eZc/P4ypWJMdF5oI9h0hVAap+yiKAPQ0EW7z3U8HnAGbiHrjSfoCiSrlOXEKIYfnnVeANAcKAUNaNpPfR26XT3wgJmcqoDf7hQzogJS1F7yZwq04Ch/Jec0cQrpWURo8PRye78/MxiYzADtPaW8P2HJqx5Sl7rBVgWu/d7/JAlXaE2vqbvb9M+saDm8+HNmrpGtOBavZII/3nBQH5AtHmiDFTB4C5+T6jjINENXsRLOh2IPuxehwTf0Y5/9nAbKdX7t65pPz8a3MeOeygyCRh48spor6WMjyTBwxUJu6fITRlRjc9T2peZoJ3Q7+r9fh7EJo6bt40VwC8eU6peB1Y7hRnYwZP/5iAJGZQk7ynt+NuXEuELBbmbuXey5pLAhqJ2ma2C7PVwMSOsC1tFTBo8f9wVo8XlnbysUGgz7ruVhNsbjFzDt5HSGRmSbwoX8ohMPfazioMCgMWI2rXZiaRMRzHAj1KjiqbkSWwm4h+sMQegZ3VxZBCLTJ6mMyOzrOXgqgXRfiKT+W/LOwkpfxIA6TK3PJpYE8m+I63S4ofAJKmdAlxAKKlh9RkUt3b0cd0YhEh7WDlMK1Y0T4queW8dQT7M0gDA74gAh+0AnaC2tqzyg8J3Y0nbc44ab65UrTXSVRsapzBDmaHIQen8FuGzLd6lTYGcw7GnHpcKwZ1YKBkc+Y+hC5UFWw3JJk6+BTUaMlcg6lsviPYigjlfhsBjvUQ1cx05Lm8iYSZgOr4 mh6j3nZM K6EApa4+CgomJNYmGgF6D7t63R8OzuS03KB5BoPuhZDTTNSWJCUr7yODYnre2mI5qOjjZa/c5HKWr/EhpMwmi6MJtt4Hxvw6iY22oEWMhR8DFXnPznuLqiVQqEVIFugM6ZFuvWh7qJvhoWns78F05aUaUKUMwbXBx/a3HBs8IojEME0Vi1utzcm9rE/wJidL/8AgGrWg0YVh34MQnpAPtCvB1wRBR5bP6T4IbvBWnViG8k5k= 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: List-Subscribe: List-Unsubscribe: Now that freader allows to access multiple pages transparently, there is no need to limit program headers to the very first ELF file page. Remove this limitation, but still put some sane limit on amount of program headers that we are willing to iterate over (set arbitrarily to 256). Signed-off-by: Andrii Nakryiko --- lib/buildid.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/buildid.c b/lib/buildid.c index ba453a3784d1..095e79158b85 100644 --- a/lib/buildid.c +++ b/lib/buildid.c @@ -8,6 +8,8 @@ #define BUILD_ID 3 +#define MAX_PHDR_CNT 256 + struct freader { void *buf; u32 buf_sz; @@ -217,9 +219,9 @@ static int get_build_id_32(struct freader *r, unsigned char *build_id, __u32 *si phnum = READ_ONCE(ehdr->e_phnum); phoff = READ_ONCE(ehdr->e_phoff); - /* only supports phdr that fits in one page */ - if (phnum > (PAGE_SIZE - sizeof(Elf32_Ehdr)) / sizeof(Elf32_Phdr)) - return -EINVAL; + /* set upper bound on amount of segments (phdrs) we iterate */ + if (phnum > MAX_PHDR_CNT) + phnum = MAX_PHDR_CNT; for (i = 0; i < phnum; ++i) { phdr = freader_fetch(r, phoff + i * sizeof(Elf32_Phdr), sizeof(Elf32_Phdr)); @@ -250,9 +252,9 @@ static int get_build_id_64(struct freader *r, unsigned char *build_id, __u32 *si phnum = READ_ONCE(ehdr->e_phnum); phoff = READ_ONCE(ehdr->e_phoff); - /* only supports phdr that fits in one page */ - if (phnum > (PAGE_SIZE - sizeof(Elf64_Ehdr)) / sizeof(Elf64_Phdr)) - return -EINVAL; + /* set upper bound on amount of segments (phdrs) we iterate */ + if (phnum > MAX_PHDR_CNT) + phnum = MAX_PHDR_CNT; for (i = 0; i < phnum; ++i) { phdr = freader_fetch(r, phoff + i * sizeof(Elf64_Phdr), sizeof(Elf64_Phdr));