Repository navigation
[WSLC] Proxy Pt. 2: Enable session host loopback #1714
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
09b1663
22fd716
a809318
86227d2
727d749
29bef9d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,7 +33,7 @@ | |
| //! move that happens *before* any `&raw` is taken), after which callers keep it | ||
| //! as a stationary local. | ||
|
|
||
| use std::ffi::c_void; | ||
| use std::ffi::{c_void, CStr}; | ||
| use std::fmt::Write; | ||
| use std::ptr; | ||
| use std::sync::atomic::{AtomicBool, Ordering}; | ||
|
|
@@ -845,15 +845,9 @@ pub unsafe fn create_daemon_session( | |
| } | ||
| apply_session_sizing(sdk, &mut settings, sizing)?; | ||
|
|
||
| let mut session: WslcSession = ptr::null_mut(); | ||
| let mut err_msg = CoTaskMemPWSTR::null(); | ||
| let started = Instant::now(); | ||
| let hr = sdk.WslcCreateSession(&mut settings, &mut session, err_msg.as_mut_ptr()); | ||
| let session = create_session(sdk, &mut settings)?; | ||
| let created_in = started.elapsed(); | ||
| if hr != S_OK { | ||
| let msg = err_msg.to_string_lossy(); | ||
| return Err(sdk_error("WslcCreateSession failed", hr, &msg).into()); | ||
| } | ||
|
|
||
| let guard = WslcSessionGuard::from_raw( | ||
| session, | ||
|
|
@@ -898,6 +892,45 @@ pub unsafe fn create_daemon_session( | |
| Ok(guard) | ||
| } | ||
|
|
||
| /// Hostname that resolves to the Windows host loopback inside a session. WSL's | ||
| /// own CLI uses the same default. | ||
| pub(crate) const HOST_LOOPBACK_NAME: &CStr = c"host.wslc.internal"; | ||
|
|
||
| /// Create a session with host loopback enabled. A WSL runtime older than 3.0.5 | ||
| /// rejects the setting. | ||
|
Comment on lines
+899
to
+900
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isolated-only sessions (every deny-all create-and-run, where Set the hostname only for sessions that can hold a bridged container (pass
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 3.0.5 is now the minimum version. I will see if I can enforce that. |
||
| /// | ||
| /// # Safety | ||
| /// `sdk` must hold valid function pointers, `settings` must be initialised and | ||
| /// COM must be initialised on this thread. | ||
| pub(crate) unsafe fn create_session( | ||
| sdk: &WslcSdk, | ||
| settings: &mut WslcSessionSettings, | ||
| ) -> Result<WslcSession, ScriptResponse> { | ||
| let hr = sdk.WslcSetSessionSettingsHostLoopback(settings, HOST_LOOPBACK_NAME.as_ptr()); | ||
| if hr != S_OK { | ||
| return Err(sdk_error( | ||
| "WslcSetSessionSettingsHostLoopback failed", | ||
| hr, | ||
| "", | ||
| )); | ||
| } | ||
|
|
||
| let mut session: WslcSession = ptr::null_mut(); | ||
| let mut err_msg = CoTaskMemPWSTR::null(); | ||
| let hr = sdk.WslcCreateSession(settings, &mut session, err_msg.as_mut_ptr()); | ||
| if hr == WSLC_E_RUNTIME_UPDATE_NEEDED { | ||
|
theelliotm marked this conversation as resolved.
Resolved
|
||
| return Err(WslcError::Unavailable(sdk_init::prerequisite_error( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the daemon this
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 3.0.5 is now the minimum version. I will see if I can enforce that. |
||
| WslcComponentFlags::WSLC_COMPONENT_FLAG_WSL_PACKAGE, | ||
| )) | ||
| .into_response()); | ||
| } | ||
| if hr != S_OK { | ||
| let msg = err_msg.to_string_lossy(); | ||
| return Err(sdk_error("WslcCreateSession failed", hr, &msg)); | ||
| } | ||
| Ok(session) | ||
| } | ||
|
|
||
| /// Apply a session's sizing and its boot deadline to `settings`. | ||
| /// | ||
| /// The boot timeout is applied even when the caller asked for no sizing, since | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -659,14 +659,7 @@ impl WSLContainerRunner { | |
| } | ||
| } | ||
|
|
||
| // Create session while string data is still alive | ||
| let mut session: WslcSession = ptr::null_mut(); | ||
| let mut err_msg = CoTaskMemPWSTR::null(); | ||
| let hr = sdk.WslcCreateSession(&mut settings, &mut session, err_msg.as_mut_ptr()); | ||
| if hr != S_OK { | ||
| let msg = err_msg.to_string_lossy(); | ||
| return Err(sdk_error("WslcCreateSession failed", hr, &msg)); | ||
| } | ||
| let session = container_steps::create_session(sdk, &mut settings)?; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On x64/WSL 3.0.5 a bridged create-and-run sandbox fetched another sandbox's port mapping via Don't enable session host loopback until per-container/per-port enforcement exists, and add a two-sandbox negative test to
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wow. Investigating. |
||
| let _ = writeln!(logger, "[WSLC] Session created: {session_name_str}"); | ||
|
|
||
| Ok(WslcSessionGuard::from_raw( | ||
|
|
@@ -3274,7 +3267,7 @@ mod tests { | |
| sdk_init::prerequisite_error(WslcComponentFlags::WSLC_COMPONENT_FLAG_WSL_PACKAGE); | ||
|
|
||
| assert!(message.contains("WslPackage")); | ||
| assert!(message.contains("3.0.3")); | ||
| assert!(message.contains("3.0.5")); | ||
| assert!(message.contains("wsl --update")); | ||
| assert!(!message.contains("--pre-release")); | ||
| assert!(!message.contains("Virtual Machine Platform")); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The daemon now enables host loopback, but
PROTOCOL_VERSIONstays 9 andready_daemon()reuses any ready v9 daemon, so after an upgrade a still-running pre-PR daemon (alive while it holds sandboxes) keeps creating sessions withouthost.wslc.internal, and a new daemon gives old clients the new access.Shall we bump the protocol version?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will bump.