]> xenbits.xensource.com Git - xen.git/commitdiff
tools/ocaml/xenstored: Fix path length validation
authorEdwin Török <edvin.torok@citrix.com>
Tue, 15 Dec 2020 13:29:44 +0000 (14:29 +0100)
committerJan Beulich <jbeulich@suse.com>
Tue, 15 Dec 2020 13:29:44 +0000 (14:29 +0100)
Currently, oxenstored checks the length of paths against 1024, then
prepends "/local/domain/$DOMID/" to relative paths.  This allows a domU
to create paths which can't subsequently be read by anyone, even dom0.
This also interferes with listing directories, etc.

Define a new oxenstored.conf entry: quota-path-max, defaulting to 1024
as before.  For paths that begin with "/local/domain/$DOMID/" check the
relative path length against this quota. For all other paths check the
entire path length.

This ensures that if the domid changes (and thus the length of a prefix
changes) a path that used to be valid stays valid (e.g. after a
live-migration).  It also ensures that regardless how the client tries
to access a path (domid-relative or absolute) it will get consistent
results, since the limit is always applied on the final canonicalized
path.

Delete the unused Domain.get_path to avoid it being confused with
Connection.get_path (which differs by a trailing slash only).

Rewrite Util.path_validate to apply the appropriate length restriction
based on whether the path is relative or not.  Remove the check for
connection_path being absolute, because it is not guest controlled data.

This is part of XSA-323.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Signed-off-by: Edwin Török <edvin.torok@citrix.com>
Acked-by: Christian Lindig <christian.lindig@citrix.com>
tools/ocaml/libs/xb/partial.ml
tools/ocaml/libs/xb/partial.mli
tools/ocaml/xenstored/define.ml
tools/ocaml/xenstored/domain.ml
tools/ocaml/xenstored/oxenstored.conf.in
tools/ocaml/xenstored/utils.ml
tools/ocaml/xenstored/xenstored.ml

index d4d1c7bdec3211dbe98f98a294f32d281841433a..b6e2a716e2637488e8c37fb8d6beb4f5e6f79271 100644 (file)
@@ -28,6 +28,7 @@ external header_of_string_internal: string -> int * int * int * int
          = "stub_header_of_string"
 
 let xenstore_payload_max = 4096 (* xen/include/public/io/xs_wire.h *)
+let xenstore_rel_path_max = 2048 (* xen/include/public/io/xs_wire.h *)
 
 let of_string s =
        let tid, rid, opint, dlen = header_of_string_internal s in
index 359a75e88db53d8adca96a9e3a9b7c9a20b38227..b9216018f5175d30a7870fbab62bd15b6262c902 100644 (file)
@@ -9,6 +9,7 @@ external header_size : unit -> int = "stub_header_size"
 external header_of_string_internal : string -> int * int * int * int
   = "stub_header_of_string"
 val xenstore_payload_max : int
+val xenstore_rel_path_max : int
 val of_string : string -> pkt
 val append : pkt -> string -> int -> unit
 val to_complete : pkt -> int
index 2965c085340e321851dbf8cdc3d60e91a7d1fde3..f574397a4c0b3ca867609e9b7b0ef09abc5494bc 100644 (file)
@@ -32,6 +32,8 @@ let conflict_rate_limit_is_aggregate = ref true
 
 let domid_self = 0x7FF0
 
+let path_max = ref Xenbus.Partial.xenstore_rel_path_max
+
 exception Not_a_directory of string
 exception Not_a_value of string
 exception Already_exist
index b0a01b06faadcee9b66e3d5051a28e7169fa9fb4..081076271a686ea39c964fe128849cc20242015d 100644 (file)
@@ -38,7 +38,6 @@ type t =
 }
 
 let is_dom0 d = d.id = 0
-let get_path dom = "/local/domain/" ^ (sprintf "%u" dom.id)
 let get_id domain = domain.id
 let get_interface d = d.interface
 let get_mfn d = d.mfn
index f84348298118298d32237cd5fc6f4e93999fdeda..4ae48e42d47da1de519e0fef192d0ea022921208 100644 (file)
@@ -61,6 +61,7 @@ quota-maxsize = 2048
 quota-maxwatch = 100
 quota-transaction = 10
 quota-maxrequests = 1024
+quota-path-max = 1024
 
 # Activate filed base backend
 persistent = false
index e8c9fe4e94c608fd1122b6621c58a9c18e2a7102..eb79bf0146e52f8be61a8d4b347ef598a007f512 100644 (file)
@@ -93,7 +93,7 @@ let read_file_single_integer filename =
 let path_validate path connection_path =
        let len = String.length path in
 
-       if len = 0 || len > 1024 then raise Define.Invalid_path;
+       if len = 0 then raise Define.Invalid_path;
 
        let abs_path =
                match String.get path 0 with
@@ -101,4 +101,17 @@ let path_validate path connection_path =
                | _   -> connection_path ^ path
        in
 
+       (* Regardless whether client specified absolute or relative path,
+          canonicalize it (above) and, for domain-relative paths, check the
+          length of the relative part.
+
+          This prevents paths becoming invalid across migrate when the length
+          of the domid changes in @param connection_path.
+        *)
+       let len = String.length abs_path in
+       let on_absolute _ _ = len in
+       let on_relative _ offset = len - offset in
+       let len = Scanf.ksscanf abs_path on_absolute "/local/domain/%d/%n" on_relative in
+       if len > !Define.path_max then raise Define.Invalid_path;
+
        abs_path
index 6926a4de41b34ca352e311a8caf69cbd411d2d8b..8f04cda1901675e363a4f7a19d0096a0dcbcab30 100644 (file)
@@ -102,6 +102,7 @@ let parse_config filename =
                ("quota-maxentity", Config.Set_int Quota.maxent);
                ("quota-maxsize", Config.Set_int Quota.maxsize);
                ("quota-maxrequests", Config.Set_int Define.maxrequests);
+               ("quota-path-max", Config.Set_int Define.path_max);
                ("test-eagain", Config.Set_bool Transaction.test_eagain);
                ("persistent", Config.Set_bool Disk.enable);
                ("xenstored-log-file", Config.String Logging.set_xenstored_log_destination);