[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] ide: set an upper limit to nb_sectors
From: |
Philippe Mathieu-Daudé |
Subject: |
Re: [PATCH] ide: set an upper limit to nb_sectors |
Date: |
Tue, 19 Jan 2021 15:13:10 +0100 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 |
Hi Prasad,
On 1/19/21 2:42 PM, P J P wrote:
> From: Prasad J Pandit <pjp@fedoraproject.org>
>
> 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 <pbonzini@redhat.com>
> Signed-off-by: Prasad J Pandit <pjp@fedoraproject.org>
> ---
> 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);
/* An explanation here would be useful */
or better, add a self-explaining definition for this magic value.
> + s->nb_sectors = MIN(nb_sectors, (uint64_t)INT_MAX << 2);
> +}