summaryrefslogtreecommitdiff
path: root/sys/kern/subr_disk.c
AgeCommit message (Collapse)Author
2023-02-10Remove explicit rejection of zero duid in disk_map() added in 1.262.Miod Vallat
Spoofed labels have zero duid and there is no reason not to allow them to work with duid notation. ok kn@
2022-11-11Revert last until we can guarantee gh_guid can't escape to theKenneth R Westerback
d_uid written to disk.
2022-11-11Use the first 8 bytes of GPT gh_guid as the default d_uid. gh_guid isKenneth R Westerback
initialized with arc4random().
2022-11-10Add mbr_get_fstype() and use it to translate MBR dp_typ fieldsKenneth R Westerback
into FS_* values. Similar to what gpt_get_fstype() does. Code is clearer and better positioned for planned enhancements to spoofing. No intentional functional change.
2022-11-09gpt_get_fstype() doesn't modify its parameter so make saidKenneth R Westerback
parameter const.
2022-11-07Nuke last references to d_drivedata.Kenneth R Westerback
2022-10-11Give checkdisklabel() a new parameter supplying the dev_t of theKenneth R Westerback
device whose disklabel is being checked. Within checkdisklabel() use this information to discover a device name iff (sic) the label is an obsolete version. Use the name to generate a meaningful warning message asking the user to rewrite the disklabel and thus promote it to the current version. Suggested by, feedback from and ok deraadt@
2022-09-23Don't hardcode disk major device types inside DEBUG block. UseKenneth R Westerback
findblkname() and DISKUNIT(). Allows all block devices, not just sd* and vnd* to generate useful names in DEBUG output. Cluebat by deraadt@
2022-09-15Remove unneeded interim DPRINTF() verbiage. Make DEBUG compileKenneth R Westerback
again.
2022-09-11Remove the DKF_LABELVALID flag from struct disk. Instead, trust disk driversMiod Vallat
to always be able to provide a duid, and keep ignoring whole zero duids. This fixes a race in vnd setup where the disk_attach callback could run before any I/O occurs on the vnd, thus not having a label available yet. noticed by otto@ and kn@; ok kn@
2022-09-11Add #define's for GPT partition attribute bits REQUIRED, IGNOREKenneth R Westerback
and BOOTABLE, set BOOTABLE attribute bit instead of using the incorrect GPTDOSACTIVE value, have 'fdisk -v' print out GPT partition attributes if any of the 64 bits are set, don't spoof any partition with REQUIRED bit set. Prompted by kettenis@ stumbling across a machine with 40+ (!!) REQUIRED GPT partitions. Tested & ok kettenis@
2022-09-03Allow suspend with root on sdmmc(4).Mark Kettenis
ok deraadt@
2022-09-02Constify nam2blk[], chrtoblktbl[] and octeon devmap[].Miod Vallat
ok mpi@ millert@
2022-09-02Don't ignore an OpenBSD GPT partition just because the GPT saysKenneth R Westerback
it extends beyond the edge of the disk the GPT currently inhabits. We only care if enough of it is addressable that a disklabel is accessible. Brings GPT handling of 'OpenBSD partitions extending too far' into line with the MBR handling of the same situation.
2022-09-02Nuke variable partlba that is set but not used.Kenneth R Westerback
2022-09-02Relax GTP header validity check by allowing 1 sector size usableKenneth R Westerback
LBA area (gh_lba_start == gh_lba_end) and allowing either or both of gh_lba_start and gh_lba_end to exceed the size of the disk the GPT currently inhabits. Reduces false negatives and inappropriate fall through to MBR spoofing and allows repair of otherwise valid GPT.
2022-09-01Stop setting d_bbsize and d_sbsize. Nobody has paidKenneth R Westerback
any attention for some time. ok otto@ as part of larger diff
2022-08-20Restore the exemption from start/size checks that OpenBSD (A6)Kenneth R Westerback
MBR partitions previously enjoyed. Found and fix tested by matthieu@
2022-08-14remove unneeded includes in sys/kernJonathan Gray
ok mpi@ miod@
2022-08-12Revert to pre-r1.249 more laissez-faire checks for valid MBRKenneth R Westerback
partitions. miod@ (re)discovered an off-by-one in some device size calculations. Whether the ancient misbehaviour of some devices to confuse number of sectors with highest valid sector address or something newer. Should fix miod@'s octeon boot disk.
2022-08-12Coverity says multiplying two uint32_t's and assigning them toKenneth R Westerback
a uint64_t may not produce the (humanly) obvious result. Cast one of them to a (uint64_t) in the hope of invoking the appropriate int promotion god. CID 1519495
2022-08-11Don't trust gpt header data read from disk until after itsKenneth R Westerback
validity is checked. Found the hard way by kn@ Cluebats from millert@ and deraadt@. Fix tested by and ok kn@
2022-08-06Refactor readdoslabel() into a more readable form using variousKenneth R Westerback
helper functions. The refactored code ensures disklabels are read from/written to disk only from/to unused space or an OpenBSD partition. This prevents accidental damage to filesystems that start immediately following an MBR or GPT. The refactored code also finds the disklabel present on the i386/amd64 floppyXX.img, rather than spoofing the media as a single MSDOS partition. Tweak and positive comments from jmatthew@
2022-01-02Stop writing big-endian checksums into the little-endian GPTKenneth R Westerback
header fields gh_csum and gh_part_csum. Constrain kernel to accepting only correct little-endian checksums. Temporarily allow fdisk(8) to read either endian GPTs so that big-endian GPTs can be made correct by a simple 'fdisk -e' && 'w'. Fixes inter-architecture, inter-OS GPT portability and GPT fdisk(8) on big-endian architectures. Broken since initial GPT implementation. Suggestions and ok kettenis@
2021-12-22While malloc sleeps, the disk list could change during sysctl. ThenAlexander Bluhm
allocated memory could be too short for the list of disks. Retry allocating enough space until it did not change. The disk list and duid memory are protected by kernel lock. Use asserts to mark this explicitly. Reported-by: syzbot+807423f6868bbfb836bc@syzkaller.appspotmail.com OK anton@ mpi@
2021-10-24use NULL not 0 for pointer values in kernJonathan Gray
ok semarie@
2021-06-13Back off a couple of the more paranoid checks while spoofing GPTKenneth R Westerback
partitions into the disklabel. First, since the alt header is never accessed there is no need to worry about it being inaccessible. Second, the GPT header claiming to cover more sectors than the device has is no reason to ignore all the partitions. The partition actually present could still be useful. Issues encountered in the wild by mlarkin@ while accessing some disk images. ok deraadt@
2021-06-02Use the same logic in all copies of gpt_chk_mbr(), relaxing theKenneth R Westerback
media length check to allow EFI GPT partitions to be smaller that the entire disk. Consistently use GPTSECTOR instead of randomly tossing in some literal '1's. ok kettenis@
2021-06-01Make spoofed disklabel boundstart and boundend default to the boundsKenneth R Westerback
of the usable LBA range defined by the GPT header. And then shrink them to the bounds of the first OpenBSD partition if one is found. While here simplify the logic, eliminate some superfluous variables and reduce use of magic numbers. Improvement suggested by sobrado@ ok kettenis@
2021-05-27Relax criteria for recognizing GPT formatted media by allowing theKenneth R Westerback
EFI GPT partition (0xEE) in the protective MBR to be smaller that the actual size of the media. This allows GPT disk images dd'ed onto larger physical media to be recognized by fdisk(8) and the kernel. Feedback from kettenis@ on various earlier versions.
2021-05-14Whitespace tweaks and a couple of stray u_int* in gpt_chk_mbr().Kenneth R Westerback
No intentional functional change.
2021-05-14Tweak the two copies of gpt_chk_mbr() to return the index of the MBRKenneth R Westerback
0xEE (DOSPTYP_EFI) partition, or -1 no usable such partition is found. Adopt a consistent idiom to capture the index for future use. Clean up the gpt_chk_mbr() logic to make it clearer what constraints are being applied when looking for the DOSTYP_EFI partition. No intentional functional change.
2021-05-08Spoof GPT partitions of type 21686148-6449-6e6f-744e-656564454649 (a.k.a.Kenneth R Westerback
"IdontNeedEFI", a.k.a. "BIOS boot") as FS_BOOT. Often used to contain the second stage boot loader binary on disk images. Makes it easier to recognize/overwrite/remove the contents. Not yet supported in fdisk(8). Example image provided by mlarkin@
2021-01-19kern/subr_disk.c: convert ifunit() to if_unit(9)mvs
ok dlg@
2020-05-29dev/rndvar.h no longer has statistical interfaces (removed during variousTheo de Raadt
conversion steps). it only contains kernel prototypes for 4 interfaces, all of which legitimately belong in sys/systm.h, which are already included by all enqueue_randomness() users.
2020-03-13Simplify logic, the "netboot" interface is always related to `bootdv'.Martin Pieuchot
Logic is hard, so keep only one of two logically equivalent statements. CID 271085 ok kettenis@, deraadt@, miod@
2019-12-26tsleep -> tsleep_nsec(9) in setroot()kn
OK cheloha bluhm
2018-04-28replace add_*_randomness with enqueue_randomness()Jasper Lievisse Adriaanse
this gets rid of the source annotation which doesn't really add anything other than adding complexitiy. randomess is generally good enough that the few extra bits that the source type would add are not worth it. ok mikeb@ deraadt@
2018-03-05fix a memory leak in readdoslabel()Jonathan Gray
ok krw@
2017-08-07Turns out gcc complains about %02hhx. So simply use %02x instead. This isMark Kettenis
accepted by both clang and gcc and safe given that varargs arguments are promoted to int anyway. Using %h in the kernel is discouraged anyway according to bluhm@. Unbreaks the tree on gcc architectures. ok pirofti@, bluhm@, florian@
2017-08-06Use %hhx instead of %hx to print u_char. Silences clang warning.Mark Kettenis
ok jca@, florian@
2017-05-04Also pass the blk offset to disk_unbusy(), so that it can pass it toTheo de Raadt
the random subsystem as entropy. This value is pretty much unknown, and anyways our entropy input ring does not saturate from knowns. ok mikeb djm
2017-04-20Tweak lock inits to make the system runnable with witness(4)Visa Hankala
on amd64 and i386.
2016-09-02Don't bother with 'ghpartnum' in gpt_chk_hdr(); it's not usedTom Cosgrove
ok krw@
2016-05-21Fix logic bug in DUID generation - we want to generate DUIDs until we haveJoel Sing
one that is not a duplicate and not a zero DUID. ok krw@
2016-05-21Cleanup some of the DUID code and refactor for readability.Joel Sing
ok krw@ kettenis@
2016-05-20Remove dead assignment/unused variable.Joel Sing
2016-05-19Let setroot() pick the boot disk based on the DUID provided in bootduid ifMark Kettenis
a boot disk has not been selected by its caller. ok jsing@, millert@
2016-02-08"exceeds past the end" -> "extends past the end" in comment.Kenneth R Westerback
2015-12-24Make gpt_chk_mbr() instances even more identicaller by alwaysKenneth R Westerback
returning 0 or 1 since only boolean checks of the result are done. No need for EINVAL as a return value.