From patchwork Tue Jul 30 20:39:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrii Nakryiko X-Patchwork-Id: 13747870 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 13864C3DA49 for ; Tue, 30 Jul 2024 20:39:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 980EC6B009C; Tue, 30 Jul 2024 16:39:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8E1176B009D; Tue, 30 Jul 2024 16:39:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 734A76B009E; Tue, 30 Jul 2024 16:39:46 -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 547886B009C for ; Tue, 30 Jul 2024 16:39:46 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 179D3A048A for ; Tue, 30 Jul 2024 20:39:46 +0000 (UTC) X-FDA: 82397585172.19.5BF6233 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf05.hostedemail.com (Postfix) with ESMTP id 18EEA100016 for ; Tue, 30 Jul 2024 20:39:43 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=cdF8aL+o; spf=pass (imf05.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=1722371957; 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=R/qI/s5JXHyAce2/cYqT4W+1cshjIee+Wb6EkhER37I=; b=oKM0Rup/eYeVk8/Kkzav9GywDTd/+0kxh6NKTG+EyZcLMbhe6NYj4HTFPl851hFwYtzYkM evn0SBi+ahpR+apKbExi+mch+nbCzHGJDAQMQsOrDzrCriY2Wghf9KZJ44gU58MR8CYwHA 1IQvqtKx8W7YwaDkbH4KZHRR3zDdSaw= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=cdF8aL+o; spf=pass (imf05.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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1722371957; a=rsa-sha256; cv=none; b=ohYl35UT8QQJ8GDFVOQw07mo5HQTXJoL7RveqXpNyfEU+IfuY2VI2MGc+wPvK0U0v/1aAG INA8YDkBG6YjzbYAZWhkqZAINfE2J5Ug1UZmCUblX2Qe80zUUAeYAKnY7lUYLVsNGADyQJ MULgftfFwi3cdQCHhPlG5H83URaQwo8= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 82D38CE116D; Tue, 30 Jul 2024 20:39:41 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9E189C32782; Tue, 30 Jul 2024 20:39:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722371980; bh=L5Vw+vnTqV23U/YAvF1BJ8hsl5vO8thQWupiLEtL3t0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cdF8aL+omLwMD7juVUd9qTLY6t8I5+wuqDBQM6vN0qVd3vJssbaT6H57XKDCpvhWT BHdr0BHNHgGo1BVoybKHiQn+Gv/W5sjGXkVSmDlZIR+WQVV72ezblveJT5HZSGu6// 8hh3k83fVGCphdLC/DPDTE39Xk/wKQf4sjxssYJ6OUhNAVDS/CwarwoFm/n3i8f28C tCK29d9yFVLjjTqf7pfb0FrQpe57Kc+qBOC1AiDG7295hAENyV6fRc2B71owh7cg+3 889a0VWLJAg5TFaPsoMvSmdOeNgCCeEpqGA9DG9XXIHJn39/COyaKfM7dcZE6mJQ/U MwX2ScXQHjamg== 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, Andrii Nakryiko Subject: [PATCH v3 bpf-next 07/10] lib/buildid: don't limit .note.gnu.build-id to the first page in ELF Date: Tue, 30 Jul 2024 13:39:11 -0700 Message-ID: <20240730203914.1182569-8-andrii@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240730203914.1182569-1-andrii@kernel.org> References: <20240730203914.1182569-1-andrii@kernel.org> MIME-Version: 1.0 X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: 18EEA100016 X-Stat-Signature: mrm4s7mto1npj4mo3w5qiycqg47pctqd X-HE-Tag: 1722371983-291810 X-HE-Meta: U2FsdGVkX1/hPrNK1UdJwKN+0EOHn/7CfkHdMSvU9AqgTa5q8KYtt6X8lsynsIuxpE7l+6S4YsTjEeMR4uoZ2VopTy/B8+WX7UdVqomEXc0nAZ7fbviP4S5Q98AIuyQpDAEFoJOSRQKIwJ/EX85tYTIO2+880LBohIawvUhDCXkd9LTv36kSghkEg3ZYJnHyGG+gh4pLX0MbMC2wrOFn02Np8fb0u8rr0sP4sTwrib5Fdg8VwDFnTJxOX7sgr4ZGUE1mI1AiZUp31NN+HFSCKEqMSiu7JNG3C4ZXoVsC+LYvqwq4b2PCjgGoqROxxpKtMb2BOLyJcCsdqho/IMe2mAP9AZjNvOgxYCOeaOMHFrG0qRuz7Mgwc1x5yEHV+4erOG6Tl0A/sM9l5CkXfAZc6Mt8dCNZtUm6rUn1Y+2/dfKIhpl+uIDlPHnljE7lwU1n9ivYKAmt6akKVXPc3TJpKgemA+HSHMOVPwsitTuAwQOzCez1F6hw6Z31bM5pOCaxOmZhu+wio/zBw5cLBuWiJKBCEWRaGER4EwQgvfdl1lo85ehJnXjpfIesgxoeCJcb9vvEeQ1I+nT9/m2M2kLa4z8bbFbK8U3dmogZgbYkJvnCNyjEk98tsRxiP9JtoAy7GG7KkIvTV/PVIN87vCVVjQBnIMdwLcDtuRVVRycGkyIFxrtmd4o7Foc/8GxKkGseCC/bJy2CSxenS1CetaAvD4fLbhsvw4+wmR/00pUtJ+MjyBITqtckAD6y4TjXE00DVJYFh7fC22UT/C/bqcHG/WSWQaHnybdalVfql8Ds+SCr/9OuqIOAZBxqLMjjdRNZE4l/Kg40MFbBEv6KT5kg6QMS1r8tVma2lQyTnarXlIyNZZ5hNdAKEBvVigdPBJ5+gHmsTYUPa5c0NQCK4PFHdFM63m4ULZ3PYjdn32Tsef6QeAbseh5i0+iNY+gLau9UePxhtLr1Y0+A6m1UNNh 0rXH2TQU K9m73v6Lz+PxBJRVdx2zuQphWP2pF59gicLySe2LV4hIU2chyFKNpjylau5HsuwQKr9wwbJgLHrrY0MpLWR9AIfkRthZaI5qg3ya5hVk+wxxuzMqb6X0ivHKxjcnUc5iwndyxJNsMQqCTV3PUsGXWQj7opvB3K63i1496wZXaQ2Xt04WiPYjH8pXlvwPvsajvZg4UQnCW6Ny0Ax8td8SKDmf8zFFz7RXQdHU0le3jqI0tM+c= 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, 6 insertions(+), 20 deletions(-) diff --git a/lib/buildid.c b/lib/buildid.c index 6b5558cd95bf..78cfb3048385 100644 --- a/lib/buildid.c +++ b/lib/buildid.c @@ -155,9 +155,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, - u64 note_offs, Elf32_Word note_size) +static int parse_build_id(struct freader *r, unsigned char *build_id, __u32 *size, + u64 note_offs, Elf32_Word note_size) { const char note_name[] = "GNU"; const size_t note_name_sz = sizeof(note_name); @@ -166,6 +165,10 @@ static int parse_build_id_buf(struct freader *r, u32 name_sz, desc_sz; const char *data; + /* check for overflow */ + if (note_offs + note_size < note_offs) + return -EINVAL; + while (note_offs + sizeof(Elf32_Nhdr) < note_end) { nhdr = freader_fetch(r, note_offs, sizeof(Elf32_Nhdr) + note_name_sz); if (!nhdr) @@ -199,23 +202,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, - u64 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) {