Update flask_op hypercall interface
cover Update flask_op hypercall interface
The FLASK hypercall interface originally attempted to emulate the read/write interface used by SELinux, passing human-readable strings to and from the hypervisor. This resulted in unnecessary string parsing and conversion in the hypervisor and toolstack.
This series (primarily patch #3) converts the hypercall to use a union-of-structures similar to the other Xen hypercalls. The wrappers in libxc have been updated to preserve API compatibility where possible.
[PATCH 1/4] tools/flask: remove libflask
[PATCH 2/4] .gitignore/.hgignore: add missing output files [PATCH 3/4] flask: Update flask_op hypercall structure [PATCH 4/4] xen: Remove unused vsscanf/sscanf functions
PATCH 1/4 tools/flask: remove libflask
This library has been deprecated since July 2010; remove the in-tree users and library.
--- tools/flask/Makefile | 1 - tools/flask/libflask/Makefile | 58 ---- tools/flask/libflask/flask_op.c | 559 ------------------------------- tools/flask/libflask/include/libflask.h | 57 ---- tools/flask/utils/Makefile | 15 +- tools/flask/utils/get-bool.c | 9 +- tools/flask/utils/getenforce.c | 3 +- tools/flask/utils/label-pci.c | 17 +- tools/flask/utils/loadpolicy.c | 3 +- tools/flask/utils/set-bool.c | 5 +- tools/flask/utils/setenforce.c | 7 +- tools/libxc/xc_flask.c | 59 ++++ tools/libxc/xenctrl.h | 3 + tools/python/setup.py | 2 +- tools/python/xen/lowlevel/flask/flask.c | 13 +- 15 files changed, 94 insertions(+), 717 deletions(-) delete mode 100644 tools/flask/libflask/Makefile delete mode 100644 tools/flask/libflask/flask_op.c delete mode 100644 tools/flask/libflask/include/libflask.h
tools/flask/Makefile +0 -1
@@ -2,7 +2,6 @@ XEN_ROOT = $(CURDIR)/../.. include $(XEN_ROOT)/tools/Rules.mk SUBDIRS := -SUBDIRS += libflask SUBDIRS += utils .PHONY: all clean install
tools/flask/libflask/Makefile deleted +0 -58
58 lines not on this page · raw message
tools/flask/libflask/flask_op.c deleted +0 -559
559 lines not on this page · raw message
tools/flask/libflask/include/libflask.h deleted +0 -57
57 lines not on this page · raw message
tools/flask/utils/Makefile +6 -9
@@ -1,11 +1,8 @@ XEN_ROOT=$(CURDIR)/../../.. include $(XEN_ROOT)/tools/Rules.mk -LIBFLASK_ROOT = $(XEN_ROOT)/tools/flask/libflask - CFLAGS += -Wall -g -Werror CFLAGS += $(CFLAGS_libxenctrl) -CFLAGS += -I$(LIBFLASK_ROOT)/include TESTDIR = testsuite/tmp TESTFLAGS= -DTESTING
@@ -19,22 +16,22 @@ CLIENTS_OBJS := $(patsubst flask-%,%.o,$(CLIENTS)) all: $(CLIENTS) flask-loadpolicy: loadpolicy.o - $(CC) $(LDFLAGS) $< $(LDLIBS) -L$(LIBFLASK_ROOT) -lflask $(LDLIBS_libxenctrl) -o $@ + $(CC) $(LDFLAGS) $< $(LDLIBS) $(LDLIBS_libxenctrl) -o $@ flask-setenforce: setenforce.o - $(CC) $(LDFLAGS) $< $(LDLIBS) -L$(LIBFLASK_ROOT) -lflask $(LDLIBS_libxenctrl) -o $@ + $(CC) $(LDFLAGS) $< $(LDLIBS) $(LDLIBS_libxenctrl) -o $@ flask-getenforce: getenforce.o - $(CC) $(LDFLAGS) $< $(LDLIBS) -L$(LIBFLASK_ROOT) -lflask $(LDLIBS_libxenctrl) -o $@ + $(CC) $(LDFLAGS) $< $(LDLIBS) $(LDLIBS_libxenctrl) -o $@ flask-label-pci: label-pci.o - $(CC) $(LDFLAGS) $< $(LDLIBS) -L$(LIBFLASK_ROOT) -lflask $(LDLIBS_libxenctrl) -o $@ + $(CC) $(LDFLAGS) $< $(LDLIBS) $(LDLIBS_libxenctrl) -o $@ flask-get-bool: get-bool.o - $(CC) $(LDFLAGS) $< $(LDLIBS) -L$(LIBFLASK_ROOT) -lflask $(LDLIBS_libxenctrl) -o $@ + $(CC) $(LDFLAGS) $< $(LDLIBS) $(LDLIBS_libxenctrl) -o $@ flask-set-bool: set-bool.o - $(CC) $(LDFLAGS) $< $(LDLIBS) -L$(LIBFLASK_ROOT) -lflask $(LDLIBS_libxenctrl) -o $@ + $(CC) $(LDFLAGS) $< $(LDLIBS) $(LDLIBS_libxenctrl) -o $@ .PHONY: clean clean:
tools/flask/utils/get-bool.c +4 -5
@@ -16,7 +16,6 @@#include <string.h> #include <unistd.h> #include <inttypes.h> -#include <libflask.h> static void usage (char **argv) {
@@ -29,11 +28,11 @@ static int all_bools(xc_interface *xch)int err =0 , i =0 , curr, pend;char name[256 ];while (1 ) { - err =flask_getbool_byid (xch, i, name, &curr, &pend); + err =xc_flask_getbool_byid (xch, i, name,sizeof name, &curr, &pend);if (err <0 ) {if (errno ==ENOENT )return 0 ; -fprintf (stderr,"flask_getbool: Unable to get boolean #%d: %s (%d)" , +fprintf (stderr,"xc_flask_getbool: Unable to get boolean #%d: %s (%d)" , i,strerror (errno), err);return 2 ; }
@@ -69,9 +68,9 @@ int main(int argc, char **argv) goto done; } - err =flask_getbool_byname (xch, argv[1 ], &curr, &pend); + err =xc_flask_getbool_byname (xch, argv[1 ], &curr, &pend);if (err) { -fprintf (stderr,"flask_getbool: Unable to get boolean %s: %s (%d)" , +fprintf (stderr,"xc_flask_getbool: Unable to get boolean %s: %s (%d)" , argv[1 ],strerror (errno), err); err =2 ; goto done;
tools/flask/utils/getenforce.c +1 -2
@@ -16,7 +16,6 @@#include <sys/stat.h> #include <string.h> #include <unistd.h> -#include <libflask.h> static void usage (int argCnt,const char *args[]) {
@@ -41,7 +40,7 @@ int main (int argCnt, const char *args[]) goto done; } - ret =flask_getenforce (xch); + ret =xc_flask_getenforce (xch);if ( ret <0 ) { errno = -ret;
tools/flask/utils/label-pci.c +8 -9
@@ -16,7 +16,6 @@#include <string.h> #include <unistd.h> #include <inttypes.h> -#include <libflask.h> /* Pulled from linux/include/linux/ioport.h */ #define IORESOURCE_TYPE_BITS 0x00001f00/* Resource type */
@@ -69,9 +68,9 @@ int main (int argCnt, char *argv[]) goto done; } - ret =flask_add_device (xch, sbdf, argv[2 ]); + ret =xc_flask_add_device (xch, sbdf, argv[2 ]);if (ret) { -fprintf (stderr,"flask_add_device: Unable to set context of PCI device %s (0x%x) to %s: %d\n" , +fprintf (stderr,"xc_flask_add_device: Unable to set context of PCI device %s (0x%x) to %s: %d\n" , argv[1 ], sbdf, argv[2 ], ret); err =2 ; goto done;
@@ -80,9 +79,9 @@ int main (int argCnt, char *argv[])while (fscanf (f,"0x%" SCNx64" 0x%" SCNx64" 0x%" SCNx64"\n" , &start, &end, &flags) ==3 ) {if (flags &IORESOURCE_IO ) {// printf("Port %"PRIx64"-%"PRIx64"\n", start, end); - ret =flask_add_ioport (xch, start, end, argv[2 ]); + ret =xc_flask_add_ioport (xch, start, end, argv[2 ]);if (ret) { -fprintf (stderr,"flask_add_ioport %" PRIx64"-%" PRIx64" failed: %d\n" , +fprintf (stderr,"xc_flask_add_ioport %" PRIx64"-%" PRIx64" failed: %d\n" , start, end, ret); err =2 ; }
@@ -90,9 +89,9 @@ int main (int argCnt, char *argv[]) start >>=12 ; end >>=12 ;// printf("IOMEM %"PRIx64"-%"PRIx64"\n", start, end); - ret =flask_add_iomem (xch, start, end, argv[2 ]); + ret =xc_flask_add_iomem (xch, start, end, argv[2 ]);if (ret) { -fprintf (stderr,"flask_add_iomem %" PRIx64"-%" PRIx64" failed: %d\n" , +fprintf (stderr,"xc_flask_add_iomem %" PRIx64"-%" PRIx64" failed: %d\n" , start, end, ret); err =2 ; }
@@ -108,9 +107,9 @@ int main (int argCnt, char *argv[])if (fscanf (f,"%" SCNu64, &start) !=1 ) start =0 ;if (start) { - ret =flask_add_pirq (xch, start, argv[2 ]); + ret =xc_flask_add_pirq (xch, start, argv[2 ]);if (ret) { -fprintf (stderr,"flask_add_pirq %" PRIu64" failed: %d\n" , +fprintf (stderr,"xc_flask_add_pirq %" PRIu64" failed: %d\n" , start, ret); err =2 ; }
tools/flask/utils/loadpolicy.c +1 -2
@@ -17,7 +17,6 @@#include <sys/stat.h> #include <string.h> #include <unistd.h> -#include <libflask.h> #define USE_MMAP
@@ -94,7 +93,7 @@ int main (int argCnt, const char *args[]) }#endif - ret =flask_load (xch, polMemCp, info.st_size); + ret =xc_flask_load (xch, polMemCp, info.st_size);if ( ret <0 ) { errno = -ret;
tools/flask/utils/set-bool.c +2 -3
@@ -16,7 +16,6 @@#include <string.h> #include <unistd.h> #include <inttypes.h> -#include <libflask.h> static void usage (char **argv) {
@@ -56,9 +55,9 @@ int main(int argc, char **argv) goto done; } - err =flask_setbool (xch, argv[1 ], value,1 ); + err =xc_flask_setbool (xch, argv[1 ], value,1 );if (err) { -fprintf (stderr,"flask_setbool: Unable to set boolean %s=%s: %s (%d)" , +fprintf (stderr,"xc_flask_setbool: Unable to set boolean %s=%s: %s (%d)" , argv[1 ], argv[2 ],strerror (errno), err); err =2 ; goto done;
tools/flask/utils/setenforce.c +3 -4
@@ -16,7 +16,6 @@#include <sys/stat.h> #include <string.h> #include <unistd.h> -#include <libflask.h> static void usage (int argCnt,const char *args[]) {
@@ -45,12 +44,12 @@ int main (int argCnt, const char *args[])if (strlen (args[1 ]) ==1 && (args[1 ][0 ] =='0' || args[1 ][0 ] =='1' )){ mode =strtol (args[1 ], &end,10 ); - ret =flask_setenforce (xch, mode); + ret =xc_flask_setenforce (xch, mode); }else {if (strcasecmp (args[1 ],"enforcing" ) ==0 ){ - ret =flask_setenforce (xch,1 ); + ret =xc_flask_setenforce (xch,1 ); }else if (strcasecmp (args[1 ],"permissive" ) ==0 ){ - ret =flask_setenforce (xch,0 ); + ret =xc_flask_setenforce (xch,0 ); }else {usage (argCnt, args); }
tools/libxc/xc_flask.c +59 -0
65 lines not on this page · raw message
tools/libxc/xenctrl.h +3 -0
@@ -1957,6 +1957,9 @@ int xc_flask_context_to_sid(xc_interface *xc_handle, char *buf, uint32_t size, uint xc_flask_sid_to_context (xc_interface *xc_handle,int sid,char *buf,uint32_t size);int xc_flask_getenforce (xc_interface *xc_handle);int xc_flask_setenforce (xc_interface *xc_handle,int mode); +int xc_flask_getbool_byid (xc_interface *xc_handle,int id,char *name,uint32_t size,int *curr,int *pend); +int xc_flask_getbool_byname (xc_interface *xc_handle,char *name,int *curr,int *pend); +int xc_flask_setbool (xc_interface *xc_handle,char *name,int value,int commit);int xc_flask_add_pirq (xc_interface *xc_handle,unsigned int pirq,char *scontext);int xc_flask_add_ioport (xc_interface *xc_handle,unsigned long low,unsigned long high,char *scontext);
tools/python/setup.py +1 -1
@@ -48,7 +48,7 @@ flask = Extension("flask", include_dirs = [ PATH_XEN, PATH_LIBXC, "xen/lowlevel/flask", "../flask/libflask/include" ], library_dirs = [ PATH_LIBXC, "../flask/libflask" ], - libraries = [ "xenctrl", "flask" ], + libraries = [ "xenctrl" ], depends = [ PATH_LIBXC + "/libxenctrl.so", XEN_ROOT + "/tools/flask/libflask/libflask.so" ], sources = [ "xen/lowlevel/flask/flask.c" ])
tools/python/xen/lowlevel/flask/flask.c +6 -7
@@ -12,7 +12,6 @@#include <Python.h> #include <xenctrl.h> -#include <libflask.h> #define PKG "xen.lowlevel.flask"#define CLS "flask"
@@ -58,7 +57,7 @@ static PyObject *pyflask_context_to_sid(PyObject *self, PyObject *args,return PyErr_SetFromErrno (xc_error_obj); } - ret =flask_context_to_sid (xc_handle, buf, len, &sid); + ret =xc_flask_context_to_sid (xc_handle, buf, len, &sid);xc_interface_close (xc_handle);
@@ -92,7 +91,7 @@ static PyObject *pyflask_sid_to_context(PyObject *self, PyObject *args,return PyErr_SetFromErrno (xc_error_obj); } - ret =flask_sid_to_context (xc_handle, sid, ctx, ctx_len); + ret =xc_flask_sid_to_context (xc_handle, sid, ctx, ctx_len);xc_interface_close (xc_handle);
@@ -121,7 +120,7 @@ static PyObject *pyflask_load(PyObject *self, PyObject *args, PyObject *kwds)return PyErr_SetFromErrno (xc_error_obj); } - ret =flask_load (xc_handle, policy, len); + ret =xc_flask_load (xc_handle, policy, len);xc_interface_close (xc_handle);
@@ -143,7 +142,7 @@ static PyObject *pyflask_getenforce(PyObject *self)return PyErr_SetFromErrno (xc_error_obj); } - ret =flask_getenforce (xc_handle); + ret =xc_flask_getenforce (xc_handle);xc_interface_close (xc_handle);
@@ -173,7 +172,7 @@ static PyObject *pyflask_setenforce(PyObject *self, PyObject *args,return PyErr_SetFromErrno (xc_error_obj); } - ret =flask_setenforce (xc_handle, mode); + ret =xc_flask_setenforce (xc_handle, mode);xc_interface_close (xc_handle);
@@ -209,7 +208,7 @@ static PyObject *pyflask_access(PyObject *self, PyObject *args,return PyErr_SetFromErrno (xc_error_obj); } - ret =flask_access (xc_handle, scon, tcon, tclass, req, &allowed, &decided, + ret =xc_flask_access (xc_handle, scon, tcon, tclass, req, &allowed, &decided, &auditallow, &auditdeny, &seqno);xc_interface_close (xc_handle);
Signature · 1 line
1.7.7.6
Re: [PATCH 1/4] tools/flask: remove libflask
Quoted 7 lines · Daniel De Graaf
This library has been deprecated since July 2010; remove the in-tree users and library.
tools/python/setup.py +1
-1- ln -sf libflask.so.$(MAJOR) $(DESTDIR)$(LIBDIR)/libflask.so +++ b/tools/python/setup.py
tools/python/setup.py flask = Extension("flask", · line 54
Quoted 8 lines
tools/python/setup.py +1
-1@@ -48,7 +48,7 @@ flask = Extension("flask", include_dirs = [ PATH_XEN, PATH_LIBXC, "xen/lowlevel/flask", "../flask/libflask/include" ], library_dirs = [ PATH_LIBXC, "../flask/libflask" ], - libraries = [ "xenctrl", "flask" ], + libraries = [ "xenctrl" ], depends = [ PATH_LIBXC + "/libxenctrl.so", XEN_ROOT + "/tools/flask/libflask/libflask.so" ], sources = [ "xen/lowlevel/flask/flask.c" ])
For some reason this changeset does not cause buildfailures in automated testing. My xen-unstable rpm packages fail to build in SLES11, but not in openSuSE for some reason.
Is there a chance that libflask.so is built after this python thing runs? In other words: Is there a makefile dependency missing?
Olaf
...
building 'flask' extension
error: ../../tools/flask/libflask/libflask.so: No such file or directory make[3]: *** [install] Error 1
make[3]: Leaving directory `/usr/src/packages/BUILD/xen-4.2.24701/non-dbg/tools/python' make[2]: *** [subdir-install-python] Error 2
...
Re: [PATCH 1/4] tools/flask: remove libflask
On Tue, Feb 07, Olaf Hering wrote:
After poking at this some more, isnt the patch removing the libflask directory? I think it should have removed also all references to that directory. setup.py (or python 2.6) in SLES11 can not cope with it, while python 2.7 in openSuSE seems to ignore the remove directory.
I will send a tested patch which removes the references to libflask.
Olaf
Quoted 41 lines · Daniel De Graaf
Quoted 8 lines
This library has been deprecated since July 2010; remove the in-tree users and library.
tools/python/setup.py +1
-1- ln -sf libflask.so.$(MAJOR) $(DESTDIR)$(LIBDIR)/libflask.so +++ b/tools/python/setup.pytools/python/setup.py flask = Extension("flask", · line 54
Quoted 8 lines
tools/python/setup.py +1
-1@@ -48,7 +48,7 @@ flask = Extension("flask", include_dirs = [ PATH_XEN, PATH_LIBXC, "xen/lowlevel/flask", "../flask/libflask/include" ], library_dirs = [ PATH_LIBXC, "../flask/libflask" ], - libraries = [ "xenctrl", "flask" ], + libraries = [ "xenctrl" ], depends = [ PATH_LIBXC + "/libxenctrl.so", XEN_ROOT + "/tools/flask/libflask/libflask.so" ], sources = [ "xen/lowlevel/flask/flask.c" ])For some reason this changeset does not cause buildfailures in automated testing. My xen-unstable rpm packages fail to build in SLES11, but not in openSuSE for some reason.
Is there a chance that libflask.so is built after this python thing runs? In other words: Is there a makefile dependency missing?
Olaf
...
building 'flask' extension
error: ../../tools/flask/libflask/libflask.so: No such file or directory make[3]: *** [install] Error 1
make[3]: Leaving directory `/usr/src/packages/BUILD/xen-4.2.24701/non-dbg/tools/python' make[2]: *** [subdir-install-python] Error 2
..._______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
PATCH 2/4 .gitignore/.hgignore: add missing output files
In reply to Daniel De Graaf - extras/mini-os/include/list.h (already in .hgignore)
- tools/flask/flask-{get,set}-bool
- tools/flask/loadpolicy no longer exists
- tools/xenstore/init-xenstore-domain
--- .gitignore | 5 ++++- .hgignore | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-)
.gitignore +4 -1
@@ -64,6 +64,7 @@ extras/mini-os/include/ia64/mini-os extras/mini-os/include/ia64/offsets.h extras/mini-os/include/x86/mini-os extras/mini-os/include/xen +extras/mini-os/include/list.h extras/mini-os/mini-os* install/* linux-[^/]*-paravirt/*
@@ -150,10 +151,11 @@ tools/firmware/rombios/rombios[^/]*.s tools/firmware/rombios/32bit/32bitbios_flat.h tools/firmware/vgabios/vbetables-gen tools/firmware/vgabios/vbetables.h -tools/flask/loadpolicy/flask-loadpolicy tools/flask/utils/flask-getenforce +tools/flask/utils/flask-get-bool tools/flask/utils/flask-loadpolicy tools/flask/utils/flask-setenforce +tools/flask/utils/flask-set-bool tools/flask/utils/flask-label-pci tools/fs-back/fs-backend tools/hotplug/common/hotplugpath.sh
@@ -236,6 +238,7 @@ tools/xenpaging/xenpaging tools/xenpmd/xenpmd tools/xenstat/xentop/xentop tools/xenstore/testsuite/tmp/* +tools/xenstore/init-xenstore-domain tools/xenstore/xen tools/xenstore/xenstore tools/xenstore/xenstore-chmod
.hgignore +3 -1
@@ -154,10 +154,11 @@ ^tools/firmware/rombios/32bit/32bitbios_flat\.h$ ^tools/firmware/vgabios/vbetables-gen$ ^tools/firmware/vgabios/vbetables\.h$ -^tools/flask/loadpolicy/flask-loadpolicy$ ^tools/flask/utils/flask-getenforce$ +^tools/flask/utils/flask-get-bool$ ^tools/flask/utils/flask-loadpolicy$ ^tools/flask/utils/flask-setenforce$ +^tools/flask/utils/flask-set-bool$ ^tools/flask/utils/flask-label-pci$ ^tools/fs-back/fs-backend$ ^tools/hotplug/common/hotplugpath\.sh$
@@ -249,6 +250,7 @@ ^tools/xenpmd/xenpmd$ ^tools/xenstat/xentop/xentop$ ^tools/xenstore/testsuite/tmp/.*$ +^tools/xenstore/init-xenstore-domain$ ^tools/xenstore/xen$ ^tools/xenstore/xenstore$ ^tools/xenstore/xenstore-chmod$
Signature · 1 line
1.7.7.6
PATCH 3/4 flask: Update flask_op hypercall structure
In reply to Daniel De GraafInstead of placing string parsing inside the hypervisor, use binary structures like other Xen hypercalls do.
This patch also removes libflask; if the old flask_* namespace is needed for longer backwards compatability (it was noted as deprecated in July 2010), a shim redirecting to the proper xc_flask_* calls can be created.
--- tools/libxc/xc_flask.c | 471 +++++++--------- tools/libxc/xc_private.h | 2 + tools/libxc/xenctrl.h | 4 +- xen/include/public/xsm/flask_op.h | 146 +++++- xen/xsm/flask/avc.c | 13 +- xen/xsm/flask/flask_op.c | 1128 +++++++++++-------------------------- xen/xsm/flask/include/avc.h | 3 +- xen/xsm/flask/include/security.h | 4 +- xen/xsm/flask/ss/services.c | 11 +- 9 files changed, 683 insertions(+), 1099 deletions(-)
tools/libxc/xc_flask.c +216 -255
@@ -30,18 +30,21 @@#include <sys/ioctl.h> #include <stdint.h> -#define OCON_PIRQ_STR "pirq" -#define OCON_IOPORT_STR "ioport" -#define OCON_IOMEM_STR "iomem" -#define OCON_DEVICE_STR "pcidevice" +#define OCON_ISID 0/* initial SIDs */ +#define OCON_PIRQ 1/* physical irqs */ +#define OCON_IOPORT 2/* io ports */ +#define OCON_IOMEM 3/* io memory */ +#define OCON_DEVICE 4/* pci devices */ #define INITCONTEXTLEN 256 -int xc_flask_op (xc_interface *xch,flask_op_t *op) +int xc_flask_op (xc_interface *xch,xen_flask_op_t *op) {int ret =-1 ;DECLARE_HYPERCALL ;DECLARE_HYPERCALL_BOUNCE (op,sizeof (*op),XC_HYPERCALL_BUFFER_BOUNCE_BOTH ); + op->interface_version =XEN_FLASK_INTERFACE_VERSION ; +if (xc_hypercall_bounce_pre (xch, op) ) {PERROR ("Could not bounce memory for flask op hypercall" );
@@ -63,402 +66,360 @@ int xc_flask_op(xc_interface *xch, flask_op_t *op)return ret; } -int xc_flask_load (xc_interface *xc_handle,char *buf,uint32_t size) +int xc_flask_load (xc_interface *xch,char *buf,uint32_t size) {int err; -flask_op_t op; - +DECLARE_FLASK_OP ; +DECLARE_HYPERCALL_BOUNCE (buf, size,XC_HYPERCALL_BUFFER_BOUNCE_IN ); +if (xc_hypercall_bounce_pre (xch, buf) ) + { +PERROR ("Could not bounce memory for flask op hypercall" ); +return -1 ; + } + op.cmd =FLASK_LOAD ; - op.buf = buf; - op.size = size; + op.u.load.size = size; +set_xen_guest_handle (op.u.load.buffer, buf); -if ( (err =xc_flask_op (xc_handle, &op)) !=0 ) -return err; + err =xc_flask_op (xch, &op); -return 0 ; +xc_hypercall_bounce_post (xch, buf); + +return err; } -int xc_flask_context_to_sid (xc_interface *xc_handle,char *buf,uint32_t size,uint32_t *sid) +int xc_flask_context_to_sid (xc_interface *xch,char *buf,uint32_t size,uint32_t *sid) {int err; -flask_op_t op; - +DECLARE_FLASK_OP ; +DECLARE_HYPERCALL_BOUNCE (buf, size,XC_HYPERCALL_BUFFER_BOUNCE_IN ); + +if (xc_hypercall_bounce_pre (xch, buf) ) + { +PERROR ("Could not bounce memory for flask op hypercall" ); +return -1 ; + } + op.cmd =FLASK_CONTEXT_TO_SID ; - op.buf = buf; - op.size = size; + op.u.sid_context.size = size; +set_xen_guest_handle (op.u.sid_context.context, buf); -if ( (err =xc_flask_op (xc_handle, &op)) !=0 ) -return err; - -sscanf (buf,"%u" , sid); + err =xc_flask_op (xch, &op); -return 0 ; +if ( !err ) + *sid = op.u.sid_context.sid; + +xc_hypercall_bounce_post (xch, buf); + +return err; } -int xc_flask_sid_to_context (xc_interface *xc_handle,int sid,char *buf,uint32_t size) +int xc_flask_sid_to_context (xc_interface *xch,int sid,char *buf,uint32_t size) {int err; -flask_op_t op; - +DECLARE_FLASK_OP ; +DECLARE_HYPERCALL_BOUNCE (buf, size,XC_HYPERCALL_BUFFER_BOUNCE_OUT ); + +if (xc_hypercall_bounce_pre (xch, buf) ) + { +PERROR ("Could not bounce memory for flask op hypercall" ); +return -1 ; + } + op.cmd =FLASK_SID_TO_CONTEXT ; - op.buf = buf; - op.size = size; + op.u.sid_context.sid = sid; + op.u.sid_context.size = size; +set_xen_guest_handle (op.u.sid_context.context, buf); -snprintf (buf, size,"%u" , sid); + err =xc_flask_op (xch, &op); -if ( (err =xc_flask_op (xc_handle, &op)) !=0 ) -return err; - -return 0 ; +xc_hypercall_bounce_post (xch, buf); + +return err; } -int xc_flask_getenforce (xc_interface *xc_handle) +int xc_flask_getenforce (xc_interface *xch) { -int err; -flask_op_t op; -char buf[20 ]; -int size =20 ; -int mode; - +DECLARE_FLASK_OP ; op.cmd =FLASK_GETENFORCE ; - op.buf = buf; - op.size = size; -if ( (err =xc_flask_op (xc_handle, &op)) !=0 ) -return err; - -sscanf (buf,"%i" , &mode); - -return mode; +return xc_flask_op (xch, &op); } -int xc_flask_setenforce (xc_interface *xc_handle,int mode) +int xc_flask_setenforce (xc_interface *xch,int mode) { -int err; -flask_op_t op; -char buf[20 ]; -int size =20 ; - +DECLARE_FLASK_OP ; op.cmd =FLASK_SETENFORCE ; - op.buf = buf; - op.size = size; + op.u.enforce.enforcing = mode; -snprintf (buf, size,"%i" , mode); - -if ( (err =xc_flask_op (xc_handle, &op)) !=0 ) -return err; - -return 0 ; +return xc_flask_op (xch, &op); } -int xc_flask_getbool_byid (xc_interface *xc_handle,int id,char *name,uint32_t size,int *curr,int *pend) +int xc_flask_getbool_byid (xc_interface *xch,int id,char *name,uint32_t size,int *curr,int *pend) { -flask_op_t op; -char buf[255 ];int rv; +DECLARE_FLASK_OP ; +DECLARE_HYPERCALL_BOUNCE (name, size,XC_HYPERCALL_BUFFER_BOUNCE_OUT ); + +if (xc_hypercall_bounce_pre (xch, name) ) + { +PERROR ("Could not bounce memory for flask op hypercall" ); +return -1 ; + } - op.cmd =FLASK_GETBOOL2 ; - op.buf = buf; - op.size =255 ; + op.cmd =FLASK_GETBOOL ; + op.u.boolean.bool_id = id; + op.u.boolean.size = size; +set_xen_guest_handle (op.u.boolean.name, name); -snprintf (buf,sizeof buf,"%i" , id); + rv =xc_flask_op (xch, &op); - rv =xc_flask_op (xc_handle, &op); +xc_hypercall_bounce_post (xch, name);if ( rv )return rv; -sscanf (buf,"%i %i %s" , curr, pend, name); +if ( curr ) + *curr = op.u.boolean.enforcing; +if ( pend ) + *pend = op.u.boolean.pending;return rv; } -int xc_flask_getbool_byname (xc_interface *xc_handle,char *name,int *curr,int *pend) +int xc_flask_getbool_byname (xc_interface *xch,char *name,int *curr,int *pend) { -flask_op_t op; -char buf[255 ];int rv; +DECLARE_FLASK_OP ; +DECLARE_HYPERCALL_BOUNCE (name,strlen (name),XC_HYPERCALL_BUFFER_BOUNCE_IN ); - op.cmd =FLASK_GETBOOL_NAMED ; - op.buf = buf; - op.size =255 ; + op.cmd =FLASK_GETBOOL ; + op.u.boolean.bool_id =-1 ; + op.u.boolean.size =strlen (name); +set_xen_guest_handle (op.u.boolean.name, name); -strncpy (buf, name, op.size); + rv =xc_flask_op (xch, &op); - rv =xc_flask_op (xc_handle, &op); +xc_hypercall_bounce_post (xch, name);if ( rv )return rv; -sscanf (buf,"%i %i" , curr, pend); +if ( curr ) + *curr = op.u.boolean.enforcing; +if ( pend ) + *pend = op.u.boolean.pending;return rv; } -int xc_flask_setbool (xc_interface *xc_handle,char *name,int value,int commit) +int xc_flask_setbool (xc_interface *xch,char *name,int value,int commit) { -flask_op_t op; -char buf[255 ]; -int size =255 ; +int rv; +DECLARE_FLASK_OP ; +DECLARE_HYPERCALL_BOUNCE (name,strlen (name),XC_HYPERCALL_BUFFER_BOUNCE_IN ); - op.cmd =FLASK_SETBOOL_NAMED ; - op.buf = buf; - op.size = size; + op.cmd =FLASK_SETBOOL ; + op.u.boolean.bool_id =-1 ; + op.u.boolean.new_value = value; + op.u.boolean.commit =1 ; + op.u.boolean.size =strlen (name); +set_xen_guest_handle (op.u.boolean.name, name); -snprintf (buf, size,"%s %i %i" , name, value, commit); + rv =xc_flask_op (xch, &op); -return xc_flask_op (xc_handle, &op); +xc_hypercall_bounce_post (xch, name); + +return rv; } -static int xc_flask_add (xc_interface *xc_handle,char *cat,char *arg,char *scontext) + +static int xc_flask_add (xc_interface *xch,uint32_t ocon,uint64_t low,uint64_t high,char *scontext) { -char buf[512 ]; -flask_op_t op; +uint32_t sid; +int err; +DECLARE_FLASK_OP ; + + err =xc_flask_context_to_sid (xch, scontext,strlen (scontext), &sid); +if ( err ) +return err; -memset (buf,0 ,512 ); -snprintf (buf,512 ,"%s %255s %s" , cat, scontext, arg); op.cmd =FLASK_ADD_OCONTEXT ; - op.buf = buf; - op.size =512 ; + op.u.ocontext.ocon = ocon; + op.u.ocontext.sid = sid; + op.u.ocontext.low = low; + op.u.ocontext.high = high; -return xc_flask_op (xc_handle, &op); +return xc_flask_op (xch, &op); } -int xc_flask_add_pirq (xc_interface *xc_handle,unsigned int pirq,char *scontext) +int xc_flask_add_pirq (xc_interface *xch,unsigned int pirq,char *scontext) { -char arg[16 ]; - -snprintf (arg,16 ,"%u" , pirq); -return xc_flask_add (xc_handle,OCON_PIRQ_STR , arg, scontext); +return xc_flask_add (xch,OCON_PIRQ , pirq, pirq, scontext); } -int xc_flask_add_ioport (xc_interface *xc_handle,unsigned long low,unsigned long high, +int xc_flask_add_ioport (xc_interface *xch,unsigned long low,unsigned long high,char *scontext) { -char arg[64 ]; - -snprintf (arg,64 ,"%lu %lu" , low, high); -return xc_flask_add (xc_handle,OCON_IOPORT_STR , arg, scontext); +return xc_flask_add (xch,OCON_IOPORT , low, high, scontext); } -int xc_flask_add_iomem (xc_interface *xc_handle,unsigned long low,unsigned long high, +int xc_flask_add_iomem (xc_interface *xch,unsigned long low,unsigned long high,char *scontext) { -char arg[64 ]; - -snprintf (arg,64 ,"%lu %lu" , low, high); -return xc_flask_add (xc_handle,OCON_IOMEM_STR , arg, scontext); +return xc_flask_add (xch,OCON_IOMEM , low, high, scontext); } -int xc_flask_add_device (xc_interface *xc_handle,unsigned long device,char *scontext) +int xc_flask_add_device (xc_interface *xch,unsigned long device,char *scontext) { -char arg[32 ]; - -snprintf (arg,32 ,"%lu" , device); -return xc_flask_add (xc_handle,OCON_DEVICE_STR , arg, scontext); +return xc_flask_add (xch,OCON_DEVICE , device, device, scontext); } -static int xc_flask_del (xc_interface *xc_handle,char *cat,char *arg) +static int xc_flask_del (xc_interface *xch,uint32_t ocon,uint64_t low,uint64_t high) { -char buf[256 ]; -flask_op_t op; +DECLARE_FLASK_OP ; -memset (buf,0 ,256 ); -snprintf (buf,256 ,"%s %s" , cat, arg); op.cmd =FLASK_DEL_OCONTEXT ; - op.buf = buf; - op.size =256 ; + op.u.ocontext.ocon = ocon; + op.u.ocontext.low = low; + op.u.ocontext.high = high; -return xc_flask_op (xc_handle, &op); +return xc_flask_op (xch, &op); } -int xc_flask_del_pirq (xc_interface *xc_handle,unsigned int pirq) +int xc_flask_del_pirq (xc_interface *xch,unsigned int pirq) { -char arg[16 ]; - -snprintf (arg,16 ,"%u" , pirq); -return xc_flask_del (xc_handle,OCON_PIRQ_STR , arg); +return xc_flask_del (xch,OCON_PIRQ , pirq, pirq); } -int xc_flask_del_ioport (xc_interface *xc_handle,unsigned long low,unsigned long high) +int xc_flask_del_ioport (xc_interface *xch,unsigned long low,unsigned long high) { -char arg[64 ]; - -snprintf (arg,64 ,"%lu %lu" , low, high); -return xc_flask_del (xc_handle,OCON_IOPORT_STR , arg); +return xc_flask_del (xch,OCON_IOPORT , low, high); } -int xc_flask_del_iomem (xc_interface *xc_handle,unsigned long low,unsigned long high) +int xc_flask_del_iomem (xc_interface *xch,unsigned long low,unsigned long high) { -char arg[64 ]; - -snprintf (arg,64 ,"%lu %lu" , low, high); -return xc_flask_del (xc_handle,OCON_IOMEM_STR , arg); +return xc_flask_del (xch,OCON_IOMEM , low, high); } -int xc_flask_del_device (xc_interface *xc_handle,unsigned long device) +int xc_flask_del_device (xc_interface *xch,unsigned long device) { -char arg[32 ]; - -snprintf (arg,32 ,"%lu" , device); -return xc_flask_del (xc_handle,OCON_DEVICE_STR , arg); +return xc_flask_del (xch,OCON_DEVICE , device, device); } -int xc_flask_access (xc_interface *xc_handle,const char *scon,const char *tcon, +int xc_flask_access (xc_interface *xch,const char *scon,const char *tcon,uint16_t tclass,uint32_t req,uint32_t *allowed,uint32_t *decided,uint32_t *auditallow,uint32_t *auditdeny,uint32_t *seqno) { -/* maximum number of digits in a 16-bit decimal number: */ -#define MAX_SHORT_DEC_LEN 5 - -char *buf; -int bufLen; +DECLARE_FLASK_OP ;int err; -flask_op_t op; -uint32_t dummy_allowed; -uint32_t dummy_decided; -uint32_t dummy_auditallow; -uint32_t dummy_auditdeny; -uint32_t dummy_seqno; - -if (!allowed) - allowed = &dummy_allowed; -if (!decided) - decided = &dummy_decided; -if (!auditallow) - auditallow = &dummy_auditallow; -if (!auditdeny) - auditdeny = &dummy_auditdeny; -if (!seqno) - seqno = &dummy_seqno; - -if (!scon) -return -EINVAL ; -if (!tcon) -return -EINVAL ; - - bufLen =strlen (scon) +1 +strlen (tcon) +1 + -MAX_SHORT_DEC_LEN +1 + -sizeof (req)*2 +1 ; - buf =malloc (bufLen); -snprintf (buf, bufLen,"%s %s %hu %x" , scon, tcon, tclass, req); + + err =xc_flask_context_to_sid (xch, (char *)scon,strlen (scon), &op.u.access.ssid); +if ( err ) +return err; + err =xc_flask_context_to_sid (xch, (char *)tcon,strlen (tcon), &op.u.access.tsid); +if ( err ) +return err; op.cmd =FLASK_ACCESS ; - op.buf = buf; - op.size =strlen (buf)+1 ; + op.u.access.tclass = tclass; + op.u.access.req = req; -if ( (err =xc_flask_op (xc_handle, &op)) !=0 ) - { -free (buf); + err =xc_flask_op (xch, &op); + +if ( err )return err; - } - -if (sscanf (op.buf,"%x %x %x %x %u" , - allowed, decided, - auditallow, auditdeny, - seqno) !=5 ) { - err = -EILSEQ ; - } - err = ((*allowed & req) == req)?0 : -EPERM ; +if ( allowed ) + *allowed = op.u.access.allowed; +if ( decided ) + *decided =0xffffffff ; +if ( auditallow ) + *auditallow = op.u.access.audit_allow; +if ( auditdeny ) + *auditdeny = op.u.access.audit_deny; +if ( seqno ) + *seqno = op.u.access.seqno; -return err; +if ( (op.u.access.allowed & req) != req ) + err = -EPERM ; +return err; } -int xc_flask_avc_hashstats (xc_interface *xc_handle,char *buf,int size) +int xc_flask_avc_hashstats (xc_interface *xch,char *buf,int size) {int err; -flask_op_t op; +DECLARE_FLASK_OP ; op.cmd =FLASK_AVC_HASHSTATS ; - op.buf = buf; - op.size = size; -if ( (err =xc_flask_op (xc_handle, &op)) !=0 ) - { -free (buf); -return err; - } + err =xc_flask_op (xch, &op); -return 0 ; +snprintf (buf, size, +"entries: %d\nbuckets used: %d/%d\nlongest chain: %d\n" , + op.u.hash_stats.entries, op.u.hash_stats.buckets_used, + op.u.hash_stats.buckets_total, op.u.hash_stats.max_chain_len); + +return err; } -int xc_flask_avc_cachestats (xc_interface *xc_handle,char *buf,int size) +int xc_flask_avc_cachestats (xc_interface *xch,char *buf,int size) { -int err; -flask_op_t op; +int err, n; +int i =0 ; +DECLARE_FLASK_OP ; + + n =snprintf (buf, size,"lookups hits misses allocations reclaims frees\n" ); + buf += n; + size -= n; op.cmd =FLASK_AVC_CACHESTATS ; - op.buf = buf; - op.size = size; - -if ( (err =xc_flask_op (xc_handle, &op)) !=0 ) +while ( size >0 ) { -free (buf); -return err; + op.u.cache_stats.cpu = i; + err =xc_flask_op (xch, &op); +if ( err && errno ==ENOENT ) +return 0 ; +if ( err ) +return err; + n =snprintf (buf, size,"%u %u %u %u %u %u\n" , + op.u.cache_stats.lookups, op.u.cache_stats.hits, + op.u.cache_stats.misses, op.u.cache_stats.allocations, + op.u.cache_stats.reclaims, op.u.cache_stats.frees); + buf += n; + size -= n; + i++; }return 0 ; } -int xc_flask_policyvers (xc_interface *xc_handle,char *buf,int size) +int xc_flask_policyvers (xc_interface *xch) { -int err; -flask_op_t op; - +DECLARE_FLASK_OP ; op.cmd =FLASK_POLICYVERS ; - op.buf = buf; - op.size = size; - -if ( (err =xc_flask_op (xc_handle, &op)) !=0 ) - { -free (buf); -return err; - } -return 0 ; +return xc_flask_op (xch, &op); } -int xc_flask_getavc_threshold (xc_interface *xc_handle) +int xc_flask_getavc_threshold (xc_interface *xch) { -int err; -flask_op_t op; -char buf[20 ]; -int size =20 ; -int threshold; - +DECLARE_FLASK_OP ; op.cmd =FLASK_GETAVC_THRESHOLD ; - op.buf = buf; - op.size = size; -if ( (err =xc_flask_op (xc_handle, &op)) !=0 ) -return err; - -sscanf (buf,"%i" , &threshold); - -return threshold; +return xc_flask_op (xch, &op); } -int xc_flask_setavc_threshold (xc_interface *xc_handle,int threshold) +int xc_flask_setavc_threshold (xc_interface *xch,int threshold) { -int err; -flask_op_t op; -char buf[20 ]; -int size =20 ; - +DECLARE_FLASK_OP ; op.cmd =FLASK_SETAVC_THRESHOLD ; - op.buf = buf; - op.size = size; + op.u.setavc_threshold.threshold = threshold; -snprintf (buf, size,"%i" , threshold); - -if ( (err =xc_flask_op (xc_handle, &op)) !=0 ) -return err; - -return 0 ; +return xc_flask_op (xch, &op); }/*
tools/libxc/xc_private.h +2 -0
@@ -42,11 +42,13 @@#define DECLARE_DOMCTL struct xen_domctl domctl = { 0 }#define DECLARE_SYSCTL struct xen_sysctl sysctl = { 0 }#define DECLARE_PHYSDEV_OP struct physdev_op physdev_op = { 0 } +#define DECLARE_FLASK_OP struct xen_flask_op op = { 0 }#else #define DECLARE_HYPERCALL privcmd_hypercall_t hypercall#define DECLARE_DOMCTL struct xen_domctl domctl#define DECLARE_SYSCTL struct xen_sysctl sysctl#define DECLARE_PHYSDEV_OP struct physdev_op physdev_op +#define DECLARE_FLASK_OP struct xen_flask_op op#endif #undef PAGE_SHIFT
tools/libxc/xenctrl.h +2 -2
@@ -1328,7 +1328,7 @@ int xc_sysctl(xc_interface *xch, struct xen_sysctl *sysctl);int xc_version (xc_interface *xch,int cmd,void *arg); -int xc_flask_op (xc_interface *xch,flask_op_t *op); +int xc_flask_op (xc_interface *xch,xen_flask_op_t *op);/* * Subscribe to state changes in a domain via evtchn.
@@ -1976,7 +1976,7 @@ int xc_flask_access(xc_interface *xc_handle, const char *scon, const char *tcon, uint32_t *auditallow, uint32_t *auditdeny, uint32_t *seqno);int xc_flask_avc_cachestats (xc_interface *xc_handle,char *buf,int size); -int xc_flask_policyvers (xc_interface *xc_handle,char *buf,int size); +int xc_flask_policyvers (xc_interface *xc_handle);int xc_flask_avc_hashstats (xc_interface *xc_handle,char *buf,int size);int xc_flask_getavc_threshold (xc_interface *xc_handle);int xc_flask_setavc_threshold (xc_interface *xc_handle,int threshold);
xen/include/public/xsm/flask_op.h +133 -13
157 lines not on this page · raw message
xen/xsm/flask/avc.c +8 -5
@@ -28,6 +28,7 @@#include <xen/rcupdate.h> #include <asm/atomic.h> #include <asm/current.h> +#include <public/xsm/flask_op.h> #include "avc.h" #include "avc_ss.h"
@@ -251,7 +252,7 @@ void __init avc_init(void)printk ("AVC INITIALIZED\n" ); } -int avc_get_hash_stats (char *buf,uint32_t size) +int avc_get_hash_stats (struct xen_flask_hash_stats *arg) {int i, chain_len, max_chain_len, slots_used;struct avc_node *node;
@@ -279,10 +280,12 @@ int avc_get_hash_stats(char *buf, uint32_t size)rcu_read_unlock (&avc_rcu_lock); -return snprintf (buf, size,"entries: %d\nbuckets used: %d/%d\n" -"longest chain: %d\n" , -atomic_read (&avc_cache.active_nodes), - slots_used,AVC_CACHE_SLOTS , max_chain_len); + arg->entries =atomic_read (&avc_cache.active_nodes); + arg->buckets_used = slots_used; + arg->buckets_total =AVC_CACHE_SLOTS ; + arg->max_chain_len = max_chain_len; + +return 0 ; }static void avc_node_free (struct rcu_head *rhead)
xen/xsm/flask/flask_op.c +316 -812
1,385 lines not on this page · raw message
xen/xsm/flask/include/avc.h +2 -1
@@ -104,7 +104,8 @@ int avc_add_callback(int (*callback)(u32 event, u32 ssid, u32 tsid, u32 ssid, u32 tsid, u16 tclass, u32 perms);/* Exported to selinuxfs */ -int avc_get_hash_stats (char *buf,uint32_t size); +struct xen_flask_hash_stats ; +int avc_get_hash_stats (struct xen_flask_hash_stats *arg);extern unsigned int avc_cache_threshold;#ifdef FLASK_AVC_STATS
xen/xsm/flask/include/security.h +2 -2
@@ -90,8 +90,8 @@ int security_iterate_iomem_sids(unsigned long start, unsigned long end,int security_iterate_ioport_sids (u32 start,u32 end,security_iterate_fn fn,void *data); -int security_ocontext_add (char *ocontext,unsigned long low, +int security_ocontext_add (u32 ocontext,unsigned long low,unsigned long high,u32 sid); -int security_ocontext_del (char *ocontext,unsigned int low,unsigned int high); +int security_ocontext_del (u32 ocontext,unsigned int low,unsigned int high);#endif /* _FLASK_SECURITY_H_ */
xen/xsm/flask/ss/services.c +2 -9
@@ -2097,17 +2097,14 @@ int determine_ocontext( char *ocontext )return -1 ; } -int security_ocontext_add (char *ocontext,unsigned long low,unsigned long high +int security_ocontext_add (u32 ocon,unsigned long low,unsigned long high ,u32 sid ) {int ret =0 ; -int ocon =0 ;struct ocontext *c;struct ocontext *prev;struct ocontext *add; -if ( (ocon =determine_ocontext (ocontext)) <0 ) -return -EINVAL ; if ( (add = xmalloc(struct ocontext)) == NULL )return -ENOMEM ;memset (add,0 ,sizeof (struct ocontext ));
@@ -2254,15 +2251,11 @@ int security_ocontext_add( char *ocontext, unsigned long low, unsigned long highreturn ret; } -int security_ocontext_del (char *ocontext,unsigned int low,unsigned int high ) +int security_ocontext_del (u32 ocon,unsigned int low,unsigned int high ) {int ret =0 ; -int ocon =0 ;struct ocontext *c, *before_c; -if ( (ocon =determine_ocontext (ocontext)) <0 ) -return -EINVAL ; -POLICY_WRLOCK ;switch ( ocon ) {
Signature · 1 line
1.7.7.6
PATCH 4/4 xen: Remove unused vsscanf/sscanf functions
In reply to Daniel De Graaf--- xen/common/vsprintf.c | 236 ------------------------------------------------- xen/include/xen/lib.h | 4 - 2 files changed, 0 insertions(+), 240 deletions(-)
xen/common/vsprintf.c +0 -236
@@ -512,223 +512,6 @@ int vscnprintf(char *buf, size_t size, const char *fmt, va_list args)EXPORT_SYMBOL (vscnprintf);/** -* vsscanf - Unformat a buffer into a list of arguments -* @buf: input buffer -* @fmt: format of buffer -* @args: arguments -*/ -int vsscanf (const char * buf,const char * fmt,va_list args) -{ -const char *str = buf; -const char *next; -char digit; -int num =0 ; -int qualifier; -int base; -int field_width; -int is_sign =0 ; - -while (*fmt && *str) { -/* skip any white space in format */ -/* white space in format matchs any amount of -* white space, including none, in the input. -*/ -if (isspace (*fmt)) { -while (isspace (*fmt)) - ++fmt; -while (isspace (*str)) - ++str; - } - -/* anything that is not a conversion must match exactly */ -if (*fmt !='%' && *fmt) { -if (*fmt++ != *str++) -break ; -continue ; - } - -if (!*fmt) -break ; - ++fmt; - -/* skip this conversion. -* advance both strings to next white space -*/ -if (*fmt =='*' ) { -while (!isspace (*fmt) && *fmt) - fmt++; -while (!isspace (*str) && *str) - str++; -continue ; - } - -/* get field width */ - field_width =-1 ; -if (isdigit (*fmt)) - field_width =skip_atoi (&fmt); - -/* get conversion qualifier */ - qualifier =-1 ; -if (*fmt =='h' || *fmt =='l' || *fmt =='L' || *fmt =='Z' - || *fmt =='z' ) { - qualifier = *fmt++; -if (unlikely (qualifier == *fmt)) { -if (qualifier =='h' ) { - qualifier ='H' ; - fmt++; - }else if (qualifier =='l' ) { - qualifier ='L' ; - fmt++; - } - } - } - base =10 ; - is_sign =0 ; - -if (!*fmt || !*str) -break ; - -switch (*fmt++) { -case 'c' : { - char *s = (char *) va_arg(args,char*); -if (field_width ==-1 ) - field_width =1 ; -do { - *s++ = *str++; - }while (--field_width >0 && *str); - num++; - } -continue ; -case 's' : { - char *s = (char *) va_arg(args, char *); -if (field_width ==-1 ) - field_width =INT_MAX ; -/* first, skip leading white space in buffer */ -while (isspace (*str)) - str++; - -/* now copy until next white space */ -while (*str && !isspace (*str) && field_width--) - *s++ = *str++; - *s ='\0' ; - num++; - } -continue ; -case 'n' : { -/* return number of characters read so far */ - int *i = (int *)va_arg(args,int*); - *i = str - buf; - } -continue ; -case 'o' : - base =8 ; -break ; -case 'x' : -case 'X' : - base =16 ; -break ; -case 'i' : - base =0 ; -case 'd' : - is_sign =1 ; -case 'u' : -break ; -case '%' : -/* looking for '%' in str */ -if (*str++ !='%' ) -return num; -continue ; -default : -/* invalid format; stop here */ -return num; - } - -/* have some sort of integer conversion. -* first, skip white space in buffer. -*/ -while (isspace (*str)) - str++; - - digit = *str; -if (is_sign && digit =='-' ) - digit = *(str +1 ); - -if (!digit || (base ==16 && !isxdigit (digit)) - || (base ==10 && !isdigit (digit)) - || (base ==8 && (!isdigit (digit) || digit >'7' )) - || (base ==0 && !isdigit (digit))) -break ; - -switch (qualifier) { -case 'H' :/* that's 'hh' in format */ -if (is_sign) { - signed char *s = (signed char *) va_arg(args,signed char *); - *s = (signed char )simple_strtol (str,&next,base); - }else { -unsigned char *s = (unsigned char *) - va_arg(args, unsigned char *); - *s = (unsigned char )simple_strtoul (str, &next, base); - } -break ; -case 'h' : -if (is_sign) { - short *s = (short *) va_arg(args,short *); - *s = (short )simple_strtol (str,&next,base); - }else { -unsigned short *s = (unsigned short *) - va_arg(args, unsigned short *); - *s = (unsigned short )simple_strtoul (str, &next, base); - } -break ; -case 'l' : -if (is_sign) { - long *l = (long *) va_arg(args,long *); - *l =simple_strtol (str,&next,base); - }else { -unsigned long *l = (unsigned long *) - va_arg(args,unsigned long*); - *l =simple_strtoul (str,&next,base); - } -break ; -case 'L' : -if (is_sign) { - long long *l = (long long*) va_arg(args,long long *); - *l =simple_strtoll (str,&next,base); - }else { -unsigned long long *l = (unsigned long long *) - va_arg(args,unsigned long long*); - *l =simple_strtoull (str,&next,base); - } -break ; -case 'Z' : -case 'z' : { - size_t *s = (size_t*) va_arg(args,size_t*); - *s = (size_t )simple_strtoul (str,&next,base); - } -break ; -default : -if (is_sign) { - int *i = (int *) va_arg(args, int*); - *i = (int )simple_strtol (str,&next,base); - }else { -unsigned int *i = (unsigned int *) - va_arg(args, unsigned int*); - *i = (unsigned int )simple_strtoul (str,&next,base); - } -break ; - } - num++; - -if (!next) -break ; - str = next; - } -return num; -} - -EXPORT_SYMBOL (vsscanf); - -/** * snprintf - Format a string and place it in a buffer * @buf: The buffer to place the result into * @size: The size of the buffer, including the trailing null space
@@ -779,25 +562,6 @@ int scnprintf(char * buf, size_t size, const char *fmt, ...) }EXPORT_SYMBOL (scnprintf); -/** -* sscanf - Unformat a buffer into a list of arguments -* @buf: input buffer -* @fmt: formatting of buffer -* @...: resulting arguments -*/ -int sscanf (const char * buf,const char * fmt, ...) -{ -va_list args; -int i; - -va_start (args,fmt); - i =vsscanf (buf,fmt,args); -va_end (args); -return i; -} - -EXPORT_SYMBOL (sscanf); -/* * Local variables: * mode: C
xen/include/xen/lib.h +0 -4
@@ -89,10 +89,6 @@ extern int scnprintf(char * buf, size_t size, const char * fmt, ...) __attribute__ ((format (printf, 3, 4)));extern int vscnprintf (char *buf,size_t size,const char *fmt,va_list args) __attribute__ ((format (printf,3 ,0 ))); -extern int sscanf (const char * buf,const char * fmt, ...) - __attribute__ ((format (scanf,2 ,3 ))); -extern int vsscanf (const char * buf,const char * fmt,va_list args) - __attribute__ ((format (scanf,2 ,0 )));long simple_strtol (const char *cp,const char **endp,unsigned int base);
Signature · 1 line
1.7.7.6