HomeFreeBSD

kboot: hostfs -- check for llseek failure correctly

Description

kboot: hostfs -- check for llseek failure correctly

The host_* syscalls are all raw Linux system calls, not the POSIX
wrappers that glibc / musl create. So we have to ranage change the
return value of host_llseek correctly to use the negative value hack
that all Linux system calls use.

This fixes a false positive error detection when we do something like
lseek(fd, 0xf1234567, ...); This returns 0xf1234567, which is a negative
value which used to trigger the error path. Instead, we check using the
is_linux_error() and store the return value in a long. Translate that
errno to a host errno and set the global errno to that and return
-1. lseek can't otherwise return a negative number, since it's the
offset after seeking into the file, which by definition is positive.

This kept the 'read the UEFI memory map out of physical memory' from
working on aarch64 (whose boot loader falls back to reading it since
there are restrictive kernel options that can also prevent it), since
the physical address the memory map was at on my platform was like
0xfa008018.

Sponsored by: Netflix
Differential Revision: https://reviews.freebsd.org/D44286

(cherry picked from commit d650c3efb638f1b2742429a5fb8e7c087839868b)

Details

Provenance
impAuthored on Mar 11 2024, 8:15 PM
Differential Revision
D44286: kboot: hostfs -- check for llseek failure correctly
Parents
rGd18377cbb723: kboot: Avoid UB in signed shift
Branches
Unknown
Tags
Unknown