mirror of
https://github.com/lxc/incus
synced 2026-08-02 05:26:46 +00:00
incusd/instance/lxc: Confine credentials write to credentials directory
systemd credentials name could be abused to escape the credentials folder and allow for arbitrary writes to the host filesystem allowing for privilege escalation and denial of service attacks. We now use Go's OpenRoot (openat2) to restrict all file interactions to the "credentials" directory, avoiding such attacks. This addresses CVE-2026-33945 Reported-by: https://7asecurity.com Signed-off-by: Stéphane Graber <stgraber@stgraber.org>
This commit is contained in:
parent
15a5344774
commit
d0f2c86fcb
@ -9236,16 +9236,22 @@ func (d *lxc) setupCredentials(update bool) error {
|
||||
}
|
||||
}
|
||||
|
||||
credsRoot, err := os.OpenRoot(credentialsDir)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Failed to open the credentials directory: %w", err)
|
||||
}
|
||||
|
||||
defer func() { _ = credsRoot.Close() }()
|
||||
|
||||
for k, v := range credentials {
|
||||
credentialPath := filepath.Join(credentialsDir, k)
|
||||
err := os.WriteFile(credentialPath, v, 0o400)
|
||||
err := credsRoot.WriteFile(k, v, 0o400)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Failed to write credential %q: %w", k, err)
|
||||
}
|
||||
|
||||
err = os.Chown(credentialPath, int(rootUID), int(rootGID))
|
||||
err = credsRoot.Chown(k, int(rootUID), int(rootGID))
|
||||
if err != nil {
|
||||
return fmt.Errorf("Failed setting permissions for file %q: %w", credentialPath, err)
|
||||
return fmt.Errorf("Failed setting permissions for file %q: %w", k, err)
|
||||
}
|
||||
|
||||
delete(oldCredentials, k)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user