From patchwork Thu Aug 29 17:42: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: 13783514 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 ED01EC87FCD for ; Thu, 29 Aug 2024 17:42:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 542926B00B1; Thu, 29 Aug 2024 13:42:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4CA696B00B2; Thu, 29 Aug 2024 13:42:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 31D9F6B00B3; Thu, 29 Aug 2024 13:42:52 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 021AF6B00B1 for ; Thu, 29 Aug 2024 13:42:51 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 9FCABA11C2 for ; Thu, 29 Aug 2024 17:42:51 +0000 (UTC) X-FDA: 82506003342.24.361DB27 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by imf28.hostedemail.com (Postfix) with ESMTP id E1D31C001C for ; Thu, 29 Aug 2024 17:42:49 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=Y13JdG8x; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf28.hostedemail.com: domain of andrii@kernel.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=andrii@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724953297; a=rsa-sha256; cv=none; b=tKTpgKvcmCqXD+Zb9OqSXpjj6scfRFVZKcSZN5u0gaF8EpvAL0tA5IrnQbcZanuaCDWJYc TW94ceZ4aTD1nj4rPknC/rdFyY7Bq6uNue+FvCFSMjCppKJFduHv5CGgs0kG2Fa6qvly/R EIwwoafk1WVvOBeSdmTYS/GDvbg6Aoc= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=Y13JdG8x; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf28.hostedemail.com: domain of andrii@kernel.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=andrii@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724953297; 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=D6qr6cjavPLmp//bC38sq+z7dCMkMMFwxvjl4VMnEpk=; b=yjfdXGLMsSYM+CXnK4E5/b2LHH8W0z0MQuVvI141Ib0eDHj24iDXemxpWSuOHd827cBcT5 xxx8rwEkK8WW65nqFi6wRMNeTCTFO3Z2EX79foK2vSQP/m2rrpoRvcwu7Pb5LM91Lm/i5U Ge0TjPA5wBYM2041jwIKAHSrJjx6x8k= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by ams.source.kernel.org (Postfix) with ESMTP id ED964AE2CA3; Thu, 29 Aug 2024 17:42:42 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BC5C9C4CEC1; Thu, 29 Aug 2024 17:42:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1724953367; bh=5CLcAmrYIJlnXm0mQvpn/y1HhZ+JoZho6ovLxlNSww4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Y13JdG8xb8iuDxI4s46rTFLZcD10pfqV7vza38UzKeRzQoCwxEVNo8hA2eTGhuETW Hyaadvu2kZkMMtxCumBkixN0Xvv5Y9MbdYW8QWzqfeg8ltNMJoiz/vf94PsTyv8uAC oneOA1xwnIxNnE+vQFX01ZZQjSWinI6oygsunq7alY+uWLbMljQTmMdnde3Edi4a1I vYivD6IyJT7izocTWPg65srGF6Py9G66+mTfeexfdBLnjehN5cj+lktTmyamZTWuhU /98hLgNJGq6USK0h7pkav5KZ6OCiM901bnwTnvOWgCbFm51BIy/pG8ht7rZrKJkbXk EDBG8rM8TzYAA== 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 , Eduard Zingerman Subject: [PATCH v7 bpf-next 04/10] lib/buildid: remove single-page limit for PHDR search Date: Thu, 29 Aug 2024 10:42:26 -0700 Message-ID: <20240829174232.3133883-5-andrii@kernel.org> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20240829174232.3133883-1-andrii@kernel.org> References: <20240829174232.3133883-1-andrii@kernel.org> MIME-Version: 1.0 X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: E1D31C001C X-Stat-Signature: zndcfrh3t9s7d7z459wfwrutwhdxw1e7 X-Rspam-User: X-HE-Tag: 1724953369-349792 X-HE-Meta: U2FsdGVkX18eFXnqiqlSJl2kG6F1/+UUiP6Vhxn5WM+C7xXObkPbpI1NYB82ap/lCrq4QqyUKzibhlgzZYP9aIc2Y+9trE8GGSvDVwCOv8WxytZyKl9G0iLLUhKDuWAVpf/L7Fpw1pTGuIT/fGKFhwi7anE7NZHy5cBxE599s6Ad3+prnOfFZ+9rCnXiIO6LidTRjy0pzEHrXgKWdZWZkAPfoDw2H8TagF8HBN+Ck60ffcehiYOPmR00r6xqIEqxILr/znIG7Tnypo80X+7xqyWTUEjomQXjnqqJ7dXXK0jKPpQICXHb4k/ZrL5Qa3XilkwWZPcqk2QYfSzuV97YOo/CK9pBzGLFQxTCcJUPMbmQkYWEP5EmEJIcwiOPS2gH+k1/ixCHWPTKQ96sWU50ZAMM0SxRvl7djmb2dpvN7iyv86QDd3p2GpCi/CfgPeQOJABuw3eJ8w0n2mLiY1tL+QwH+vKv/2BElg6QLIZJiQ0PTA/zguv+4Am5DEY7J6qRPsdUOg9dM4k1IkJLBpb8Y7WS4vl35nskjdUDc2BTC5OZqGoPZMGKhN4rmJSmM3E4v48+6QsekZNNt8LGPd2/o+awpnBttylUR91LbVp8dZVV0xZoZLfG1syO568GnUWv2mA7qr6JKeoDYvcYMviAUYY4TO3jnIS8yhHWy/B3wDu+bqbAcaGRgPeum1MdeS6OA9zA6yrf/XMWmMSufRPYzGxZaFrxSlUizR+Gofxpbko7u+UGy8EQTgHyDEV/+DQLFuEZV78k7ZSaTmUnvtOWpasxp9Gc/DkGSf1mgbhYn3xsvfHUw1ugmYXP+/v8KXVjqabLjzctDON7ZmZ2XDqkEEK4F0MSLYUkzx/h6NLBFiIoygl7TiV99rwaBVkqcZF7Xiy2XyUC2wyhVdGosmyTMN85nZ03esJfIH3EvK1Xb1x0vFaiIp5jQkEufP5jON0rl6NAvWmcG4IAk7L90S3 S2HTzJ58 FxCBQqE15n/brLVpYike/+RMZ4SmxOdMw4fo7ThOWJUHt4SwWyIojIwfaEE4RMpr659FBJrrnuUuihd5NEfBoPIeHfO2muOlZef1nTlXJEV4apFwt87Jetpare1GDIaePfRZaiKFw3eJVQpDzFPyslybrSbCF7zNqMHVnfcYiMJ5sMrYb412z4FhugPDNSVwziZpzyXzDM++BVO2NnEZnsUxEbSbAbXd4Bug3Ry9NL+1/aj+22i/4yCajTkkM67W76chW 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). Reviewed-by: Eduard Zingerman 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)