From nobody Tue Nov 26 08:49:31 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1709463184; cv=none; d=zohomail.com; s=zohoarc; b=Z5NPXV+Jo5zXgv6DzWDbf8h1BKCaisrCn72QDStnw3K9q2AJpbX1QpXTr/BnLuak8lSRcfT8GmfWTzGNXOSOma/1Pj0cLJrENMyh3SHr4mayE77+Ekqc3f5FmIruCqsTxGHPGbVkkjaICP+6GLcDms+cK0A5F+hl9SHAA0sE2LE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709463184; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=8euAnCNzIztjXeyNg7DMouGQMP5MoiXBmM3i2w8JTRU=; b=GhXD2X59vB8vmKXsPyqbGdOeT3qwJxWN+4HDnt3L31+or4O/p5WptxrPB+wdozpb/BJ4xkYR0XBa4sBDSy7sT2mQwsvy5ZjTPBPpSrFKuUCGRg9ODNUHCXLWE16U6Lho+RiaR7y/dWKnOVtp8VZn47iVIpNbrwiY+APDird4aXY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1709463184298816.1013817987119; Sun, 3 Mar 2024 02:53:04 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rgjRD-0002Hj-GX; Sun, 03 Mar 2024 05:51:23 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rgjRB-0002HG-VW for qemu-devel@nongnu.org; Sun, 03 Mar 2024 05:51:22 -0500 Received: from mail-pg1-x535.google.com ([2607:f8b0:4864:20::535]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rgjRA-0001rN-UV for qemu-devel@nongnu.org; Sun, 03 Mar 2024 05:51:21 -0500 Received: by mail-pg1-x535.google.com with SMTP id 41be03b00d2f7-5e4613f2b56so3291781a12.1 for ; Sun, 03 Mar 2024 02:51:20 -0800 (PST) Received: from localhost ([2400:4050:a840:1e00:9ac7:6d57:2b16:6932]) by smtp.gmail.com with UTF8SMTPSA id kz16-20020a170902f9d000b001da0a698095sm6456090plb.282.2024.03.03.02.51.18 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 03 Mar 2024 02:51:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1709463079; x=1710067879; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=8euAnCNzIztjXeyNg7DMouGQMP5MoiXBmM3i2w8JTRU=; b=ZUm6bv9Ule0ReE74AFoPw3lJBh4DV0hIeJxnqJuJxYy26LWAaNpaM9nRCghFIkiMDl PK4AbXV9Cdc9VZFsmzZpkwTe20MIi6XzP5W9ugObW5adg7EsH6ZRm7ZzFwhVjrBjOx4B NICCXWG7bWkZEA3tw6nCT1eFPXv3ZEml40KFWJNCTT0dqy9brmaa4DO4o7DtD6cSa2P2 /E528hlwbIQQD30/WSnA7JuvRcCokfFGTEFnL4WeEVrZMN7/WF5BMcI53dAra+xLsAOW Zqrd+M79KRz9Oy9TU/aHX3Zehbvfkm4+37N2KflYD2WWdCs/c5uI2L68cjQehLol3nCV kJFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709463079; x=1710067879; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8euAnCNzIztjXeyNg7DMouGQMP5MoiXBmM3i2w8JTRU=; b=vjX9VBYXXlVG6WOgrSHTZ439CB75vl7clD5W1/0XHsqh8/7i3QcRkkrm0NTzfWsLyP NMWyyqyhApgrrlIr/+gVqrEx7TSj5Y3HQuEYrr6/v7mQRYZsh4AW8rRgach5h0qDl+Uk GD42k8otkeKXxQhzsW+d9l8ptaOHUStOUAZfBPpMm3Ox1V/AmtaErgekXIdVoarGf578 viLjAWQBh1kFQUysErnZYqY++gi9Tj4cC9hZRZSyxb7MTISt3YfDmAVjOIBWV9A6qCGl o0LSkLcQOhpRktx7Hq+OwXGjG+Pg713WweG63puGi91KG6NAAwFoGJIKVGA4mOuKryPn Us1w== X-Gm-Message-State: AOJu0YxINmdAAYSO7Z1IxDyN+ME/yCPYdRbKWrKFJ7nfMZmFOKiSR3ND JvpNJ9lUryZ3KH1fIwTuK5Rfrq29ETi9y95Wi5ue3m5Qf6nd01gKnZ5ssvbLllib1/on9O4u1bS c X-Google-Smtp-Source: AGHT+IEZ3rXPtNTO69XiXPFL/qSa5befnHTK0lTbNn4rLzlPG+lqYGI/QtXFCQoB4Yq+8kZguo9y/w== X-Received: by 2002:a17:902:f681:b0:1dc:84ab:95d with SMTP id l1-20020a170902f68100b001dc84ab095dmr6947426plg.45.1709463079469; Sun, 03 Mar 2024 02:51:19 -0800 (PST) From: Akihiko Odaki Date: Sun, 03 Mar 2024 19:50:37 +0900 Subject: [PATCH 3/7] contrib/elf2dmp: Ensure segment fits in file MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240303-elf2dmp-v1-3-bea6649fe3e6@daynix.com> References: <20240303-elf2dmp-v1-0-bea6649fe3e6@daynix.com> In-Reply-To: <20240303-elf2dmp-v1-0-bea6649fe3e6@daynix.com> To: Viktor Prutyanov Cc: qemu-devel@nongnu.org, Akihiko Odaki X-Mailer: b4 0.12.3 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::535; envelope-from=akihiko.odaki@daynix.com; helo=mail-pg1-x535.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @daynix-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1709463185715100002 This makes elf2dmp more robust against corrupted inputs. Signed-off-by: Akihiko Odaki --- contrib/elf2dmp/addrspace.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/contrib/elf2dmp/addrspace.c b/contrib/elf2dmp/addrspace.c index 980a7aa5f8fb..d546a400dfda 100644 --- a/contrib/elf2dmp/addrspace.c +++ b/contrib/elf2dmp/addrspace.c @@ -88,11 +88,12 @@ int pa_space_create(struct pa_space *ps, QEMU_Elf *qemu= _elf) ps->block =3D g_new(struct pa_block, ps->block_nr); =20 for (i =3D 0; i < phdr_nr; i++) { - if (phdr[i].p_type =3D=3D PT_LOAD) { + if (phdr[i].p_type =3D=3D PT_LOAD && phdr[i].p_offset < qemu_elf->= size) { ps->block[block_i] =3D (struct pa_block) { .addr =3D (uint8_t *)qemu_elf->map + phdr[i].p_offset, .paddr =3D phdr[i].p_paddr, - .size =3D phdr[i].p_filesz, + .size =3D MIN(phdr[i].p_filesz, + qemu_elf->size - phdr[i].p_offset), }; pa_block_align(&ps->block[block_i]); block_i =3D ps->block[block_i].size ? (block_i + 1) : block_i; --=20 2.44.0