My recent patch [1] to the Linux privcmd module introduced a mechanism
to restrict an open file handle to subsequently only accept operations for
a specified domain.
This patch extends the libxendevicemodel API and make use of the
mechanism in the Linux-specific code to restrict operations on the
interface handle.
[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>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
_IOC(_IOC_NONE, 'P', 4, sizeof(privcmd_mmapbatch_v2_t))
#define IOCTL_PRIVCMD_DM_OP \
_IOC(_IOC_NONE, 'P', 5, sizeof(privcmd_dm_op_t))
+#define IOCTL_PRIVCMD_RESTRICT \
+ _IOC(_IOC_NONE, 'P', 6, sizeof(domid_t))
#endif /* __LINUX_PUBLIC_PRIVCMD_H__ */
* License along with this library; If not, see <http://www.gnu.org/licenses/>.
*/
+#include <errno.h>
+
#include "private.h"
int osdep_xendevicemodel_open(xendevicemodel_handle *dmod)
return xendevicemodel_xcall(dmod, domid, nr_bufs, bufs);
}
+int osdep_xendevicemodel_restrict(xendevicemodel_handle *dmod,
+ domid_t domid)
+{
+ errno = EOPNOTSUPP;
+ return -1;
+}
+
/*
* Local variables:
* mode: C
return xendevicemodel_op(dmod, domid, 1, &op, sizeof(op));
}
+int xendevicemodel_restrict(xendevicemodel_handle *dmod, domid_t domid)
+{
+ return osdep_xendevicemodel_restrict(dmod, domid);
+}
+
/*
* Local variables:
* mode: C
xendevicemodel_handle *dmod, domid_t domid, int vcpu, uint8_t vector,
uint8_t type, uint32_t error_code, uint8_t insn_len, uint64_t cr2);
+/**
+ * This function restricts the use of this handle to the specified
+ * domain.
+ *
+ * @parm dmod handle to the open devicemodel interface
+ * @parm domid the domain id
+ * @return 0 on success, -1 on failure.
+ */
+int xendevicemodel_restrict(xendevicemodel_handle *dmod, domid_t domid);
+
#endif /* __XEN_TOOLS__ */
#endif /* XENDEVICEMODEL_H */
xendevicemodel_modified_memory;
xendevicemodel_set_mem_type;
xendevicemodel_inject_event;
+ xendevicemodel_restrict;
xendevicemodel_close;
local: *; /* Do not expose anything by default */
};
return 0;
}
+int osdep_xendevicemodel_restrict(xendevicemodel_handle *dmod,
+ domid_t domid)
+{
+ if (dmod->fd < 0) {
+ errno = EOPNOTSUPP;
+ return -1;
+ }
+
+ return ioctl(dmod->fd, IOCTL_PRIVCMD_RESTRICT, &domid);
+}
+
/*
* Local variables:
* mode: C
domid_t domid, unsigned int nr_bufs,
struct xendevicemodel_buf bufs[]);
+int osdep_xendevicemodel_restrict(
+ xendevicemodel_handle *dmod, domid_t domid);
+
#define PERROR(_f...) \
xtl_log(dmod->logger, XTL_ERROR, errno, "xendevicemodel", _f)