Re: [PATCH] hw/ide: Don't divide by zero if guest specifies 0 sectors
"Denis V. Lunev" <[email protected]> Tue, 4 Aug 2026 18:28:05 +0200
| Newsgroups | gmane.comp.emulators.qemu.block,gmane.comp.emulators.qemu |
|---|---|
| Message-ID | <[email protected]> |
I have spent some time on what the ATA contract actually says about
INITIALIZE DEVICE PARAMETERS, mostly because of the reasoning quoted
below, and ended up with a set of findings.
On 30.06.2026 12:42, Peter Maydell wrote:
> INITIALIZE DRIVE
> PARAMETERS is specified to not check the input values for validity;
> instead no error is posted until some other command makes an illegal
> access. So we have to cope with a 0 divisor here.
1) That premise does not hold for ATA-2 and later. ATA-5 8.16.8, with
the same wording in ATA-4 8.16.8:
If the host requests a CHS translation that is not supported by
the device, the device shall return command aborted. [...]
If the requested CHS translation is not supported, the device
shall fail all media access commands with an ID Not Found error
until a valid CHS translation is established.
ATA-2 7.18 speaks to the "no error is posted" behaviour directly in
NOTE 26: previous ATA specifications were unclear, some
implementations indicate no error at all, but most of those still
fail media access commands. The command was dropped entirely in
ATA-6 along with CHS addressing.
2) Zero sectors per logical track is an unsupported translation by
definition, not a borderline case: ATA-5 6.2 numbers CHS sectors
from one, and ATA-2 D.2.8 limits IDENTIFY DEVICE word 56 to values
between 1 and 255. So 8.16.6 has us abort the command, and the
error belongs there rather than on the later access.
Your question below the --- line, whether we should check the addresses
a guest uses against the CHS limits it selected, is a real gap as well,
but I would keep it apart from the crash fix.
For me this changes where the fix has to live. There are further
consequences, one of them around migration, but they are much easier to
discuss with the code in hand, so let me send that first.
Den