From c5b7c9f4799508ed6f940755243ab47dc55558ce Mon Sep 17 00:00:00 2001 From: Lucas CHOLLET Date: Sun, 7 Aug 2022 18:10:26 +0200 Subject: [PATCH] LibCore+LaunchServer: Move portal directory to `/tmp/user/%uid` The `/tmp/user` directory is owned by root, this solution prevents malicious users to interfere with other users' portals. This commit also moves `launch`'s portal in the user directory. --- Base/home/anon/.config/SystemServer.ini | 2 +- Userland/Applications/Help/main.cpp | 2 +- Userland/Applications/Mail/main.cpp | 2 +- Userland/Applications/Terminal/main.cpp | 2 +- Userland/Applications/TextEditor/main.cpp | 2 +- Userland/Demos/Eyes/main.cpp | 2 +- Userland/Games/2048/main.cpp | 2 +- Userland/Games/Chess/main.cpp | 2 +- Userland/Games/FlappyBug/main.cpp | 2 +- Userland/Games/GameOfLife/main.cpp | 2 +- Userland/Games/Hearts/main.cpp | 2 +- Userland/Games/MasterWord/main.cpp | 2 +- Userland/Games/Minesweeper/main.cpp | 2 +- Userland/Games/Snake/main.cpp | 2 +- Userland/Libraries/LibCore/Account.cpp | 13 +++++++++---- Userland/Libraries/LibDesktop/Launcher.cpp | 2 +- Userland/Services/LoginServer/main.cpp | 2 +- 17 files changed, 25 insertions(+), 20 deletions(-) diff --git a/Base/home/anon/.config/SystemServer.ini b/Base/home/anon/.config/SystemServer.ini index 91927be505..ac9f6f7166 100644 --- a/Base/home/anon/.config/SystemServer.ini +++ b/Base/home/anon/.config/SystemServer.ini @@ -1,5 +1,5 @@ [LaunchServer] -Socket=/tmp/100/portal/launch +Socket=/tmp/user/100/portal/launch SocketPermissions=600 Lazy=true SystemModes=text,graphical diff --git a/Userland/Applications/Help/main.cpp b/Userland/Applications/Help/main.cpp index 12e0af993e..654ef0fee0 100644 --- a/Userland/Applications/Help/main.cpp +++ b/Userland/Applications/Help/main.cpp @@ -34,7 +34,7 @@ ErrorOr serenity_main(Main::Arguments arguments) TRY(Core::System::unveil("/res", "r")); TRY(Core::System::unveil("/usr/share/man", "r")); TRY(Core::System::unveil("/tmp/portal/filesystemaccess", "rw")); - TRY(Core::System::unveil("/tmp/100/portal/launch", "rw")); + TRY(Core::System::unveil("/tmp/user/100/portal/launch", "rw")); TRY(Core::System::unveil("/tmp/portal/webcontent", "rw")); TRY(Core::System::unveil(nullptr, nullptr)); diff --git a/Userland/Applications/Mail/main.cpp b/Userland/Applications/Mail/main.cpp index 8dc701955b..98afeb3517 100644 --- a/Userland/Applications/Mail/main.cpp +++ b/Userland/Applications/Mail/main.cpp @@ -28,7 +28,7 @@ ErrorOr serenity_main(Main::Arguments arguments) TRY(Core::System::unveil("/etc", "r")); TRY(Core::System::unveil("/tmp/portal/webcontent", "rw")); TRY(Core::System::unveil("/tmp/portal/lookup", "rw")); - TRY(Core::System::unveil("/tmp/100/portal/launch", "rw")); + TRY(Core::System::unveil("/tmp/user/100/portal/launch", "rw")); TRY(Core::System::unveil(nullptr, nullptr)); TRY(Desktop::Launcher::add_allowed_url(URL::create_with_file_protocol("/bin/MailSettings"))); diff --git a/Userland/Applications/Terminal/main.cpp b/Userland/Applications/Terminal/main.cpp index 404323b5cd..ac3d84e9e1 100644 --- a/Userland/Applications/Terminal/main.cpp +++ b/Userland/Applications/Terminal/main.cpp @@ -432,7 +432,7 @@ ErrorOr serenity_main(Main::Arguments arguments) TRY(Core::System::unveil("/bin/TerminalSettings", "x")); TRY(Core::System::unveil("/bin/utmpupdate", "x")); TRY(Core::System::unveil("/etc/FileIconProvider.ini", "r")); - TRY(Core::System::unveil("/tmp/100/portal/launch", "rw")); + TRY(Core::System::unveil("/tmp/user/100/portal/launch", "rw")); TRY(Core::System::unveil("/tmp/portal/config", "rw")); TRY(Core::System::unveil(nullptr, nullptr)); diff --git a/Userland/Applications/TextEditor/main.cpp b/Userland/Applications/TextEditor/main.cpp index 53b5826ea6..90225e365d 100644 --- a/Userland/Applications/TextEditor/main.cpp +++ b/Userland/Applications/TextEditor/main.cpp @@ -32,7 +32,7 @@ ErrorOr serenity_main(Main::Arguments arguments) parser.parse(arguments); TRY(Core::System::unveil("/res", "r")); - TRY(Core::System::unveil("/tmp/100/portal/launch", "rw")); + TRY(Core::System::unveil("/tmp/user/100/portal/launch", "rw")); TRY(Core::System::unveil("/tmp/portal/webcontent", "rw")); TRY(Core::System::unveil("/tmp/portal/filesystemaccess", "rw")); TRY(Core::System::unveil(nullptr, nullptr)); diff --git a/Userland/Demos/Eyes/main.cpp b/Userland/Demos/Eyes/main.cpp index 05312e3200..2b13e1a41c 100644 --- a/Userland/Demos/Eyes/main.cpp +++ b/Userland/Demos/Eyes/main.cpp @@ -38,7 +38,7 @@ ErrorOr serenity_main(Main::Arguments arguments) auto app = TRY(GUI::Application::try_create(arguments)); TRY(Core::System::unveil("/res", "r")); - TRY(Core::System::unveil("/tmp/100/portal/launch", "rw")); + TRY(Core::System::unveil("/tmp/user/100/portal/launch", "rw")); TRY(Core::System::unveil(nullptr, nullptr)); if ((grid_rows > 0) ^ (grid_columns > 0)) { diff --git a/Userland/Games/2048/main.cpp b/Userland/Games/2048/main.cpp index bd9b64f3e2..4379297c14 100644 --- a/Userland/Games/2048/main.cpp +++ b/Userland/Games/2048/main.cpp @@ -45,7 +45,7 @@ ErrorOr serenity_main(Main::Arguments arguments) TRY(Core::System::pledge("stdio rpath recvfd sendfd")); TRY(Core::System::unveil("/res", "r")); - TRY(Core::System::unveil("/tmp/100/portal/launch", "rw")); + TRY(Core::System::unveil("/tmp/user/100/portal/launch", "rw")); TRY(Core::System::unveil(nullptr, nullptr)); size_t board_size = Config::read_i32("2048"sv, ""sv, "board_size"sv, 4); diff --git a/Userland/Games/Chess/main.cpp b/Userland/Games/Chess/main.cpp index 8fe0d46f2b..3f91cf3da5 100644 --- a/Userland/Games/Chess/main.cpp +++ b/Userland/Games/Chess/main.cpp @@ -39,7 +39,7 @@ ErrorOr serenity_main(Main::Arguments arguments) TRY(Core::System::unveil("/res", "r")); TRY(Core::System::unveil("/bin/ChessEngine", "x")); TRY(Core::System::unveil("/etc/passwd", "r")); - TRY(Core::System::unveil("/tmp/100/portal/launch", "rw")); + TRY(Core::System::unveil("/tmp/user/100/portal/launch", "rw")); TRY(Core::System::unveil("/tmp/portal/filesystemaccess", "rw")); TRY(Core::System::unveil(nullptr, nullptr)); diff --git a/Userland/Games/FlappyBug/main.cpp b/Userland/Games/FlappyBug/main.cpp index 8792b9e55e..ce059f7caf 100644 --- a/Userland/Games/FlappyBug/main.cpp +++ b/Userland/Games/FlappyBug/main.cpp @@ -31,7 +31,7 @@ ErrorOr serenity_main(Main::Arguments arguments) TRY(Core::System::pledge("stdio rpath recvfd sendfd")); TRY(Core::System::unveil("/res", "r")); - TRY(Core::System::unveil("/tmp/100/portal/launch", "rw")); + TRY(Core::System::unveil("/tmp/user/100/portal/launch", "rw")); TRY(Core::System::unveil(nullptr, nullptr)); u32 high_score = Config::read_i32("FlappyBug"sv, "Game"sv, "HighScore"sv, 0); diff --git a/Userland/Games/GameOfLife/main.cpp b/Userland/Games/GameOfLife/main.cpp index 135cee17ef..5a68350471 100644 --- a/Userland/Games/GameOfLife/main.cpp +++ b/Userland/Games/GameOfLife/main.cpp @@ -37,7 +37,7 @@ ErrorOr serenity_main(Main::Arguments arguments) TRY(Core::System::pledge("stdio rpath recvfd sendfd")); TRY(Core::System::unveil("/res", "r")); - TRY(Core::System::unveil("/tmp/100/portal/launch", "rw")); + TRY(Core::System::unveil("/tmp/user/100/portal/launch", "rw")); TRY(Core::System::unveil(nullptr, nullptr)); auto app_icon = TRY(GUI::Icon::try_create_default_icon("app-gameoflife"sv)); diff --git a/Userland/Games/Hearts/main.cpp b/Userland/Games/Hearts/main.cpp index 513798bdf0..b9c013fa68 100644 --- a/Userland/Games/Hearts/main.cpp +++ b/Userland/Games/Hearts/main.cpp @@ -41,7 +41,7 @@ ErrorOr serenity_main(Main::Arguments arguments) TRY(Core::System::pledge("stdio recvfd sendfd rpath")); TRY(Core::System::unveil("/res", "r")); - TRY(Core::System::unveil("/tmp/100/portal/launch", "rw")); + TRY(Core::System::unveil("/tmp/user/100/portal/launch", "rw")); TRY(Core::System::unveil(nullptr, nullptr)); auto window = TRY(GUI::Window::try_create()); diff --git a/Userland/Games/MasterWord/main.cpp b/Userland/Games/MasterWord/main.cpp index 82f8a6acce..3f87669ac1 100644 --- a/Userland/Games/MasterWord/main.cpp +++ b/Userland/Games/MasterWord/main.cpp @@ -33,7 +33,7 @@ ErrorOr serenity_main(Main::Arguments arguments) TRY(Core::System::pledge("stdio rpath recvfd sendfd")); TRY(Core::System::unveil("/res", "r")); - TRY(Core::System::unveil("/tmp/100/portal/launch", "rw")); + TRY(Core::System::unveil("/tmp/user/100/portal/launch", "rw")); TRY(Core::System::unveil(nullptr, nullptr)); auto app_icon = TRY(GUI::Icon::try_create_default_icon("app-masterword"sv)); diff --git a/Userland/Games/Minesweeper/main.cpp b/Userland/Games/Minesweeper/main.cpp index 91d5a5fd59..190f1d10f3 100644 --- a/Userland/Games/Minesweeper/main.cpp +++ b/Userland/Games/Minesweeper/main.cpp @@ -39,7 +39,7 @@ ErrorOr serenity_main(Main::Arguments arguments) TRY(Core::System::pledge("stdio rpath recvfd sendfd")); TRY(Core::System::unveil("/res", "r")); - TRY(Core::System::unveil("/tmp/100/portal/launch", "rw")); + TRY(Core::System::unveil("/tmp/user/100/portal/launch", "rw")); TRY(Core::System::unveil(nullptr, nullptr)); auto app_icon = TRY(GUI::Icon::try_create_default_icon("app-minesweeper"sv)); diff --git a/Userland/Games/Snake/main.cpp b/Userland/Games/Snake/main.cpp index a8f3173385..e65341d939 100644 --- a/Userland/Games/Snake/main.cpp +++ b/Userland/Games/Snake/main.cpp @@ -34,7 +34,7 @@ ErrorOr serenity_main(Main::Arguments arguments) TRY(Core::System::pledge("stdio rpath recvfd sendfd")); TRY(Core::System::unveil("/res", "r")); - TRY(Core::System::unveil("/tmp/100/portal/launch", "rw")); + TRY(Core::System::unveil("/tmp/user/100/portal/launch", "rw")); TRY(Core::System::unveil(nullptr, nullptr)); auto app_icon = TRY(GUI::Icon::try_create_default_icon("app-snake"sv)); diff --git a/Userland/Libraries/LibCore/Account.cpp b/Userland/Libraries/LibCore/Account.cpp index a7e34e3b3b..715721570a 100644 --- a/Userland/Libraries/LibCore/Account.cpp +++ b/Userland/Libraries/LibCore/Account.cpp @@ -142,6 +142,15 @@ bool Account::authenticate(SecretString const& password) const bool Account::login() const { + auto const temporary_directory = String::formatted("/tmp/user/{}", m_uid); + if (auto result = Core::Directory::create(temporary_directory, Core::Directory::CreateDirectories::Yes); result.is_error()) { + dbgln("{}", result.release_error()); + return false; + } + + if (chown(temporary_directory.characters(), m_uid, m_gid) < 0) + return false; + if (setgroups(m_extra_gids.size(), m_extra_gids.data()) < 0) return false; @@ -151,10 +160,6 @@ bool Account::login() const if (setuid(m_uid) < 0) return false; - auto const temporary_directory = String::formatted("/tmp/{}", m_uid); - if (auto result = Core::Directory::create(temporary_directory, Core::Directory::CreateDirectories::No); result.is_error()) - dbgln("{}", result.release_error()); - return true; } diff --git a/Userland/Libraries/LibDesktop/Launcher.cpp b/Userland/Libraries/LibDesktop/Launcher.cpp index 5169bc7257..6dc00d0a05 100644 --- a/Userland/Libraries/LibDesktop/Launcher.cpp +++ b/Userland/Libraries/LibDesktop/Launcher.cpp @@ -36,7 +36,7 @@ auto Launcher::Details::from_details_str(String const& details_str) -> NonnullRe class ConnectionToLaunchServer final : public IPC::ConnectionToServer , public LaunchClientEndpoint { - IPC_CLIENT_CONNECTION(ConnectionToLaunchServer, "/tmp/100/portal/launch") + IPC_CLIENT_CONNECTION(ConnectionToLaunchServer, "/tmp/user/100/portal/launch") private: ConnectionToLaunchServer(NonnullOwnPtr socket) : IPC::ConnectionToServer(*this, move(socket)) diff --git a/Userland/Services/LoginServer/main.cpp b/Userland/Services/LoginServer/main.cpp index 66f922c1f0..8b539c9540 100644 --- a/Userland/Services/LoginServer/main.cpp +++ b/Userland/Services/LoginServer/main.cpp @@ -56,7 +56,7 @@ ErrorOr serenity_main(Main::Arguments arguments) { auto app = TRY(GUI::Application::try_create(arguments)); - TRY(Core::System::pledge("stdio recvfd sendfd cpath rpath exec proc id")); + TRY(Core::System::pledge("stdio recvfd sendfd cpath chown rpath exec proc id")); TRY(Core::System::unveil("/home", "r")); TRY(Core::System::unveil("/tmp", "c")); TRY(Core::System::unveil("/etc/passwd", "r"));