From nobody Tue Nov 18 15:24:39 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1611064747; cv=none; d=zohomail.com; s=zohoarc; b=eVeV/omrhLMn+R+ksppesDJUpEvC85jQwESNwPLReE50FmF45PFDEfwb2k3y4adoTSHioP1LCGUYFIjES9/7NIqrSI3r5+idoaBi472RezzCQpWqqUsz7Fysdcey5Adtasr5lUUfvsqFThyMfbYKpBu31jh2Nq5rRARB9MPEtFw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1611064747; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=uKZSfYPDamc5qkghmJlQyIL2Vd8/5EXDq0NcqeIeZP8=; b=oD7HPB/YXr0YZ9v8la0SNuBWPGNs1tOhxHY0PFL7S+FRU51qp37IXr/o/RS6NvKNTZH/80xRXYRM4i/svYAwzhhP2tCqBbvCaTZ8WpYSQ0jlE2vljupGYVVt+6WGMZzb/uz8sSYMFs1S4/anqthwZn5kcdiBxnktGIBQZkVCUwM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1611064747594917.6033760812917; Tue, 19 Jan 2021 05:59:07 -0800 (PST) Received: from localhost ([::1]:53960 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l1rXF-0006gI-H0 for importer@patchew.org; Tue, 19 Jan 2021 08:59:06 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:56516) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l1rJ4-0006xX-16 for qemu-devel@nongnu.org; Tue, 19 Jan 2021 08:44:26 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:44971) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l1rJ1-00046T-Vw for qemu-devel@nongnu.org; Tue, 19 Jan 2021 08:44:25 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-562-wANvM2nnNJq7U0CteR-NYQ-1; Tue, 19 Jan 2021 08:44:20 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2832A1075649; Tue, 19 Jan 2021 13:44:19 +0000 (UTC) Received: from localhost.localdomain (ovpn-117-126.sin2.redhat.com [10.67.117.126]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 20CAD60BF1; Tue, 19 Jan 2021 13:44:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611063862; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=uKZSfYPDamc5qkghmJlQyIL2Vd8/5EXDq0NcqeIeZP8=; b=BMArtHkfulIImTmd4U+RVg58pFA771+yXlZNvROJFzUxIgMvwCxc076GNPe1tHuANdoFHC b/tqIphyA0ZxJF1zZKWykfFKCFPqforre63be0I2nW5RV1lZDjP6ofuUbwE29S/ejTSpza H5tvoCr/HSjehNkzXpHmNniLUNm3g90= X-MC-Unique: wANvM2nnNJq7U0CteR-NYQ-1 From: P J P To: Paolo Bonzini Subject: [PATCH] ide: set an upper limit to nb_sectors Date: Tue, 19 Jan 2021 19:12:11 +0530 Message-Id: <20210119134211.494133-1-ppandit@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=ppandit@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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=63.128.21.124; envelope-from=ppandit@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -29 X-Spam_score: -3.0 X-Spam_bar: --- X-Spam_report: (-3.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.195, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Prasad J Pandit , John Snow , QEMU Developers , Markus Armbruster Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Prasad J Pandit Set an upper limit to number of sectors on an IDE disk media. This is to ensure that logical block addresses (LBA) and nb_sector arguments remain within INT_MAX range. Suggested-by: Paolo Bonzini Signed-off-by: Prasad J Pandit --- hw/ide/core.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) Update: limit s->nb_sectors count -> https://lists.gnu.org/archive/html/qemu-devel/2021-01/msg04270.html -> https://lists.gnu.org/archive/html/qemu-devel/2021-01/msg04173.html diff --git a/hw/ide/core.c b/hw/ide/core.c index b49e4cfbc6..064998804a 100644 --- a/hw/ide/core.c +++ b/hw/ide/core.c @@ -1161,15 +1161,21 @@ static void ide_cfata_metadata_write(IDEState *s) s->nsector << 9), 0x200 - 2)); } +static void ide_set_nb_sectors(IDEState *s) +{ + uint64_t nb_sectors; + + blk_get_geometry(s->blk, &nb_sectors); + s->nb_sectors =3D MIN(nb_sectors, (uint64_t)INT_MAX << 2); +} + /* called when the inserted state of the media has changed */ static void ide_cd_change_cb(void *opaque, bool load, Error **errp) { IDEState *s =3D opaque; - uint64_t nb_sectors; s->tray_open =3D !load; - blk_get_geometry(s->blk, &nb_sectors); - s->nb_sectors =3D nb_sectors; + ide_set_nb_sectors(s); /* * First indicate to the guest that a CD has been removed. That's @@ -2475,14 +2481,12 @@ static bool ide_cd_is_medium_locked(void *opaque) static void ide_resize_cb(void *opaque) { IDEState *s =3D opaque; - uint64_t nb_sectors; if (!s->identify_set) { return; } - blk_get_geometry(s->blk, &nb_sectors); - s->nb_sectors =3D nb_sectors; + ide_set_nb_sectors(s); /* Update the identify data buffer. */ if (s->drive_kind =3D=3D IDE_CFATA) { @@ -2511,17 +2515,14 @@ int ide_init_drive(IDEState *s, BlockBackend *blk, = IDEDriveKind kind, uint32_t cylinders, uint32_t heads, uint32_t secs, int chs_trans, Error **errp) { - uint64_t nb_sectors; - s->blk =3D blk; s->drive_kind =3D kind; - - blk_get_geometry(blk, &nb_sectors); s->cylinders =3D cylinders; s->heads =3D heads; s->sectors =3D secs; s->chs_trans =3D chs_trans; - s->nb_sectors =3D nb_sectors; + ide_set_nb_sectors(s); + s->wwn =3D wwn; /* The SMART values should be preserved across power cycles but they aren't. */ -- 2.29.2