From patchwork Wed Aug 14 18:54:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrii Nakryiko X-Patchwork-Id: 13763838 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 25BBFC531DC for ; Wed, 14 Aug 2024 18:54:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8ADFE6B0092; Wed, 14 Aug 2024 14:54:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 860856B0093; Wed, 14 Aug 2024 14:54:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6FEE06B0095; Wed, 14 Aug 2024 14:54:37 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 4E2D66B0092 for ; Wed, 14 Aug 2024 14:54:37 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id ED65F160EDE for ; Wed, 14 Aug 2024 18:54:36 +0000 (UTC) X-FDA: 82451752152.14.4CF3835 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf16.hostedemail.com (Postfix) with ESMTP id 46CD3180018 for ; Wed, 14 Aug 2024 18:54:35 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="pEZuyU/1"; spf=pass (imf16.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=1723661639; 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=GOI369kom8/1lwI/dpS7EaG3Jx9c+Y8m/KJsikyz+mo=; b=YOer8TlHEmUGuFgIqtqlZHN3LOd/MTvGISLw3tmwzlYavlx3K4RPSDQWHrw63spFeuYiy2 nDfUBFOMXsJSrXf9jHn0fDxdhtEf3ai/X+qDcDabNuBcabMm+oDB/AS9tp4dqnIlVAvjwC 9ncPI/zVyyzY3x4vDAJvupTYgqkOzyc= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="pEZuyU/1"; spf=pass (imf16.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=1723661639; a=rsa-sha256; cv=none; b=JV3SGoHXrUPj1KFWEdfmxPrfeCd912R1QocAtp6cwwcjBgWADau0hlMvLgtGIY6sFrL3Mu U9eJmQarDzUiMUHfwH1TQYnetDMAkchMeEyfiAzS02CTn0/JS4Mcll5N+M6c8ZweoU+kZE LosEUNE0skbmmkjbZZxmcxx6PRCLsGM= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 6B27761BDC; Wed, 14 Aug 2024 18:54:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1BDEDC4AF0E; Wed, 14 Aug 2024 18:54:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1723661674; bh=EKylHdmMyJh/v4m6K+s9kOSONMY3dxjgOdsYFysplh0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pEZuyU/1rAcAXZiVqWCU1ZGahkQkGHNe1bUgVRj9L2g1e1y9NIUi4KQwh0he+/y3i 2nwUHlOoNOlOLD0tuOYrkwv5GqJht2gscy2mqQHppF69YaOiMmeea/39g1oiAVY5St 3/ANUyoG6PXVM3PloR0GBOmHx3vAZmHzLz3eLz1TfXmEyQQNV7mNLlS6wuD9merH7u L+yBFHUGf6w/ErARe+gyGaK8sfCAdz3v64xUWN4VAExkHhPsb3YYIemUM17EQbvmUT E2tn0fnxASqDsb8kMS4JrSBmmWrHZ5fRDfpMq00n1t9bzTtHJoe7dXyVQqPW15O4N4 KPavrNLcdnQYg== 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, linux-fsdevel@vger.kernel.org, willy@infradead.org, Andrii Nakryiko Subject: [PATCH v6 bpf-next 04/10] lib/buildid: remove single-page limit for PHDR search Date: Wed, 14 Aug 2024 11:54:11 -0700 Message-ID: <20240814185417.1171430-5-andrii@kernel.org> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20240814185417.1171430-1-andrii@kernel.org> References: <20240814185417.1171430-1-andrii@kernel.org> MIME-Version: 1.0 X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: 46CD3180018 X-Stat-Signature: 6mkgu5uwp1sdi7wrnxxgc3yw5ut9ws3x X-HE-Tag: 1723661675-94976 X-HE-Meta: U2FsdGVkX18x8Pe7bN+2jDRxME0oEXho29GFwGhcAp58ZN1fJuYuY02+j+Z9xmC3Ad20lBqbvF+TyLhAxIWMRZ9eEbe/rdoGW9DyAUmeviAxKixzxKzzNyPdZSRsQ34ntAKsT8HeAEmojWN0JhAKT40JwWQTHTLaCTwZxUmZoG6SmYIJjQ1ogFaO5CqdtElyxD9gsU6EK5z8TTUuV/eTFdFADJMtW3oPhnaDHgYFNlmCTnxNyM9F39JwuDmhIavqZp+sGw5CuIr2AvFtEEEQe0VWGGh4hy9xzSe93GgxOn7tyTM2cisgN+U6N3eVDWXzKpl24WVDrxisnPNEJB3fH2TDNJRUuTBhXb6E6L90FW2TZJSgrKOekliGta6RVRwYDDrz73VlLSSHCftmOOnBscFX4XeVD74ypBODduw6QLCTP2aQM5SFLtMuRZ/l5B2YP829AbTG77lDsuuzbj2iXx/3n1jMaCvqzanDBLn0dyxefn5uIhevk1SGvCspjFYtVapSEn1V1iWUYTG8uuYQYPVeD9g1w6JX4laZiHgKtLsItBxkpGIYUyGI9VDP8KC/bnmxkNuWIJq2snVuENJ5oTPWXcLt3i9Y1zFw7iZIfQlkfdRJmGN8UvQAWQpdOQm7rhCDFybHJtCPt3v9cFlMkEoGs5tXZvRMMxGhU9mafulFm0VS7SDaiLUW1DSXj9j+UKKcM91RWu3Lc4SSX6m3n+pW/R1VdlLk3o67hE7Q6TRBrcRf2yFSs9xCDjc+vEqMResLS7BZBcQMXBlJlsnWPiiC6iQUQo+fZSBmvYSt6yjz4N3jNUj/kNnqUA0RJQi7Abq6fSSTxLDaHsAIFZ7colPaYEts/4sVMV+JB76ZH6+KTgxrCPktmDrS11HaSSlneo4MxiZMoRlavrS5R8wfEkCeEDnaet1H2vFKKNPk8Nhp/SuniOg2FcYfc47AM1SUFV+eSXqU1rcc9KisYUz q6wAAezK +ZIJPngrUy6BlXFcZGPT/kqyNKJXnGBLvN7G/Vq1LoZxirFX0lyitLioeYAom3PcrOznPxmqPbe0md0l7XpA3hdaMEk1neXq7MvTDPvi8iLDbU6I/vpejJTYpq/2IMvraN0Hfcfg3NYfjPg8ZyjkcVl05PJPjRvNTzWT/qaX17tYgLEGYzU5Cw2vC8SyvEWKJ7MRLKSZM/Eop+HtZL+L0Ppd2Gq3olLGblfAkcMxZ5uHP7O0= 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 7fb08a1d98bd..e8fc4aeb01f2 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; @@ -223,9 +225,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; /* check that phoff is not large enough to cause an overflow */ if (phoff + phnum * sizeof(Elf32_Phdr) < phoff) @@ -260,9 +262,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; /* check that phoff is not large enough to cause an overflow */ if (phoff + phnum * sizeof(Elf64_Phdr) < phoff)