direct-io.hg

changeset 12378:38c16b375298

Fix handling of the entries-per-domain quota. Entries which are created by
the guest but deleted by dom0 were remaining accounted against the guest,
which meant that the guest would eventually run out of quota.

This patch also prevents unprivileged domains from changing the owner of a
node. One guest could attack another by creating nodes and then transferring
them to the ownership of another, and though the accounting could be made to
work properly in this case, domains should never be transferring nodes in any
case, so it seems safer just to disallow the operation entirely.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
author Ewan Mellor <ewan@xensource.com>
date Mon Nov 13 10:43:29 2006 +0000 (2006-11-13)
parents 0b385df5f236
children f78bfe7bff73
files tools/xenstore/xenstored_core.c tools/xenstore/xenstored_domain.c tools/xenstore/xenstored_domain.h
line diff
     1.1 --- a/tools/xenstore/xenstored_core.c	Mon Nov 13 09:49:12 2006 +0000
     1.2 +++ b/tools/xenstore/xenstored_core.c	Mon Nov 13 10:43:29 2006 +0000
     1.3 @@ -791,7 +791,7 @@ static void delete_node_single(struct co
     1.4  		corrupt(conn, "Could not delete '%s'", node->name);
     1.5  		return;
     1.6  	}
     1.7 -	domain_entry_dec(conn);
     1.8 +	domain_entry_dec(conn, node);
     1.9  }
    1.10  
    1.11  /* Must not be / */
    1.12 @@ -842,7 +842,7 @@ static struct node *construct_node(struc
    1.13  	node->children = node->data = NULL;
    1.14  	node->childlen = node->datalen = 0;
    1.15  	node->parent = parent;
    1.16 -	domain_entry_inc(conn);
    1.17 +	domain_entry_inc(conn, node);
    1.18  	return node;
    1.19  }
    1.20  
    1.21 @@ -878,7 +878,7 @@ static struct node *create_node(struct c
    1.22  	 * something goes wrong. */
    1.23  	for (i = node; i; i = i->parent) {
    1.24  		if (!write_node(conn, i)) {
    1.25 -			domain_entry_dec(conn);
    1.26 +			domain_entry_dec(conn, i);
    1.27  			return NULL;
    1.28  		}
    1.29  		talloc_set_destructor(i, destroy_node);
    1.30 @@ -1108,6 +1108,7 @@ static void do_get_perms(struct connecti
    1.31  static void do_set_perms(struct connection *conn, struct buffered_data *in)
    1.32  {
    1.33  	unsigned int num;
    1.34 +	struct xs_permissions *perms;
    1.35  	char *name, *permstr;
    1.36  	struct node *node;
    1.37  
    1.38 @@ -1129,12 +1130,24 @@ static void do_set_perms(struct connecti
    1.39  		return;
    1.40  	}
    1.41  
    1.42 -	node->perms = talloc_array(node, struct xs_permissions, num);
    1.43 -	node->num_perms = num;
    1.44 -	if (!xs_strings_to_perms(node->perms, num, permstr)) {
    1.45 +	perms = talloc_array(node, struct xs_permissions, num);
    1.46 +	if (!xs_strings_to_perms(perms, num, permstr)) {
    1.47  		send_error(conn, errno);
    1.48  		return;
    1.49  	}
    1.50 +
    1.51 +	/* Unprivileged domains may not change the owner. */
    1.52 +	if (domain_is_unprivileged(conn) &&
    1.53 +	    perms[0].id != node->perms[0].id) {
    1.54 +		send_error(conn, EPERM);
    1.55 +		return;
    1.56 +	}
    1.57 +
    1.58 +	domain_entry_dec(conn, node);
    1.59 +	node->perms = perms;
    1.60 +	node->num_perms = num;
    1.61 +	domain_entry_inc(conn, node);
    1.62 +
    1.63  	if (!write_node(conn, node)) {
    1.64  		send_error(conn, errno);
    1.65  		return;
     2.1 --- a/tools/xenstore/xenstored_domain.c	Mon Nov 13 09:49:12 2006 +0000
     2.2 +++ b/tools/xenstore/xenstored_domain.c	Mon Nov 13 10:43:29 2006 +0000
     2.3 @@ -501,18 +501,35 @@ int domain_init(void)
     2.4  	return xce_handle;
     2.5  }
     2.6  
     2.7 -void domain_entry_inc(struct connection *conn)
     2.8 +void domain_entry_inc(struct connection *conn, struct node *node)
     2.9  {
    2.10 -	if (!conn || !conn->domain)
    2.11 +	struct domain *d;
    2.12 +
    2.13 +	if (!conn)
    2.14  		return;
    2.15 -	conn->domain->nbentry++;
    2.16 +
    2.17 +	if (node->perms && node->perms[0].id != conn->id) {
    2.18 +		d = find_domain_by_domid(node->perms[0].id);
    2.19 +		if (d)
    2.20 +			d->nbentry++;
    2.21 +	}
    2.22 +	else if (conn->domain) {
    2.23 +		conn->domain->nbentry++;
    2.24 +	}
    2.25  }
    2.26  
    2.27 -void domain_entry_dec(struct connection *conn)
    2.28 +void domain_entry_dec(struct connection *conn, struct node *node)
    2.29  {
    2.30 -	if (!conn || !conn->domain)
    2.31 +	struct domain *d;
    2.32 +
    2.33 +	if (!conn)
    2.34  		return;
    2.35 -	if (conn->domain->nbentry)
    2.36 +
    2.37 +	if (node->perms && node->perms[0].id != conn->id) {
    2.38 +		d = find_domain_by_domid(node->perms[0].id);
    2.39 +		if (d && d->nbentry)
    2.40 +			d->nbentry--;
    2.41 +	} else if (conn->domain && conn->domain->nbentry)
    2.42  		conn->domain->nbentry--;
    2.43  }
    2.44  
     3.1 --- a/tools/xenstore/xenstored_domain.h	Mon Nov 13 09:49:12 2006 +0000
     3.2 +++ b/tools/xenstore/xenstored_domain.h	Mon Nov 13 10:43:29 2006 +0000
     3.3 @@ -50,8 +50,8 @@ bool domain_can_write(struct connection 
     3.4  bool domain_is_unprivileged(struct connection *conn);
     3.5  
     3.6  /* Quota manipulation */
     3.7 -void domain_entry_inc(struct connection *conn);
     3.8 -void domain_entry_dec(struct connection *conn);
     3.9 +void domain_entry_inc(struct connection *conn, struct node *);
    3.10 +void domain_entry_dec(struct connection *conn, struct node *);
    3.11  int domain_entry(struct connection *conn);
    3.12  void domain_watch_inc(struct connection *conn);
    3.13  void domain_watch_dec(struct connection *conn);