Commit Graph

5979 Commits

Author SHA1 Message Date
Andreas Kling
c89fe8a6a3 Kernel: Fix bad TOCTOU pattern in syscalls that take a parameter struct
Our syscall calling convention only allows passing up to 3 arguments in
registers. For syscalls that take more arguments, we bake them into a
struct and pass a pointer to that struct instead.

When doing pointer validation, this is what we would do:

    1) Validate the "params" struct
    2) Validate "params->some_pointer"
    3) ... other stuff ...
    4) Use "params->some_pointer"

Since the parameter struct is stored in userspace, it can be modified
by userspace after validation has completed.

This was a recurring pattern in many syscalls that was further hidden
by me using structured binding declarations to give convenient local
names to things in the parameter struct:

    auto& [some_pointer, ...] = *params;
    memcpy(some_pointer, ...);

This devilishly makes "some_pointer" look like a local variable but
it's actually more like an alias for "params->some_pointer" and will
expand to a dereference when accessed!

This patch fixes the issues by explicitly copying out each member from
the parameter structs before validating them, and then never using
the "param" pointers beyond that.

Thanks to braindead for finding this bug! :^)
2020-01-05 10:37:57 +01:00
Andreas Kling
7ae7a60caa LibELF: Fix stack overflow in ELFImage::relocations()
Thanks to braindead for finding the bug! :^)
2020-01-05 10:37:54 +01:00
Sergey Bugaev
0f42908073 LibHTML: Respect the system theme
LibHTML will now use the palette colors for the default document background and
the text. As always, a page can override this default styling with CSS if it
really wants a specific color or style.

Fixes https://github.com/SerenityOS/serenity/issues/963
2020-01-05 10:21:15 +01:00
Shannon Booth
7557251fac WindowServer: Move menu related code from WindowManager to MenuManager
Menus are now owned by menu manager instead of being split between the
window manager and menu manager. If the window server wants to change
a menu, or call menu related functionality, this will need to be done
through the menu manager.

Further refactoring is likely needed, but this seems like a good start
for seperating menu logic from window logic.
2020-01-05 09:02:24 +01:00
marprok
adff54879c Userland: Support multiple input files.
The user can now give more than one files to the cut command.
2020-01-05 09:00:47 +01:00
Shannon Booth
861f40f014 AK+LibCore: Add an IDAllocator and use to allocate timer ids 2020-01-05 09:00:05 +01:00
Shannon Booth
d5fea1b235 AK: Add a u64 Trait type
This allows u64s to be used in HashMaps.
2020-01-05 09:00:05 +01:00
Elisée Maurer
9e22b83343 Documentation: Suggest gcc-9 on Ubuntu since PPA doesn't have 8 anymore 2020-01-05 08:57:43 +01:00
Jami Kettunen
08c7b5068e Base: Space out some names in app files 2020-01-04 22:29:21 +01:00
Andreas Kling
5a02a0d140 LibGUI: Refine the per-item rects in GItemView
Previously we would consider anything in the large padded area around
each item to also be part of the item for mouse event purposes.
This didn't feel right when rubberbanding, so this patch factors out
the per-item rect computation into a get_item_rects() helper which can
then be used by the various functions that need it.
2020-01-04 21:36:42 +01:00
Andreas Kling
6e21d5c432 LibGUI: Add basic rubber band selection in GItemView 2020-01-04 21:18:48 +01:00
Andreas Kling
d4761762f2 Kernel: Remove some unused Process members 2020-01-04 19:53:29 +01:00
Andreas Kling
3a27790fa7 Kernel: Use Thread::from_tid() in more places 2020-01-04 18:56:04 +01:00
Andreas Kling
95ba0d5a02 Kernel: Remove unused "putch" syscall 2020-01-04 16:00:25 +01:00
Jami Kettunen
874a6c4039 WindowServer: Introduce keyboard shortcuts for fast window management 2020-01-04 14:58:50 +01:00
Jami Kettunen
6c2fa0ee0a WindowServer: Maximize a window if it is dragged to top of the screen 2020-01-04 14:58:50 +01:00
Jami Kettunen
74ae6ac94b WindowServer: Various window pop-up menu fixes & QoL tweaks 2020-01-04 14:58:50 +01:00
Jami Kettunen
eab34a7de3 WindowServer+LibGUI: Implement minimizable property to windows 2020-01-04 14:58:50 +01:00
Jami Kettunen
a641f4d213 WindowServer: Set no active window if no new candidates are available 2020-01-04 14:58:50 +01:00
Andreas Kling
c663b1034a su: Use setgroups() to switch over to the target user's extra GIDs
Before this, su would leave the process's extra GIDs untouched,
simply inheriting them from whoever spawned su.

Now we grab the target user's groups from /etc/group and setgroups().
2020-01-04 13:48:55 +01:00
Andreas Kling
5abc30e057 Kernel: Allow setgroups() to drop all groups with nullptr
Previously we'd EFAULT for setgroups(0, nullptr), but we can just as
well tolerate it if someone wants to drop groups without a pointer.
2020-01-04 13:47:54 +01:00
Andreas Kling
69af59d061 Base: Only allow members of the "wheel" group to use /bin/su 2020-01-04 13:35:25 +01:00
Andreas Kling
d4b4883d55 id: Remove weird commas from output 2020-01-04 13:26:51 +01:00
Andreas Kling
f558c8e36a Base: Add an "audio" group that gets to write to /dev/audio 2020-01-04 13:25:13 +01:00
Andreas Kling
498659773c Base: Add a "phys" group for users with physical access
Only users in this group can access the screen, mouse and keyboard.
2020-01-04 13:21:33 +01:00
Andreas Kling
9bd4bf41fb SystemServer: Explicitly open /dev/null for services without StdIO
Spawning services with nothing open at all on the standard I/O fds is
way too harsh. We now open /dev/null for them instead.
2020-01-04 13:15:01 +01:00
Andreas Kling
c2b7c43f3c SystemServer: Fetch any extra GIDs and call setgroups() before spawn
We now pick up all the user's extra GIDs from /etc/group and make
sure those are set before exec'ing a service.

This means we finally get to enjoy being in more than one group. :^)
2020-01-04 13:11:43 +01:00
Andreas Kling
b4b8b8850a LibC: Fix broken setgroups() wrapper
This was invoking the wrong syscall (getgroups), oops! We had not been
using it yet, so it makes sense.
2020-01-04 13:01:14 +01:00
Andreas Kling
12eb1f5d74 Kernel: Entries in /dev/pts should be accessible only to the owner
This fixes an issue where anyone could snoop on any pseudoterminal.
2020-01-04 12:46:48 +01:00
Andreas Kling
c6254916ba Base: Make /dev/hd{a,b,c,d} superuser-only 2020-01-04 12:46:45 +01:00
Andreas Kling
20ac4e44d1 Base: Add "tty" group and make /dev/tty* be root:tty mode 610
This fixes an issue where anyone could snoop on the virtual consoles.
2020-01-04 12:46:09 +01:00
Andreas Kling
4f4dc47ec3 TTYServer: Use fork+exec instead of system()
No point in spawning an extra shell process just to spawn a shell. :^)
2020-01-04 12:33:34 +01:00
Andreas Kling
b5da0b78eb Kernel: File::open() should apply r/w mode from the provided options
This has been a FIXME for a long time. We now apply the provided
read/write permissions to the constructed FileDescription when opening
a File object via File::open().
2020-01-04 12:30:55 +01:00
Andreas Kling
32d0967f5f SystemServer: Don't let services inherit standard in/out and TTY
We were letting services inherit writable fds for /dev/tty0, as well as
having /dev/tty0 as their controlling terminal.

Lock this down by closing fds {0,1,2} when spawning a service. We also
detach from the controlling terminal. An exception is made for services
with an explicit StdIO setting. In those cases, we now switch the
controlling terminal to the specified path if possible.
2020-01-04 12:17:13 +01:00
Andreas Kling
755938c650 ls: Show directories with the sticky bit in a special color
This makes /tmp show up with a green background in "ls" output.
2020-01-04 11:38:02 +01:00
Andreas Kling
e79c33eabb Kernel: The root inode of a TmpFS should have the sticky bit set
We were running without the sticky bit and mode 777, which meant that
the /tmp directory was world-writable *without* protection.

With this fixed, it's no longer possible for everyone to steal root's
files in /tmp.
2020-01-04 11:33:36 +01:00
Andreas Kling
4398eec03c Build: Lock down the /mod and /boot directories
Make these directories accessible to root only. Unprivileged users have
no need to look at the kernel binary or kernel modules.
2020-01-04 11:12:59 +01:00
Andreas Kling
2d244a70a1 WindowServer+LibGUI: Simplify handling of paint event rects
Now that Vector<T> is convertible to Vector<T, n>, we don't have to
manually copy the paint event rectangles.
2020-01-04 11:03:37 +01:00
Andreas Kling
6dec88c7fa AK: Allow copying a Vector from a Vector with different inline capacity 2020-01-04 10:57:30 +01:00
Andreas Kling
4f11528a65 WindowServer: Remove some unused WSClientConnection functions 2020-01-04 10:41:42 +01:00
Andrew Kaster
767f4c7421 LibELF+LibC: Split ELFDynamicObject into a Loader + Object
Separate some responsibilities:

ELFDynamicLoader is responsible for loading elf binaries from disk and
performing relocations, calling init functions, and eventually calling
finalizer functions.

ELFDynamicObject is a helper class to parse the .dynamic section of an
elf binary, or the table of Elf32_Dyn entries at the _DYNAMIC symbol.
ELFDynamicObject now owns the helper classes for Relocations, Symbols,
Sections and the like that ELFDynamicLoader will use to perform
relocations and symbol lookup.

Because these new helpers are constructed from offsets into the .dynamic
section within the loaded .data section of the binary, we don't need the
ELFImage for nearly as much of the loading processes as we did before.
Therefore we can remove most of the extra DynamicXXX classes and just
keep the one that lets us find the location of _DYNAMIC in the new ELF.

And finally, since we changed the name of the class that dlopen/dlsym
care about, we need to compile/link and use the new ELFDynamicLoader
class in LibC.
2020-01-04 10:39:04 +01:00
Conrad Pankoff
85b95f472d Kernel: Remove unused PCI.{h,cpp} 2020-01-04 10:06:07 +01:00
erf
53733be5fd Kernel: Make LocalSocket pre-bind GID be gid_t (#1012) 2020-01-04 10:05:01 +01:00
Andreas Kling
70a41420a9 LibCore: Fix crash on RPC client disconnect
The RPC client management was not updated for the changes that made
CObject reference-counted it seems. :^)
2020-01-03 20:27:48 +01:00
Andreas Kling
e76e533a69 LibCore: Stop making the RPC sockets go=rw
Now that we can fchmod() on a pre-bind() socket, use that to lock down
the RPC sockets we publish in all CEventLoop-driven programs.
2020-01-03 20:21:39 +01:00
Andreas Kling
15b57488d9 SystemServer: Make service sockets owned by the configured user
Also make the sockets readable and writable only by that user.

This fixes a bug where anyone could connect to anyone else's services,
most obviously WindowServer.
2020-01-03 20:16:49 +01:00
Andreas Kling
d84299c7be Kernel: Allow fchmod() and fchown() on pre-bind() local sockets
In order to ensure a specific owner and mode when the local socket
filesystem endpoint is instantiated, we need to be able to call
fchmod() and fchown() on a socket fd between socket() and bind().

This is because until we call bind(), there is no filesystem inode
for the socket yet.
2020-01-03 20:14:56 +01:00
Andreas Kling
4abbedb6e4 Kernel: Allow passing initial UID and GID when creating new inodes
If we're creating something that should have a different owner than the
current process's UID/GID, we need to plumb that all the way through
VFS down to the FS functions.
2020-01-03 20:13:21 +01:00
Andreas Kling
82760998a9 Ext2FS: Take the inode lock in Ext2FSInode::metadata()
Remove an unnecessary InterruptDisabler to make this not assert. :^)
2020-01-03 17:48:02 +01:00
Andreas Kling
aba7829724 Kernel: InodeVMObject can't call Inode::size() with interrupts disabled
Inode::size() may try to take a lock, so we can't be calling it with
interrupts disabled.

This fixes a kernel hang when trying to execute a binary in a TmpFS.
2020-01-03 15:40:03 +01:00