[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v1 3/4] tools/ocaml/xenstored: reject invalid watch paths early


  • To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Edwin Török <edvin.torok@xxxxxxxxxx>
  • Date: Fri, 15 Jan 2021 22:29:08 +0000
  • Authentication-results: esa2.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none
  • Cc: Edwin Török <edvin.torok@xxxxxxxxxx>, "Christian Lindig" <christian.lindig@xxxxxxxxxx>, David Scott <dave@xxxxxxxxxx>, "Ian Jackson" <iwj@xxxxxxxxxxxxxx>, Wei Liu <wl@xxxxxxx>
  • Delivery-date: Fri, 15 Jan 2021 22:52:48 +0000
  • Ironport-sdr: +/LaM1m+rcM5Pq74ZGY60/XWuFJNnjkfXHsM05xZlzUgtwMAilYZZNon8dyE9gIa6mse3zQ1m4 OgskTagfrfHONx+iCP+6tBsPPbCvTEo7E2Qo1PNSJXX7DdpK7K2wJ5JLDvqnZrk9ncvSOqE5hV kU4HUUVCwYUGXEeW1ckW+zzD2rXMv6eOgk3eMxFDnsHoNhrU35JBjrctwRWiH6wQ7moClydpx1 KSNkEg0iuiQU0jtwde1QYUZ8GqJWGvVyi3GnqXadR9SUrLjUHDIcZTzA1tiv57YvPM85beVs0H OTo=
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

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.

This was found by an older version of the fuzzer:
```
Test live-update failed (507 shrink steps):
[NEW; (0, None, WATCH ([""; ""], "")); (0, None, CONTROL live-update ())]
```

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

Signed-off-by: Edwin Török <edvin.torok@xxxxxxxxxx>
---
 tools/ocaml/xenstored/connection.ml  | 5 ++---
 tools/ocaml/xenstored/connections.ml | 4 +++-
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/tools/ocaml/xenstored/connection.ml 
b/tools/ocaml/xenstored/connection.ml
index 1f9fe9e3b2..c7f22e5ee9 100644
--- a/tools/ocaml/xenstored/connection.ml
+++ b/tools/ocaml/xenstored/connection.ml
@@ -163,18 +163,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
diff --git a/tools/ocaml/xenstored/connections.ml 
b/tools/ocaml/xenstored/connections.ml
index 8a66eeec3a..3c7429fe7f 100644
--- a/tools/ocaml/xenstored/connections.ml
+++ b/tools/ocaml/xenstored/connections.ml
@@ -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
-- 
2.29.2




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.