Skip to content
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

fix: fix a crash in safeStorage on Linux #33913

Conversation

RaisinTen
Copy link
Member

@RaisinTen RaisinTen commented Apr 25, 2022

Description of Change

On Linux, isEncryptionAvailable() was crashing instead of returning a
boolean before the 'ready' event was emitted by the app. The reason of
the crash is that CreateKeyStorage()
expects the config to be set but the function responsible for setting the
config, SetConfig(),
is called only after the app is ready inside PostCreateMainMessageLoop().
So this changes IsEncryptionAvailable() to return false when the app
is not ready on Linux and uses that instead of the raw API in other
places like EncryptString() and DecryptString().

Fixes: #32206
Signed-off-by: Darshan Sen raisinten@gmail.com

Checklist

Release Notes

Notes: Fixed a crash in safeStorage on Linux.

@RaisinTen RaisinTen requested review from a team as code owners April 25, 2022 12:14
@electron-cation electron-cation bot added the new-pr 🌱 PR opened in the last 24 hours label Apr 25, 2022
@RaisinTen RaisinTen force-pushed the fix/return-boolean-from-safeStorage.isEncryptionAvailable-instead-of-crashing branch from 3dcf54a to 656f235 Compare April 25, 2022 12:23
Copy link
Member

@nornagon nornagon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is worth a patch. Can we throw a JS exception instead if the function is called before the app is ready?

@RaisinTen RaisinTen force-pushed the fix/return-boolean-from-safeStorage.isEncryptionAvailable-instead-of-crashing branch 2 times, most recently from 73832a7 to bfb392d Compare April 26, 2022 08:02
@RaisinTen RaisinTen changed the title fix: return boolean from safeStorage.isEncryptionAvailable() instead of crashing fix: fix a crash in safeStorage on Linux Apr 26, 2022
@RaisinTen RaisinTen force-pushed the fix/return-boolean-from-safeStorage.isEncryptionAvailable-instead-of-crashing branch from bfb392d to 5f4350a Compare April 26, 2022 08:05
@RaisinTen
Copy link
Member Author

@nornagon done, now isEncryptionAvailable() returns false if the app is not ready on Linux and the other APIs of safeStorage like encryptString() and decryptString() throws exceptions instead of crashing if isEncryptionAvailable() returns false.

@RaisinTen RaisinTen requested a review from nornagon April 26, 2022 11:26
Copy link
Member

@ckerr ckerr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. What's happening is OSCrypt has a CHECK() to confirm that the config has been set, and Electron does that in ElectronBrowserMainParts::PostCreateMainMessageLoop.

An alternative would be to set the config sooner in Electron's life cycle, but from a quick read I can't tell if that would have ripple effects.

Cross-platform app devs are already going to be waiting for ready on Windows, so documenting the same for Linux + fixing the crash is reasonable.

@ckerr ckerr added the semver/patch backwards-compatible bug fixes label Apr 27, 2022
@electron-cation electron-cation bot removed the new-pr 🌱 PR opened in the last 24 hours label Apr 27, 2022
@RaisinTen
Copy link
Member Author

@nornagon could you PTAL?

spec-main/api-safe-storage-spec.ts Outdated Show resolved Hide resolved
On Linux, `isEncryptionAvailable()` was crashing instead of returning a
boolean before the 'ready' event was emitted by the app. The reason of
the crash is that [`CreateKeyStorage()`](https://source.chromium.org/chromium/chromium/src/+/main:components/os_crypt/os_crypt_linux.cc;l=74;drc=35be6215ec8f09e50176f36753c68f26c63d1885;bpv=1;bpt=0)
expects the config to be set but the function responsible for setting the
config, [`SetConfig()`](https://source.chromium.org/chromium/chromium/src/+/main:components/os_crypt/os_crypt_linux.cc;l=237;drc=35be6215ec8f09e50176f36753c68f26c63d1885;bpv=1;bpt=0),
is called only after the app is ready inside [`PostCreateMainMessageLoop()`](https://github.com/electron/electron/blob/main/shell/browser/electron_browser_main_parts.cc#L499).
So this changes `IsEncryptionAvailable()` to return `false` when the app
is not ready on Linux and uses that instead of the raw API in other
places like `EncryptString()` and `DecryptString()`.

Fixes: electron#32206
Signed-off-by: Darshan Sen <raisinten@gmail.com>
@RaisinTen RaisinTen force-pushed the fix/return-boolean-from-safeStorage.isEncryptionAvailable-instead-of-crashing branch from 17c80bb to 4197bc3 Compare May 5, 2022 08:24
@RaisinTen RaisinTen requested a review from nornagon May 5, 2022 10:22
@jkleinsc jkleinsc merged commit 03e68e2 into electron:main May 9, 2022
@release-clerk
Copy link

release-clerk bot commented May 9, 2022

Release Notes Persisted

Fixed a crash in safeStorage on Linux.

@trop trop bot added merged/18-x-y and removed target/18-x-y labels May 9, 2022
RaisinTen added a commit to RaisinTen/electron that referenced this pull request May 17, 2022
On Linux, `isEncryptionAvailable()` was crashing instead of returning a
boolean before the 'ready' event was emitted by the app. The reason of
the crash is that [`CreateKeyStorage()`](https://source.chromium.org/chromium/chromium/src/+/main:components/os_crypt/os_crypt_linux.cc;l=74;drc=35be6215ec8f09e50176f36753c68f26c63d1885;bpv=1;bpt=0)
expects the config to be set but the function responsible for setting the
config, [`SetConfig()`](https://source.chromium.org/chromium/chromium/src/+/main:components/os_crypt/os_crypt_linux.cc;l=237;drc=35be6215ec8f09e50176f36753c68f26c63d1885;bpv=1;bpt=0),
is called only after the app is ready inside [`PostCreateMainMessageLoop()`](https://github.com/electron/electron/blob/main/shell/browser/electron_browser_main_parts.cc#L499).
So this changes `IsEncryptionAvailable()` to return `false` when the app
is not ready on Linux and uses that instead of the raw API in other
places like `EncryptString()` and `DecryptString()`.

Fixes: electron#32206
Signed-off-by: Darshan Sen <raisinten@gmail.com>
@trop
Copy link
Contributor

trop bot commented May 17, 2022

@RaisinTen has manually backported this PR to "17-x-y", please check out #34261

RaisinTen added a commit to RaisinTen/electron that referenced this pull request May 17, 2022
On Linux, `isEncryptionAvailable()` was crashing instead of returning a
boolean before the 'ready' event was emitted by the app. The reason of
the crash is that [`CreateKeyStorage()`](https://source.chromium.org/chromium/chromium/src/+/main:components/os_crypt/os_crypt_linux.cc;l=74;drc=35be6215ec8f09e50176f36753c68f26c63d1885;bpv=1;bpt=0)
expects the config to be set but the function responsible for setting the
config, [`SetConfig()`](https://source.chromium.org/chromium/chromium/src/+/main:components/os_crypt/os_crypt_linux.cc;l=237;drc=35be6215ec8f09e50176f36753c68f26c63d1885;bpv=1;bpt=0),
is called only after the app is ready inside [`PostCreateMainMessageLoop()`](https://github.com/electron/electron/blob/main/shell/browser/electron_browser_main_parts.cc#L499).
So this changes `IsEncryptionAvailable()` to return `false` when the app
is not ready on Linux and uses that instead of the raw API in other
places like `EncryptString()` and `DecryptString()`.

Fixes: electron#32206
Signed-off-by: Darshan Sen <raisinten@gmail.com>
@trop
Copy link
Contributor

trop bot commented May 17, 2022

@RaisinTen has manually backported this PR to "16-x-y", please check out #34262

RaisinTen added a commit to RaisinTen/electron that referenced this pull request May 17, 2022
On Linux, `isEncryptionAvailable()` was crashing instead of returning a
boolean before the 'ready' event was emitted by the app. The reason of
the crash is that [`CreateKeyStorage()`](https://source.chromium.org/chromium/chromium/src/+/main:components/os_crypt/os_crypt_linux.cc;l=74;drc=35be6215ec8f09e50176f36753c68f26c63d1885;bpv=1;bpt=0)
expects the config to be set but the function responsible for setting the
config, [`SetConfig()`](https://source.chromium.org/chromium/chromium/src/+/main:components/os_crypt/os_crypt_linux.cc;l=237;drc=35be6215ec8f09e50176f36753c68f26c63d1885;bpv=1;bpt=0),
is called only after the app is ready inside [`PostCreateMainMessageLoop()`](https://github.com/electron/electron/blob/main/shell/browser/electron_browser_main_parts.cc#L499).
So this changes `IsEncryptionAvailable()` to return `false` when the app
is not ready on Linux and uses that instead of the raw API in other
places like `EncryptString()` and `DecryptString()`.

Fixes: electron#32206
Signed-off-by: Darshan Sen <raisinten@gmail.com>
@trop
Copy link
Contributor

trop bot commented May 17, 2022

@RaisinTen has manually backported this PR to "15-x-y", please check out #34263

jkleinsc pushed a commit that referenced this pull request May 18, 2022
* fix: fix a crash in `safeStorage` on Linux (#33913)

On Linux, `isEncryptionAvailable()` was crashing instead of returning a
boolean before the 'ready' event was emitted by the app. The reason of
the crash is that [`CreateKeyStorage()`](https://source.chromium.org/chromium/chromium/src/+/main:components/os_crypt/os_crypt_linux.cc;l=74;drc=35be6215ec8f09e50176f36753c68f26c63d1885;bpv=1;bpt=0)
expects the config to be set but the function responsible for setting the
config, [`SetConfig()`](https://source.chromium.org/chromium/chromium/src/+/main:components/os_crypt/os_crypt_linux.cc;l=237;drc=35be6215ec8f09e50176f36753c68f26c63d1885;bpv=1;bpt=0),
is called only after the app is ready inside [`PostCreateMainMessageLoop()`](https://github.com/electron/electron/blob/main/shell/browser/electron_browser_main_parts.cc#L499).
So this changes `IsEncryptionAvailable()` to return `false` when the app
is not ready on Linux and uses that instead of the raw API in other
places like `EncryptString()` and `DecryptString()`.

Fixes: #32206
Signed-off-by: Darshan Sen <raisinten@gmail.com>

* fix: replace BUILDFLAG(IS_LINUX) with defined(OS_LINUX)

Signed-off-by: Darshan Sen <raisinten@gmail.com>

* Linux: Send OSCrypt raw encryption key to the Network Service

This backports 0e09738.

Signed-off-by: Darshan Sen <raisinten@gmail.com>

* fix: add ifdef guard around NetworkService::SetEncryptionKey()

network::mojom::NetworkService::SetEncryptionKey() is only available on
Windows and macOS.

Signed-off-by: Darshan Sen <raisinten@gmail.com>
khalwa pushed a commit to solarwindscloud/electron that referenced this pull request Feb 22, 2023
On Linux, `isEncryptionAvailable()` was crashing instead of returning a
boolean before the 'ready' event was emitted by the app. The reason of
the crash is that [`CreateKeyStorage()`](https://source.chromium.org/chromium/chromium/src/+/main:components/os_crypt/os_crypt_linux.cc;l=74;drc=35be6215ec8f09e50176f36753c68f26c63d1885;bpv=1;bpt=0)
expects the config to be set but the function responsible for setting the
config, [`SetConfig()`](https://source.chromium.org/chromium/chromium/src/+/main:components/os_crypt/os_crypt_linux.cc;l=237;drc=35be6215ec8f09e50176f36753c68f26c63d1885;bpv=1;bpt=0),
is called only after the app is ready inside [`PostCreateMainMessageLoop()`](https://github.com/electron/electron/blob/main/shell/browser/electron_browser_main_parts.cc#L499).
So this changes `IsEncryptionAvailable()` to return `false` when the app
is not ready on Linux and uses that instead of the raw API in other
places like `EncryptString()` and `DecryptString()`.

Fixes: electron#32206
Signed-off-by: Darshan Sen <raisinten@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver/patch backwards-compatible bug fixes
Projects
None yet
4 participants