Skip to content
Merged
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
2 changes: 1 addition & 1 deletion localization/strings/en-US/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ To force WSL2 to stop and detach the disk, run 'wsl.exe {}'.</value>
<comment>"mount" is a technical term meaning to make a disk/filesystem accessible. Use the standard technical term in your locale, or keep "mount" if commonly used.</comment>
</data>
<data name="MessageDiskMountNameInvalid" xml:space="preserve">
<value>The specified mount name contains an invalid '/' character. Please retry without the invalid character.</value>
<value>The mount name cannot be empty, '.', '..', or contain '/'. Please retry with a valid mount name.</value>
<comment>"mount" is a technical term meaning to make a disk/filesystem accessible. Use the standard technical term in your locale, or keep "mount" if commonly used.</comment>
</data>
<data name="MessageDiskMounted" xml:space="preserve">
Expand Down
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 @@ -2595,23 +2595,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 @@ -3516,7 +3516,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
3 changes: 1 addition & 2 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
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 @@ -2742,8 +2742,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
23 changes: 23 additions & 0 deletions test/windows/MountTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,29 @@ 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);
const auto [output, error] = LxsstuLaunchWslAndCaptureOutput(mountCommand, -1);
VERIFY_ARE_EQUAL(
output,
L"The mount name cannot be empty, '.', '..', or contain '/'. Please retry with a valid mount name.\r\n"
L"Error code: Wsl/Service/MountDisk/WSL_E_VM_MODE_INVALID_MOUNT_NAME\r\n",
name);
VERIFY_ARE_EQUAL(error, L"", 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