From patchwork Tue Aug 13 00:29:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrii Nakryiko X-Patchwork-Id: 13761171 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 854B2C3DA7F for ; Tue, 13 Aug 2024 00:30:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 165176B00A8; Mon, 12 Aug 2024 20:30:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0ECB06B00AA; Mon, 12 Aug 2024 20:30:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EF5376B00A9; Mon, 12 Aug 2024 20:30:04 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id D10B76B00A7 for ; Mon, 12 Aug 2024 20:30:04 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 4F95C1404EC for ; Tue, 13 Aug 2024 00:30:04 +0000 (UTC) X-FDA: 82445339928.12.E7B8A22 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf18.hostedemail.com (Postfix) with ESMTP id 3DDC21C000B for ; Tue, 13 Aug 2024 00:30:01 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=CSIuTR65; spf=pass (imf18.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=1723508932; 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=lxwDaike7t904dBFVG5osPxj4hb/83rOGME35OaH+P0=; b=FYG/yl8wlQGkV1ggMPbUmiNO/UZK5zlyosJkc7j7jAcLTBr5L1+8TIjvI00GtP0ldb2KnY Ho9ff/aV2J/cSzoq+dnEh3LFiHlD2VAfdMdOPH6K5YBqNj/o3uxJ3YPfVA+VlGjGfZK4Al 6ROGGRyC36atHq6RQNkH8rEkTxm9AuQ= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1723508932; a=rsa-sha256; cv=none; b=ywArOVgAvvElzuM8EDRy51/JO0o5uiFB1WgaUulhmDOZdIPgr7LsNvGYXPZhsy+wbo4r+t 3aDVcWQQGYxIkHP+BUNcMQSzv4gTD/65Ep0m9lndpMb1crGzpXkFjTDYFlLkl+m/sdK1pJ bwO0Gb51Xb5ldaA0ohOQyemHzV5h7R8= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=CSIuTR65; spf=pass (imf18.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 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 634F6CE10FC; Tue, 13 Aug 2024 00:29:59 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 717F9C4AF10; Tue, 13 Aug 2024 00:29:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1723508998; bh=/aF9doTSwVxK8vkPFzpWOWPf6Y2a+7ple020IwwLDSw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CSIuTR65Xeh7z7t1hE2mLF8gqKL8SUrC6KKO1sp3imVjDaj7n1StQQTBeiTnQvvZ9 NE4meYoSfiKsHoRg6YKXW8JY975TdfKaD20mIzyYa6hDJbsDZo7xX8Hy9/J2WU3MN2 djc03c+xYkX8D0FFlUTuWFZHmqv0lN1ft3s4jf9l5nRDH/3JpIli5CqO38RPbb/9ec YxBNNXOM9Q7SZSsk4CbDavbZFJVXLwWEvPctCtkoKv+uFbu1wwXSeFTe2DeDp1WzjR qs8rR/YE4e1U3XqRd+rvjmyck26bukq9fLRKDiCqyP8u+nW+ll9zfmVn8Z0qOSeiiS afMvKeW9QS8ow== 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 07/10] lib/buildid: don't limit .note.gnu.build-id to the first page in ELF Date: Mon, 12 Aug 2024 17:29:29 -0700 Message-ID: <20240813002932.3373935-8-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-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 3DDC21C000B X-Stat-Signature: eiewjendm974bfsyp3z6mtn4pg4ae38o X-HE-Tag: 1723509001-296544 X-HE-Meta: U2FsdGVkX19e9ng62JjIYTGDs6YPfxAXvdrMFVLNi+Hx25y+fxZ5GpnwpWSrCsoLCgTwQ9K6iYSROFloPyAU3rFpx8zZQLAWuyZ5I31LnqP/hyyYAwgp/mfJg9lShWbfeUJh8hZNcLKZZ1KPqXssVGrWrLygQYzGD7dIRWVJJszxYuEARyFzu6nBD9F9fG4Uz/DtTnK1BOVzzIw+utNAi2ekFB/iiQ8/4YNui5VQAttWiDfingqrwv8gES5Br97C0Dp7xdZ31GnGXAoyPYTDoBZ/Gc7diC8QTwIXBqjFs0AlWOVtvNjS+MLZyIiNFqsJgMgqi+BXO1c+Jsv8qxjD2hjRhboVZIFu+dD7ACC2HIGidqGtlLZBNyyHSYVgWFHPd6504eR1Ph8AfDC+kQZjfIRm0VRdgwzZ5fCLE8QQl9es7kRGGSoonCoACFzSTq8JbQfBsYDQtlfhp6RQtVITETzZN5KMIsvPR/ViPuHZsldYf+MaYEJMcAlA9Yy4N+MJPyX2WTr2U+aHdLVPj6RNfPFmTXw5FKad5glNyQEw9HwBoZzH/j1maGs+7IqsvUxvyCRdt20wpkkdYdb3pL4bVWrIN5Na67m6yJww3JYs9ss2WNoLNxTSGliPqyjDkftjP+xh016r/p0XKkZmV0AWmUJ8pmZnZWtJpb4lmy379BslulDGwhK5dNItWRdy83UpNJAxtyf9E2XmduWQREDdlRrV1L0NCNTDk07in5Ns5kQIfJ8MDVbBYu5b6NxVDqNaP0+s88hRe25m6fHa0sXmy0vDqvO/cYYrh1+QdQC3vgew+smsDhno1y6ykxtPw724wnl50umUNEAwRBHmOcZcGy4vynpFJSwTjMlGoaj7bziXl35rdXo8KX4agwDDAp6VEclGu6CXAS18HMJErW2Kx3gikQLqbLr8nUX0ogQtQ0ywGSsGXfndc62DZDVoyu19bck8/zcKEqUMZpQh4x9 ok1RZP4z b9/1BsmjohRGX95F3xwy4s3Tw/xMCfbJDIiFICLBhshzt/kr5IaDnxV/MY4V25TUHjzBSo2IF5H924peW/OineiDk7p/eHs+o7j79mioiKYnHZ90Srv//399FvzxVoBhFfqpXt10iVxpJ0OXGExlVG83jXeVdHSN1ZsomK7g54b3DQSlNPpJiN/0J1EBl6+99Z6y9Sr0J4LiH5m+jLFMmoopa5kQdfbWML87EixjphPhqXv23u1n8l1sorzn+LTCk3sJYI3hOHw0s7MI= 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: 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 e78bef392cfd..3f7a588f7fd2 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) {