tools/ocaml/xenstored: delete watch from trie too when resetting watches
authorEdwin Török <edvin.torok@citrix.com>
Tue, 15 Dec 2020 12:37:14 +0000 (13:37 +0100)
committerJan Beulich <jbeulich@suse.com>
Tue, 15 Dec 2020 12:37:14 +0000 (13:37 +0100)
commit491a077ed4c51f26ee77bc92ca346942482cf24e
treef5fc853003893a8554a8655b2c60f4ed9c439b53
parentd2fa370d3ef9cbe22d7256c608671cdcdf6e0083
tools/ocaml/xenstored: delete watch from trie too when resetting watches

c/s f8c72b526129 "oxenstored: implement XS_RESET_WATCHES" from Xen 4.6
introduced reset watches support in oxenstored by mirroring the change
in cxenstored.

However the OCaml version has some additional data structures to
optimize watch firing, and just resetting the watches in one of the data
structures creates a security bug where a malicious guest kernel can
exceed its watch quota, driving oxenstored into OOM:
 * create watches
 * reset watches (this still keeps the watches lingering in another data
   structure, using memory)
 * create some more watches
 * loop until oxenstored dies

The guest kernel doesn't necessarily have to be malicious to trigger
this:
 * if control/platform-feature-xs_reset_watches is set
 * the guest kexecs (e.g. because it crashes)
 * on boot more watches are set up
 * this will slowly "leak" memory for watches in oxenstored, driving it
   towards OOM.

This is XSA-330.

Fixes: f8c72b526129 ("oxenstored: implement XS_RESET_WATCHES")
Signed-off-by: Edwin Török <edvin.torok@citrix.com>
Acked-by: Christian Lindig <christian.lindig@citrix.com>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
tools/ocaml/xenstored/connections.ml
tools/ocaml/xenstored/process.ml