Commit Graph

420 Commits

Author SHA1 Message Date
Jonas 'Sortie' Termansen 9d87d76957 Abort on overlapping memcpy. 2021-05-30 23:48:19 +02:00
Juhani Krekelä 7f9a62d916 Implement Alt + key mapping to Esc followed by key in kernel tty 2021-05-05 00:19:56 +02:00
Jonas 'Sortie' Termansen c25f36cd53 Fix faccessat(2) not supporting root access. 2021-02-17 23:11:31 +01:00
Jonas 'Sortie' Termansen a6295e6d90 Allow poll on all kinds of files. 2021-02-17 23:11:31 +01:00
Jonas 'Sortie' Termansen fb106181a9 Fix sigsuspend(2) not running signal handlers with the temporary mask. 2021-02-13 22:35:39 +01:00
Jonas 'Sortie' Termansen aadeef6a7c Fix psctl(2) not setting uid, euid, gid, and egid. 2021-02-11 20:47:49 +01:00
Jonas 'Sortie' Termansen fff849b151 Fix improper uses of ScopedLockSignal. 2021-02-11 20:47:47 +01:00
Jonas 'Sortie' Termansen 7139de4a53 Add stty(1). 2020-11-25 20:47:19 +01:00
Jonas 'Sortie' Termansen 20d4c09e26 Undefine the eol character in the default terminal settings. 2020-11-22 17:39:55 +01:00
Jonas 'Sortie' Termansen be02a7996b Fix kramfs not initializing the owner of new directories. 2020-10-18 13:36:28 +02:00
Jonas 'Sortie' Termansen 245ec6458a Fix poll(2) not just clearing revents on negative fds. 2020-03-15 23:04:28 +01:00
Jonas 'Sortie' Termansen 20c1f1d0d4 Add signal mask support to ppoll(2). 2018-12-08 22:54:28 +01:00
Jonas 'Sortie' Termansen 9993a1c0fc Add --append-to kernel(7) multiboot module option. 2018-12-08 22:54:28 +01:00
Jonas 'Sortie' Termansen d0ab651fbd Document the options for the kernel(7) multiboot modules. 2018-12-08 22:54:28 +01:00
Jonas 'Sortie' Termansen b3e9865e53 Handle SOCK_NONBLOCK at the file descriptor level. 2018-12-08 22:34:50 +01:00
Jonas 'Sortie' Termansen 1f659c49c6 Fix multiboot header not coming first in the executable.
The default linker script places .text.unlikely prior to .text.
2018-12-08 22:34:49 +01:00
Jonas 'Sortie' Termansen d3a64e1163 Fix chmod(2), chown(2), and utimens(2) opening the path for writing.
The change 9d29e96c3b "Fix open(2) allowing
opening directories invalidly and check O_TRUNC errors." broke the chmod(2),
chown(2), and utimens(2) system calls on directories, because they can no
longer be opened for writing.

This changes fixes the regression by opening such paths for reading. There
is currently no filesystem permission checks for those system calls. However,
those system calls should check the permissions at the time of the operation
rather than relying on the file having been opened for writing previously.
2018-09-01 17:24:40 +02:00
Jonas 'Sortie' Termansen b1ad606303 Fix system calls panicing when creating threads in the kernel process.
This fixes a regression in 62bd9bf901.
2018-08-12 23:24:42 +02:00
Kartik Agaram 9d29e96c3b Fix open(2) allowing opening directories invalidly and check O_TRUNC errors.
Among other things, redirecting to a directory will now display an error
as it should.

Also fix a bug when opening /dev/pts: O_WRITE on a directory is a POSIX
violation.
2018-08-09 23:19:07 +02:00
Jonas 'Sortie' Termansen b767063c9a Fix deadlock when resizing display when a graphical process is running. 2018-08-08 23:46:19 +02:00
Jonas 'Sortie' Termansen 969a3e599b Fix signal dispatch if sigreturn is NULL. 2018-08-07 23:55:57 +02:00
Jonas 'Sortie' Termansen ab228e1062 Fix Clock::LockLock setting we_disabled_interrupts before disabling interrupts. 2018-08-07 23:55:57 +02:00
Jonas 'Sortie' Termansen 5be7b52422 Fix LFBTextBuffer GetChar starting worker thread when paused. 2018-08-06 23:59:35 +02:00
Jonas 'Sortie' Termansen 62bd9bf901 Fix pid 1 deadlocking when exiting with children.
The child processes of pid 1 were being reparented to pid 1, causing an
infinite loop. This change fixes the problem by adding a hook that runs in
the last thread about to exit in a process. When pid 1 exits, the hook will
prevent more processes and threads from being created, and then broadcast
kill all processes and threads. The hook is not run in LastPrayer(), as that
function runs in a worker thread and it can't block waiting for another
thread to run LastPrayer() in the same thread.
2018-08-06 23:59:35 +02:00
Jonas 'Sortie' Termansen c14e6c05b9 Fix waitpid(2) when the status pointer is NULL. 2018-08-06 23:59:35 +02:00
Jonas 'Sortie' Termansen 29555d72bb Fix <fcntl.h> including <sys/stat.h> namespace pollution.
POSIX allows <fcntl.h> to include <sys/stat.h>, but doesn't require it.
There's little reason to do that, since they are separate headers, and
<fcntl.h> just needs the mode_t constants. Fix the code accidentally
relying on <fcntl.h> including <sys/stat.h>. The mode_t constants are now
provided in their own kernel header <sortix/mode.h>.

Additionally fix <sys/stat.h> pulling in all of <sys/types.h>, which is not
allowed by POSIX, which only requires a few types to be declared. Fix the
code accidentally relying on <sys/stat.h> including <sys/types.h>.

Finally fix <dirent.h> pulling in <stdint.h> through <sortix/dirent.h>.

The <sortix/__/dt.h> and <sortix/__/stat.h> headers are no longer required
and their contents have been merged into <sortix/__/dirent.h>.
2018-08-06 23:59:34 +02:00
Jonas 'Sortie' Termansen d393b67d72 Fix st_blksize and st_blocks kernel values. 2018-03-31 00:55:33 +02:00
Jonas 'Sortie' Termansen 66b35fb74c Fix incompatibilities in the kernel tar extraction. 2018-03-30 23:42:37 +02:00
Jonas 'Sortie' Termansen 65a960dab0 Fix trailing slashes in manifests created by the kernel. 2017-12-04 23:56:46 +01:00
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
Jonas 'Sortie' Termansen 9ee05a5afc Fix kernel/addralloc.cpp file header comment. 2017-08-20 12:44:59 +02:00
Jonas 'Sortie' Termansen c14d7fa3b8 Fix <signal.h> namespace pollution for strict C. 2017-08-20 12:44:33 +02:00
Jonas 'Sortie' Termansen 33dcd40c6d Fix system headers using C89 incompatible comments. 2017-07-10 13:37:46 +02:00
Jonas 'Sortie' Termansen 9321f4d78e Fix initrd_get_inode return value not being checked for error. 2017-07-02 21:55:37 +02:00
Pedro Falcato 087e3b3fda
Fail with ENOSYS on bad system calls. 2017-06-14 20:00:50 +01:00
Pedro Falcato c0a44e72a6
Clear the direction flag upon entry to the kernel. 2017-06-12 21:26:26 +01:00
Jonas 'Sortie' Termansen 9f9f4d4e3f Print an kernel error rather than panicing if init(8) exits abnormally.
This avoids the misimpression that a kernel bug happened and it avoids
clearing the screen of potentially useful information about an init(8)
crash.
2017-05-21 23:28:12 +02:00
Jonas 'Sortie' Termansen 9f1965f36e Prioritize the interrupt worker thread. 2017-05-18 22:40:46 +02:00
Jonas 'Sortie' Termansen 4c98e3f960 Fix pipe and unix socket iovec support. 2017-05-15 22:11:24 +02:00
Jonas 'Sortie' Termansen 7bc9e067ec Fix operator spacing in kernel/textbuffer.cpp. 2017-04-18 23:32:00 +02:00
Jonas 'Sortie' Termansen acc32ccb49 Make interrupt work thread reliable. 2017-04-12 23:22:09 +02:00
Jonas 'Sortie' Termansen 86ac3d3725 Fix the signal dispatch handler is callable from user-space. 2017-04-12 23:22:09 +02:00
Jonas 'Sortie' Termansen d45417651f Refactor kernel command line parsing. 2017-04-08 22:20:03 +02:00
Jonas 'Sortie' Termansen 35d3c7e0b5 Fix technical typo. 2017-04-08 22:20:03 +02:00
Nicholas De Nova 9dd8a8e84c Check overflows in the descriptor table. 2017-04-03 18:07:23 -05:00
Jonas 'Sortie' Termansen 4ffd6f5e20 Fix mode constants not in octal. 2017-03-19 13:25:27 +01:00
Jonas 'Sortie' Termansen ef2e478607 Implement getpeername(2) and getsockname(2). 2017-02-26 22:24:35 +01:00
Jonas 'Sortie' Termansen 4eb9caaa39 Fix non-blocking accept4(2) and getting the Unix socket peer address.
Rename the internal kernel method from accept to accept4.

fixup! Fix non-blocking accept4(2) and getting the unix socket peer address.
2017-02-26 22:24:18 +01:00
Jonas 'Sortie' Termansen 8f3e11b162 Fix missing mutex in Unix socket shutdown. 2017-02-25 17:22:40 +01:00
Meisaka Yukara 961ba9ec6c Add cache-aware memory mapping functions.
This commit is joint work by Meisaka Yukara <Meisaka.Yukara@gmail.com> and
Jonas 'Sortie' Termansen <sortie@maxsi.org>.
2017-02-19 12:13:32 +01:00
Meisaka Yukara 307223a5a7 Add PCI scanning functions and busmastering functions.
This commit is joint work by Meisaka Yukara <Meisaka.Yukara@gmail.com> and
Jonas 'Sortie' Termansen <sortie@maxsi.org>.
2017-02-19 12:10:59 +01:00
Jonas 'Sortie' Termansen fcefd86432 Implement shutdown(2). 2017-02-18 15:29:40 +01:00
Jonas 'Sortie' Termansen 4b2cf28bbf Add socket(2).
This removes the /dev/net socket interface.

This is an incompatible ABI change.
2017-02-14 20:43:31 +01:00
Jonas 'Sortie' Termansen a53dd5d29d Support deallocating kernel timers in timer handlers. 2017-02-14 20:43:30 +01:00
Jonas 'Sortie' Termansen 7a8a71674e Move readv/writev family and sendmsg/recvmsg into drivers. 2017-02-13 22:04:21 +01:00
Jonas 'Sortie' Termansen 28229eb6e6 Fix pipe2(2) not supporting O_NONBLOCK. 2017-02-13 21:12:24 +01:00
Jonas 'Sortie' Termansen e9ee189d29 Fix BGA driver crashes without vbox guest additions. 2017-01-22 22:28:58 +01:00
Jonas 'Sortie' Termansen bdc791f692 Fix saving and restoring console cursor position. 2017-01-22 22:28:58 +01:00
Nicholas De Nova 73d984bca3 Panic upon detection of xz, gzip, or bzip2 magic in loaded modules. 2016-12-29 12:57:57 -06:00
Jonas 'Sortie' Termansen 0cf88fd58a Revert "Add <limits.h>."
This reverts commit f6cde2d7a6.

gcc detected this header existing and emitted its own limits.h that
included the libc limits.h. This caused the #include_next chain to reach
the end and including the header failed.

Undoing this commit for now until the compiler toolchain is updated to
avoid this problem.
2016-12-27 21:58:07 +01:00
Jonas 'Sortie' Termansen 0bb608b09e Support 8-bit/24-bit color and more escape codes in the graphical console.
The console has gained these escape codes:
 - Set color to any of 256 entries in the palette.
 - Set color to any 24-bit RGB value.
 - Inverse mode.
 - Bold mode.
 - Underline mode.
 - Move cursor to line N.
 - \a is now ignored.

The effectively unused ATTR_CHAR has been removed. Parsing of escape codes
has been improved. The graphical palette has been changed to the tango
colors, which makes Sortix look a bit differently. Some user-space programs
have been changed to use different colors that look better under the new
palette.

Remove const from methods that weren't really const and remove mutable
keyword workaround.
2016-11-27 11:19:03 +01:00
Jonas 'Sortie' Termansen ce54be34da Add VirtualBox Guest Additions. 2016-11-27 11:18:49 +01:00
Jonas 'Sortie' Termansen e7c5d032d1 Refactor graphical resolution changes. 2016-11-27 11:18:48 +01:00
Jonas 'Sortie' Termansen 0342e03073 Add debug uart utility functions. 2016-11-27 11:18:48 +01:00
Jonas 'Sortie' Termansen b38c84852c Add pseudo terminals.
This is a compatible ABI change riding on the previous commit's bump.
2016-11-23 22:31:05 +01:00
Jonas 'Sortie' Termansen 6ef5a5cee3 Detect whether the terminal has a display and a keyboard layout.
A new ioctl TIOCGDISPLAYS allow detecting which displays the terminal
has associated. The ability to set a keyboard layout can be detected
with tcgetblob kblayout.

Improve the user-space multi-monitor support while here.

The kernel now sets TERM rather than init(8).

This is a compatible ABI change riding on the previous commit's bump.
2016-11-23 22:31:04 +01:00
Jonas 'Sortie' Termansen db7182ddc3 Add support for sessions.
This change refactors the process group implementation and adds support
for sessions. The setsid(2) and getsid(2) system calls were added.

psctl(2) now has PSCTL_TTYNAME, which lets you get the name of a process's
terminal, and ps(1) now uses it.

The initial terminal is now called /dev/tty1.

/dev/tty is now a factory for the current terminal.

A global lock now protects the process hierarchy which makes it safe to
access other processes. This refactor removes potential vulnerabilities
and increases system robustness.

A number of terminal ioctls have been added.

This is a compatible ABI change.
2016-11-23 22:30:47 +01:00
Jonas 'Sortie' Termansen d529a1e332 Add factory inode support. 2016-11-23 21:46:06 +01:00
Jonas 'Sortie' Termansen f6cde2d7a6 Add <limits.h>. 2016-11-22 21:36:43 +01:00
Philippe Michaud-Boudreault 4890297611 Optimize is_power_of_two. 2016-11-06 17:42:13 +01:00
Jonas 'Sortie' Termansen d720f16537 Add ONLCR and OCRNL.
This is a compatible ABI change.
2016-11-05 23:38:40 +01:00
Jonas 'Sortie' Termansen 9603be8e65 Split LogTerminal into a base class with the core terminal semantics.
No semantic change.
2016-11-05 17:00:43 +01:00
Jonas 'Sortie' Termansen d84715c6ef Fix SIGTTIN during tty reading not setting errno to EINTR. 2016-11-05 16:19:50 +01:00
Jonas 'Sortie' Termansen 51e13b9357 Fix terminal escape keystroke not sending escape byte. 2016-11-03 22:31:17 +01:00
Jonas 'Sortie' Termansen eacfc72f2f Fix concurrent serial port read and write. 2016-11-03 22:10:45 +01:00
Jonas 'Sortie' Termansen 8951adc5f0 Add VMIN support. 2016-11-03 08:36:46 +01:00
Pedro Falcato 205a3e7156
Remove not_rsp and not_esp. 2016-10-30 12:03:47 +00:00
Jonas 'Sortie' Termansen 2d91c7d385 Fix exit_thread(2) multi-threaded process destruction. 2016-10-17 18:38:04 +02:00
Jonas 'Sortie' Termansen 84c0844f56 Seed kernel entropy with randomness from the previous boot.
The bootloader will now load the /boot/random.seed file if it exists, in
which case the kernel will use it as the initial kernel entropy. The kernel
warns if no random seed was loaded, unless the --no-random-seed option was
given. This option is used for live environments that inherently have no
prior secret state. The kernel initializes its entropy pool from the random
seed as of the first things, so randomness is available very early on.

init(8) will emit a fresh /boot/random.seed file on boot to avoid the same
entropy being used twice. init(8) also writes out /boot/random.seed on
system shutdown where the system has the most entropy. init(8) will warn if
writing the file fails, except if /boot is a real-only filesystem, and
keeping such state is impossible. The system administrator is then
responsible for ensuring the bootloader somehow passes a fresh random seed
on the next boot.

/boot/random.seed must be owned by the root user and root group and must
have file permissions 600 to avoid unprivileged users can read it. The file
is passed to the kernel by the bootloader as a multiboot module with the
command line --random-seed.

If no random seed is loaded, the kernel attempts a poor quality fallback
where it seeds the kernel arc4random(3) continuously with the current time.
The timing variance may provide some effective entropy. There is no real
kernel entropy gathering yet. The read of the CMOS real time clock is moved
to an early point in the kernel boot, so the current time is available as
fallback entropy.

The kernel access of the random seed module is supposed to be infallible
and happens before the kernel log is set up, but there is not yet a failsafe
API for mapping single pages in the early kernel.

sysupgrade(8) creates /boot/random.seed if it's absent as a temporary
compatibility measure for people upgrading from the 1.0 release. The GRUB
port will need to be upgraded with support for /boot/random.seed in the
10_sortix script. Installation with manual bootloader configuration will
need to load the random seed with the --random-seed command line. With GRUB,
this can be done with: module /boot/random.seed --random-seed
2016-10-04 00:34:50 +02:00
Jonas 'Sortie' Termansen 6944250bd1 Allow detecting fallback video modes. 2016-10-03 21:38:34 +02:00
Jonas 'Sortie' Termansen a97e1ef16c Modernize carray(1) and fix missing allocation checks.
Add short options for most long options. Rename the -i option to -H, but
support -i for compatibility until the next release cycle, where -i will
become the short option of --identifier. Rename --include to --headers
and support --include until the next release cycle.

Add carray(1) manual page which makes --help unnecessary, and remove
--version as it surely matches your local Sortix version.
2016-09-29 00:01:41 +02:00
Jonas 'Sortie' Termansen 848eaaf593 Port build utilities to musl. 2016-09-29 00:01:40 +02:00
Jonas 'Sortie' Termansen 91a6ee7919 Add 24-bit graphics support to kernel. 2016-09-28 20:29:18 +02:00
Jonas 'Sortie' Termansen c8487ff12b Fix readlinkat(2) return value truncation. 2016-09-28 20:15:36 +02:00
Jonas 'Sortie' Termansen 394d3d7115 Fix kernel not using BRAND_DEFAULT_HOSTNAME. 2016-09-28 20:15:36 +02:00
Jonas 'Sortie' Termansen 0e78aec1c3 Fix console scrolling bottleneck. 2016-09-25 22:28:17 +02:00
Jonas 'Sortie' Termansen f28fc4ac39 Fix non-blocking recv(2) and send(2). 2016-08-22 01:47:31 +02:00
Jonas 'Sortie' Termansen 8ec5d9af44 Fix linked list and shadowing bugs in kernel clock and timer code. 2016-08-21 00:04:27 +02:00
Jonas 'Sortie' Termansen 2b6463aa95 Fix drivers not detecting PCI devices without an interrupt line. 2016-08-21 00:03:58 +02:00
Jonas 'Sortie' Termansen da89dec2e2 Fix AHCI port IDENTIFY timeout taking 10 seconds. 2016-08-21 00:03:57 +02:00
Jonas 'Sortie' Termansen 8f81f990f8 Fix undefined stack register after switch into long mode.
Thanks to dminuoso for pointing out the issue.
2016-07-29 15:20:05 +02:00
Jonas 'Sortie' Termansen 1dbd1f760a Fix missing validation of program entry points. 2016-07-29 15:20:04 +02:00
Jonas 'Sortie' Termansen 2e03bd94d3 Add protection against sigreturn oriented programming (SROP).
This change hardens against invalid calls to sigreturn, which is a very
useful gadget when compromising a process. The system call now verifies
it is a real return from a signal and aborts the process otherwise. This
should render such attacks impossible in threads that are not servicing a
signal, and infeasible in threads that are handling signals they are yet to
return from.

The kernel now keeps track for each thread how many signals are being
handled but haven't returned yet.

Each thread now has a random signal value. It is re-randomized when the
thread handles a signal and the current signal counter is zero. This is
xorred with the context address and used as canary on the stack during
signal dispatch, protecting the saved context on the stack. This works
mostly like the regular stack protector.

The kernel now keeps track of the stack pointer for a single handled
signal per thread. It doesn't seem worth it to keep track of multiple
handled signals, as more than one is rare. Note that each delivered signal
will not necessarily result in a sigreturn because it is valid for a thread
to longjmp(3) out of a signal handler to a valid jmp_buf.

The sigreturn system call will abort if either:

- It was not called from the kernel sigreturn page.
- The thread is not currently processing a signal.
- The thread is processing a single signal, and the stack pointer did not
  have the expected value.
- It fails to read the context on the stack.
- The canary is wrong.
2016-05-15 22:43:29 +02:00
Jonas 'Sortie' Termansen 9b98679885 Clean up errno. 2016-05-15 22:43:29 +02:00
Jonas 'Sortie' Termansen 01a9779fc6 Compile libc with -ffreestanding.
This properly avoids problems where the compiler is unaware that this is the
implementation and assumes it can rely on the implementation. For instance,
it might implement calloc using a call to calloc.

Restructure the code that wrongly assumed __STDC_HOSTED__ meant userspace.
2016-05-15 22:43:29 +02:00
Jonas 'Sortie' Termansen 1ca1a068a1 Make the branding system more neutral. 2016-05-15 22:43:29 +02:00
Jonas 'Sortie' Termansen 1826fc32cd Fix signal delivery stack alignment. 2016-05-15 19:30:51 +02:00
Jonas 'Sortie' Termansen e69565fd15 Remove compatibility with Sortix 0.9. 2016-05-15 01:31:48 +02:00
Jonas 'Sortie' Termansen ecfe121a8c Add assertions to Signal::DispatchHandler callers. 2016-03-28 17:37:37 +02:00
Jonas 'Sortie' Termansen c1e5bcba7f Fix S_IROTH having the wrong value. 2016-03-28 16:25:42 +02:00