1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 15:27:35 +00:00

Kernel: Add "accept" pledge promise for accepting incoming connections

This patch adds a new "accept" promise that allows you to call accept()
on an already listening socket. This lets programs set up a socket for
for listening and then dropping "inet" and/or "unix" so that only
incoming (and existing) connections are allowed from that point on.
No new outgoing connections or listening server sockets can be created.

In addition to accept() it also allows getsockopt() with SOL_SOCKET
and SO_PEERCRED, which is used to find the PID/UID/GID of the socket
peer. This is used by our IPC library when creating shared buffers that
should only be accessible to a specific peer process.

This allows us to drop "unix" in WindowServer and LookupServer. :^)

It also makes the debugging/introspection RPC sockets in CEventLoop
based programs work again.
This commit is contained in:
Andreas Kling 2020-01-17 11:12:06 +01:00
parent a9b24ebbe8
commit 26a31c7efb
29 changed files with 63 additions and 55 deletions

View file

@ -9,14 +9,14 @@
int main(int argc, char** argv)
{
if (pledge("stdio shared_buffer unix rpath cpath fattr", nullptr) < 0) {
if (pledge("stdio shared_buffer accept rpath unix cpath fattr", nullptr) < 0) {
perror("pledge");
return 1;
}
GApplication app(argc, argv);
if (pledge("stdio shared_buffer rpath", nullptr) < 0) {
if (pledge("stdio shared_buffer accept rpath", nullptr) < 0) {
perror("pledge");
return 1;
}

View file

@ -30,7 +30,7 @@ static const char* home_url = "file:///home/anon/www/welcome.html";
int main(int argc, char** argv)
{
if (pledge("stdio unix shared_buffer cpath rpath fattr", nullptr) < 0) {
if (pledge("stdio shared_buffer accept unix cpath rpath fattr", nullptr) < 0) {
perror("pledge");
return 1;
}
@ -40,7 +40,7 @@ int main(int argc, char** argv)
// Connect to the ProtocolServer immediately so we can drop the "unix" pledge.
ResourceLoader::the();
if (pledge("stdio shared_buffer rpath", nullptr) < 0) {
if (pledge("stdio shared_buffer accept rpath", nullptr) < 0) {
perror("pledge");
return 1;
}

View file

@ -9,14 +9,14 @@
int main(int argc, char** argv)
{
if (pledge("stdio shared_buffer unix rpath cpath fattr", nullptr) < 0) {
if (pledge("stdio shared_buffer rpath accept unix cpath fattr", nullptr) < 0) {
perror("pledge");
return 1;
}
GApplication app(argc, argv);
if (pledge("stdio shared_buffer rpath", nullptr) < 0) {
if (pledge("stdio shared_buffer rpath accept", nullptr) < 0) {
perror("pledge");
return 1;
}

View file

@ -12,14 +12,14 @@
int main(int argc, char** argv)
{
if (pledge("stdio shared_buffer unix rpath cpath wpath fattr", nullptr) < 0) {
if (pledge("stdio shared_buffer rpath accept unix cpath wpath fattr", nullptr) < 0) {
perror("pledge");
return 1;
}
GApplication app(argc, argv);
if (pledge("stdio shared_buffer rpath cpath wpath", nullptr) < 0) {
if (pledge("stdio shared_buffer rpath accept cpath wpath", nullptr) < 0) {
perror("pledge");
return 1;
}

View file

@ -31,7 +31,7 @@
int main(int argc, char** argv)
{
if (pledge("stdio thread unix shared_buffer cpath rpath wpath fattr proc exec", nullptr) < 0) {
if (pledge("stdio thread shared_buffer accept unix cpath rpath wpath fattr proc exec", nullptr) < 0) {
perror("pledge");
return 1;
}
@ -50,7 +50,7 @@ int main(int argc, char** argv)
GApplication app(argc, argv);
if (pledge("stdio thread shared_buffer cpath rpath wpath fattr proc exec", nullptr) < 0) {
if (pledge("stdio thread shared_buffer accept cpath rpath wpath fattr proc exec", nullptr) < 0) {
perror("pledge");
return 1;
}

View file

@ -9,14 +9,14 @@
int main(int argc, char** argv)
{
if (pledge("stdio shared_buffer unix rpath cpath wpath fattr", nullptr) < 0) {
if (pledge("stdio shared_buffer rpath accept unix cpath wpath fattr", nullptr) < 0) {
perror("pledge");
return 1;
}
GApplication app(argc, argv);
if (pledge("stdio shared_buffer rpath cpath wpath", nullptr) < 0) {
if (pledge("stdio shared_buffer rpath accept cpath wpath", nullptr) < 0) {
perror("pledge");
return 1;
}

View file

@ -24,14 +24,14 @@
int main(int argc, char* argv[])
{
if (pledge("stdio unix shared_buffer cpath rpath fattr", nullptr) < 0) {
if (pledge("stdio shared_buffer accept rpath unix cpath fattr", nullptr) < 0) {
perror("pledge");
return 1;
}
GApplication app(argc, argv);
if (pledge("stdio shared_buffer rpath", nullptr) < 0) {
if (pledge("stdio shared_buffer accept rpath", nullptr) < 0) {
perror("pledge");
return 1;
}

View file

@ -4,14 +4,14 @@
int main(int argc, char** argv)
{
if (pledge("stdio shared_buffer unix rpath cpath wpath fattr", nullptr) < 0) {
if (pledge("stdio shared_buffer accept rpath unix cpath wpath fattr", nullptr) < 0) {
perror("pledge");
return 1;
}
GApplication app(argc, argv);
if (pledge("stdio shared_buffer rpath cpath wpath", nullptr) < 0) {
if (pledge("stdio shared_buffer accept rpath cpath wpath", nullptr) < 0) {
perror("pledge");
return 1;
}

View file

@ -15,14 +15,14 @@
int main(int argc, char** argv)
{
if (pledge("stdio shared_buffer unix rpath wpath cpath fattr", nullptr) < 0) {
if (pledge("stdio shared_buffer accept rpath unix wpath cpath fattr", nullptr) < 0) {
perror("pledge");
return 1;
}
GApplication app(argc, argv);
if (pledge("stdio shared_buffer rpath wpath cpath", nullptr) < 0) {
if (pledge("stdio shared_buffer accept rpath wpath cpath", nullptr) < 0) {
perror("pledge");
return 1;
}

View file

@ -11,14 +11,14 @@
int main(int argc, char** argv)
{
if (pledge("stdio unix shared_buffer rpath cpath fattr", nullptr) < 0) {
if (pledge("stdio shared_buffer accept rpath unix cpath fattr", nullptr) < 0) {
perror("pledge");
return 1;
}
GApplication app(argc, argv);
if (pledge("stdio shared_buffer rpath", nullptr) < 0) {
if (pledge("stdio shared_buffer accept rpath", nullptr) < 0) {
perror("pledge");
return 1;
}

View file

@ -12,14 +12,14 @@
int main(int argc, char** argv)
{
if (pledge("stdio unix shared_buffer cpath rpath fattr", nullptr) < 0) {
if (pledge("stdio shared_buffer accept rpath unix cpath fattr", nullptr) < 0) {
perror("pledge");
return 1;
}
GApplication app(argc, argv);
if (pledge("stdio unix shared_buffer rpath", nullptr) < 0) {
if (pledge("stdio shared_buffer accept rpath unix", nullptr) < 0) {
perror("pledge");
return 1;
}
@ -27,7 +27,7 @@ int main(int argc, char** argv)
auto audio_client = AClientConnection::construct();
audio_client->handshake();
if (pledge("stdio shared_buffer rpath", nullptr) < 0) {
if (pledge("stdio shared_buffer accept rpath", nullptr) < 0) {
perror("pledge");
return 1;
}

View file

@ -49,14 +49,14 @@ static NonnullRefPtr<GWidget> build_graphs_tab();
int main(int argc, char** argv)
{
if (pledge("stdio proc shared_buffer rpath unix cpath fattr", nullptr) < 0) {
if (pledge("stdio proc shared_buffer accept rpath unix cpath fattr", nullptr) < 0) {
perror("pledge");
return 1;
}
GApplication app(argc, argv);
if (pledge("stdio proc shared_buffer rpath", nullptr) < 0) {
if (pledge("stdio proc shared_buffer accept rpath", nullptr) < 0) {
perror("pledge");
return 1;
}

View file

@ -5,14 +5,14 @@
int main(int argc, char** argv)
{
if (pledge("stdio shared_buffer proc exec rpath unix cpath fattr", nullptr) < 0) {
if (pledge("stdio shared_buffer accept proc exec rpath unix cpath fattr", nullptr) < 0) {
perror("pledge");
return 1;
}
GApplication app(argc, argv);
if (pledge("stdio shared_buffer proc exec rpath", nullptr) < 0) {
if (pledge("stdio shared_buffer accept proc exec rpath", nullptr) < 0) {
perror("pledge");
return 1;
}

View file

@ -136,7 +136,7 @@ RefPtr<GWindow> create_settings_window(TerminalWidget& terminal, RefPtr<CConfigF
int main(int argc, char** argv)
{
if (pledge("stdio tty rpath cpath wpath shared_buffer proc exec unix fattr", nullptr) < 0) {
if (pledge("stdio tty rpath accept cpath wpath shared_buffer proc exec unix fattr", nullptr) < 0) {
perror("pledge");
return 1;
}
@ -153,7 +153,7 @@ int main(int argc, char** argv)
GApplication app(argc, argv);
if (pledge("stdio tty rpath cpath wpath shared_buffer proc exec", nullptr) < 0) {
if (pledge("stdio tty rpath accept cpath wpath shared_buffer proc exec", nullptr) < 0) {
perror("pledge");
return 1;
}

View file

@ -4,14 +4,14 @@
int main(int argc, char** argv)
{
if (pledge("stdio rpath cpath wpath shared_buffer unix fattr", nullptr) < 0) {
if (pledge("stdio rpath accept cpath wpath shared_buffer unix fattr", nullptr) < 0) {
perror("pledge");
return 1;
}
GApplication app(argc, argv);
if (pledge("stdio rpath cpath wpath shared_buffer", nullptr) < 0) {
if (pledge("stdio rpath accept cpath wpath shared_buffer", nullptr) < 0) {
perror("pledge");
return 1;
}