From d2b9cac637e4d1ae43b8e692579a9f34a8002cfa Mon Sep 17 00:00:00 2001 From: Feng Wang Date: Thu, 2 Jul 2026 17:21:41 +0800 Subject: [PATCH 1/2] delay plan 9 registration after OOBE --- src/windows/service/exe/WslCoreInstance.cpp | 8 ++++++++ test/windows/UnitTests.cpp | 17 +++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/windows/service/exe/WslCoreInstance.cpp b/src/windows/service/exe/WslCoreInstance.cpp index ba5c0a8235..6d9a1b773b 100644 --- a/src/windows/service/exe/WslCoreInstance.cpp +++ b/src/windows/service/exe/WslCoreInstance.cpp @@ -309,6 +309,8 @@ void WslCoreInstance::ReadOOBEResult(wil::unique_socket&& Socket, wsl::windows:: registration.Write(wsl::windows::service::Property::DefaultUid, static_cast(oobeResult->DefaultUid)); m_defaultUid = static_cast(oobeResult->DefaultUid); } + + RegisterPlan9ConnectionTarget(m_userToken.get()); } } @@ -530,6 +532,12 @@ void WslCoreInstance::Stop() void WslCoreInstance::RegisterPlan9ConnectionTarget(_In_ HANDLE userToken) { + // m_defaultUid is not set before OOBE is complete. + if (m_configuration.RunOOBE) + { + return; + } + // If Plan 9 is running, add a connection target to the P9Rdr driver. if (m_plan9Port != LX_INIT_UTILITY_VM_INVALID_PORT) { diff --git a/test/windows/UnitTests.cpp b/test/windows/UnitTests.cpp index 1109b96870..8cf5637f2a 100644 --- a/test/windows/UnitTests.cpp +++ b/test/windows/UnitTests.cpp @@ -4441,12 +4441,29 @@ VERSION_ID="Invalid|Format" TerminateDistribution(); + // The distro's files should not be exposed via \\wsl.localhost before OOBE is completed. + const std::wstring testFilePathLinux = L"/tmp/oobe_file_test"; + const std::wstring testFilePathWindows = L"\\\\wsl.localhost\\" LXSS_DISTRO_NAME_TEST_L L"\\tmp\\oobe_file_test"; + { + const wil::unique_hfile file(CreateFile( + testFilePathWindows.c_str(), GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr)); + VERIFY_IS_FALSE(file.is_valid()); + } + validateOutput(nullptr, L"OOBE\n"); VERIFY_ARE_EQUAL(runOOBE.Get(), 0); // Validate that DefaultUid was set validateOutput(L"id -u", L"1010\n"); VERIFY_ARE_EQUAL(defaultUid.Get(), 1010); + + // The distro's files should now be exposed. And new file should be created with the correct uid. + { + const wil::unique_hfile file(CreateFile( + testFilePathWindows.c_str(), GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr)); + VERIFY_IS_TRUE(file.is_valid()); + validateOutput(std::format(L"stat -c %u {}", testFilePathLinux).c_str(), L"1010\n"); + } } // Verify that the default UID isn't changed if it's not present in wsl-distribution.conf. From d22e508cc9f3dc134f96fd1007910c93aab89a9d Mon Sep 17 00:00:00 2001 From: Feng Wang Date: Fri, 3 Jul 2026 11:18:58 +0800 Subject: [PATCH 2/2] apply fix to wsl1 --- src/windows/service/exe/LxssInstance.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/windows/service/exe/LxssInstance.cpp b/src/windows/service/exe/LxssInstance.cpp index 54fe3b186e..5f94172b52 100644 --- a/src/windows/service/exe/LxssInstance.cpp +++ b/src/windows/service/exe/LxssInstance.cpp @@ -425,6 +425,12 @@ void LxssInstance::Stop() void LxssInstance::RegisterPlan9ConnectionTarget(_In_ HANDLE userToken) { + // m_defaultUid is not set before OOBE is complete. + if (m_configuration.RunOOBE) + { + return; + } + const auto path = m_configuration.BasePath / LXSS_PLAN9_UNIX_SOCKET; using unique_unicode_string = wil::unique_struct; unique_unicode_string socketPath; @@ -577,6 +583,8 @@ wil::unique_handle LxssInstance::_CreateLxProcess( registration.Write(wsl::windows::service::Property::DefaultUid, static_cast(OobeResult->DefaultUid)); m_defaultUid = static_cast(OobeResult->DefaultUid); } + + RegisterPlan9ConnectionTarget(m_userToken.get()); } } CATCH_LOG()