Files
xen/tools/flask/libflask/flask_op.c
T
Keir Fraser 2325e69721 [XSM][FLASK] Argument handling bugs in XSM:FLASK
Addresses a number of argument handling bugs in the flask_op hypercall
in the XSM:Flask module.  Thanks to Rafal Wojtczuk at McAfee for
reporting the issues and Tim Deegan at Citrix for providing an
initial patch.

This patch addresses the following issues:
 - bounds checking and validation on input arguments to flask_op
 - updated ABI/API, size and cmd are now uint32_t
 - updated userspace tools and libraries to account for ABI/API
 changes
 - implemented all copies using from/to guest, better portability
 - implemented upper bounds checking on op->cmd, op->size
 - implemented sanity checking on op->size and op->buf
 - implemented bit vector for checking from/to usage on op->cmd

Signed-off-by: George Coker <gscoker@alpha.ncsc.mil>
2008-07-21 09:41:36 +01:00

73 lines
1.4 KiB
C

/*
*
* Authors: Michael LeMay, <mdlemay@epoch.ncsc.mil>
* George Coker, <gscoker@alpha.ncsc.mil>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*/
#include <unistd.h>
#include <stdio.h>
#include <errno.h>
#include <fcntl.h>
#include <string.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdlib.h>
#include <stdint.h>
#include <sys/ioctl.h>
#include <flask.h>
#include <xenctrl.h>
int flask_load(int xc_handle, char *buf, uint32_t size)
{
int err;
flask_op_t op;
op.cmd = FLASK_LOAD;
op.buf = buf;
op.size = size;
if ( (err = xc_flask_op(xc_handle, &op)) != 0 )
return err;
return 0;
}
int flask_context_to_sid(int xc_handle, char *buf, uint32_t size, uint32_t *sid)
{
int err;
flask_op_t op;
op.cmd = FLASK_CONTEXT_TO_SID;
op.buf = buf;
op.size = size;
if ( (err = xc_flask_op(xc_handle, &op)) != 0 )
return err;
sscanf(buf, "%u", sid);
return 0;
}
int flask_sid_to_context(int xc_handle, int sid, char *buf, uint32_t size)
{
int err;
flask_op_t op;
op.cmd = FLASK_SID_TO_CONTEXT;
op.buf = buf;
op.size = size;
snprintf(buf, size, "%u", sid);
if ( (err = xc_flask_op(xc_handle, &op)) != 0 )
return err;
return 0;
}