Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/linux/init/DnsServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ class DnsServer
wil::unique_fd m_tcpConnection;

// Offset in m_currentDnsRequest indicating how much of the current DNS request on
// the TCP connection has been read. Using 2 bytes to represent the offset as the request length is represented using 2 bytes.
uint16_t m_currentRequestOffset = 0;
// the TCP connection has been read.
size_t m_currentRequestOffset = 0;

// Buffer containing the current DNS request received on the TCP connection.
std::vector<gsl::byte> m_currentDnsRequest;
Expand Down
32 changes: 21 additions & 11 deletions src/linux/init/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2572,23 +2572,33 @@ Return Value:
continue;
}

int Status{};
auto Pid = waitpid(-1, &Status, WNOHANG);
if (Pid == 0)
{
continue;
}
else if (Pid > 0)
bool distroInitExited = false;
for (;;)
{
if (Pid == distroInitPid.value())
int Status{};
auto Pid = waitpid(-1, &Status, WNOHANG);
if (Pid == 0)
{
break;
}
else if (Pid > 0)
{
distroInitExited |= (Pid == distroInitPid.value());
}
else if (errno == ECHILD)
{
LOG_ERROR("Init has exited. Terminating distribution");
break;
}
else
{
FATAL_ERROR("waitpid failed {}", errno);
}
}
else if (errno != ECHILD)

if (distroInitExited)
{
FATAL_ERROR("waitpid failed {}", errno);
LOG_ERROR("Init has exited. Terminating distribution");
break;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/linux/init/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3494,7 +3494,7 @@ int ProcessCreateProcessMessage(wsl::shared::Transaction& Transaction, gsl::span
{
execResult = 0;
}
else if (execResult == sizeof(execResult))
else if (ReadResult == sizeof(execResult))
{
// Otherwise, return the error code to the service
execResult = abs(execResult);
Expand Down
10 changes: 6 additions & 4 deletions src/windows/common/WslCoreMessageQueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,11 @@ class WslCoreMessageQueue
const auto queueLock = m_lock.lock_exclusive();
THROW_HR_IF(HRESULT_FROM_WIN32(ERROR_CANCELLED), m_isCanceled);
m_workItems.emplace_back(new_result);

// always maintain a 1:1 ratio for calls to submit_with_results() and ::SubmitThreadpoolWork
SubmitThreadpoolWork(m_tpHandle.get());
Comment thread
chemwolf6922 marked this conversation as resolved.
}

// always maintain a 1:1 ratio for calls to SubmitWorkWithResults() and ::SubmitThreadpoolWork
SubmitThreadpoolWork(m_tpHandle.get());
return new_result;
}
catch (...)
Expand All @@ -194,10 +195,11 @@ class WslCoreMessageQueue
const auto queueLock = m_lock.lock_exclusive();
THROW_HR_IF(HRESULT_FROM_WIN32(ERROR_CANCELLED), m_isCanceled);
m_workItems.emplace_back(std::forward<SimpleFunction_t>(functor));

// always maintain a 1:1 ratio for calls to submit() and ::SubmitThreadpoolWork
SubmitThreadpoolWork(m_tpHandle.get());
}

// always maintain a 1:1 ratio for calls to SubmitWork() and ::SubmitThreadpoolWork
SubmitThreadpoolWork(m_tpHandle.get());
return true;
}
catch (...)
Expand Down
7 changes: 3 additions & 4 deletions src/windows/service/exe/LxssUserSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -891,11 +891,10 @@ HRESULT LxssUserSessionImpl::MountDisk(
_Out_ int* Step,
_Out_ LPWSTR* MountName)
{
ExecutionContext context(Context::MountDisk);

std::lock_guard lock(m_instanceLock);
return wil::ResultFromException([&]() {
_CreateVm();
ExecutionContext context(Context::MountDisk);
const auto MountDiskType = WI_IsFlagSet(Flags, LXSS_ATTACH_MOUNT_FLAGS_VHD) ? WslCoreVm::DiskType::VHD : WslCoreVm::DiskType::PassThrough;
const auto MountResult = m_utilityVm->MountDisk(Disk, MountDiskType, PartitionIndex, Name, Type, Options);
const auto MountNameWide = wsl::shared::string::MultiByteToWide(MountResult.MountPointName);
Expand Down Expand Up @@ -967,8 +966,6 @@ HRESULT LxssUserSessionImpl::MoveDistribution(_In_ LPCGUID DistroGuid, _In_ LPCW
::SetSecurityInfo(vhdHandle.get(), SE_FILE_OBJECT, OWNER_SECURITY_INFORMATION, originalOwner, nullptr, nullptr, nullptr));
};

setVhdOwner(newVhdPath);

auto revert = wil::scope_exit_log(WI_DIAGNOSTICS_INFO, [&]() {
THROW_IF_WIN32_BOOL_FALSE(MoveFileEx(
newVhdPath.c_str(), distro.VhdFilePath.c_str(), MOVEFILE_COPY_ALLOWED | MOVEFILE_REPLACE_EXISTING | MOVEFILE_WRITE_THROUGH));
Expand All @@ -980,6 +977,8 @@ HRESULT LxssUserSessionImpl::MoveDistribution(_In_ LPCGUID DistroGuid, _In_ LPCW
registration.Write(Property::BasePath, distro.BasePath.c_str());
});

setVhdOwner(newVhdPath);

// Update the registry location
registration.Write(Property::BasePath, Location);
registration.Write(Property::VhdFileName, newVhdPath.filename().c_str());
Expand Down
7 changes: 4 additions & 3 deletions src/windows/service/exe/WslCoreVm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1000,7 +1000,7 @@ ULONG WslCoreVm::AttachDiskLockHeld(
if (WI_IsFlagSet(diskFlags, DiskStateFlags::Online))
{
const auto diskHandle = wsl::windows::common::disk::OpenDevice(Disk, GENERIC_READ | GENERIC_WRITE, m_vmConfig.MountDeviceTimeout);
wsl::windows::common::disk::SetOnline(diskHandle.get(), false, m_vmConfig.MountDeviceTimeout);
wsl::windows::common::disk::SetOnline(diskHandle.get(), true, m_vmConfig.MountDeviceTimeout);
}
});

Expand Down Expand Up @@ -2752,8 +2752,9 @@ std::string WslCoreVm::s_GetMountTargetName(_In_ PCWSTR Disk, _In_opt_ PCWSTR Na
if (ARGUMENT_PRESENT(Name))
{
auto mountName = wsl::shared::string::WideToMultiByte(Name);
// Throw if the name contains '/' since it is a linux path separator
THROW_HR_IF(WSL_E_VM_MODE_INVALID_MOUNT_NAME, mountName.find('/') != std::string::npos);
THROW_HR_IF(
WSL_E_VM_MODE_INVALID_MOUNT_NAME,
mountName.empty() || mountName == "." || mountName == ".." || mountName.find('/') != std::string::npos);
return mountName;
}

Expand Down
17 changes: 17 additions & 0 deletions test/windows/MountTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,23 @@ class MountTests
WaitForDiskReady();
}

WSL2_TEST_METHOD(SpecifyInvalidMountName)
{
SKIP_UNSUPPORTED_ARM64_MOUNT_TEST();

FormatDisk({L"ext4"}, true);

for (const auto* name : {L"\"\"", L".", L"..", L"foo/bar"})
{
const auto mountCommand = std::format(L"--mount {} --vhd --name {} --partition 1", VhdDevice, name);
VERIFY_ARE_NOT_EQUAL(LxsstuLaunchWsl(mountCommand), (DWORD)0, name);
}

const auto disk = GetBlockDeviceInWsl();
VERIFY_IS_TRUE(IsBlockDevicePresent(disk));
VERIFY_IS_FALSE(GetBlockDeviceMount(disk + L"1").has_value());
}

// Test ensuring that name collision detection works in --mount --name
WSL2_TEST_METHOD(SpecifyMountNameCollision)
{
Expand Down
Loading