[pbs-devel] [PATCH proxmox-backup v3 5/5] fix: api: avoid race condition in set_backup_owner

Stefan Sterz s.sterz at proxmox.com
Tue May 24 10:28:16 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, 7 insertions(+), 2 deletions(-)

diff --git a/src/api2/admin/datastore.rs b/src/api2/admin/datastore.rs
index 932ed35f..eaff1677 100644
--- a/src/api2/admin/datastore.rs
+++ b/src/api2/admin/datastore.rs
@@ -2174,10 +2174,9 @@ pub fn set_backup_owner(
     let datastore = DataStore::lookup_datastore(&store, Some(Operation::Write))?;
 
     let backup_group = datastore.backup_group(ns, backup_group);
+    let owner = backup_group.get_owner()?;
 
     if owner_check_required {
-        let owner = backup_group.get_owner()?;
-
         let allowed = match (owner.is_token(), new_owner.is_token()) {
             (true, true) => {
                 // API token to API token, owned by same user
@@ -2224,6 +2223,12 @@ pub fn set_backup_owner(
         );
     }
 
+    let _guard = backup_group.lock()?;
+
+    if owner != backup_group.get_owner()? {
+        bail!("{owner} does not own this group anymore");
+    }
+
     backup_group.set_owner(&new_owner, true)?;
 
     Ok(())
-- 
2.30.2






More information about the pbs-devel mailing list