-
Notifications
You must be signed in to change notification settings - Fork 798
Fixed a COM deadlock on Windows that could cause orbit to become unresponsive during BitLocker encryption #40142
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
7fefe3b
Fixed a COM deadlock on Windows that could cause orbit to become unre…
getvictor 7abf0d8
Removing dead code.
getvictor ab8a282
Merge remote-tracking branch 'origin/main' into victor/38405-bitlocke…
getvictor 5ed281b
Fixed panic reviewer comment
getvictor File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| * Fixed a COM deadlock on Windows that could cause orbit to become unresponsive during BitLocker encryption enforcement. BitLocker operations now run on a dedicated COM thread instead of sharing the global comshim singleton with other subsystems. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,19 +1,3 @@ | ||
| //go:build !windows | ||
|
|
||
| package bitlocker | ||
|
|
||
| func GetRecoveryKeys(targetVolume string) (map[string]string, error) { | ||
| return nil, nil | ||
| } | ||
|
|
||
| func EncryptVolume(targetVolume string) (string, error) { | ||
| return "", nil | ||
| } | ||
|
|
||
| func DecryptVolume(targetVolume string) error { | ||
| return nil | ||
| } | ||
|
|
||
| func GetEncryptionStatus() ([]VolumeStatus, error) { | ||
| return nil, nil | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| //go:build !windows | ||
|
|
||
| package bitlocker | ||
|
|
||
| // COMWorker is a no-op on non-Windows platforms. | ||
| type COMWorker struct{} | ||
|
|
||
| // NewCOMWorker returns a no-op COMWorker on non-Windows platforms. | ||
| func NewCOMWorker() (*COMWorker, error) { return &COMWorker{}, nil } | ||
|
|
||
| // Close is a no-op on non-Windows platforms. | ||
| func (w *COMWorker) Close() {} | ||
|
|
||
| // GetEncryptionStatus is a no-op on non-Windows platforms. | ||
| func (w *COMWorker) GetEncryptionStatus() ([]VolumeStatus, error) { return nil, nil } | ||
|
|
||
| // EncryptVolume is a no-op on non-Windows platforms. | ||
| func (w *COMWorker) EncryptVolume(string) (string, error) { return "", nil } | ||
|
|
||
| // DecryptVolume is a no-op on non-Windows platforms. | ||
| func (w *COMWorker) DecryptVolume(string) error { return nil } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| //go:build windows | ||
|
|
||
| package bitlocker | ||
|
|
||
| import ( | ||
| "errors" | ||
| "runtime" | ||
| "sync" | ||
|
|
||
| "github.com/go-ole/go-ole" | ||
| ) | ||
|
|
||
| // ErrWorkerClosed is returned when an operation is attempted on a closed COMWorker. | ||
| var ErrWorkerClosed = errors.New("COM worker is closed") | ||
|
|
||
| type comWorkItem struct { | ||
| fn func() (any, error) | ||
| result chan comWorkResult | ||
| } | ||
|
|
||
| type comWorkResult struct { | ||
| val any | ||
| err error | ||
| } | ||
|
|
||
| // COMWorker runs all BitLocker COM/WMI operations on a single dedicated OS | ||
| // thread. This prevents deadlocks with other COM callers (MDM Bridge, Windows | ||
| // Update) that share the global comshim singleton. | ||
| type COMWorker struct { | ||
| workCh chan comWorkItem | ||
| done chan struct{} | ||
| closeOnce sync.Once | ||
| } | ||
|
|
||
| // NewCOMWorker creates a new COMWorker that initializes COM on a dedicated OS | ||
| // thread and processes all BitLocker operations serially on that thread. | ||
| func NewCOMWorker() (*COMWorker, error) { | ||
| w := &COMWorker{ | ||
| workCh: make(chan comWorkItem), | ||
| done: make(chan struct{}), | ||
| } | ||
| initErr := make(chan error, 1) | ||
| go w.loop(initErr) | ||
| if err := <-initErr; err != nil { | ||
| return nil, err | ||
| } | ||
| return w, nil | ||
| } | ||
|
|
||
| func (w *COMWorker) loop(initErr chan<- error) { | ||
| runtime.LockOSThread() | ||
| defer runtime.UnlockOSThread() | ||
|
|
||
| if err := ole.CoInitializeEx(0, ole.COINIT_MULTITHREADED); err != nil { | ||
| initErr <- err | ||
| close(w.done) | ||
| return | ||
| } | ||
| defer ole.CoUninitialize() | ||
| initErr <- nil | ||
|
|
||
| for item := range w.workCh { | ||
| val, err := item.fn() | ||
| item.result <- comWorkResult{val, err} | ||
| } | ||
| close(w.done) | ||
| } | ||
|
|
||
| // Close shuts down the COM worker goroutine and waits for it to finish. | ||
| func (w *COMWorker) Close() { | ||
| w.closeOnce.Do(func() { | ||
| close(w.workCh) | ||
| }) | ||
| <-w.done | ||
| } | ||
|
|
||
| func (w *COMWorker) exec(fn func() (any, error)) comWorkResult { | ||
| ch := make(chan comWorkResult, 1) | ||
| select { | ||
| case w.workCh <- comWorkItem{fn: fn, result: ch}: | ||
| return <-ch | ||
| case <-w.done: | ||
| return comWorkResult{err: ErrWorkerClosed} | ||
| } | ||
| } | ||
|
|
||
| // GetEncryptionStatus returns the BitLocker encryption status for all logical volumes. | ||
| func (w *COMWorker) GetEncryptionStatus() ([]VolumeStatus, error) { | ||
| r := w.exec(func() (any, error) { return getEncryptionStatusOnCOMThread() }) | ||
| status, _ := r.val.([]VolumeStatus) | ||
| return status, r.err | ||
| } | ||
|
|
||
| // EncryptVolume encrypts the specified volume and returns the recovery key. | ||
| func (w *COMWorker) EncryptVolume(targetVolume string) (string, error) { | ||
| r := w.exec(func() (any, error) { return encryptVolumeOnCOMThread(targetVolume) }) | ||
| key, _ := r.val.(string) | ||
| return key, r.err | ||
| } | ||
|
|
||
| // DecryptVolume decrypts the specified volume. | ||
| func (w *COMWorker) DecryptVolume(targetVolume string) error { | ||
| r := w.exec(func() (any, error) { return nil, decryptVolumeOnCOMThread(targetVolume) }) | ||
| return r.err | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
Dead code that was never used.
EncryptVolumereturns the recovery key as part of the encryption process.