Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for Xenstore permission related issues #81

Merged
merged 3 commits into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions xen-dom-mgmt/src/xen-dom-xs.c
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,12 @@ int xs_initialize_xenstore(uint32_t domid, const struct xen_domain *domain)
"device/suspend/event-channel",
NULL };

sprintf(lbuffer, "%s/%d", basepref, domid);
rc = xss_write_guest_domain_rw(lbuffer, "", domid);
if (rc) {
goto deinit;
}

// TODO: generate properly
snprintf(uuid, INIT_XENSTORE_UUID_BUF_SIZE, "00000000-0000-0000-0000-%012d", domid);

Expand Down
14 changes: 6 additions & 8 deletions xenstore-srv/src/xenstore_srv.c
Original file line number Diff line number Diff line change
Expand Up @@ -839,7 +839,6 @@ static int xss_do_write(const char *const_path, const char *data, uint32_t domid
char *tok, *tok_state, *new_value;
size_t data_len = str_byte_size(data);
size_t namelen;
sys_dlist_t *inspected_list;

path = k_malloc(str_byte_size(const_path));
if (!path) {
Expand All @@ -849,19 +848,18 @@ static int xss_do_write(const char *const_path, const char *data, uint32_t domid

strcpy(path, const_path);
k_mutex_lock(&xsel_mutex, K_FOREVER);
inspected_list = &root_xenstore.child_list;
parent_entry = &root_xenstore;

for (tok = strtok_r(path, "/", &tok_state); tok != NULL; tok = strtok_r(NULL, "/", &tok_state)) {
SYS_DLIST_FOR_EACH_CONTAINER(inspected_list, iter, node) {
parent_entry = iter;
SYS_DLIST_FOR_EACH_CONTAINER(&parent_entry->child_list, iter, node) {
if (strcmp(iter->key, tok) == 0) {
break;
}
}

if (iter == NULL) {
if (parent_entry && !check_perms(parent_entry, XS_PERM_WRITE, domid)) {
LOG_INF("Permission denied for domid#%u (%s)", domid, path);
LOG_INF("Permission denied for domid#%u (%s)", domid, const_path);
rc = -EACCES;
goto free_allocated;
}
Expand All @@ -887,7 +885,7 @@ static int xss_do_write(const char *const_path, const char *data, uint32_t domid

sys_dlist_init(&iter->child_list);
sys_dnode_init(&iter->node);
sys_dlist_append(inspected_list, &iter->node);
sys_dlist_append(&parent_entry->child_list, &iter->node);
if (perms && perms_num) {
rc = set_perms_by_array(iter, perms, perms_num);
} else {
Expand All @@ -903,12 +901,12 @@ static int xss_do_write(const char *const_path, const char *data, uint32_t domid
}
}

inspected_list = &iter->child_list;
parent_entry = iter;
}

if (iter && data_len > 0) {
if (!check_perms(iter, XS_PERM_WRITE, domid)) {
LOG_INF("Permission denied for domid#%u (%s)", domid, path);
LOG_INF("Permission denied for domid#%u (%s)", domid, const_path);
rc = -EACCES;
goto free_allocated;
}
Expand Down