From patchwork Tue Aug 13 00:29:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrii Nakryiko X-Patchwork-Id: 13761167 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 C3241C52D7C for ; Tue, 13 Aug 2024 00:29:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4F09B6B00A1; Mon, 12 Aug 2024 20:29:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 494416B00A3; Mon, 12 Aug 2024 20:29:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 336166B00A2; Mon, 12 Aug 2024 20:29:52 -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 1261A6B009F for ; Mon, 12 Aug 2024 20:29:52 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 87202C04FE for ; Tue, 13 Aug 2024 00:29:51 +0000 (UTC) X-FDA: 82445339382.11.E424317 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf01.hostedemail.com (Postfix) with ESMTP id E642840017 for ; Tue, 13 Aug 2024 00:29:49 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="YI/np7Sr"; spf=pass (imf01.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=1723508919; 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=AQMFyLVclZzE0k9dmuhFY5zmWyqzaAw4QB8U87ndMB0=; b=8Nktc8416weAK5/ikZNfDyKQ3v3pEtcM5MYhJJou+qv5mgH3wrtD3ogeWnECOJJ7ek6nMe xjy7/U4BaMXG1CJPHqypdpDvTtek9hWeC/kqergJOstqyBxAQBDnLw3M08H8y9Liys/WTs +VEbrcdvbdcli5PpIoo2V+nNEc1E62U= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1723508919; a=rsa-sha256; cv=none; b=NRKAD/uAszQq1B/sEq/JzKNp8ZPGZwAyWnjEjAF4GZbSPLom6Llh2ciciXWEc6alIrCgXB 3tujCgDK+9RSAzjShc57q90cG2ITW5o94g1mlp9F1D8ki/xzxq95Lr2pgbygEJG/KE03B9 6Hdr+Df+Efgb1QdxzyMaKLCfnAOMBnE= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="YI/np7Sr"; spf=pass (imf01.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 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 2A99E614FB; Tue, 13 Aug 2024 00:29:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B3AC9C4AF0D; Tue, 13 Aug 2024 00:29:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1723508988; bh=nj7ojDVOgz/yh4I+l3hU9jrVg8UwzU+SfIEUQDZjSOI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YI/np7Src3nYBmxFhL4ZN6d1xO6aRcrT3FAsB4drJAL3RoGLmHTRvPDsAS4XA08HU Xhgf+d10QVJzZK//pm3vdl9boA+e1z2Hq9y7LLd++fCP6WH6nAswdmJwzOnW+cGa0r yI/1UK7N3142yRwE6Q9DmQHGr9pbHrBkCITnprxtuitLIxseAMBn+9/DF4ur6I4zQy ju+7cvhH+5Nybrk84ux9Wr0zlbNDhdL3wii1SW216oH2pIgI9iz0RhIfJtudv+MOH0 NsA+MGh9R3G6h2jsjPnWoQsiuL+lJS2EmhA+FKu75crSt8AmW4bHOLH3tjZzxJq5Rt s7w7jFFxwILyw== 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 v5 bpf-next 04/10] lib/buildid: remove single-page limit for PHDR search Date: Mon, 12 Aug 2024 17:29:26 -0700 Message-ID: <20240813002932.3373935-5-andrii@kernel.org> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20240813002932.3373935-1-andrii@kernel.org> References: <20240813002932.3373935-1-andrii@kernel.org> MIME-Version: 1.0 X-Stat-Signature: ytkjukm77chgqf4nh6eo9uhjxaunpzx7 X-Rspamd-Queue-Id: E642840017 X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1723508989-723024 X-HE-Meta: U2FsdGVkX1+kFXl86GxQVnTPmvn+nLmD7hgB1y7cf3oi6v7JjYdrE/lGJ7pvpEKwfA2gMumuvezK0JOd8MWzSaY1Cnd4QTyYrnf/+RPnBS7Nu1l/Fn2Rp7Vup6f22NZwJYHHDDnquOZkXLot9DxXnjoW/9LYpAy4FLMNmOnS9rzjn27szMF4DS+g8w/gnhEToqIQO8j6TMBn2DppAg+DY//eeojmLpcaHVZ6NCVw+87GBWQF5lzYKEDvj/qAVax5bkzRFtzrDOR9yaCov94ONUStNi1lF6XnqxmoThVqgyBXA8EwxBd57zX0uVB2nUOKOa0OcMIHLPTmcAyK1SC6qZ00uE8Dvbyfa6LTvQwQj2DGKF6AppaMbT+08bSWQkj2nwhRz5rEydStnvymk/84dA6RqA7obcqpQe2lhQbVSsVXkt1d8Ujgl4Ag4BXQS/7iO3ZIeEEagvhT4lEG/zHC0BHBQvOQxZxqyH9jOdXEijb7y+SPEjFHMfCKVzJYOpCO33iYnMBU7EhTpSv6z+uNPZgeszYXD7ZkBNINq3OqcAkvr8M668dy8XLweUQiymDqkifKbUlBdHeX+kZGqtUQqNoN3wuTIKH7n7xA7YVYJzvrnHOD6Fs+UKIcsNivpdM9FbOBhlRJ7LInG4kQI9DuvBLVsByvJtWvmRpZ65wypst4W1a32xlXntsXqQbl1fX8M7Ey2yqR7uvVq8mfdb9HXHkdiMB7HtnMc4h7QllyPEb9X0d/6Zk9PQb23OZFjqw4VjhJJsmrFhFQLGoaI3pvAyJ+uDe4VQRAG48S3SFteDyknkAF+/PXFTLGu4cz4odzrC+KrLx+YMKcue6OZAvJTCrrlwLRW8l9Uz9Y4tPT+5R4k4RznGutGuAb5JMiFX+l2qPrl3JKCwMuihknA9B3iQDJy6gDhoBI4idCyTTV3F/C1Ik/xOhRZ2SAuY0rw39+hwR66Pjga5BmL7OcYrW xW4oVdEJ pAliNlPffu0BfR3a0LLDERVL2rTaXF5KxW9QSccLJMhnTXHE4Zdu4u4djE6p3m1aRJsWqefAt5UQ8I8yxMWVzHSziIQS6aKRhhkMssw3Vhx7HV4BnuwgJxt9LGtdUk5RICVbXuw80br4s94T4MJUjVt16fCi0roPGfs3wOayRXLuJGNTqHLtckoz35AzdpQu8pgFQwQ3D4HistiC/Ogkkx8Z9MgZwS/ZmhIIGUhN+t1Q5fEM= 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 abf5d1c7eb47..8296428ff82f 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)