tools/ocaml/xenstored: Fix path length validation
authorEdwin Török <edvin.torok@citrix.com>
Tue, 15 Dec 2020 13:08:17 +0000 (14:08 +0100)
committerJan Beulich <jbeulich@suse.com>
Tue, 15 Dec 2020 13:08:17 +0000 (14:08 +0100)
commit49ed711a956e8bd0c634e1c030d4734eadad673b
treeb88772b2166f6fe8b50286f777cf0aebe67ab772
parentdc871dda66a1ac1e0fc1ca5e35e380a145aaa739
tools/ocaml/xenstored: Fix path length validation

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