Page MenuHomeFreeBSD

stand: userboot: improve userdisk error handling
Needs ReviewPublic

Authored by novel on Sat, Aug 29, 6:49 AM.
Tags
None
Referenced Files
F169252351: D59262.diff
Tue, Sep 1, 1:44 AM
F169207962: D59262.id.diff
Mon, Aug 31, 8:22 PM
Unknown Object (File)
Sun, Aug 30, 6:41 AM
Unknown Object (File)
Sun, Aug 30, 3:15 AM
Unknown Object (File)
Sun, Aug 30, 1:03 AM
Unknown Object (File)
Sat, Aug 29, 8:24 PM
Unknown Object (File)
Sat, Aug 29, 6:30 PM
Unknown Object (File)
Sat, Aug 29, 4:44 PM
Subscribers

Details

Reviewers
manu
Group Reviewers
bhyve
Summary

Currently, userdisk_init() iterates through disks and
checks whether DIOCGSECTORSIZE and DIOCGMEDIASIZE ioctls
are available for the device. If either ioctl fails, userdisk_init()
returns ENXIO with ud_info only partially initialized.
devinit() records the failure, but loader_main() ignores
devinit()'s return value, so later code may access an
uninitialized entry.

In certain cases this code can still boot from a disk even if
userdisk_init() returns ENXIO, for example, when the first of
two disks is valid and the second errors out.

To address this issue while not breaking the current behavior, do
the following:

  • Extend the 'userdisk_info' struct with the boolean 'ud_usable' field, and mark disks that do not support the ioctls mentioned above with ud_usable = false.
  • Update userdisk_print() not to print unusable disks.
  • Update userdisk_open() to return EIO for unusable disks.
  • Update extract_currdev() to pick the first usable disk instead of the first disk. Introduce userboot_disk_firstunit() for that.

Additionally, reset counters on ud_info allocation failure to prevent
accessing unallocated data.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped
Build Status
Buildable 76291
Build 73174: arc lint + arc unit