[pbs-devel] [PATCH proxmox-backup v2 4/4] fix: api: avoid race condition in set_backup_owner
Stefan Sterz
s.sterz at proxmox.com
Wed Apr 13 11:11:51 CEST 2022
when two clients change the owner of a backup store, a race condition
arose. add locking to avoid this.
Signed-off-by: Stefan Sterz <s.sterz at proxmox.com>
---
src/api2/admin/datastore.rs | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/src/api2/admin/datastore.rs b/src/api2/admin/datastore.rs
index 45a576ea..3dbf2246 100644
--- a/src/api2/admin/datastore.rs
+++ b/src/api2/admin/datastore.rs
@@ -1914,11 +1914,12 @@ pub fn set_backup_owner(
let privs = user_info.lookup_privs(&auth_id, &["datastore", &store]);
+ let owner = datastore.get_owner(&backup_group)?;
+
let allowed = if (privs & PRIV_DATASTORE_MODIFY) != 0 {
// High-privilege user/token
true
} else if (privs & PRIV_DATASTORE_BACKUP) != 0 {
- let owner = datastore.get_owner(&backup_group)?;
match (owner.is_token(), new_owner.is_token()) {
(true, true) => {
@@ -1965,6 +1966,12 @@ pub fn set_backup_owner(
new_owner);
}
+ let _guard = datastore.lock_group(&backup_group)?;
+
+ if owner != datastore.get_owner(&backup_group)? {
+ bail!("{} does not own this group anymore", owner);
+ }
+
datastore.set_owner(&backup_group, &new_owner, true)?;
Ok(())
--
2.30.2
More information about the pbs-devel
mailing list