From patchwork Wed Aug 28 21:43:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Wielaard X-Patchwork-Id: 96643 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 35259385DDF8 for ; Wed, 28 Aug 2024 21:43:17 +0000 (GMT) X-Original-To: elfutils-devel@sourceware.org Delivered-To: elfutils-devel@sourceware.org Received: from gnu.wildebeest.org (gnu.wildebeest.org [45.83.234.184]) by sourceware.org (Postfix) with ESMTPS id BE3313858D39 for ; Wed, 28 Aug 2024 21:43:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BE3313858D39 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=klomp.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=klomp.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org BE3313858D39 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=45.83.234.184 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1724881388; cv=none; b=sP53a8e1lrx5q6awY8r2pRT0SrNuQsATJ8UsMSAyIteiHpqrZqMxJBmQbX9asV3XnCD7KSoVgF/vgJOehN2xajQ7geTF18WF6/4zC5ZdNAjXh2rmMNxTvuCUy8WUr4mRvY7QvbJJr1Kgx+YXGbU4yzqGIG7AI4C11scHlJNxzI0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1724881388; c=relaxed/simple; bh=duzSm4s/NOXR1ceZrD4JFD4bHN4vu9+EprmbukUTX9s=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=nzk7NR+IfuBPIouNEUvuk+am2cYk3jW4YXUmbSCGi4slbG3dZr6ndP2FYL7WaRvo8JjI/8QNXB/XeN4ODjfYv00ptXlgCiM4m0dsbugp/FUy8PdM438Ns3hGaZd4xN3XA7Nnkbx4TkUP97yS7vXrLmXYLAA09s1mmjCIUSobghg= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from mwielaar-thinkpadp1gen3.rmtnl.csb (deer0x08.wildebeest.org [172.31.17.138]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by gnu.wildebeest.org (Postfix) with ESMTPSA id 8E920303AA16; Wed, 28 Aug 2024 23:43:05 +0200 (CEST) Received: by mwielaar-thinkpadp1gen3.rmtnl.csb (Postfix, from userid 10916) id 5B1ED3BB746; Wed, 28 Aug 2024 23:43:05 +0200 (CEST) From: Mark Wielaard To: elfutils-devel@sourceware.org Cc: Mark Wielaard Subject: [PATCH] elf*_xlatetof: do not check ELF_T_NHDR[8] has integer number of records Date: Wed, 28 Aug 2024 23:43:02 +0200 Message-ID: <20240828214302.367437-1-mark@klomp.org> X-Mailer: git-send-email 2.46.0 MIME-Version: 1.0 X-Spam-Status: No, score=-8.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: elfutils-devel@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Elfutils-devel mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: elfutils-devel-bounces~patchwork=sourceware.org@sourceware.org commit bc0f7450c "elf*_xlatetom: do not check ELF_T_NHDR has integer number of records" fixed https://bugzilla.redhat.com/show_bug.cgi?id=835877 But only for xlatetom. Do the same for xlatetof. * elf32_xlatetof.c (elfw2(LIBELFBITS, xlatetof)): Do not check for integer number of records in case of ELF_T_NHDR[8]. Signed-off-by: Mark Wielaard --- libelf/elf32_xlatetof.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libelf/elf32_xlatetof.c b/libelf/elf32_xlatetof.c index ab857409329a..ab3e609ee5d2 100644 --- a/libelf/elf32_xlatetof.c +++ b/libelf/elf32_xlatetof.c @@ -51,7 +51,11 @@ elfw2(LIBELFBITS, xlatetof) (Elf_Data *dest, const Elf_Data *src, data types are identical. */ size_t recsize = __libelf_type_sizes[ELFW(ELFCLASS,LIBELFBITS) - 1][src->d_type]; - if (src->d_size % recsize != 0) + /* We shouldn't require integer number of records when processing + notes. Payload bytes follow the header immediately, it's not an + array of records as is the case otherwise. */ + if (src->d_type != ELF_T_NHDR && src->d_type != ELF_T_NHDR8 + && src->d_size % recsize != 0) { __libelf_seterrno (ELF_E_INVALID_DATA); return NULL;