Commit graph

927 commits

Author SHA1 Message Date
Jared Miller
d4000bb8f7
Correct more typos (#500) 2022-07-21 20:53:30 -07:00
Justine Tunney
8b469389f6 Remove plenty of makefile misconfigurations 2022-07-21 09:20:59 -07:00
Justine Tunney
9172fd42a0 Add Landlock sandboxing to GNU Make 2022-07-21 09:16:27 -07:00
Justine Tunney
1837dc2e85 Make improvements
- Introduce path module to redbean
- Fix glitch with linenoise printing extra line on eof
- Introduce closefrom() and close_range() system calls
- Make file descriptor closing more secure in pledge.com
2022-07-21 03:36:42 -07:00
Paul Kulchenko
439ad21b12
Allow .well-known/ hidden paths (#499) 2022-07-20 23:26:49 -07:00
Jared Miller
7e2eae5c15
Remove trailing whitespace from all files (#497) 2022-07-20 20:31:16 -07:00
Justine Tunney
d3f3cb7ab4 Fix build 2022-07-20 14:00:38 -07:00
Justine Tunney
097634d75c Make pledge.com binary 4kb smaller 2022-07-20 13:59:28 -07:00
jared
ed205e98a1
WIP: Correct all typos (#498) 2022-07-20 14:01:15 -07:00
Justine Tunney
98254a7c1f Make pledge() and unveil() work amazingly
This change reconciles our pledge() implementation with the OpenBSD
kernel source code. We now a polyfill that's much closer to OpenBSD's
behavior. For example, it was discovered that "stdio" permits threads.
There were a bunch of Linux system calls that needed to be added, like
sched_yield(). The exec / execnative category division is now dropped.
We're instead using OpenBSD's "prot_exec" promise for launching APE
binaries and dynamic shared objects. We also now filter clone() flags.

The pledge.com command has been greatly improved. It now does unveiling
by default when Landlock is available. It's now smart enough to unveil a
superset of paths that OpenBSD automatically unveils with pledge(), such
as /etc/localtime. pledge.com also now checks if the executable being
launched is a dynamic shared object, in which case it unveils libraries.

These changes now make it possible to pledge curl on ubuntu 20.04 glibc:

    pledge.com -p 'stdio rpath prot_exec inet dns tty sendfd recvfd' \
        curl -s https://justine.lol/hello.txt

Here's what pledging curl on Alpine 3.16 with Musl Libc looks like:

    pledge.com -p 'stdio rpath prot_exec dns inet' \
        curl -s https://justine.lol/hello.txt

Here's what pledging curl.com w/ ape loader looks like:

    pledge.com -p 'stdio rpath prot_exec dns inet' \
        o//examples/curl.com https://justine.lol/hello.txt

The most secure sandbox, is curl.com converted to static ELF:

    o//tool/build/assimilate.com o//examples/curl.com
    pledge.com -p 'stdio rpath dns inet' \
        o//examples/curl.com https://justine.lol/hello.txt

A weird corner case needed to be handled when resolving symbolic links
during the unveiling process, that's arguably a Landlock bug. It's not
surprising since Musl and Glibc are also inconsistent here too.
2022-07-19 21:33:49 -07:00
Justine Tunney
92cb144fff Revise wording of support vector in readme 2022-07-19 16:05:19 -07:00
Justine Tunney
f716435260 Whitelist some more system calls with pledge() 2022-07-19 02:54:10 -07:00
Justine Tunney
6e52a84a51 Prevent unveil() from being used multiple times
See #493
2022-07-19 02:12:32 -07:00
Justine Tunney
f7e22a33a1 Disable kernel verbose strace output 2022-07-19 00:33:36 -07:00
Justine Tunney
69f4152f38 Always initialize thread local storage
We had previously not enabled TLS in MODE=tiny in order to keep the
smallest example programs (e.g. life.com) just 16kb in size. But it
was error prone doing that, so now we just always enable it because
this change uses hacks to ensure it won't increase life.com's size.

This change also fixes a bug on NetBSD, where signal handlers would
break thread local storage if SA_SIGINFO was being used. This looks
like it might be a bug in NetBSD, but it's got a simple workaround.
2022-07-19 00:21:46 -07:00
Justine Tunney
057e8f5b54 Fix O_CLOEXEC behavior with unveil() 2022-07-18 21:05:46 -07:00
Justine Tunney
bf59defc0c Fix GitHub Actions build
This is an unusual failure that seems to happen intermittently across
the various build modes. It should not be possible for life.elf to be
exiting with status zero.
2022-07-18 20:45:18 -07:00
Paul Kulchenko
574eba8352
Add redbean OnLogLatency hook (#495) 2022-07-18 20:17:14 -07:00
Stephen Gregoratto
6598940d8a
Make unveil() improvements (#493)
- Merge the multiple masks to just one.
- Add documentation to for sys_unveil.
- Inline the chomp function in the unveil tool.
2022-07-18 08:26:40 -07:00
Justine Tunney
e81edf7b04 Improve pledge() and unveil()
The pledge.com command now supports the new [WIP] unveil() support. For
example, to strongly sandbox our command for listing directories.

    o//tool/build/assimilate.com o//examples/ls.com
    pledge.com -v /etc -p 'stdio rpath' o//examples/ls.com /etc

This file system sandboxing is going to be perfect for us, because APE
binaries are self-contained static executables that really don't use the
filesystem that much. On the other hand, with non-static executables,
sandboxing is going to be more difficult. For example, here's how to
sandbox the `ls` command on the latest Alpine:

    pledge.com -v rx:/lib -v /usr/lib -v /etc -p 'stdio rpath exec' ls /etc

This change fixes the `execpromises` API with pledge().

This change also adds unix.unveil() to redbean.

Fixes #494
2022-07-18 07:58:20 -07:00
Justine Tunney
b1d9d11be1 Simplify TLS and reduce startup latency
This change simplifies the thread-local storage support code. On Windows
and Mac OS X the startup latency of __enable_tls() has been reduced from
30ms to 1ms. On Windows, TLS memory accesses will now go much faster due
to better self-modifying code that prevents a function call and acquires
our thread information block pointer in a single instruction.
2022-07-18 04:10:54 -07:00
Justine Tunney
38c3fa63fe Write some tests for unveil()
See #490
2022-07-18 02:27:26 -07:00
Stephen Gregoratto
1c6b5c0acd
[WIP] Polyfill OpenBSD unveil for Linux (#490) 2022-07-18 02:12:42 -07:00
Justine Tunney
4f4889ddf7 Use futexes on OpenBSD and improve threading 2022-07-17 19:59:49 -07:00
Justine Tunney
5b11033d4d Add redbean -I flag for launching browser
It's now possible with any redbean (including redbean-original) to
launch the system web browser without having to use the Lua API. For
example, you can create an args file:

    echo -I/ >.args
    zip redbean-original.com .args

That will white-label redbean so it launches a specific page when you
double-click on the executable.

See https://github.com/jart/cosmopolitan/discussions/472
2022-07-17 06:12:57 -07:00
Justine Tunney
4d25f8c3c9 Add tcp syn packet fingerprinting to redbean
This change also fixes bugs in enoprotoopt reporting with setsockopt and
getsockopt error returns.
2022-07-17 02:43:49 -07:00
Justine Tunney
866b21a151 Get redbean -X running in blinkenlights again
This change improves the loading of APE executables in Blinkenlights and
adds some system call wrappers that were previous missing.
2022-07-16 11:52:45 -07:00
Wiebe
4700984456
Update Redbean help.txt (#492)
Fix typos and add previously undocumented functions:

- GetHttpReason
- IsHiddenPath
- IsAcceptablePath
- IsReasonablePath
- ProgramTimeout
2022-07-16 11:00:28 -07:00
S. Neuhaus
ea04d00752
Fix typo in readme (#486) 2022-07-16 10:56:10 -07:00
Justine Tunney
6c724c0f1a Update experiment with tty audio 2022-07-15 23:07:32 -07:00
Justine Tunney
aa34340f3d Add pipelining to cocmd 2022-07-15 20:47:20 -07:00
Justine Tunney
b4e38851ff Fix pthread isystem reference
Fixes #489
2022-07-15 18:48:24 -07:00
Justine Tunney
13d67fed38 Add latest Linux syscalls including landlock
See #485
2022-07-15 18:29:49 -07:00
Justine Tunney
2e3958c6dc Make some touchups 2022-07-15 18:07:34 -07:00
Justine Tunney
6c49e36537 Release redbean 2.0.13 2022-07-15 07:47:36 -07:00
Justine Tunney
7f966de489 Limit pledge.com default virtual mem to total ram 2022-07-15 06:53:01 -07:00
Justine Tunney
baf51a4a23 Add utf-8 validation to ljson 2022-07-15 06:20:07 -07:00
Justine Tunney
ccd057a85d Permit MAP_POPULATE with pledge() 2022-07-14 13:04:28 -07:00
Justine Tunney
0a589add41 Third time's a charm with stack remaining checker 2022-07-14 07:38:44 -07:00
Justine Tunney
28b9d9f781 Fix C stack remaining check in MODE=tiny 2022-07-14 07:23:15 -07:00
Justine Tunney
bcdd5c5f74 Fix ljson stack check 2022-07-14 07:07:17 -07:00
Justine Tunney
4901e1b8cb Fix MODE=tiny build 2022-07-14 05:42:24 -07:00
Justine Tunney
1d744ea11b Improve upon the new pledge command 2022-07-14 04:39:45 -07:00
Justine Tunney
b707fca77a Make JSON parser perfectly conformant 2022-07-13 23:02:19 -07:00
Justine Tunney
60164a7266 Add assimilate.com command for APE binaries 2022-07-13 20:56:24 -07:00
Gautham
0cea6c560f
Make JSON parser nearly perfectly compliant (#483) 2022-07-13 07:38:23 -07:00
Justine Tunney
1d490fcb94 Add pledge.com for launching commands in a sandbox 2022-07-13 04:31:46 -07:00
Gautham
12d9f7ade6
Make ljson more strict (#482) 2022-07-13 02:39:19 -07:00
Justine Tunney
30cc2c8dc1 Release redbean 2.0.12 2022-07-13 00:05:31 -07:00
Justine Tunney
e3cd476a9b Improve Lua and JSON serialization 2022-07-12 23:35:11 -07:00