tools/ocaml/xenstored: Fix path length validation
authorEdwin Török <edvin.torok@citrix.com>
Tue, 15 Dec 2020 12:36:39 +0000 (13:36 +0100)
committerJan Beulich <jbeulich@suse.com>
Tue, 15 Dec 2020 12:36:39 +0000 (13:36 +0100)
commitbf0703992c62d89e30a9051c363055387257f24f
tree8c4c35a1d81dbf44a0ed2d4eeea402eee78b87c5
parentc46eff921209a2526f0055cdb76fbf69176b729e
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