Always apply electron sandbox SUID fix
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
package helper
|
package helper
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
@@ -13,6 +13,11 @@ import (
|
|||||||
|
|
||||||
var pmElectronUpdate *updater.File
|
var pmElectronUpdate *updater.File
|
||||||
|
|
||||||
|
const suidBitWarning = `Failed to set SUID permissions for chrome-sandbox.
|
||||||
|
This is required for Linux kernel versions that do not have unprivileged user namespaces (CONFIG_USER_NS_UNPRIVILEGED) enabled.
|
||||||
|
If you're running and up-to-date distribution kernel you can likely ignore this warning. If you encounter issue starting the
|
||||||
|
user interface please either update your kernel or set the SUID bit (mode 0%0o) on %s`
|
||||||
|
|
||||||
// EnsureChromeSandboxPermissions makes sure the chrome-sandbox distributed
|
// EnsureChromeSandboxPermissions makes sure the chrome-sandbox distributed
|
||||||
// by our app-electron package has the SUID bit set on systems that do not
|
// by our app-electron package has the SUID bit set on systems that do not
|
||||||
// allow unprivileged CLONE_NEWUSER (clone(3)).
|
// allow unprivileged CLONE_NEWUSER (clone(3)).
|
||||||
@@ -23,56 +28,29 @@ func EnsureChromeSandboxPermissions(reg *updater.ResourceRegistry) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := os.Stat("/proc/self/ns/user")
|
|
||||||
if err == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
if !os.IsNotExist(err) {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
// err == ENOENT
|
|
||||||
|
|
||||||
if pmElectronUpdate != nil && !pmElectronUpdate.UpgradeAvailable() {
|
if pmElectronUpdate != nil && !pmElectronUpdate.UpgradeAvailable() {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
identifier := PlatformIdentifier("app/portmaster-app.zip")
|
identifier := PlatformIdentifier("app/portmaster-app.zip")
|
||||||
|
|
||||||
log.Debug("updates: kernel support for unprivileged USERNS_CLONE disabled")
|
var err error
|
||||||
|
|
||||||
pmElectronUpdate, err = reg.GetFile(identifier)
|
pmElectronUpdate, err = reg.GetFile(identifier)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return fmt.Errorf("failed to get file: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
unpackedPath := strings.TrimSuffix(
|
unpackedPath := strings.TrimSuffix(
|
||||||
pmElectronUpdate.Path(),
|
pmElectronUpdate.Path(),
|
||||||
filepath.Ext(pmElectronUpdate.Path()),
|
filepath.Ext(pmElectronUpdate.Path()),
|
||||||
)
|
)
|
||||||
sandboxFile := filepath.Join(unpackedPath, "chrome-sandbox")
|
sandboxFile := filepath.Join(unpackedPath, "chrome-sandbox")
|
||||||
if err := os.Chmod(sandboxFile, 0o0755|os.ModeSetuid); err != nil {
|
if err := os.Chmod(sandboxFile, 0o0755|os.ModeSetuid); err != nil {
|
||||||
return err
|
log.Warningf(suidBitWarning, 0o0755 | os.ModeSetuid, sandboxFile)
|
||||||
|
|
||||||
|
return fmt.Errorf("failed to chmod: %w", err)
|
||||||
}
|
}
|
||||||
log.Infof("updates: fixed SUID permission for chrome-sandbox")
|
log.Infof("updates: fixed SUID permission for chrome-sandbox")
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkSysctl(setting string, value byte) bool { //nolint:deadcode,unused // TODO: Do we still need this?
|
|
||||||
c, err := sysctl(setting)
|
|
||||||
if err != nil {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
if len(c) < 1 {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
return c[0] == value
|
|
||||||
}
|
|
||||||
|
|
||||||
func sysctl(setting string) ([]byte, error) { //nolint:unused // TODO: Do we still need this?
|
|
||||||
parts := append([]string{"/proc", "sys"}, strings.Split(setting, ".")...)
|
|
||||||
path := filepath.Join(parts...)
|
|
||||||
content, err := ioutil.ReadFile(path)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return content, nil
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user