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

Stefan Sterz s.sterz at proxmox.com
Wed Aug 24 14:48:29 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 | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/src/api2/admin/datastore.rs b/src/api2/admin/datastore.rs
index 7b103fb7..8a9e4d99 100644
--- a/src/api2/admin/datastore.rs
+++ b/src/api2/admin/datastore.rs
@@ -2181,9 +2181,9 @@ pub async 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) => {
@@ -2231,6 +2231,12 @@ pub async 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