From 8f5e98423884babefb6ad1b55226407faefbde04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Tue, 11 Aug 2026 15:14:28 +0200 Subject: [PATCH] DriverManagerScreen: reject zip-slip in custom driver install Both meta.json's "name" field and the zip entry names from a custom GPU driver zip were joined onto GetDriverPath() verbatim - Path::operator/ does no ".." normalization, and ZipFileReader doesn't sanitize entry names either. A crafted driver zip (these are commonly downloaded/shared from third-party sites, e.g. Turnip/Mesa driver packages) could use a ".." component to write files outside the intended drivers// directory. Reuse the existing HasParentDirComponent() helper to reject such names. --- UI/DriverManagerScreen.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/UI/DriverManagerScreen.cpp b/UI/DriverManagerScreen.cpp index 3ad5fa8219..62d9d68692 100644 --- a/UI/DriverManagerScreen.cpp +++ b/UI/DriverManagerScreen.cpp @@ -11,6 +11,7 @@ #include "Core/Config.h" #include "Core/System.h" +#include "Core/Util/PathUtil.h" #include "Common/UI/View.h" #include "UI/DriverManagerScreen.h" @@ -251,6 +252,15 @@ void DriverManagerScreen::OnCustomDriverInstall(UI::EventParams &e) { } delete[] metaData; + // meta.name and the zip entry names below both get joined onto GetDriverPath() + // verbatim (Path::operator/ does no ".." normalization) - without checking for + // parent-directory components, a crafted driver zip could write files outside + // the intended drivers// directory (zip slip, CWE-22). + if (HasParentDirComponent(meta.name)) { + g_OSD.Show(OSDType::MESSAGE_ERROR, gr->T("The chosen ZIP file doesn't contain a valid driver"), "invalid driver name"); + return; + } + const Path newCustomDriver = GetDriverPath() / meta.name; NOTICE_LOG(Log::G3D, "Installing driver into '%s'", newCustomDriver.c_str()); File::CreateFullPath(newCustomDriver); @@ -259,6 +269,11 @@ void DriverManagerScreen::OnCustomDriverInstall(UI::EventParams &e) { zipFileReader->GetFileListing("", &zipListing, nullptr); for (auto file : zipListing) { + if (HasParentDirComponent(file.name)) { + WARN_LOG(Log::G3D, "Skipping zip entry with parent directory component: %s", file.name.c_str()); + continue; + } + File::CreateEmptyFile(newCustomDriver / file.name); size_t size;