]> xenbits.xensource.com Git - people/aperard/xen-unstable.git/commitdiff
tools/xenstored: domain_entry_fix(): Handle conflicting transaction
authorJulien Grall <jgrall@amazon.com>
Fri, 22 Sep 2023 10:32:16 +0000 (11:32 +0100)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Wed, 27 Sep 2023 15:29:27 +0000 (16:29 +0100)
The function domain_entry_fix() will be initially called to check if the
quota is correct before attempt to commit any nodes. So it would be
possible that accounting is temporarily negative. This is the case
in the following sequence:

  1) Create 50 nodes
  2) Start two transactions
  3) Delete all the nodes in each transaction
  4) Commit the two transactions

Because the first transaction will have succeed and updated the
accounting, there is no guarantee that 'd->nbentry + num' will still
be above 0. So the assert() would be triggered.
The assert() was introduced in dbef1f748289 ("tools/xenstore: simplify
and fix per domain node accounting") with the assumption that the
value can't be negative. As this is not true revert to the original
check but restricted to the path where we don't update. Take the
opportunity to explain the rationale behind the check.

This CVE-2023-34323 / XSA-440.

Fixes: dbef1f748289 ("tools/xenstore: simplify and fix per domain node accounting")
Signed-off-by: Julien Grall <jgrall@amazon.com>
Reviewed-by: Juergen Gross <jgross@suse.com>
tools/xenstore/xenstored_domain.c

index aa86892fed9ee062e7609503861839b7b609e741..6074df210c6e8784d21fe9fe05e9a2ac30ce03ef 100644 (file)
@@ -1094,10 +1094,20 @@ int domain_entry_fix(unsigned int domid, int num, bool update)
        }
 
        cnt = d->nbentry + num;
-       assert(cnt >= 0);
 
-       if (update)
+       if (update) {
+               assert(cnt >= 0);
                d->nbentry = cnt;
+       } else if (cnt < 0) {
+               /*
+                * In a transaction when a node is being added/removed AND
+                * the same node has been added/removed outside the
+                * transaction in parallel, the result value may be negative.
+                * This is no problem, as the transaction will fail due to
+                * the resulting conflict. So override 'cnt'.
+                */
+               cnt = 0;
+       }
 
        return domid_is_unprivileged(domid) ? cnt : 0;
 }