]> xenbits.xensource.com Git - xen.git/commitdiff
tools/oxenstored: Reject invalid watch paths early
authorEdwin Török <edvin.torok@citrix.com>
Fri, 15 Jan 2021 19:28:37 +0000 (19:28 +0000)
committerIan Jackson <iwj@xenproject.org>
Fri, 19 Mar 2021 13:46:44 +0000 (13:46 +0000)
Watches on invalid paths were accepted, but they would never trigger.  The
client also got no notification that its watch is bad and would never trigger.

Found again by the structured fuzzer, due to an error on live update reload:
the invalid watch paths would get rejected during live update and the list of
watches would be different pre/post live update.

The testcase is watch on `//`, which is an invalid path.

Signed-off-by: Edwin Török <edvin.torok@citrix.com>
Acked-by: Christian Lindig <christian.lindig@citrix.com>
Release-Acked-by: Ian Jackson <iwj@xenproject.org>
(cherry picked from commit dc8caf214fb882546b0e93317b9828247a7c9da8)

tools/ocaml/xenstored/connection.ml
tools/ocaml/xenstored/connections.ml

index 850539e43abc6a5f095f124b59973657b7372049..daf8d804f7ef154f21891142a1fe2788a85f1ece 100644 (file)
@@ -158,18 +158,17 @@ let get_children_watches con path =
 let is_dom0 con =
        Perms.Connection.is_dom0 (get_perm con)
 
-let add_watch con path token =
+let add_watch con (path, apath) token =
        if !Quota.activate && !Define.maxwatch > 0 &&
           not (is_dom0 con) && con.nb_watches > !Define.maxwatch then
                raise Quota.Limit_reached;
-       let apath = get_watch_path con path in
        let l = get_watches con apath in
        if List.exists (fun w -> w.token = token) l then
                raise Define.Already_exist;
        let watch = watch_create ~con ~token ~path in
        Hashtbl.replace con.watches apath (watch :: l);
        con.nb_watches <- con.nb_watches + 1;
-       apath, watch
+       watch
 
 let del_watch con path token =
        let apath = get_watch_path con path in
index 1a70d412d549c94b74b5f00e21d1aef238134a62..7efdf3e5e05e14fcdcf04c278bc2ee5f6e5a0195 100644 (file)
@@ -114,8 +114,10 @@ let key_of_path path =
        "" :: Store.Path.to_string_list path
 
 let add_watch cons con path token =
-       let apath, watch = Connection.add_watch con path token in
+       let apath = Connection.get_watch_path con path in
+       (* fail on invalid paths early by calling key_of_str before adding watch *)
        let key = key_of_str apath in
+       let watch = Connection.add_watch con (path, apath) token in
        let watches =
                if Trie.mem cons.watches key
                then Trie.find cons.watches key