Page MenuHomeFreeBSD

bhyveload: validate character disk devices
ClosedPublic

Authored by novel on Fri, Aug 28, 6:04 PM.
Tags
None
Referenced Files
F172865320: D59253.id187200.diff
Mon, Sep 21, 4:56 PM
F172852798: D59253.diff
Mon, Sep 21, 2:37 PM
F172844208: D59253.diff
Mon, Sep 21, 12:47 PM
F172787890: D59253.id187135.diff
Mon, Sep 21, 12:13 AM
Unknown Object (File)
Sat, Sep 19, 10:20 PM
Unknown Object (File)
Sat, Sep 19, 1:33 PM
Unknown Object (File)
Sat, Sep 19, 7:49 AM
Unknown Object (File)
Sat, Sep 19, 12:25 AM

Details

Summary

Currently, bhyveload(8) does not validate the supplied disk
image path. For example, it allows passing the /dev/null
device, which later fails in userboot because it does not
support DIOCGSECTORSIZE and DIOCGMEDIASIZE ioctls (see
userdisk_init() in stand/userboot/userboot/userboot_disk.c).

Fix that by checking DIOCGSECTORSIZE and DIOCGMEDIASIZE ioctls early.
A similar check already exists in bhyve(8). While here, make
cb_diskioctl() report the obtained sector size instead of
hard-coding 512.

MFC after: 2 weeks
Sponsored by: The FreeBSD Foundation

Test Plan

Unpatched:

# bhyveload -m 2048 -d /dev/null test
Consoles: userboot  

FreeBSD/amd64 User boot lua, Revision 3.0
(Thu Aug 27 10:40:55 UTC 2026 root@freebsd14)
Bus error
#

Patched:

# bhyveload -m 2048 -d /dev/null test
bhyveload: Could not open '/dev/null': Inappropriate ioctl for device
# echo $?
64
#

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

novel requested review of this revision.Fri, Aug 28, 6:04 PM
markj added a subscriber: markj.
markj added inline comments.
usr.sbin/bhyveload/bhyveload.c
763

Note that cb_diskioctl() hard-codes a sector size of 512, so here we're checking what the disk reports and then throwing away the result.

This revision is now accepted and ready to land.Thu, Sep 17, 3:27 PM

cb_diskioctl: report the actual sector size

This revision now requires review to proceed.Fri, Sep 18, 6:19 PM

cb_diskioctl: report the actual sector size

novel marked an inline comment as done.
markj added inline comments.
usr.sbin/bhyveload/bhyveload.c
368–375

I would just fetch it again here rather than keeping around extra state, just like we issue DIOCGMEDIASIZE below.

This revision is now accepted and ready to land.Fri, Sep 18, 7:01 PM

Do not cache sector size, fetch it directly in cb_diskioctl()

This revision now requires review to proceed.Sat, Sep 19, 7:14 AM
This revision is now accepted and ready to land.Mon, Sep 21, 12:50 PM
This revision was automatically updated to reflect the committed changes.