tools/libxenforeignmemory: add a call to restrict the handle

Commit 8ef5f344d0 "tools/libxendevicemodel: add a call to restrict the
handle" added a function to the devicemodel interface to restrict
operations through the API to a specific domain, where a capable under-
lying privcmd driver exists.

This patch adds similar functionality to the xenforeignmemory API. This
will be necessary (as much as xendevicemodel restriction) for limiting
the scope of device models to specific domains.

NOTE: My patch to the linux kernel [1] added the appropriate checks to
      the foreign memory ioctls.

[1] https://git.kernel.org/cgit/linux/kernel/git/ostr/linux.git/commit/?id=4610d240

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
Acked-by: Wei Liu <wei.liu2@citrix.com>
This commit is contained in:
Paul Durrant authored and Wei Liu committed 2017-03-24 12:23:47 +00:00
1 parent 60c59f5876
commit 5823d6eb40
9 files changed
+55

No files matched your search

+6
View File
@@ -106,6 +106,12 @@ int xenforeignmemory_unmap(xenforeignmemory_handle *fmem,
return osdep_xenforeignmemory_unmap(fmem, addr, num);
}
int xenforeignmemory_restrict(xenforeignmemory_handle *fmem,
domid_t domid)
{
return osdep_xenforeignmemory_restrict(fmem, domid);
}
/*
* Local variables:
* mode: C
+7
View File
@@ -96,6 +96,13 @@ int osdep_xenforeignmemory_unmap(xenforeignmemory_handle *fmem,
return munmap(addr, num << PAGE_SHIFT);
}
int osdep_xenforeignmemory_restrict(xenforeignmemory_handle *fmem,
domid_t domid)
{
errno = -EOPNOTSUPP;
return -1;
}
/*
* Local variables:
* mode: C
@@ -115,6 +115,17 @@ void *xenforeignmemory_map(xenforeignmemory_handle *fmem, uint32_t dom,
int xenforeignmemory_unmap(xenforeignmemory_handle *fmem,
void *addr, size_t pages);
/**
* This function restricts the use of this handle to the specified
* domain.
*
* @parm fmem handle to the open foreignmemory interface
* @parm domid the domain id
* @return 0 on success, -1 on failure.
*/
int xenforeignmemory_restrict(xenforeignmemory_handle *fmem,
domid_t domid);
#endif
/*
@@ -4,5 +4,6 @@ VERS_1.0 {
xenforeignmemory_close;
xenforeignmemory_map;
xenforeignmemory_unmap;
xenforeignmemory_restrict;
local: *; /* Do not expose anything by default */
};
+6
View File
@@ -272,6 +272,12 @@ int osdep_xenforeignmemory_unmap(xenforeignmemory_handle *fmem,
return munmap(addr, num << PAGE_SHIFT);
}
int osdep_xenforeignmemory_restrict(xenforeignmemory_handle *fmem,
domid_t domid)
{
return ioctl(fmem->fd, IOCTL_PRIVCMD_RESTRICT, &domid);
}
/*
* Local variables:
* mode: C
+7
View File
@@ -58,6 +58,13 @@ int osdep_xenforeignmemory_unmap(xenforeignmemory_handle *fmem,
return munmap(addr, num << PAGE_SHIFT);
}
int osdep_xenforeignmemory_restrict(xenforeignmemory_handle *fmem,
domid_t domid)
{
errno = -EOPNOTSUPP;
return -1;
}
/*
* Local variables:
* mode: C
+7
View File
@@ -100,6 +100,13 @@ int osdep_xenforeignmemory_unmap(xenforeignmemory_handle *fmem,
return munmap(addr, num*XC_PAGE_SIZE);
}
int osdep_xenforeignmemory_restrict(xenforeignmemory_handle *fmem,
domid_t domid)
{
errno = -EOPNOTSUPP;
return -1;
}
/*
* Local variables:
* mode: C
+3
View File
@@ -32,6 +32,9 @@ void *osdep_xenforeignmemory_map(xenforeignmemory_handle *fmem,
int osdep_xenforeignmemory_unmap(xenforeignmemory_handle *fmem,
void *addr, size_t num);
int osdep_xenforeignmemory_restrict(xenforeignmemory_handle *fmem,
domid_t domid);
#if defined(__NetBSD__) || defined(__sun__)
/* Strictly compat for those two only only */
void *compat_mapforeign_batch(xenforeignmem_handle *fmem, uint32_t dom,
+7
View File
@@ -98,6 +98,13 @@ int osdep_xenforeignmemory_unmap(xenforeignmemory_handle *fmem,
return munmap(addr, num*XC_PAGE_SIZE);
}
int osdep_xenforeignmemory_restrict(xenforeignmemory_handle *fmem,
domid_t domid)
{
errno = -EOPNOTSUPP;
return -1;
}
/*
* Local variables:
* mode: C
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.