From patchwork Wed Aug 14 18:54:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrii Nakryiko X-Patchwork-Id: 13763842 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 93BA8C3DA4A for ; Wed, 14 Aug 2024 18:54:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8FCB96B009C; Wed, 14 Aug 2024 14:54:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8872B6B009E; Wed, 14 Aug 2024 14:54:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6FE9E6B009D; Wed, 14 Aug 2024 14:54:47 -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 54D676B009B for ; Wed, 14 Aug 2024 14:54:47 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id D58301C4892 for ; Wed, 14 Aug 2024 18:54:46 +0000 (UTC) X-FDA: 82451752572.10.FF26C00 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf21.hostedemail.com (Postfix) with ESMTP id 47D591C0018 for ; Wed, 14 Aug 2024 18:54:45 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=P2oqJnxL; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf21.hostedemail.com: domain of andrii@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=andrii@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1723661672; a=rsa-sha256; cv=none; b=20Qxjk23Xd9mI/DtB68/K2/gKmk3okPHicrl0CdHI08wOK4Vc7LF94HwDFzHvqMksuOI4O BhaABC0DISOTw7DgnHUPzIigm70HnPQR/OpFeofRFbJEvgeqQZekaFpQxCT+5FBYSPsGJh lQ6wbBM+IqfBulmmvDxmE9JcOxm0I/s= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=P2oqJnxL; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf21.hostedemail.com: domain of andrii@kernel.org designates 139.178.84.217 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=1723661672; 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=9YiQaCoghCsLWmYlkim+fevjXSaq+VK3Z6NDIW8idvo=; b=lLQNrX3YKh6oLha1lR27Yqxcg0aW3DBbGCqzhp82IOzmu2dvQqGMBcox+iG0ZEcQGvRheF UXyx0tcezTIHYLMz/rxxgP/XGSj43W1nqPTTA9TJ2uyesKJD8XcPhkkDDR7MYqpckQdV0F MVsBNkDL5GY45Dk2eM4RNdnoZV0GXqE= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 527D561B7A; Wed, 14 Aug 2024 18:54:44 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DA7F2C116B1; Wed, 14 Aug 2024 18:54:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1723661684; bh=qWFr1Itiok941tgbEAKnQiv3NKSiQ5xxi7FLGt3tlz8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=P2oqJnxLIfziQGtAWipaX+42KrmgI7kmyiGn9lCHfQ7YV3hbZPyYqp1qrq0nJ7X4J vu2YQPTDjpU8CpoWnwkvkyZAWwGTy44DuRUGgLazKDfdZroDOHFMuBgtlmoT9Pq65i ltaSyU8EaRPg1S3AE6xw0mNfdUbufjlcwoYJtLc8UrEiv4mxakxwHH/B+W14kqzcFi jBxGbO6vK12zWE6PV7P+e37JNhp/cl63EZ8saqPP3DJwHvbmVpB4F6D7WZt3nwhJRT FJDhOUlK2ZI00qVZqfD/TQAWgdi7nVUz+b+2uKyg2KAfoEOgZ1UlCgVBYRVgd97KPR erJOLImS3PZzg== 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 07/10] lib/buildid: don't limit .note.gnu.build-id to the first page in ELF Date: Wed, 14 Aug 2024 11:54:14 -0700 Message-ID: <20240814185417.1171430-8-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-Rspam-User: X-Rspamd-Queue-Id: 47D591C0018 X-Rspamd-Server: rspam01 X-Stat-Signature: tyh6ggfs8uz678yd4uspb8f593hr4urj X-HE-Tag: 1723661685-687222 X-HE-Meta: U2FsdGVkX1+2Z8miqjTL8Al7rZerSOWMJLxTIrFaSpw0h86P9aMJdrF9wWonDoRoa5OELuxQgBdWUo+NQQVMxumv6MJ/AnqdBTtPBWrbB9Go6va1QXqVqv+9NacNTd1A+dFIoG9xM45CTZaMMJ3qRK3pjjGlFj2J2dWFe3tG8yNz01zXH9KUMUg1KrmbArRKHvjFO4bXH61gXacm7rRSAkHOUkMH49ekyUqygr21c051WJiA24ruoR0+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Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: With freader we don't need to restrict ourselves to a single page, so let's allow ELF notes to be at any valid position with the file. We also merge parse_build_id() and parse_build_id_buf() as now the only difference between them is note offset overflow, which makes sense to check in all situations. Signed-off-by: Andrii Nakryiko --- lib/buildid.c | 26 +++++--------------------- 1 file changed, 5 insertions(+), 21 deletions(-) diff --git a/lib/buildid.c b/lib/buildid.c index 5da5a32a1af8..b404b89f61a3 100644 --- a/lib/buildid.c +++ b/lib/buildid.c @@ -153,9 +153,8 @@ static void freader_cleanup(struct freader *r) * 32-bit and 64-bit system, because Elf32_Nhdr and Elf64_Nhdr are * identical. */ -static int parse_build_id_buf(struct freader *r, - unsigned char *build_id, __u32 *size, - loff_t note_off, Elf32_Word note_size) +static int parse_build_id(struct freader *r, unsigned char *build_id, __u32 *size, + loff_t note_off, Elf32_Word note_size) { const char note_name[] = "GNU"; const size_t note_name_sz = sizeof(note_name); @@ -163,7 +162,9 @@ static int parse_build_id_buf(struct freader *r, const Elf32_Nhdr *nhdr; const char *data; - note_end = note_off + note_size; + if (check_add_overflow(note_off, note_size, ¬e_end)) + return -EINVAL; + while (note_end - note_off > sizeof(Elf32_Nhdr) + note_name_sz) { nhdr = freader_fetch(r, note_off, sizeof(Elf32_Nhdr) + note_name_sz); if (!nhdr) @@ -202,23 +203,6 @@ static int parse_build_id_buf(struct freader *r, return -EINVAL; } -static inline int parse_build_id(struct freader *r, - unsigned char *build_id, - __u32 *size, - loff_t note_start_off, - Elf32_Word note_size) -{ - /* check for overflow */ - if (note_start_off + note_size < note_start_off) - return -EINVAL; - - /* only supports note that fits in the first page */ - if (note_start_off + note_size > PAGE_SIZE) - return -EINVAL; - - return parse_build_id_buf(r, build_id, size, note_start_off, note_size); -} - /* Parse build ID from 32-bit ELF */ static int get_build_id_32(struct freader *r, unsigned char *build_id, __u32 *size) {