Skip to content

Commit 976fb49

Browse files
benhillisBen HillisCopilot
authored
Revert "Mount plugin folders on behalf of the user owning the wsl session" (#41331) (#41515)
Temporarily reverting the identity-based plugin folder mount change (both the WslCoreVm.cpp behavior change and the accompanying MountFolderAccess test coverage) introduced in #41331. This reverts commit 78b9cf2. Co-authored-by: Ben Hillis Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 75cd0f0 commit 976fb49

4 files changed

Lines changed: 4 additions & 79 deletions

File tree

‎src/windows/service/exe/WslCoreVm.cpp‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2101,8 +2101,7 @@ void WslCoreVm::MountRootNamespaceFolder(_In_ LPCWSTR HostPath, _In_ LPCWSTR Gue
21012101
auto lock = m_lock.lock_exclusive();
21022102

21032103
const auto flags = (ReadOnly ? hcs::Plan9ShareFlags::ReadOnly : hcs::Plan9ShareFlags::None) | hcs::Plan9ShareFlags::AllowOptions;
2104-
wsl::windows::common::hcs::AddPlan9Share(
2105-
m_system.get(), Name, Name, HostPath, LX_INIT_UTILITY_VM_PLAN9_PORT, flags, m_userToken.get());
2104+
wsl::windows::common::hcs::AddPlan9Share(m_system.get(), Name, Name, HostPath, LX_INIT_UTILITY_VM_PLAN9_PORT, flags);
21062105

21072106
wsl::shared::MessageWriter<LX_MINI_INIT_MOUNT_FOLDER_MESSAGE> message(LxMiniInitMountFolder);
21082107
message.WriteString(message->PathIndex, GuestPath);

‎test/windows/PluginTests.cpp‎

Lines changed: 1 addition & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class PluginTests
8989
return true;
9090
}
9191

92-
void ConfigurePlugin(PluginTestType testCase, LPCWSTR mountFolder = L"") const
92+
void ConfigurePlugin(PluginTestType testCase) const
9393
{
9494
StopWslService();
9595
if (!DeleteFile(logFile.c_str()))
@@ -100,7 +100,6 @@ class PluginTests
100100
const auto testKey = OpenTestRegistryKey(KEY_SET_VALUE);
101101
WriteDword(testKey.get(), nullptr, c_testType, static_cast<DWORD>(testCase));
102102
WriteString(testKey.get(), nullptr, c_logFile, logFile.c_str());
103-
WriteString(testKey.get(), nullptr, c_mountFolder, mountFolder);
104103

105104
const auto lxssKey =
106105
CreateKey(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Lxss\\Plugins", KEY_SET_VALUE, nullptr, 0);
@@ -173,62 +172,6 @@ class PluginTests
173172
ValidateLogFile(ExpectedOutput);
174173
}
175174

176-
WSL2_TEST_METHOD(MountFolderAccess)
177-
{
178-
const auto testFolder = std::filesystem::current_path() / "deny-write";
179-
VERIFY_IS_TRUE(std::filesystem::create_directory(testFolder));
180-
181-
auto cleanup = wil::scope_exit_log(WI_DIAGNOSTICS_INFO, [&]() { std::filesystem::remove_all(testFolder); });
182-
183-
const auto user = wil::get_token_information<TOKEN_USER>();
184-
EXPLICIT_ACCESSW access{};
185-
access.grfAccessPermissions = FILE_ADD_FILE;
186-
access.grfAccessMode = DENY_ACCESS;
187-
access.grfInheritance = NO_INHERITANCE;
188-
access.Trustee.TrusteeForm = TRUSTEE_IS_SID;
189-
access.Trustee.ptstrName = static_cast<LPWSTR>(user->User.Sid);
190-
191-
PACL acl = nullptr;
192-
wil::unique_hlocal descriptor;
193-
THROW_IF_WIN32_ERROR(GetNamedSecurityInfoW(
194-
testFolder.c_str(), SE_FILE_OBJECT, DACL_SECURITY_INFORMATION, nullptr, nullptr, &acl, nullptr, &descriptor));
195-
196-
wsl::windows::common::security::unique_acl newAcl;
197-
THROW_IF_WIN32_ERROR(SetEntriesInAclW(1, &access, acl, &newAcl));
198-
THROW_IF_WIN32_ERROR(SetNamedSecurityInfoW(
199-
const_cast<LPWSTR>(testFolder.c_str()), SE_FILE_OBJECT, DACL_SECURITY_INFORMATION, nullptr, nullptr, newAcl.get(), nullptr));
200-
201-
const auto testFile = testFolder / L"plugin-test.txt";
202-
wil::unique_hfile deniedFile{CreateFileW(testFile.c_str(), GENERIC_WRITE, 0, nullptr, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, nullptr)};
203-
VERIFY_IS_TRUE(!deniedFile);
204-
VERIFY_ARE_EQUAL(GetLastError(), ERROR_ACCESS_DENIED);
205-
206-
auto resetAcl = wil::scope_exit_log(WI_DIAGNOSTICS_INFO, [&]() {
207-
wsl::windows::common::security::unique_acl restoredAcl;
208-
access.grfAccessPermissions = 0;
209-
access.grfAccessMode = REVOKE_ACCESS;
210-
211-
THROW_IF_WIN32_ERROR(SetEntriesInAclW(1, &access, acl, &restoredAcl));
212-
213-
THROW_IF_WIN32_ERROR(SetNamedSecurityInfoW(
214-
const_cast<LPWSTR>(testFolder.c_str()), SE_FILE_OBJECT, DACL_SECURITY_INFORMATION, nullptr, nullptr, restoredAcl.get(), nullptr));
215-
});
216-
217-
ConfigurePlugin(PluginTestType::MountFolderAccess, testFolder.c_str());
218-
219-
constexpr auto ExpectedOutput =
220-
LR"(Plugin loaded. TestMode=25
221-
VM created (settings->CustomConfigurationFlags=0)
222-
/bin/sh: line 1: /test-plugin-access/plugin-test.txt: Permission denied
223-
Distribution started, name=test_distro, package=, PidNs=*, InitPid=*, Flavor=debian, Version=13
224-
Distribution Stopping, name=test_distro, package=, PidNs=*, Flavor=debian, Version=13
225-
VM Stopping)";
226-
227-
StartWsl(0);
228-
VERIFY_IS_FALSE(std::filesystem::exists(testFile));
229-
ValidateLogFile(ExpectedOutput);
230-
}
231-
232175
WSL2_TEST_METHOD(CustomKernelOverriddenByPolicy)
233176
{
234177
RegistryKeyChange policy(

‎test/windows/PluginTests.h‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,11 @@ enum class PluginTestType
4444
WslcImagePull,
4545
WslcVmRestart,
4646
WslcVmStopCommitted,
47-
WslcVmNeverStarted,
48-
MountFolderAccess
47+
WslcVmNeverStarted
4948
};
5049

5150
constexpr auto c_testType = L"TestType";
5251
constexpr auto c_logFile = L"LogFile";
53-
constexpr auto c_mountFolder = L"MountFolder";
5452

5553
inline wil::unique_hkey OpenTestRegistryKey(REGSAM AccessMask)
5654
{

‎test/windows/testplugin/Plugin.cpp‎

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -123,21 +123,6 @@ HRESULT OnVmStarted(const WSLSessionInformation* Session, const WSLVmCreationSet
123123
return E_ABORT;
124124
}
125125
}
126-
else if (g_testType == PluginTestType::MountFolderAccess)
127-
{
128-
const auto key = OpenTestRegistryKey(KEY_READ);
129-
const auto mountSource = ReadString(key.get(), nullptr, c_mountFolder);
130-
131-
RETURN_IF_FAILED(
132-
g_api->MountFolder(Session->SessionId, mountSource.c_str(), L"/test-plugin-access", false, L"test-plugin-access"));
133-
134-
std::vector<const char*> arguments = {"/bin/sh", "-c", "{ echo test > /test-plugin-access/plugin-test.txt; } 2>&1", nullptr};
135-
wil::unique_socket socket;
136-
RETURN_IF_FAILED(g_api->ExecuteBinary(Session->SessionId, arguments[0], arguments.data(), &socket));
137-
138-
const auto output = ReadFromSocket(socket.get());
139-
g_logfile.write(output.data(), output.size());
140-
}
141126
else if (g_testType == PluginTestType::ApiErrors)
142127
{
143128
auto result = g_api->MountFolder(Session->SessionId, L"C:\\DoesNotExit", L"/dummy", true, L"test-plugin-mount");
@@ -802,7 +787,7 @@ EXTERN_C __declspec(dllexport) HRESULT WSLPLUGINAPI_ENTRYPOINTV1(const WSLPlugin
802787
THROW_HR_IF(E_UNEXPECTED, !g_logfile);
803788

804789
g_testType = static_cast(ReadDword(key.get(), nullptr, c_testType, static_cast<DWORD>(PluginTestType::Invalid)));
805-
THROW_HR_IF(E_INVALIDARG, static_cast<DWORD>(g_testType) <= 0 || static_cast<DWORD>(g_testType) > static_cast<DWORD>(PluginTestType::MountFolderAccess));
790+
THROW_HR_IF(E_INVALIDARG, static_cast<DWORD>(g_testType) <= 0 || static_cast<DWORD>(g_testType) > static_cast<DWORD>(PluginTestType::WslcVmNeverStarted));
806791

807792
g_logfile << "Plugin loaded. TestMode=" << static_cast<DWORD>(g_testType) << std::endl;
808793
g_api = Api;

0 commit comments

Comments
 (0)