From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 128E83B298; Mon, 14 Oct 2024 15:25:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728919551; cv=none; b=FsK9zt2i+p9UQ5XAnWdZd8hUIxGdoILCILLqB0DjxDx2v2IVQkHxDAxusQlYqaLdROStPMHoASZuQv1O05lYLKmAimqsdC4yOcKJlsvcb57zvfpI9bf8iik6TOKl75UbczUuHkDziJCS+BRRRS+h4KvaNfkI5xgCyWZS+JsmKSM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728919551; c=relaxed/simple; bh=ucnnpnh1t88k4ho7w3aDBTAA9KU6SWEtIrcIV/yiA8Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=O2cXJM/nPOjROdZ9cLkoYO2sgzgMPqtiZJS5tZVsanb2I20PL0xCyrEd6qg95r4lXlZt4Gu3xvtOGqRg06aMFJUAwMsmGonVDCz7XaSn2ev8bjUr5m4RjphsMoRLG0w6X6vqiSBhtBRSywm/2sGAbWdS8iMP/LJfZPubYa4rVMo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=Y0zW0fDv; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="Y0zW0fDv" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 778EAC4CEC3; Mon, 14 Oct 2024 15:25:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1728919550; bh=ucnnpnh1t88k4ho7w3aDBTAA9KU6SWEtIrcIV/yiA8Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Y0zW0fDvSrKBDXODFxYD1pwUnlhrENYOeeWr8Bns0thWcKYQtu4xTEDpzK4hQBHmt lcoI+izFQ4v5qBc3tdc/EFawhSsL8AJ2yQsJua+4je2wfMd+jyMXmPYnS2GFcYfxPt nOi0iLwsaJid/fTM9CSl6xC69VYlolAqC8N3ZV4M= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Alexey Dobriyan , Jiri Olsa , Andrew Morton , Sasha Levin Subject: [PATCH 6.1 631/798] build-id: require program headers to be right after ELF header Date: Mon, 14 Oct 2024 16:19:45 +0200 Message-ID: <20241014141242.827141489@linuxfoundation.org> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241014141217.941104064@linuxfoundation.org> References: <20241014141217.941104064@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Alexey Dobriyan [ Upstream commit 961a2851324561caed579764ffbee3db82b32829 ] Neither ELF spec not ELF loader require program header to be placed right after ELF header, but build-id code very much assumes such placement: See find_get_page(vma->vm_file->f_mapping, 0); line and checks against PAGE_SIZE. Returns errors for now until someone rewrites build-id parser to be more inline with load_elf_binary(). Link: https://lkml.kernel.org/r/d58bc281-6ca7-467a-9a64-40fa214bd63e@p183 Signed-off-by: Alexey Dobriyan Reviewed-by: Jiri Olsa Signed-off-by: Andrew Morton Stable-dep-of: 905415ff3ffb ("lib/buildid: harden build ID parsing logic") Signed-off-by: Sasha Levin --- lib/buildid.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/buildid.c b/lib/buildid.c index dfc62625cae4e..493537344fc81 100644 --- a/lib/buildid.c +++ b/lib/buildid.c @@ -73,6 +73,13 @@ static int get_build_id_32(const void *page_addr, unsigned char *build_id, Elf32_Phdr *phdr; int i; + /* + * FIXME + * Neither ELF spec nor ELF loader require that program headers + * start immediately after ELF header. + */ + if (ehdr->e_phoff != sizeof(Elf32_Ehdr)) + return -EINVAL; /* only supports phdr that fits in one page */ if (ehdr->e_phnum > (PAGE_SIZE - sizeof(Elf32_Ehdr)) / sizeof(Elf32_Phdr)) @@ -98,6 +105,13 @@ static int get_build_id_64(const void *page_addr, unsigned char *build_id, Elf64_Phdr *phdr; int i; + /* + * FIXME + * Neither ELF spec nor ELF loader require that program headers + * start immediately after ELF header. + */ + if (ehdr->e_phoff != sizeof(Elf64_Ehdr)) + return -EINVAL; /* only supports phdr that fits in one page */ if (ehdr->e_phnum > (PAGE_SIZE - sizeof(Elf64_Ehdr)) / sizeof(Elf64_Phdr)) -- 2.43.0