Commit Graph

6055 Commits

Author SHA1 Message Date
Andreas Kling
28ee5b0e98 TmpFS: Reads past the end of a file should be zero-length 2020-01-08 12:47:41 +01:00
Andreas Kling
50056d1d84 Kernel: mmap() should fail with ENODEV for directories 2020-01-08 12:47:37 +01:00
Shannon Booth
3f35cd2f7d WSWindowServer: Only close menubar on a mouse down
This allows you to click on the menu, then use the menu keys to browse
the menu. Beforehand, you would click the window, release the button,
and the menu would close :(
2020-01-08 11:36:49 +01:00
Shannon Booth
7fb7b399a3 WSWindowManager: Use early return to limit nesting
Let's be a little nicer on the eyes :^)
2020-01-08 11:36:49 +01:00
Shannon Booth
4683424e7a WSMenu: Support menu navigation through key presses
Add event handling for key presses for navigating a menu. The currently
hovered menu item is tracked through an index which is either
incremented or decremented on up or down arrow key presses, changing the
hovered item.

Whenever there is a mouse move event, we ensure that the current index
matches the currently hovered item so that the mouse and keyboard do not
get out of sync.

If the right key is pressed, and we are on a submenu menu item, we
'enter' that submenu. While we are currently in a submenu, we forward
all keypress events to that submenu for handling. This allows us to
traverse the heirachy of a menu. While in a submenu, if the left key is
pressed, we leave that submenu and start handling the keypresses
ourselves again.

There is currently a small issue where the mouse hover and key hover can
get out of sync. The mouse can be traversing a submenu, but the parent
menu has no idea that the mouse has 'entered' a submenu, so will handle
the key presses itself, instead of forwarding them to the submenu. One
potential fix for this is for a menu to tell its menu parent that the
submenu is being traversed.
2020-01-08 11:36:49 +01:00
Shannon Booth
27cb91e3e0 WSMenuManager: On menu close, close the currently hovered menu item
Ensure that the current hover is not still hovered when the menu is
opened again.
2020-01-08 11:36:49 +01:00
Shannon Booth
0c1bc91e88 WSWindowServer: Remove uneccessary special casing
From my testing I could not see this code doing anything. Listen the
FIXME, and remove this.
2020-01-08 11:36:49 +01:00
Andreas Kling
372f9e9a11 Kernel: Enable SMAP protection on IRQ and exception entry
It would be nice to do this in the assembly code, but we have to check
if the feature is available before doing a CLAC, so I've put this in
the C++ code for now.
2020-01-08 10:37:53 +01:00
Andreas Kling
fe9680f0a4 Kernel: Validate PROT_READ and PROT_WRITE against underlying file
This patch fixes some issues with the mmap() and mprotect() syscalls,
neither of whom were checking the permission bits of the underlying
files when mapping an inode MAP_SHARED.

This made it possible to subvert execution of any running program
by simply memory-mapping its executable and replacing some of the code.

Test: Kernel/mmap-write-into-running-programs-executable-file.cpp
2020-01-07 19:32:32 +01:00
Andreas Kling
faf32153f6 Kernel: Take const Process& in InodeMetadata::may_{read,write,execute} 2020-01-07 19:24:06 +01:00
DAlperin
dcc4704fb5 LibGUI: Preserve existing GItemView selection on rubber band (#1031) 2020-01-07 16:18:12 +01:00
Andreas Kling
5387a19268 Kernel: Make Process::file_description() vend a RefPtr<FileDescription>
This encourages callers to strongly reference file descriptions while
working with them.

This fixes a use-after-free issue where one thread would close() an
open fd while another thread was blocked on it becoming readable.

Test: Kernel/uaf-close-while-blocked-in-read.cpp
2020-01-07 15:53:42 +01:00
Andreas Kling
a47f3031ae LibC: Add MAP_FILE for mmap() 2020-01-07 15:35:41 +01:00
Andreas Kling
a49d9c774f TmpFS: Add ASSERT(offset >= 0) to read_bytes() and write_bytes() 2020-01-07 15:25:56 +01:00
Andreas Kling
c48acafcba AK: Add assertions to FixedArray::operator[]
Let's catch ourselves if we ever index out of bounds into one of these.
2020-01-07 14:49:33 +01:00
Andreas Kling
6a4b376021 Kernel: Validate ftruncate(fd, length) syscall inputs
- EINVAL if 'length' is negative
- EBADF if 'fd' is not open for writing
2020-01-07 14:48:43 +01:00
Andreas Kling
bb9db9d430 TmpFS: Add "." and ".." entries to all directories
It was so weird not seeing them in "ls -la" output :^)
2020-01-07 14:48:43 +01:00
Conrad Pankoff
0e7cee58c0 LibGUI: Run clang-format on GModel.h to neaten up some formatting 2020-01-07 12:46:22 +01:00
Conrad Pankoff
84f0be37f0 LibCore: Fix a typo in CConfigFile.h 2020-01-07 12:46:02 +01:00
Conrad Pankoff
c7fd39f3b1 AK: Add dirname() to FileSystemPath 2020-01-07 12:36:30 +01:00
Andreas Kling
3f3169c225 FileManager: Unbreak build after "select all" changes 2020-01-07 11:12:33 +01:00
Shannon Booth
6192467de9 Filemanager: Add Ctrl+A select all action
Unfortunately this means that current_view() needed to be made non-const
as changing the selection is a non-const operation.
2020-01-07 11:06:27 +01:00
Shannon Booth
7cf15bcb75 GAbstractView: Add function for adding all to selection 2020-01-07 11:06:27 +01:00
N00byEdge
00596296c4 LibDraw: Add support for parsing #RGBA colors
This was the nicest way of making this happen, I think.
Fitting it into the 4 length function ended up becoming too hard to read.

Closes #1027
2020-01-07 11:03:35 +01:00
0xtechnobabble
123dcada05 Themes: Support rubberband selection theming 2020-01-07 11:02:43 +01:00
Andreas Kling
56a2c21e0c Kernel: Don't leak kmalloc pointers through FIFO absolute paths
Instead of using the FIFO's memory address as part of its absolute path
identity, just use an incrementing FIFO index instead.

Note that this is not used for anything other than debugging (it helps
you identify which file descriptors refer to the same FIFO by looking
at /proc/PID/fds
2020-01-07 10:29:47 +01:00
Andreas Kling
5646a95161 Kernel: Make Socket::absolute_path() pure virtual
This is overridden by all subclasses, so can just be pure virtual.
2020-01-07 10:24:45 +01:00
Andreas Kling
78a63930cc Kernel+LibELF: Validate PT_LOAD and PT_TLS offsets before memcpy()'ing
Before this, you could make the kernel copy memory from anywhere by
setting up an ELF executable with a program header specifying file
offsets outside the file.

Since ELFImage didn't even know how large it was, we had no clue that
we were copying things from outside the ELF.

Fix this by adding a size field to ELFImage and validating program
header ranges before memcpy()'ing to them.

The ELF code is definitely going to need more validation and checking.
2020-01-06 21:04:57 +01:00
Andreas Kling
9bf1fe9439 LibC: Remove thread-specific TID cache
As Sergey pointed out forever ago, this value is wrong after fork().
2020-01-06 14:39:52 +01:00
Andreas Kling
8088fa0556 Kernel: Process::send_signal() should prefer main thread
The main/first thread in a process always has the same TID as the PID.
2020-01-06 14:37:26 +01:00
Andreas Kling
a803312eb4 Kernel: Send SIGCHLD to the thread with same PID as my PPID
Instead of delivering SIGCHLD to "any thread" in the process with PPID,
send it to the thread with the same TID as my PPID.
2020-01-06 14:35:42 +01:00
Andreas Kling
cd42ccd686 Kernel: The waitpid() syscall was not storing to "wstatus" in all cases 2020-01-06 14:34:04 +01:00
Andreas Kling
0e6ea49410 Kernel: Fix SMAP violation when doing a crash dump 2020-01-06 14:26:47 +01:00
Andreas Kling
8e7420ddf2 Kernel: Harden memory mapping of the kernel image
We now map the kernel's text and rodata segments read+execute.
We also make the data and bss segments non-executable.

Thanks to q3k for the idea! :^)
2020-01-06 13:55:39 +01:00
Andreas Kling
47cc3e68c6 Kernel: Remove bogus kernel image access validation checks
This code had been misinterpreting the Multiboot ELF section headers
since the beginning. Furthermore QEMU wasn't even passing us any
headers at all, so this wasn't checking anything.
2020-01-06 13:27:14 +01:00
Andreas Kling
99f71a9a2c Kernel: Randomize the stack canary on startup 2020-01-06 13:05:40 +01:00
Andreas Kling
0614c3dd3c Kernel: Build the kernel as a position-independent executable
This is a prerequisite for KASLR, which we should eventually be doing.
2020-01-06 13:04:11 +01:00
Andreas Kling
53bda09d15 Kernel: Make utime() take path+length, remove SmapDisabler 2020-01-06 12:23:30 +01:00
Andreas Kling
1226fec19e Kernel: Remove SmapDisablers in stat() and lstat() 2020-01-06 12:13:48 +01:00
Andreas Kling
08cfcb888c Kernel: Add KResult::error() to make it look symmetrical with KResultOr 2020-01-06 12:08:27 +01:00
Andreas Kling
a47f0c93de Kernel: Pass name+length to mmap() and remove SmapDisabler 2020-01-06 12:04:55 +01:00
Andreas Kling
33025a8049 Kernel: Pass name+length to set_mmap_name() and remove SmapDisabler 2020-01-06 11:56:59 +01:00
Andreas Kling
6af8392cf8 Kernel: Remove SmapDisabler in futex() 2020-01-06 11:44:15 +01:00
Andreas Kling
a30fb5c5c1 Kernel: SMAP fixes for module_load() and module_unload()
Remove SmapDisabler in module_load() + use get_syscall_path_argument().
Also fix a SMAP violation in module_unload().
2020-01-06 11:36:16 +01:00
Andreas Kling
7c916b9fe9 Kernel: Make realpath() take path+length, get rid of SmapDisabler 2020-01-06 11:32:25 +01:00
Andreas Kling
d6b06fd5a3 Kernel: Make watch_file() syscall take path length as a size_t
We don't care to handle negative path lengths anyway.
2020-01-06 11:15:49 +01:00
Andreas Kling
cf7df95ffe Kernel: Use get_syscall_path_argument() for syscalls that take paths 2020-01-06 11:15:49 +01:00
Andreas Kling
0df72d4712 Kernel: Pass path+length to mkdir(), rmdir() and chmod() 2020-01-06 11:15:49 +01:00
Andreas Kling
53d3b6b0a7 LibC: Make the syscall wrappers for stat/lstat/chdir return EFAULT
If we pass a null path to these syscall wrappers, just return EFAULT
directly from the wrapper instead of segfaulting by calling strlen().
This is a compromise, since we now have to pass the path length to the
kernel, so we can't rely on the kernel to tell us that the path is at
a bad memory address.
2020-01-06 11:15:49 +01:00
Andreas Kling
642137f014 Kernel: Make access() take path+length
Also, let's return EFAULT for nullptr at the LibC layer. We can't do
all bad addresses this way, but we can at least do null. :^)
2020-01-06 11:15:48 +01:00