From patchwork Wed Jul 24 22:52:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrii Nakryiko X-Patchwork-Id: 13741431 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 0FAC6C3DA61 for ; Wed, 24 Jul 2024 22:52:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9BE826B009B; Wed, 24 Jul 2024 18:52:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 96D416B009C; Wed, 24 Jul 2024 18:52:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 80E106B009D; Wed, 24 Jul 2024 18:52:29 -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 5F2086B009B for ; Wed, 24 Jul 2024 18:52:29 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 1B243140C93 for ; Wed, 24 Jul 2024 22:52:29 +0000 (UTC) X-FDA: 82376146818.07.3B3966C Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf07.hostedemail.com (Postfix) with ESMTP id 277F24000C for ; Wed, 24 Jul 2024 22:52:26 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=UjGKrOEr; spf=pass (imf07.hostedemail.com: domain of andrii@kernel.org designates 145.40.73.55 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=1721861524; 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=30l0Nzy5VjI9ZJ/8KJLNGnELHLJCo9GumCm2dYcbpXc=; b=Nej94dlpvzrnhqTVYgUjiSkUb6KUDdXFyIG/62no7Qyqp02tnkF+uoMCshebYA7Fnbwwjv O1b6AT/AHb1eib1zRRKznCuMzyneFtJnCllT1kLA9K62SXxFJkM8RLllt58x9Nz18JNHmo o+aalk5yIxGSfLsxwRocYZ4xm2LtXkg= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=UjGKrOEr; spf=pass (imf07.hostedemail.com: domain of andrii@kernel.org designates 145.40.73.55 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=1721861524; a=rsa-sha256; cv=none; b=IkUrm2eOGosxDrOz6HimhyMjtohOeb4h79ak8oIsNUcsXQ7seGwOhO4sYk38yKN/dHMsjR q+Aw0dqO1L6j/p7Gil1wA1Nhj+M1aaxtZZ1MlB6jKpxGO5kTzsIGOrIUWAIbHB06ruidRh n8NKkl799UjdIF+Sv0buEw8ccE3hVRM= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 5792DCE1280; Wed, 24 Jul 2024 22:52:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 826EAC32781; Wed, 24 Jul 2024 22:52:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1721861543; bh=azpAbr+6SOKGRgY4Eh1WfByGTMRsHGb35RAVJRMiCV8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UjGKrOEr8SUACvJMfJ7sDCw9seYAgaMF3ZMxmmZpq4vj4qMYa9xiqeAmuuKoohnBo 7+duYW6MfOp2gbqM7OlYLUwOZZASzT+SMf6Ho3xL2Pi2VfeWd1EAN9VDOf7BXja1lc mjCGPgBTNySMRJpVrFk0vOteGjmcj5j3cRTooKuOIj5POsidfNKxtbMTM+Jf0ZOcGK dq7xrFoHuU8iDX8rQmcWNNDNH7M7TsroTDYTF5aHNuwhOLmlgW/kXUn8YE2RQAG4sh m957If7WczlcdFQOpAXnRrOnl7eSXxJbNVc0s21u2tDNru3WMztTenxeZuJSV+UdDp RQQWSQ+iWStvA== 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, Andrii Nakryiko Subject: [PATCH v2 bpf-next 03/10] lib/buildid: remove single-page limit for PHDR search Date: Wed, 24 Jul 2024 15:52:03 -0700 Message-ID: <20240724225210.545423-4-andrii@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240724225210.545423-1-andrii@kernel.org> References: <20240724225210.545423-1-andrii@kernel.org> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 277F24000C X-Stat-Signature: 5xcffqume9bzektetf3t843c5o7e77y5 X-HE-Tag: 1721861546-379905 X-HE-Meta: U2FsdGVkX18i9kfYYbHJQ3azd1jDp8nkhzm0dFezLAaP9zvaSAo5N13KIYLZHcVuMfnudbo3AInsFS9GU4XokC72A0nd6zZSPh9AaRRy+nBASNQqYFaBM5KZOLlLil7YQKd7zzfjPdaQS0qEcxcxXKjK50tbyuqPE/e+CERUqbw/SqgudU5cBeeTWTAF4sx+zrp9bhoMRATusHdm35/+9CL/Of8y3oQXZ9vto2ums0YtlCzJs3acp5O8KMR5BGCsDQkIxSoj5ZVVCUJQuh41sD/fLiLLUaZfAnYOVig0T99JhjPzCMiFAkijl210ZXwsaz+vFyxmggBTpQ07TX5jyefRK39h9rkI4nSh53KQ9jJNUa/RUBob75GbCSfavFTFoF1czNtz8A80uYcn2aKNjgN1/zRNPy0pYKTpyYJKC00TP4RJT07SPgiYrufr1yd0YJRcif67SOB1ncXn4seVC51LFngT7yS4WuLkgi4tKuqqavO4URI/d9OthZUpYp5CeCCb4I0CRKKdmzIife+gvJusoUCm5eIjwcu3W5ng56mkTAgd2TQHyq5cIt2lpDSy0KrTUVEG09vHQ789XEMAFtr/TTvA59oD8KgRU/xt/ljfbQv/sVYgv8Yu2x0wMjt48DPAYJWL5gBfi1KXiz6aBE9974l23rVzf1uNEv2134xQy+wCDv4eKkzhTR/FCTHcNUWfKkK9rZ8KtBFbAtx+Lh+WcrZ6CoyLkFErQFYnXHAr/iT8cYWw5LjGNf7GSInsVCAMUmMQkcg0090ubooMn9Uhin+gRJ+y/fNHumO3GTR8wUrYchSaFjpUGI5qFfZ//Jb5OcvQcD1EnPOUTvnABq6O4+XmmBQSQ/bd2vVDDnbV8eeW0ZO3fuC4j6xT978ZxKjZ8h+Z3F5yM2MwFTdtsWAqb0UUkOX0RiEhLVTnfAVqdPFFkQKy7+qrIGVjUdIAKLm0Pm0jo1RjaT42Awi mW39szBa z3rkwPlzsMOlaGAcqFuugu5OPmBXtDpcoiHlD17Qe65/Dn4DcYySXPdfIR/iiWCHkrfqD1zllojRJQVGxJpUwknCuYm31tF7YukLSdnlz+2B/uT1wIgstdVxUnLlf9GR3jIusZ8oHr/uYm+AH7H4LdcW/V1iE+0jlPBSWAOPpXzmY5JqVo00om34Dm+gz2jVusNqIlCJQJotOsF9Ion5jD3pmJHc1o7A3ORB1vBLpGlK+Kqc= 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 ce48ffab4111..49fcb9a549bf 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; @@ -216,9 +218,9 @@ static int get_build_id_32(struct freader *r, unsigned char *build_id, __u32 *si phnum = 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)); @@ -248,9 +250,9 @@ static int get_build_id_64(struct freader *r, unsigned char *build_id, __u32 *si phnum = 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));