Skip to content

Commit 909d5eb

Browse files
benhillisBen HillisCopilot
authored
Validate NUL-termination of flexible-array Buffer in interop messages (#40402)
* Validate NUL-termination of flexible-array Buffer in interop messages Use string::FromMessageBuffer<T>() instead of directly accessing the Buffer[] flexible-array member in interop message structs. FromMessageBuffer validates that a NUL terminator exists within the span bounds, preventing out-of-bounds reads when a malformed message contains no Buffer data or lacks NUL termination. Affected message handlers: - LxInitMessageQueryEnvironmentVariable (config.cpp) - LxInitMessageCreateLoginSession (config.cpp) - LxMiniInitMessageUnmount (main.cpp) Co-authored-by: Copilot <[email protected]> * Remove unused Message parameter name in WSLC_UNMOUNT handler After switching to FromMessageBuffer, the Message parameter is no longer referenced directly. Remove the name to avoid -Wunused-parameter. Co-authored-by: Copilot <[email protected]> --------- Co-authored-by: Ben Hillis <[email protected]> Co-authored-by: Copilot <[email protected]>
1 parent 73e63e4 commit 909d5eb

3 files changed

Lines changed: 8 additions & 7 deletions

File tree

‎src/linux/init/WSLCInit.cpp‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -670,13 +670,13 @@ void HandleMessageImpl(
670670
Transaction.SendResultMessage(result < 0 ? errno : 0);
671671
}
672672

673-
void HandleMessageImpl(
674-
wsl::shared::SocketChannel& Channel, wsl::shared::Transaction& Transaction, const WSLC_UNMOUNT& Message, const gsl::span<gsl::byte>& Buffer)
673+
void HandleMessageImpl(wsl::shared::SocketChannel& Channel, wsl::shared::Transaction& Transaction, const WSLC_UNMOUNT&, const gsl::span<gsl::byte>& Buffer)
675674
{
676-
auto result = umount(Message.Buffer) < 0 ? errno : 0;
675+
auto* path = wsl::shared::string::FromMessageBuffer<WSLC_UNMOUNT>(Buffer);
676+
auto result = umount(path) < 0 ? errno : 0;
677677
if (result == 0)
678678
{
679-
result = rmdir(Message.Buffer) < 0 ? errno : 0;
679+
result = rmdir(path) < 0 ? errno : 0;
680680
}
681681

682682
Transaction.SendResultMessage<int32_t>(result);

‎src/linux/init/config.cpp‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ try
394394
return;
395395
}
396396

397-
auto Value = UtilGetEnvironmentVariable(Query->Buffer);
397+
auto Value = UtilGetEnvironmentVariable(wsl::shared::string::FromMessageBuffer<LX_INIT_QUERY_ENVIRONMENT_VARIABLE>(Message));
398398
wsl::shared::MessageWriter<LX_INIT_QUERY_ENVIRONMENT_VARIABLE> Response(LxInitMessageQueryEnvironmentVariable);
399399
Response.WriteString(Value);
400400
Transaction.Send<LX_INIT_QUERY_ENVIRONMENT_VARIABLE>(Response.Span());
@@ -427,7 +427,8 @@ try
427427
}
428428
else
429429
{
430-
success = CreateLoginSession(Config, CreateSession->Buffer, CreateSession->Uid);
430+
success = CreateLoginSession(
431+
Config, wsl::shared::string::FromMessageBuffer<LX_INIT_CREATE_LOGIN_SESSION>(Message), CreateSession->Uid);
431432
}
432433

433434
break;

‎src/linux/init/main.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2925,7 +2925,7 @@ Return Value:
29252925
return;
29262926
}
29272927

2928-
Target = GetMountTarget(Message->Buffer);
2928+
Target = GetMountTarget(wsl::shared::string::FromMessageBuffer<LX_MINI_INIT_UNMOUNT_MESSAGE>(Buffer));
29292929

29302930
Step = LxMiniInitMountStepUnmount;
29312931
Result = umount(Target.c_str());

0 commit comments

Comments
 (0)