sortix-mirror/kernel
Jonas 'Sortie' Termansen 568c97c77f Fix SEEK_END, file offset overflow, and read/write/mkpartition syscall bugs.
Fix SEEK_END seeking twice as far as requested. Centralize lseek handling in
one place and avoid overflow bugs. Inode lseek handlers now only need to
handle SEEK_END with offset 0. Prevent the file offset from ever going below
zero or overflowing.

Character devices are now not seekable, but lseek will pretend they are, yet
always stay at the file offset 0. pread/pwrite on character devices will now
ignore the file offset and call read/write.

This change prevents character devices from being memory mapped, notably
/dev/zero can no longer be memory mapped. None of the current ports seem
to rely on this behavior and will work with just MAP_ANONYMOUS.

Refactor read and write system calls to have a shared return statement for
both seekable and non-seekable IO.

Fix file offset overflow bugs in read and write system calls.

Fix system calls returning EPERM instead of properly returning EBADF when
the file has not been opened in the right mode.

Truncate IO counts and total vector IO length so the IO operation does not
do any IO beyond OFF_MAX. Truncate also total vector IO length for recvmsg
and sendmsg. Fail with EINVAL if total vector IO length exceeds SSIZE_MAX.

Don't stop early if the total IO length is zero, so zero length IO now block
on any locks internal to the inode.

Handle reads at the maximum file offset with an end of file condition and
handle writes of at least one byte at the maximum file offset by failing
with EFBIG.

Refactor UtilMemoryBuffer to store the file size using off_t instead of
size_t to avoid casts and keep file sizes in the off_t type. Properly
handle errors in the code, such as failing with EROFS instead of EBADF if
the backing memory is not writeable, and failing with EFBIG if writing
beyond the end of the file.

Fix mkpartition not rejecting invalid partition start offsets and lengths.
Strictly enforce partition start and length checks in the partition code.
Enforce partitions exist within regular files or block devices.

Fix a few indention issues.
2017-12-04 23:56:46 +01:00
..
disk Fix SEEK_END, file offset overflow, and read/write/mkpartition syscall bugs. 2017-12-04 23:56:46 +01:00
fs Fix SEEK_END, file offset overflow, and read/write/mkpartition syscall bugs. 2017-12-04 23:56:46 +01:00
gpu/bga Add cache-aware memory mapping functions. 2017-02-19 12:13:32 +01:00
include/sortix Fix SEEK_END, file offset overflow, and read/write/mkpartition syscall bugs. 2017-12-04 23:56:46 +01:00
kb Relicense Sortix to the ISC license. 2016-03-05 22:21:50 +01:00
mouse Relicense Sortix to the ISC license. 2016-03-05 22:21:50 +01:00
net Implement getpeername(2) and getsockname(2). 2017-02-26 22:24:35 +01:00
x64 Clear the direction flag upon entry to the kernel. 2017-06-12 21:26:26 +01:00
x86 Clear the direction flag upon entry to the kernel. 2017-06-12 21:26:26 +01:00
x86-family Prioritize the interrupt worker thread. 2017-05-18 22:40:46 +02:00
.gitignore Allow bootloader bitmap framebuffer modesetting. 2016-01-08 19:56:11 +01:00
Makefile Add socket(2). 2017-02-14 20:43:31 +01:00
addralloc.cpp Fix kernel/addralloc.cpp file header comment. 2017-08-20 12:44:59 +02:00
alarm.cpp Relicense Sortix to the ISC license. 2016-03-05 22:21:50 +01:00
clock.cpp Make interrupt work thread reliable. 2017-04-12 23:22:09 +02:00
com.cpp Fix concurrent serial port read and write. 2016-11-03 22:10:45 +01:00
com.h Relicense Sortix to the ISC license. 2016-03-05 22:21:50 +01:00
copy.cpp Relicense Sortix to the ISC license. 2016-03-05 22:21:50 +01:00
descriptor.cpp Fix SEEK_END, file offset overflow, and read/write/mkpartition syscall bugs. 2017-12-04 23:56:46 +01:00
dtable.cpp Check overflows in the descriptor table. 2017-04-03 18:07:23 -05:00
elf.cpp Optimize is_power_of_two. 2016-11-06 17:42:13 +01:00
end.cpp Relicense Sortix to the ISC license. 2016-03-05 22:21:50 +01:00
fcache.cpp Fix SEEK_END, file offset overflow, and read/write/mkpartition syscall bugs. 2017-12-04 23:56:46 +01:00
fsfunc.cpp Relicense Sortix to the ISC license. 2016-03-05 22:21:50 +01:00
hostname.cpp Fix kernel not using BRAND_DEFAULT_HOSTNAME. 2016-09-28 20:15:36 +02:00
identity.cpp Relicense Sortix to the ISC license. 2016-03-05 22:21:50 +01:00
initrd.cpp Fix initrd_get_inode return value not being checked for error. 2017-07-02 21:55:37 +02:00
initrd.h Relicense Sortix to the ISC license. 2016-03-05 22:21:50 +01:00
inode.cpp Fix SEEK_END, file offset overflow, and read/write/mkpartition syscall bugs. 2017-12-04 23:56:46 +01:00
interlock.cpp Relicense Sortix to the ISC license. 2016-03-05 22:21:50 +01:00
interrupt.cpp Prioritize the interrupt worker thread. 2017-05-18 22:40:46 +02:00
io.cpp Fix SEEK_END, file offset overflow, and read/write/mkpartition syscall bugs. 2017-12-04 23:56:46 +01:00
ioctx.cpp Relicense Sortix to the ISC license. 2016-03-05 22:21:50 +01:00
kernel.cpp Print an kernel error rather than panicing if init(8) exits abnormally. 2017-05-21 23:28:12 +02:00
kernelinfo.cpp Add tagline. 2016-03-26 23:50:50 +01:00
kthread.cpp Relicense Sortix to the ISC license. 2016-03-05 22:21:50 +01:00
lfbtextbuffer.cpp Support 8-bit/24-bit color and more escape codes in the graphical console. 2016-11-27 11:19:03 +01:00
lfbtextbuffer.h Support 8-bit/24-bit color and more escape codes in the graphical console. 2016-11-27 11:19:03 +01:00
libk.cpp Seed kernel entropy with randomness from the previous boot. 2016-10-04 00:34:50 +02:00
linebuffer.cpp Relicense Sortix to the ISC license. 2016-03-05 22:21:50 +01:00
linebuffer.h Relicense Sortix to the ISC license. 2016-03-05 22:21:50 +01:00
log.cpp Add cache-aware memory mapping functions. 2017-02-19 12:13:32 +01:00
logterminal.cpp Detect whether the terminal has a display and a keyboard layout. 2016-11-23 22:31:04 +01:00
logterminal.h Add support for sessions. 2016-11-23 22:30:47 +01:00
memorymanagement.cpp Fix SEEK_END, file offset overflow, and read/write/mkpartition syscall bugs. 2017-12-04 23:56:46 +01:00
mtable.cpp Relicense Sortix to the ISC license. 2016-03-05 22:21:50 +01:00
multiboot.h Upgrade to latest upstream multiboot header. 2014-12-01 22:51:07 +01:00
op-new.cpp Relicense Sortix to the ISC license. 2016-03-05 22:21:50 +01:00
palette.h Support 8-bit/24-bit color and more escape codes in the graphical console. 2016-11-27 11:19:03 +01:00
panic.cpp Fix technical typo. 2017-04-08 22:20:03 +02:00
partition.cpp Fix SEEK_END, file offset overflow, and read/write/mkpartition syscall bugs. 2017-12-04 23:56:46 +01:00
partition.h Relicense Sortix to the ISC license. 2016-03-05 22:21:50 +01:00
pci-mmio.cpp Add cache-aware memory mapping functions. 2017-02-19 12:13:32 +01:00
pci.cpp Add PCI scanning functions and busmastering functions. 2017-02-19 12:10:59 +01:00
pipe.cpp Fix SEEK_END, file offset overflow, and read/write/mkpartition syscall bugs. 2017-12-04 23:56:46 +01:00
poll.cpp Relicense Sortix to the ISC license. 2016-03-05 22:21:50 +01:00
process.cpp Add support for sessions. 2016-11-23 22:30:47 +01:00
psctl.cpp Add support for sessions. 2016-11-23 22:30:47 +01:00
ptable.cpp Relicense Sortix to the ISC license. 2016-03-05 22:21:50 +01:00
pty.cpp Add pseudo terminals. 2016-11-23 22:31:05 +01:00
pty.h Add pseudo terminals. 2016-11-23 22:31:05 +01:00
random.cpp Seed kernel entropy with randomness from the previous boot. 2016-10-04 00:34:50 +02:00
refcount.cpp Relicense Sortix to the ISC license. 2016-03-05 22:21:50 +01:00
registers.cpp Relicense Sortix to the ISC license. 2016-03-05 22:21:50 +01:00
resource.cpp Add support for sessions. 2016-11-23 22:30:47 +01:00
scheduler.cpp Prioritize the interrupt worker thread. 2017-05-18 22:40:46 +02:00
segment.cpp Relicense Sortix to the ISC license. 2016-03-05 22:21:50 +01:00
signal.cpp Add support for sessions. 2016-11-23 22:30:47 +01:00
sockopt.cpp Relicense Sortix to the ISC license. 2016-03-05 22:21:50 +01:00
string.cpp Relicense Sortix to the ISC license. 2016-03-05 22:21:50 +01:00
syscall.cpp Fail with ENOSYS on bad system calls. 2017-06-14 20:00:50 +01:00
textbuffer.cpp Fix operator spacing in kernel/textbuffer.cpp. 2017-04-18 23:32:00 +02:00
textterminal.cpp Fix saving and restoring console cursor position. 2017-01-22 22:28:58 +01:00
textterminal.h Support 8-bit/24-bit color and more escape codes in the graphical console. 2016-11-27 11:19:03 +01:00
thread.cpp Fix exit_thread(2) multi-threaded process destruction. 2016-10-17 18:38:04 +02:00
time.cpp Relicense Sortix to the ISC license. 2016-03-05 22:21:50 +01:00
timer.cpp Make interrupt work thread reliable. 2017-04-12 23:22:09 +02:00
tty.cpp Add support for sessions. 2016-11-23 22:30:47 +01:00
tty.h Add support for sessions. 2016-11-23 22:30:47 +01:00
uart.cpp Add debug uart utility functions. 2016-11-27 11:18:48 +01:00
uart.h Add debug uart utility functions. 2016-11-27 11:18:48 +01:00
user-timer.cpp Relicense Sortix to the ISC license. 2016-03-05 22:21:50 +01:00
vga.cpp Relicense Sortix to the ISC license. 2016-03-05 22:21:50 +01:00
vga.h Relicense Sortix to the ISC license. 2016-03-05 22:21:50 +01:00
vgafont.f16 Allow bootloader bitmap framebuffer modesetting. 2016-01-08 19:56:11 +01:00
vgatextbuffer.cpp Support 8-bit/24-bit color and more escape codes in the graphical console. 2016-11-27 11:19:03 +01:00
vgatextbuffer.h Refactor graphical resolution changes. 2016-11-27 11:18:48 +01:00
video.cpp Refactor graphical resolution changes. 2016-11-27 11:18:48 +01:00
vnode.cpp Implement getpeername(2) and getsockname(2). 2017-02-26 22:24:35 +01:00
worker.cpp Relicense Sortix to the ISC license. 2016-03-05 22:21:50 +01:00