Commit graph

115 commits

Author SHA1 Message Date
Andreas Kling
c8ff2184bd LibCore: Add Core::System::posix_fallocate() 2022-11-29 11:09:19 +01:00
Liav A
718ae68621 Kernel+LibCore+LibC: Implement support for forcing unveil on exec
To accomplish this, we add another VeilState which is called
LockedInherited. The idea is to apply exec unveil data, similar to
execpromises of the pledge syscall, on the current exec'ed program
during the execve sequence. When applying the forced unveil data, the
veil state is set to be locked but the special state of LockedInherited
ensures that if the new program tries to unveil paths, the request will
silently be ignored, so the program will continue running without
receiving an error, but is still can only use the paths that were
unveiled before the exec syscall. This in turn, allows us to use the
unveil syscall with a special utility to sandbox other userland programs
in terms of what is visible to them on the filesystem, and is usable on
both programs that use or don't use the unveil syscall in their code.
2022-11-26 12:42:15 -07:00
Ali Mohammad Pur
2110e7cf85 Everywhere: Add support for compilation under emscripten
Co-Authored-By: Andrew Kaster <akaster@serenityos.org>
2022-11-26 02:23:15 +03:30
Liav A
8d8b0d0a34 Userland: Add support for jails
This happens in two ways:
1. LibCore now has two new methods for creating Jails and attaching
   processes to a Jail.
2. We introduce 3 new utilities - lsjails, jail-create and jails-attach,
   which list jails, create jails and attach processes to a Jail,
   respectively.
2022-11-05 18:00:58 -06:00
Liav A
0d1af1ad63 LibCore: Add System::exec_command method
This method was taken from the pls utility and its purpose is to execute
a given command with all the required requirements such as providing a
suitable exec environment.
2022-11-05 18:00:58 -06:00
Peter Elliott
415eb17490 LibCore: Add Core::System::readlink 2022-10-31 22:10:22 +00:00
Liav A
d102ea5f81 Userland: Unveil /usr/lib/Loader.so when using 'x' permissions on unveil
We should not rely on the Kernel to unveil this for us, so if a program
needs to execute another program it should unveil the dynamic loader too
to prevent crashing.
To do this, we check if the user program tried to unveil a binary with
at least using the 'x' permission, so we will try to also unveil the
dynamic loader too.
2022-10-24 19:41:32 -06:00
Andrew Kaster
1d533acbc0 AK+Userland: Replace Linux, macOS, and *BSD macros with platform defines
We have such nice platform macros, let's clean up any remnants of manual
__my_platform__ macros in LibCore, LibCompress and AK.
2022-10-10 12:23:12 +02:00
Andrew Kaster
828441852f Everywhere: Replace uses of __serenity__ with AK_OS_SERENITY
Now that we have OS macros for essentially every supported OS, let's try
to use them everywhere.
2022-10-10 12:23:12 +02:00
Peter Elliott
7af5eef0dd SystemServer+LoginServer+Userland: Switch to sid-based sockets
This commit does three things atomically:
- switch over Core::Account+SystemServer+LoginServer to sid based socket
  names.
- change socket names with %uid to %sid.
- add/update necessary pledges and unveils.

Userland: Switch over servers to sid based sockets

Userland: Properly pledge and unveil for sid based sockets
2022-10-03 11:11:29 +02:00
Peter Elliott
71728f3ea6 LibCore: Add Core::System wrapper for getsid() 2022-10-03 11:11:29 +02:00
Lucas CHOLLET
08dcc40aa5 LibCore: Allow the setgroups wrapper to be used on Lagom
i.e. move Core::System::setgroups() outside the `__serenity__` define.
The base function is already used by LibCore::Account.
2022-09-27 21:29:44 +01:00
Andrew Kaster
8f38367d46 LibCore: Only include Account.h on Serenity in EventLoop and System
Core::Acount is only used within ``#ifdef __serenity__`` blocks in these
files, so guard the inclusion of Account.h in the same way.

This fixes the Android build of these files.
2022-09-22 11:07:21 -04:00
Tim Schumacher
5f99934dce Userland: Consolidate most PATH resolving into a single implementation
We previously had at least three different implementations for resolving
executables in the PATH, all of which had slightly different
characteristics.

Merge those into a single implementation to keep the behaviour
consistent, and maybe to make that implementation more configurable in
the future.
2022-08-23 19:00:04 +01:00
Tim Schumacher
39a3775f48 Userland: Rely on a single authoritative source for the default PATH 2022-08-23 19:00:04 +01:00
Lucas CHOLLET
9cfd1b1a67 LibCore: Make Core::System::unveil aware of %uid in path
This brings support for user-dependent paths in `unveil`.
2022-08-14 21:52:35 +01:00
Tim Schumacher
c44b9acac3 LibCore: Add System::link() 2022-07-25 22:21:01 +01:00
Itamar
91a03bc6ae LibCore: Add function for searching a file in $PATH
This extracts the logic of searching for a file in $PATH from
System::exec to a separate function.
2022-07-21 16:40:11 +02:00
Daniel Bertalan
4bed2ef66b LibCore: Port System::anon_create to FreeBSD
FreeBSD implements the Linux API, so this was very simple luckily.
2022-07-19 12:39:24 +02:00
Andrew Kaster
d84fc60f96 LibCore: Add support for compiling for Android with API Version >= 30
Most changes are around user and group management, which are exposed in
the Android NDK differently than other Unices.

We require version 30 for memfd_create, version 28 for posix_spawn, and
so on. It's possible a shim for memfd_create could be used, but since
Google is mandating new apps use API level 30 as of Nov 2022, this seems
suitable.
2022-07-19 10:44:02 +01:00
sin-ack
3f3f45580a Everywhere: Add sv suffix to strings relying on StringView(char const*)
Each of these strings would previously rely on StringView's char const*
constructor overload, which would call __builtin_strlen on the string.
Since we now have operator ""sv, we can replace these with much simpler
versions. This opens the door to being able to remove
StringView(char const*).

No functional changes.
2022-07-12 23:11:35 +02:00
sin-ack
c70f45ff44 Everywhere: Explicitly specify the size in StringView constructors
This commit moves the length calculations out to be directly on the
StringView users. This is an important step towards the goal of removing
StringView(char const*), as it moves the responsibility of calculating
the size of the string to the user of the StringView (which will prevent
naive uses causing OOB access).
2022-07-12 23:11:35 +02:00
gggggg-gggggg
d728017578 Kernel+LibC+LibCore: Pass fcntl extra argument as pointer-sized variable
The extra argument to fcntl is a pointer in the case of F_GETLK/F_SETLK
and we were pulling out a u32, leading to pointer truncation on x86_64.
Among other things, this fixes Assistant on x86_64 :^)
2022-07-10 20:09:11 +02:00
Kenneth Myhra
fbe22af86e Everywhere: Use my fairly new and shiny serenityos.org email :^) 2022-06-30 15:59:42 +01:00
Lucas CHOLLET
d288c700c7 LibCore: Add a wrapper for endgrent() 2022-06-09 22:08:04 +02:00
MacDue
0295d79339 LibCore: Add posix_spawn() wrapper to Core::System 2022-05-25 23:14:22 +01:00
sin-ack
bc7c8879c5 Kernel+LibC+LibCore: Implement the unlinkat(2) syscall 2022-04-23 10:43:32 -07:00
Sam Atkins
32ab09a930 LibCore: Add a wrapper for execvpe() and friends
This is a single function, which behaves like the various LibC exec()
functions depending on the passed parameters. No direct equivalent is
made for execl() - you have to wrap your arguments in a Span of some
kind.

On Serenity, this calls the syscall directly, whereas Lagom forwards to
the appropriate LibC function.
2022-04-11 21:09:42 +02:00
kleines Filmröllchen
ceba27c3fe LibCore: Add openat() syscall wrapper and improve open's implementation
We don't need va_args in open(), we can just use a default parameter.
2022-04-11 00:08:48 +02:00
Idan Horowitz
086969277e Everywhere: Run clang-format 2022-04-01 21:24:45 +01:00
Kenneth Myhra
0015040ebd LibCore: Add syscall wrapper for access() 2022-03-29 21:28:29 -07:00
Brian Gianforcaro
6eebd69b70 LibCore: Add Core::System::drop_privileges()
In a few places we intentionally drop privileges to reduce the potential
security surface area of networked program, with the pattern of:

```
if (setgid(getgid()) || setuid(getuid()) {
    return 1;
}
```

We can make this a bit nicer to use by creating a wrapper.
2022-03-22 11:39:20 +01:00
Lucas CHOLLET
5d29f64c99 LibCore: Add wrapper for posix_openpt(), grantpt() and unlockpt() 2022-03-02 18:08:05 +01:00
Lucas CHOLLET
ddf9987c39 LibCore+LibC: Add wrapper for setenv
I also added a common interface with StringView compatible parameters:

int serenity_setenv(const char*, ssize_t, const char*, ssize_t, int)

This function is called by both C and C++ API for setenv().
2022-03-02 18:08:05 +01:00
Lucas CHOLLET
b1af1b399e LibCore: Add tcsetpgrp(int, pid_t) wrapper 2022-03-02 18:08:05 +01:00
Lucas CHOLLET
19d5974e3a LibCore: Add killpg() wrapper 2022-03-02 18:08:05 +01:00
Lenny Maiorani
b455363ce7 LibCore: Add rmdir system call wrapper 2022-02-28 13:57:26 +01:00
Isak Holmstrom
4f716caa33 LibCore: Add FreeBSD as OpenBSD/Apple in System.cpp & System.h 2022-02-17 09:26:56 +00:00
sin-ack
37658e6fa6 LibCore: Implement System::fchown 2022-02-14 11:44:09 +01:00
Filiph Sandström
3ebb3d9d52 LibCore: Add Darwin anon_create support 2022-02-13 17:54:34 +00:00
rvictorr
73303f0dc1 LibCore: Add syscall wrapper for profiling_free_buffer() 2022-02-13 12:40:36 +01:00
rvictorr
014c0d68c0 LibCore: Add syscall wrapper for profiling_disable() 2022-02-13 12:40:36 +01:00
rvictorr
c6a743f22c LibCore: Add syscall wrapper for profiling_enable() 2022-02-13 12:40:36 +01:00
kleines Filmröllchen
cf1f58d51c LibCore/System: Add anon_create syscall wrapper
This wrapper is particularly helpful as we use a combination of similar
syscalls on Linux to simulate the behavior of the Serenity-exclusive
anon_create syscall. Users therefore won't have to worry about the
platform anymore :^)
2022-02-10 21:35:17 +01:00
Kenneth Myhra
c10abd6be2 LibCore: Add mkfifo() syscall wrapper 2022-01-24 14:01:58 +03:30
Kenneth Myhra
9fe1ebebdc LibCore: Add mknod() syscall wrapper 2022-01-24 14:01:58 +03:30
Liav A
24efc74318 LibCore: Print the actual errno if sysbeep failed 2022-01-23 00:40:54 +00:00
Federico Guerinoni
2291ef6c3c LibCore: Add syscall wrapper for umount() 2022-01-22 13:31:52 +02:00
Maciej
ccb8374434 LibCore: Add Core::System wrapper for disown() 2022-01-21 13:44:36 +01:00
mjz19910
a9fb34ca6f LibCore: Add ErrorOr wrapper for adjtime 2022-01-21 01:52:22 +01:00