Commit Graph

6055 Commits

Author SHA1 Message Date
joshua stein
275bc0d587 LibVT: fix pixel size calculations in terminal_did_resize
The scrollbar width must be factored in, and one too many
m_line_spacing were being factored into the height.  These caused an
initial terminal opening in 80x25 to get resized right away and
shrunk down to 77x24.
2020-01-01 19:33:19 +01:00
Andreas Kling
ea1911b561 Kernel: Share code between Region::map() and Region::remap_page()
These were doing mostly the same things, so let's just share the code.
2020-01-01 19:32:55 +01:00
Andreas Kling
fc86460134 AK: Move the userspace SharedBuffer from LibC to AK
This always felt out-of-place in LibC.
2020-01-01 18:53:34 +01:00
Andreas Kling
38f93ef13b Kernel: Disable x86 RDTSC instruction in userspace
It's still possible to read the TSC via the read_tsc() syscall, but we
will now clear some of the bottom bits for unprivileged users.
2020-01-01 18:22:20 +01:00
Jami Kettunen
dfd759f75a WindowServer: Implement switching windows in reverse order 2020-01-01 18:10:50 +01:00
Andrew Kaster
58517bc068 LibC: Use LibELF in dlfcn.cpp to dynamically load libraries 2020-01-01 17:48:41 +01:00
Andrew Kaster
a18b37880e LibELF: Add ELFDynamicObject to dynamically load libaries
This patch also adds some missing relocation defines to exec_elf.h,
and a few helper classes/methods to ELFImage so that we can use it
for our dynamically loaded libs and not just main program images from
the kernel :)
2020-01-01 17:48:41 +01:00
Andrew Kaster
b6590b7f83 Demos: Add a dynamic linking demo to show off dlfcn methods
The LinkDemo program calls dlopen/dlsym/dlclose to try and load
a dyanmic library from /usr/lib. It read a global variable and
calls a global function (extern "C" of course :) ).

There a few hacks left in the LinkLib dynamic library, however.
In order to get the linker to stop complaining, we have to use
-nostartfiles -ffreestanding otherwise it will link crt0.o to our
shared object, which is definitely not right as the _init function
for a main program (that calls main) is not suitable for our lib
2020-01-01 17:48:41 +01:00
Andrew Kaster
21161342ef LibELF: Replace kprintf's in ELFImage.cpp with dbgprintf
This lets us use the class in userspace
2020-01-01 17:48:41 +01:00
Andrew Kaster
c24fe710d7 AK: Turn off demangler in userland
For some reason, the default CXXFLAGS and such don't get us the
__cxa_demangle symbol in userland.
2020-01-01 17:48:41 +01:00
Andrew Kaster
96a86463dd LibC: Move __cxa_finalize and __cxa_atexit code to their own file
These guys aren't really related to initializing the C runtime,
so move them to a new fancy file named C++ abi. Or rather, cxxabi :)
2020-01-01 17:48:41 +01:00
Dan MacDonald
d57eed289a Meta: Update link to build instructions in INSTALL.md 2020-01-01 17:33:32 +01:00
Andreas Kling
f598bbbb1d Kernel: Prevent executing I/O instructions in userspace
All threads were running with iomapbase=0 in their TSS, which the CPU
interprets as "there's an I/O permission bitmap starting at offset 0
into my TSS".

Because of that, any bits that were 1 inside the TSS would allow the
thread to execute I/O instructions on the port with that bit index.

Fix this by always setting the iomapbase to sizeof(TSS32), and also
setting the TSS descriptor's limit to sizeof(TSS32), effectively making
the I/O permissions bitmap zero-length.

This should make it no longer possible to do I/O from userspace. :^)
2020-01-01 17:31:41 +01:00
Andreas Kling
37329c2009 Kernel: Fix typo in Descriptor::set_limit()
x86 descriptor limits are 20 bytes, not 24 bytes. This was already
a 4-bit wide bitfield, so no damage done, but let's be correct.
2020-01-01 17:21:43 +01:00
Andreas Kling
fd740829d1 Kernel: Switch to eagerly restoring x86 FPU state on context switch
Lazy FPU restore is well known to be vulnerable to timing attacks,
and eager restore is a lot simpler anyway, so let's just do it eagerly.
2020-01-01 16:54:21 +01:00
Andreas Kling
9c0836ce97 Kernel: Enable x86 UMIP (User Mode Instruction Prevention) if supported
This prevents code running outside of kernel mode from using the
following instructions:

* SGDT - Store Global Descriptor Table
* SIDT - Store Interrupt Descriptor Table
* SLDT - Store Local Descriptor Table
* SMSW - Store Machine Status Word
* STR - Store Task Register

There's no need for userspace to be able to use these instructions so
let's just disable them to prevent information leakage.
2020-01-01 13:21:15 +01:00
Andreas Kling
5aeaab601e Kernel: Move CPU feature detection to Arch/x86/CPU.{cpp.h}
We now refuse to boot on machines that don't support PAE since all
of our paging code depends on it.

Also let's only enable SSE and PGE support if the CPU advertises it.
2020-01-01 12:57:00 +01:00
Conrad Pankoff
3d59db4be4 LibGUI: Close and cancel GDialog on escape
This is a small usability enhancement. If you press escape with a GDialog
focused, it will now return its "Cancel" status.
2020-01-01 02:02:29 +01:00
Andreas Kling
8602fa5b49 Kernel: Enable x86 SMEP (Supervisor Mode Execution Protection)
This prevents the kernel from jumping to code in userspace memory.
2020-01-01 01:59:52 +01:00
Jami Kettunen
cece0d230d Applications: Add new keyboard shortcuts & update few existing ones 2020-01-01 01:23:27 +01:00
Jami Kettunen
7f15604f72 HexEditor: Clarify in InputBox which offset (Hex/Dec) you're Going To 2020-01-01 01:23:27 +01:00
Andreas Kling
14cdd3fdc1 Kernel: Make module_load() and module_unload() be superuser-only
These should just fail with EPERM if you're not the superuser.
2020-01-01 00:46:08 +01:00
Jami Kettunen
6af301edec Base: Update Finnish keymap with proper AltGr support 2019-12-31 19:46:40 +01:00
Tibor Nagy
d8ddf803e2 Base: Add Hungarian keymap 2019-12-31 19:31:42 +01:00
Tibor Nagy
c431979aef Keymap: Add AltGr support 2019-12-31 19:31:42 +01:00
Tibor Nagy
624116a8b1 Kernel: Implement AltGr key support 2019-12-31 19:31:42 +01:00
Andreas Kling
36f1de3c89 Kernel: Pointer range validation should fail on wraparound
Let's reject address ranges that wrap around the 2^32 mark.
2019-12-31 18:23:17 +01:00
Andreas Kling
903b159856 Kernel: Write address validation was only checking end of write range
Thanks to yyyyyyy for finding the bug! :^)
2019-12-31 18:18:54 +01:00
Andreas Kling
d8ef13a426 ProcFS: Supervisor-only inodes should be owned by UID 0, GID 0 2019-12-31 13:22:43 +01:00
joshua stein
5b1f8ce220 WindowServer: set no menu bar when last window is removed
This is done here rather than pick_new_active_window() so that when
there are no other windows to focus but the previous window hasn't
been removed (just minimized), the menu bar remains on that client.
2019-12-31 04:23:08 +01:00
Andreas Kling
f908ee3496 WindowServer: Don't deactivate windows after moving them
Also make sure we send out the WM event for window deactivations.
This fixes an issue where the taskbar button for a window would appear
depressed, even after the window was deactivated.
2019-12-31 03:45:54 +01:00
Andreas Kling
c9ec415e2f Kernel: Always reject never-userspace addresses before checking regions
At the moment, addresses below 8MB and above 3GB are never accessible
to userspace, so just reject them without even looking at the current
process's memory regions.
2019-12-31 03:45:54 +01:00
Shannon Booth
8a0ef92100 Crash: Woops! Remove a misplaced if (true)
I was testing with this and must have forgotten to remove it :(
2019-12-31 02:43:43 +01:00
Shannon Booth
8dc6fc9aca WindowServer: Set no active windows on a click outside of any window 2019-12-31 02:34:33 +01:00
Shannon Booth
d0f9906c17 Crash: Add a "Test All Crash Types" option
Add an option "-A", that will run all of the crash types in the crash
program. In this mode, all crash tests are run in a child process so
that the crash program does not crash.

Crash uses the return status of the child process to ascertain whether
the crash happened as expected.
2019-12-31 02:14:36 +01:00
Jami Kettunen
74a18c86c9 Applications: Implement some missing MenuBars & AboutDialogs 2019-12-31 01:46:42 +01:00
Jami Kettunen
33b8d37dd3 Applications: Space out SystemMonitor & TextEditor in AboutDialogs 2019-12-31 01:46:42 +01:00
Andreas Kling
3f254bfbc8 Kernel+ping: Only allow superuser to create SOCK_RAW sockets
/bin/ping is now setuid-root, and will drop privileges immediately
after opening a raw socket.
2019-12-31 01:42:34 +01:00
Andreas Kling
5c918d0e71 dmesg: Add missing newline to error message 2019-12-31 01:32:57 +01:00
Andreas Kling
9af054af9e ProcFS: Reduce the amount of info accessible to non-superusers
This patch hardens /proc a bit by making many things only accessible
to UID 0, and also disallowing access to /proc/PID/ for anyone other
than the UID of that process (and superuser, obviously.)
2019-12-31 01:32:27 +01:00
Andreas Kling
54d182f553 Kernel: Remove some unnecessary leaking of kernel pointers into dmesg
There's a lot more of this and we need to stop printing kernel pointers
anywhere but the debug console.
2019-12-31 01:22:00 +01:00
Andreas Kling
66d5ebafa6 Kernel: Let's also not consider kernel regions to be valid user stacks
This one is less obviously exploitable than the previous one, but still
a bug nonetheless.
2019-12-31 00:28:14 +01:00
Andreas Kling
0fc24fe256 Kernel: User pointer validation should reject kernel-only addresses
We were happily allowing syscalls with pointers into kernel-only
regions (virtual address >= 0xc0000000).

This patch fixes that by only considering user regions in the current
process, and also double-checking the Region::is_user_accessible() flag
before approving an access.

Thanks to Fire30 for finding the bug! :^)
2019-12-31 00:24:35 +01:00
Andreas Kling
25d7a7efa6 WindowServer: Let's boost all threads in the active client process
Instead of just boosting the main thread, let's boost all threads in
the currently active client process.

This avoids creating internal priority inversion problems in clients.
2019-12-30 20:10:49 +01:00
Andreas Kling
a69734bf2e Kernel: Also add a process boosting mechanism
Let's also have set_process_boost() for giving all threads in a process
the same boost.
2019-12-30 20:10:00 +01:00
Andreas Kling
0dea0fd06f WindowServer: Give a thread boost to the currently active window
When the currently active (foreground) window is owned by a client,
we now apply a +10 priority boost to the client's main thread.

You normally want the window you're interacting with to be responsive,
so this little boost allows it to run a bit sooner and more often. :^)
2019-12-30 19:33:24 +01:00
Andreas Kling
610f3ad12f Kernel: Add a basic thread boosting mechanism
This patch introduces a syscall:

    int set_thread_boost(int tid, int amount)

You can use this to add a permanent boost value to the effective thread
priority of any thread with your UID (or any thread in the system if
you are the superuser.)

This is quite crude, but opens up some interesting opportunities. :^)
2019-12-30 19:23:13 +01:00
Andreas Kling
50677bf806 Kernel: Refactor scheduler to use dynamic thread priorities
Threads now have numeric priorities with a base priority in the 1-99
range.

Whenever a runnable thread is *not* scheduled, its effective priority
is incremented by 1. This is tracked in Thread::m_extra_priority.
The effective priority of a thread is m_priority + m_extra_priority.

When a runnable thread *is* scheduled, its m_extra_priority is reset to
zero and the effective priority returns to base.

This means that lower-priority threads will always eventually get
scheduled to run, once its effective priority becomes high enough to
exceed the base priority of threads "above" it.

The previous values for ThreadPriority (Low, Normal and High) are now
replaced as follows:

    Low -> 10
    Normal -> 30
    High -> 50

In other words, it will take 20 ticks for a "Low" priority thread to
get to "Normal" effective priority, and another 20 to reach "High".

This is not perfect, and I've used some quite naive data structures,
but I think the mechanism will allow us to build various new and
interesting optimizations, and we can figure out better data structures
later on. :^)
2019-12-30 18:46:17 +01:00
Andreas Kling
816d3e6208 LibHTML: Ignore all CSS rules starting with "@" for now 2019-12-30 17:09:00 +01:00
Andreas Kling
a88d409c74 AK: Use stack buffers in String::number() to avoid some malloc() calls 2019-12-30 14:52:27 +01:00