All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH-for-5.1] hw/ide: Avoid #DIV/0! FPU exception by setting CD-ROM sector count
@ 2020-07-17 10:16 Philippe Mathieu-Daudé
  2020-07-17 10:48 ` Philippe Mathieu-Daudé
  0 siblings, 1 reply; 2+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-07-17 10:16 UTC (permalink / raw)
  To: qemu-devel
  Cc: Alexander Bulekov, John Snow, Markus Armbruster, qemu-block,
	Philippe Mathieu-Daudé

libFuzzer found an undefined behavior (#DIV/0!) in ide_set_sector()
when using a CD-ROM (reproducer available on the BugLink):

  UndefinedBehaviorSanitizer:DEADLYSIGNAL
  ==12163==ERROR: UndefinedBehaviorSanitizer: FPE on unknown address 0x5616279cffdc (pc 0x5616279cffdc bp 0x7ffcdaabae90 sp 0x7ffcdaabae30 T12163)

Fix by initializing the CD-ROM number of sectors in ide_dev_initfn().

Reported-by: Alexander Bulekov <alxndr@bu.edu>
Fixes: b2df431407 ("ide scsi: Mess with geometry only for hard disk devices")
BugLink: https://bugs.launchpad.net/qemu/+bug/1887309
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
 hw/ide/qdev.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/hw/ide/qdev.c b/hw/ide/qdev.c
index 27ff1f7f66..6ce7fc317c 100644
--- a/hw/ide/qdev.c
+++ b/hw/ide/qdev.c
@@ -201,6 +201,15 @@ static void ide_dev_initfn(IDEDevice *dev, IDEDriveKind kind, Error **errp)
                               errp)) {
             return;
         }
+    } else {
+        uint64_t nb_sectors;
+
+        blk_get_geometry(dev->conf.blk, &nb_sectors);
+        if (!nb_sectors) {
+            error_setg(errp, "CD-ROM size can not be zero");
+            return;
+        }
+        dev->conf.secs = nb_sectors;
     }
     if (!blkconf_apply_backend_options(&dev->conf, kind == IDE_CD,
                                        kind != IDE_CD, errp)) {
-- 
2.21.3



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [RFC PATCH-for-5.1] hw/ide: Avoid #DIV/0! FPU exception by setting CD-ROM sector count
  2020-07-17 10:16 [RFC PATCH-for-5.1] hw/ide: Avoid #DIV/0! FPU exception by setting CD-ROM sector count Philippe Mathieu-Daudé
@ 2020-07-17 10:48 ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 2+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-07-17 10:48 UTC (permalink / raw)
  To: qemu-devel; +Cc: Alexander Bulekov, John Snow, Markus Armbruster, qemu-block

On 7/17/20 12:16 PM, Philippe Mathieu-Daudé wrote:
> libFuzzer found an undefined behavior (#DIV/0!) in ide_set_sector()
> when using a CD-ROM (reproducer available on the BugLink):
> 
>   UndefinedBehaviorSanitizer:DEADLYSIGNAL
>   ==12163==ERROR: UndefinedBehaviorSanitizer: FPE on unknown address 0x5616279cffdc (pc 0x5616279cffdc bp 0x7ffcdaabae90 sp 0x7ffcdaabae30 T12163)
> 
> Fix by initializing the CD-ROM number of sectors in ide_dev_initfn().
> 
> Reported-by: Alexander Bulekov <alxndr@bu.edu>
> Fixes: b2df431407 ("ide scsi: Mess with geometry only for hard disk devices")
> BugLink: https://bugs.launchpad.net/qemu/+bug/1887309
> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> ---
>  hw/ide/qdev.c | 9 +++++++++
>  1 file changed, 9 insertions(+)
> 
> diff --git a/hw/ide/qdev.c b/hw/ide/qdev.c
> index 27ff1f7f66..6ce7fc317c 100644
> --- a/hw/ide/qdev.c
> +++ b/hw/ide/qdev.c
> @@ -201,6 +201,15 @@ static void ide_dev_initfn(IDEDevice *dev, IDEDriveKind kind, Error **errp)
>                                errp)) {
>              return;
>          }
> +    } else {
> +        uint64_t nb_sectors;
> +
> +        blk_get_geometry(dev->conf.blk, &nb_sectors);
> +        if (!nb_sectors) {
> +            error_setg(errp, "CD-ROM size can not be zero");

Hmm this doesn't work because for some machines configure_blockdev()
creates blocks of zero size under your feet:

    default_drive(default_cdrom, snapshot,
machine_class->block_default_type, 2,
                  CDROM_OPTS);

> +            return;
> +        }
> +        dev->conf.secs = nb_sectors;
>      }
>      if (!blkconf_apply_backend_options(&dev->conf, kind == IDE_CD,
>                                         kind != IDE_CD, errp)) {
> 


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-07-17 10:49 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-17 10:16 [RFC PATCH-for-5.1] hw/ide: Avoid #DIV/0! FPU exception by setting CD-ROM sector count Philippe Mathieu-Daudé
2020-07-17 10:48 ` Philippe Mathieu-Daudé

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.