From nobody Sat Nov 23 21:38:29 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; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1730915007; cv=none; d=zohomail.com; s=zohoarc; b=XxLrUlm/sjB3h0rByf9jNZwieOjEQHwoGfX+lojHd1CI4QcqL+d/KkmXV8F+V8V9I1jjzjZ68JK4YD3MWewdRmbpgDcrx7yv3GIarI+hE7i1CdP2guaJ6FHj5iYz1U7WBq+x62YCKXdEQ9lZDoPUhpv88N8jdE4AkWH7lNu6G6k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730915007; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=mBsx0rsy+/jhtfc6pdSbD0STqvK4hr0OKKVjpDbFNmk=; b=RvuBMp3GbSCvIa8SU2gBxVvAptj2LbHAhp/Q9q+mMXd2Q/j6lqceW/+O8kZKJb/j3yLv15IEheExqsRnzIAlWIQ8si6T+WAu5c6rdv/mi1N+aSXPXQcJXzxis05hLN08q8B+U1omGjjD4D34nrrD36NWI1RzC10jzrJ3l3b+NsM= 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1730915007859869.2928579173473; Wed, 6 Nov 2024 09:43:27 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t8k3V-0003BF-33; Wed, 06 Nov 2024 12:42:57 -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 1t8k3T-0003B5-2h for qemu-devel@nongnu.org; Wed, 06 Nov 2024 12:42:55 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8k3P-0006QX-7M for qemu-devel@nongnu.org; Wed, 06 Nov 2024 12:42:53 -0500 Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-2-Q5cwb7-sMDKqaCc64zONgw-1; Wed, 06 Nov 2024 12:42:47 -0500 Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-37d458087c0so716692f8f.1 for ; Wed, 06 Nov 2024 09:42:46 -0800 (PST) Received: from [192.168.10.3] ([151.49.226.83]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-381c10e7392sm19702728f8f.55.2024.11.06.09.42.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Nov 2024 09:42:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1730914969; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=mBsx0rsy+/jhtfc6pdSbD0STqvK4hr0OKKVjpDbFNmk=; b=d58WKbMtE+vcM7ZEtz7VRMX9xx4nlT57sfr3F16jpyMV77h9CX+OKe73W4Fgw0W4peZWwV 6bk3ZuBOBIFsDOW+PJnNEq9FOu1tDdCzrKbUGpxYIW1jfLHRvlJr+kysvN2Q/VLZWLLECy YyJKaaX+a9+7ZuuUddE4T6B7sM+WFTc= X-MC-Unique: Q5cwb7-sMDKqaCc64zONgw-1 X-Mimecast-MFC-AGG-ID: Q5cwb7-sMDKqaCc64zONgw X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730914964; x=1731519764; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=mBsx0rsy+/jhtfc6pdSbD0STqvK4hr0OKKVjpDbFNmk=; b=ahCZmMiD9TkMMTeD4Wg/5hlqR4x6wVBqyMeFmJEIN5UTehJFe5dJeQGq/+bnIwTEGR CL1EAMBuu1qds2b7A4TLmPwXKbc+PvHRDnSdT1HNaD7N69sgaXMq75Tezivs46JUnTYd Ks8fLtNa/XKgLBNE0bQGlZy/RYjhGk6iXPl4F8zPEyaGrlZsopFggVmRmGMbbtpwBOmR aojxkR2hQajStBgAsa39T9ZTodbwpMLtP5t1j4360JqPS8AB/iXttRqFSWiCs9eyj8Q/ CBGD0S/+a4a4oTd726Uz6yCO4wEfZFqCoaYp0VlcNVb1a5iZhegchq+tgOwMlHZpJcyN axqQ== X-Gm-Message-State: AOJu0YyrEemWR1RrM4PdNLh4/pB81Per9cnWBmzZ3CNf3fCorboclbep 1RITD5TyZwGkgmWaunWV094+/FcJ0c4OGqYRNia7hqk2nUO6VLSWimQJXCzhTbRFGwkNgtrc7JV 5RG27J/cJ6Yt2aPopqC0ezlW8WuD6lAaBdKYmtjgfupFhKYMPCqgy05gTQYFvvcscupGEtpVP/z FgFmDdQ5utvUVN1PM4yw2vLmy54JiG/Ep89q/vfLU= X-Received: by 2002:a5d:6da9:0:b0:37c:fbb7:5082 with SMTP id ffacd0b85a97d-381ec60b96bmr52090f8f.25.1730914963822; Wed, 06 Nov 2024 09:42:43 -0800 (PST) X-Google-Smtp-Source: AGHT+IFCSMmvgbvTn2erOK67NfSSDU4gq4TgViEH6q7LvULcPD+c97y3UGBnW/CdDUDi45zVC0b1qg== X-Received: by 2002:a5d:6da9:0:b0:37c:fbb7:5082 with SMTP id ffacd0b85a97d-381ec60b96bmr52069f8f.25.1730914963446; Wed, 06 Nov 2024 09:42:43 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: dorjoychy111@gmail.com Subject: [PATCH] eif: cope with huge section offsets Date: Wed, 6 Nov 2024 18:42:41 +0100 Message-ID: <20241106174241.556373-1-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.0 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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 @redhat.com) X-ZM-MESSAGEID: 1730915009658116600 Content-Type: text/plain; charset="utf-8" Check for overflow to avoid that fseek() receives a sign-extended value. Signed-off-by: Paolo Bonzini Reviewed-by: Pierrick Bouvier --- include/qemu/osdep.h | 4 ++++ hw/core/eif.c | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h index fe7c3c5f673..fdff07fd992 100644 --- a/include/qemu/osdep.h +++ b/include/qemu/osdep.h @@ -297,6 +297,10 @@ void QEMU_ERROR("code path is reachable") #error building with G_DISABLE_ASSERT is not supported #endif =20 +#ifndef OFF_MAX +#define OFF_MAX (sizeof (off_t) =3D=3D 8 ? INT64_MAX : INT32_MAX) +#endif + #ifndef O_LARGEFILE #define O_LARGEFILE 0 #endif diff --git a/hw/core/eif.c b/hw/core/eif.c index 7f3b2edc9a7..cbcd80de58b 100644 --- a/hw/core/eif.c +++ b/hw/core/eif.c @@ -115,6 +115,10 @@ static bool read_eif_header(FILE *f, EifHeader *header= , uint32_t *crc, =20 for (int i =3D 0; i < MAX_SECTIONS; ++i) { header->section_offsets[i] =3D be64_to_cpu(header->section_offsets= [i]); + if (header->section_offsets[i] > OFF_MAX) { + error_setg(errp, "Invalid EIF image. Section offset out of bou= nds"); + return false; + } } =20 for (int i =3D 0; i < MAX_SECTIONS; ++i) { --=20 2.47.0