From patchwork Tue Jul 9 20:42:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrii Nakryiko X-Patchwork-Id: 13728508 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 C9723C2BD09 for ; Tue, 9 Jul 2024 20:43:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 575016B009B; Tue, 9 Jul 2024 16:43:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 522B66B009C; Tue, 9 Jul 2024 16:43:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3C3086B009D; Tue, 9 Jul 2024 16:43:05 -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 1630D6B009B for ; Tue, 9 Jul 2024 16:43:05 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id C1E15121A51 for ; Tue, 9 Jul 2024 20:43:04 +0000 (UTC) X-FDA: 82321388688.25.F95D833 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf29.hostedemail.com (Postfix) with ESMTP id 2A77912000D for ; Tue, 9 Jul 2024 20:43:02 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=UOtP9RNv; spf=pass (imf29.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=1720557767; a=rsa-sha256; cv=none; b=CSQpqzY29rTcWZjAXrVD09c8koiMZ+KqDs2+m5bkm707o1fIUbeLd9KhVm+O4sXRKI/zhd JrM2SMJnlOD/cULf5ENPkMpLvwevQpANzjfDQQetieohfgYqxg68twAxMFHOwShgQXmfIa HLNGCVkC3/+fMpTFP83NKLlqM0g/yX4= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=UOtP9RNv; spf=pass (imf29.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=1720557767; 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=SjQTwZdhmUFKek0WfRSS0Gyg19KBjXt4tYckWW2A4/I0M9is2QOqCAVadqyVxPY1K5//Kw jHl9QQzinrJHu/q7VbZhV6rh7KtqoXGhIxI8Qj0sYvgx4PLFxiN4XPE1POoBcVDfehaxD7 BXGn1gJuRLzLG0Ueif+rwOSYtHP1Uxs= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 4C8B5616BE; Tue, 9 Jul 2024 20:43:02 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D758EC4AF07; Tue, 9 Jul 2024 20:43:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1720557782; bh=azpAbr+6SOKGRgY4Eh1WfByGTMRsHGb35RAVJRMiCV8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UOtP9RNv/JJu5/jCkyS+M9BS7SUxW2ejks9KZ2ihPkFrlS7aAoZk8sxAThaQUKtKe FGTCLUADHeEpuzCEU2WvXjl3bJEeV/6zSrDs3zDGSWTxqoTAHEGKhdKq/h6MEpSHJd 4RcAwWx+IpDrpEJcMitOcH3zc5WznjT4ZXes4BpdcPH2uN/Y7BYcfTRwEQ6buTU2RF iejKag7U/HcGzFOXmA5TICySYvNi/wKo9oM21D58l4OipS1nccsKnT3V257DXvZ9LG hMrwJwzDYuzvt/BPe7NwBXaBKtjGPY3ujolo3mSwaRmdetENQvxL3m4XChvN0UVtzM D94czy+e+RVyQ== 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, Andrii Nakryiko Subject: [PATCH bpf-next 03/10] lib/buildid: remove single-page limit for PHDR search Date: Tue, 9 Jul 2024 13:42:38 -0700 Message-ID: <20240709204245.3847811-4-andrii@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240709204245.3847811-1-andrii@kernel.org> References: <20240709204245.3847811-1-andrii@kernel.org> MIME-Version: 1.0 X-Stat-Signature: aotk5hmpbco1iqqqu813idq5z1qkjyok X-Rspamd-Queue-Id: 2A77912000D X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1720557782-208233 X-HE-Meta: U2FsdGVkX1+RbFFC/yeA4eV17AcKNO1CJJNvSnPLkkAy0yTG00dD2fA6Py1DxWRyu79vxxFK3Djo/FZb6uolFDwx4DTvhVuoMScjM5/YF3i5hhK79fCglA1pWTC1EZrYgLcQT199esoXNfclrOSnXkBTCoCpsq86LGkfYEAQ4HbeUc86Vs1Xc5y6jy50SC9aOqgnM9R999UIL66kCwTj+LCwmErauwuqV0tpC+RmHXrZmRhmz9Xa6/NHvQ3v6d2Q9OR0b0kdek6jy7/K7ZSwSMJME324sR6231JrEbB18yXPGCKgUwLKiEdv7LSK34VQrZNWGJ542N837g9i9lNnxlWk6/06lVRogCfe9Jq4sTdsiEvm3n1ZTXY4bH5vOFthlT8AOuXyEQapVi871E+5mLThPi8CxoXPRecpLBw1U/+jht9MGUhFlTiHNNPxINBK89M98nzAq10DPhdcNyGMeha+Pg4dmnluf2kRI/77+cKRr9tGerbPrX86ffPef84gEcPOMCQUE5G15Vx0wkh5tJth0oX4TJHvY0RJo7njzMyIcJ4G+H7pEryZHd8g1T5+n7od6yokjI+ukkaaep6Q1cHOw8rR5rTdxo9uHpWRjxyfUcVx3epPLQtUgfumuOa7BPhpzl3i2LM/0ujVZqhRS0WJ2+iBoKSunoZTwmiYujuWTvnZ/FgKBOr27QQOKEUZ+Df6G3qKiYdWXSM0eRtrGmNSGDiB152PlhpIHzQFK8bHsvYBDSlaPi1JDEd9xotzBdbxiZYcLtkntA/NmDkYmN+y5tdd+liR409NQ97tfxtzpgBBXUWwdlKoFtKCKJ4x18rnD+Jle0tL7cfK3iXecpZiwvJ2kIOlS2XWrDITyfrajXpRPTt+AwuGgbHR1IDbJ/SunfY+ZemHn++7kLOMOdldrKk6BCkx0SNvDK9VZ0antJOpMRm4Si9J4kgHQsZ4L+k49NV6bnOVkULIPJF L/Tcupn/ Z5nWEedZV4mjiqcfuqtyjSFtNKcvklCSp2AxCjjMoUvLEfg+rfMrnWWuipOq44ucTye3750/fvj4UfgoCNfIPzpaJVKKOcHgk664fPv39E6EOpcWfBXEpLwwdL1MARD0/w0qajy250rMzFXcTGRX9wXjpvGLsbUVGIOV4eRYJJnGae0mKp0MjvYFgTlDAzyKIOJzy+naXx6F93S+3HZdR2VIBY8d2Ds/4YPytm4ei0WZAacY= 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));