Commit Graph

800 Commits

Author SHA1 Message Date
Omar Polo b618111a68 log more details for FastCGI errors
add the reported request id if there's a mismatch and both the gai error
and the errno value if getnameinfo fails.
2021-10-02 17:20:10 +00:00
Omar Polo 5f37f9c20d simplify error check 2021-10-02 17:20:10 +00:00
Omar Polo c016b65ca9 typo 2021-10-02 17:20:10 +00:00
Omar Polo f7ee799023 enforce PR_SET_NO_NEW_PRIVS in the logger process
otherwise landlock will refuse to enable itself and the logger process
dies.
2021-10-02 17:20:10 +00:00
Omar Polo 0c66b6ad55 forgot include 2021-09-26 20:01:32 +00:00
Omar Polo 6f27d2595a [seccomp] allow ioctl(FIONREAD)
it's needed by bufferevent_read
2021-09-26 20:00:38 +00:00
Omar Polo 2a44a2ab6e sync changelog 2021-09-26 17:00:16 +00:00
Omar Polo 741b69be96 fastcgi completely asynchronous
This changes the fastcgi implementation from a blocking I/O to an
async implementation on top of libevent' bufferevents.

Should improve the responsiveness of gmid especially when using remote
fastcgi applications.
2021-09-26 17:00:07 +00:00
Omar Polo 83fe545a2b initialize mbufhead 2021-09-26 16:43:19 +00:00
Omar Polo cb28978f0a refactor landlock
refactor the landlock-related code into something more manageable.
The only real difference is that before the logger process would try
to landlock itself to "/" without perms, something that landlock
doesn't support (now it enables landlock and then restrict itself,
which is the correct move.)
2021-09-25 08:47:29 +00:00
Omar Polo 775ef04f82 mention the thanks to cage for the bugfix
Since I was in a hurry, I forgot to mention it in the tag message :/
2021-09-24 14:21:16 +00:00
Omar Polo 0d9a5b7a18 sync release 2021-09-24 11:16:32 +00:00
Omar Polo 3571854e94 fix possible out-of-bound access
While computing the parent directory it an out-of-bound access can
occur, which usually means the server process dies.

In particular, it can be triggered by making a request for a
non-existent file in the root of a virtual host if the path matches
the `cgi` pattern.

Thanks cage for helping in debugging!
2021-09-24 10:48:51 +00:00
Omar Polo 353e3c8ebe style 2021-09-24 08:16:28 +00:00
Omar Polo e15fc95736 change struct initialization
makes more explicit which fields we're setting.

(and kill an extra empty line)
2021-09-24 08:12:40 +00:00
Omar Polo 81e0f00078 fmt 2021-09-24 08:10:07 +00:00
Omar Polo df0c2926cc use memset(3) rather than bzero(3)
There's no difference, but bzero(3) says

STANDARDS
     The bzero() function conforms to the X/Open System Interfaces option of
     the IEEE Std 1003.1-2004 (“POSIX.1”) specification.  It was removed from
     the standard in IEEE Std 1003.1-2008 (“POSIX.1”), which recommends using
     memset(3) instead.

so here we are.
2021-09-24 08:08:49 +00:00
Omar Polo a91ad7f2ff drop unnecessary bzero
the whole struct client is already memset'd to 0 in do_accept.
handle_handshake doesn't touch the request or iri buffer in the code
path that leads to handle_open_conn.  (It does so in the error router
alone.)
2021-09-24 08:08:49 +00:00
Omar Polo 79288c8b60 making more explicit the case of missing SNI
Missing SNI (i.e. servname == NULL) is already handled correctly.
puny_decode refuses to work on NULL servname, c->domain is still the
empty string and everything flows as expected towards the error at the
end.  However, it's better to bail out early and make more explicit
how the case of missing SNI is handled.
2021-09-24 07:40:24 +00:00
Martin 2b38d395cd Improve gmid.service
Changed gmid.service to not to fork the server and forced to run under
user "gmid".  gmid now waits for the network stack beeing available
before starting. Also "gmid" is now the syslog id.
2021-09-21 19:15:50 +02:00
Omar Polo 36d2d7b4b3 sync changelog 2021-09-19 17:15:24 +00:00
Omar Polo b0be065390 landlock the logger process too
Disallow everything landlock can handle.  The logger process doesn't
need any fs access (on OpenBSD it runs with pledge("stdio recvfd")).
2021-09-19 17:08:12 +00:00
Omar Polo 0ea22af280 add helper function gmid_create_landlock_rs 2021-09-19 17:08:12 +00:00
Omar Polo 67c49bc5c7 mention landlock in the README 2021-09-19 17:08:12 +00:00
Omar Polo 3499ce5a9a landlock the server process
Trying to implement some landlock policies (rules?) where possible.
The server process is, of course, the most dangerous process so start
with that.

The following should be equivalent to the unveil(2) call on OpenBSD:
allows only to read files and directories inside the vhost roots.

I'm assuming seccomp is enabled so I'm not trying to disallow actions
such as LANDLOCK_ACCESS_FS_EXECUTE or LANDLOCK_ACCESS_FS_REMOVE_FILE
which require syscalls that are already disallowed.  I'm only trying
to limit the damage that the currently allowed system calls can do.
e.g. since write(2) is allowed, gmid could modify *any* file it has
access to; this is now forbidden by landlock.

There are still too many #ifdefs for my tastes, but it's still better
than the seccomp code.
2021-09-19 17:08:12 +00:00
Omar Polo d85aa60208 define HAVE_LANDLOCK accordingly 2021-09-19 17:08:12 +00:00
Omar Polo 4c31de2915 add configure check and shim for landlock
First move towards landlock support (#3).  The shim is needed until
libc provides the proper wrappers for the landlock APIs; I hope it
doesn't take too long, but landlock was merged back in May and are
still missing.
2021-09-19 17:08:12 +00:00
Omar Polo fba809b5c7 tag 1.7.3
bump version number
2021-09-19 14:48:07 +00:00
Omar Polo ca3d8bfde6 retroactively mention the fstat64 fix 2021-09-18 11:15:40 +00:00
Omar Polo 39c5bfd64b fix changelog syntax 2021-09-18 11:09:36 +00:00
Omar Polo e30e5385f1 sort tests 2021-09-18 11:17:28 +02:00
Omar Polo b03b7d5bae sync changelog 2021-09-17 16:17:16 +00:00
Omar Polo db623d7551 fix syslog logging on FreeBSD
Due to capsicum(4), opening the log on-demand via syslog(3) fails.
openlog(LOG_NDELAY) forces the log to be opened immediately, before we
enter capsicum.

This doesn't affect OpenBSD (where pledge(2) doesn't stop syslog) nor
linux (where the log process is not sandboxed.)

Reported by Karl Jeacle, thank you!
2021-09-17 16:17:16 +00:00
Omar Polo f2478b332f sync 2021-08-23 22:44:55 +00:00
Omar Polo 2e31927606 don't crash if -n is given without -c
If -n is given without -c, config_path is still NULL and it would
crash due to a NULL deference.
2021-08-23 22:43:56 +00:00
Omar Polo 83272dfee9 don't yyerror if we can't open the file
the global var file could still be NULL and yyerror would crash.
2021-08-23 22:42:59 +00:00
Omar Polo ef352ec3b8 fix wrong arguments order for send_log 2021-08-23 22:36:01 +00:00
Omar Polo 03747a6c51 sync 2021-07-29 07:54:41 +00:00
Omar Polo 2bb1776bac keep the openssl key generation example under 80 columns 2021-07-29 09:48:43 +02:00
Anna “CyberTailor” 301e039d24 gmid.1: some spelling, grammar and crosslinks 2021-07-29 09:38:03 +02:00
Anna “CyberTailor” e308526cf6 gmid.1: provide certificate generation example 2021-07-29 09:35:09 +02:00
Anna “CyberTailor” e58a447a28 gmid.1: document logging 2021-07-29 09:31:09 +02:00
Omar Polo 2887c631ee sync 2021-07-27 09:22:17 +00:00
Omar Polo efb48052dc relax openat rule: follow symlinks
O_NOFOLLOW acts only on *the last component*, so on
open("/foo/bar/baz") only when baz is a symlink open fails.
Checking every path component is not viable.

gh issue #5 related (sort of)
2021-07-27 09:21:42 +00:00
Omar Polo a8e1e8d738 typo
Since there was 0 reports in a month can I assume it's not actually
used anywhere?
2021-07-23 06:55:32 +00:00
Omar Polo 21f7d24699 allow fstat64
used by glibc on aarch64.

Found and tested by pine, thanks!
2021-07-23 06:50:30 +00:00
Omar Polo af5f9b271e use \e instead of \\ as a mean to escape \
Just read in a mail from Ingo to tech@

> Using \\ outside macro definitions (i.e., outside the bodies of roff(7)
> .de and similar requests) is almost always wrong even in low-level roff
> code, and \\ must never be used in manual pages.
2021-07-21 07:56:41 +00:00
Omar Polo 3e0164f4c3 use certs from regress/ 2021-07-19 11:37:01 +00:00
Omar Polo 735336b21e unbreak configless mode
An un-initialized field in the configless code path leads to a crash
on the first request.
2021-07-19 11:15:44 +00:00
Omar Polo abc8801d60 typo 2021-07-19 07:45:55 +00:00