xen-vtx-unstable
changeset 5994:e173a853dc46
Merging with xen-unstable
line diff
1.1 --- a/.hgignore Tue Aug 02 02:47:41 2005 -0800 1.2 +++ b/.hgignore Tue Aug 02 10:20:46 2005 -0700 1.3 @@ -86,6 +86,8 @@ 1.4 ^tools/check/\..*$ 1.5 ^tools/cmdline/.*$ 1.6 ^tools/cmdline/xen/.*$ 1.7 +^tools/consoled/consoled$ 1.8 +^tools/consoled/xc_console$ 1.9 ^tools/debugger/pdb/pdb$ 1.10 ^tools/debugger/pdb/linux-[0-9.]*-module/.*\.ko$ 1.11 ^tools/debugger/pdb/linux-[0-9.]*-module/.*\.mod.c$ 1.12 @@ -128,8 +130,8 @@ 1.13 ^tools/misc/xc_shadow$ 1.14 ^tools/misc/xen_cpuperf$ 1.15 ^tools/misc/xenperf$ 1.16 -^tools/policy/policy_tool$ 1.17 -^tools/policy/xen/.*$ 1.18 +^tools/security/secpol_tool$ 1.19 +^tools/security/xen/.*$ 1.20 ^tools/pygrub/build/.*$ 1.21 ^tools/python/build/.*$ 1.22 ^tools/tests/test_x86_emulator$
36.1 --- a/linux-2.6-xen-sparse/arch/xen/configs/xen0_defconfig_x86_32 Tue Aug 02 02:47:41 2005 -0800 36.2 +++ b/linux-2.6-xen-sparse/arch/xen/configs/xen0_defconfig_x86_32 Tue Aug 02 10:20:46 2005 -0700 36.3 @@ -18,8 +18,8 @@ CONFIG_XEN_BLKDEV_GRANT=y 36.4 CONFIG_XEN_NETDEV_BACKEND=y 36.5 CONFIG_XEN_BLKDEV_FRONTEND=y 36.6 CONFIG_XEN_NETDEV_FRONTEND=y 36.7 -CONFIG_XEN_NETDEV_GRANT_TX=y 36.8 - CONFIG_XEN_NETDEV_GRANT_RX=y 36.9 +#CONFIG_XEN_NETDEV_GRANT_TX=y 36.10 +#CONFIG_XEN_NETDEV_GRANT_RX=y 36.11 # CONFIG_XEN_NETDEV_FRONTEND_PIPELINED_TRANSMITTER is not set 36.12 # CONFIG_XEN_BLKDEV_TAP is not set 36.13 # CONFIG_XEN_SHADOW_MODE is not set
37.1 --- a/linux-2.6-xen-sparse/arch/xen/configs/xenU_defconfig_x86_32 Tue Aug 02 02:47:41 2005 -0800 37.2 +++ b/linux-2.6-xen-sparse/arch/xen/configs/xenU_defconfig_x86_32 Tue Aug 02 10:20:46 2005 -0700 37.3 @@ -15,8 +15,8 @@ CONFIG_NO_IDLE_HZ=y 37.4 CONFIG_XEN_BLKDEV_GRANT=y 37.5 CONFIG_XEN_BLKDEV_FRONTEND=y 37.6 CONFIG_XEN_NETDEV_FRONTEND=y 37.7 -CONFIG_XEN_NETDEV_GRANT_TX=y 37.8 -CONFIG_XEN_NETDEV_GRANT_RX=y 37.9 +#CONFIG_XEN_NETDEV_GRANT_TX=y 37.10 +#CONFIG_XEN_NETDEV_GRANT_RX=y 37.11 # CONFIG_XEN_NETDEV_FRONTEND_PIPELINED_TRANSMITTER is not set 37.12 # CONFIG_XEN_BLKDEV_TAP is not set 37.13 # CONFIG_XEN_SHADOW_MODE is not set
46.1 --- a/linux-2.6-xen-sparse/arch/xen/i386/mm/fault.c Tue Aug 02 02:47:41 2005 -0800 46.2 +++ b/linux-2.6-xen-sparse/arch/xen/i386/mm/fault.c Tue Aug 02 10:20:46 2005 -0700 46.3 @@ -204,6 +204,63 @@ static inline int is_prefetch(struct pt_ 46.4 46.5 fastcall void do_invalid_op(struct pt_regs *, unsigned long); 46.6 46.7 +#ifdef CONFIG_X86_PAE 46.8 +static void dump_fault_path(unsigned long address) 46.9 +{ 46.10 + unsigned long *p, page; 46.11 + 46.12 + page = __pa(per_cpu(cur_pgd, smp_processor_id())); 46.13 + p = (unsigned long *)__va(page); 46.14 + p += (address >> 30) * 2; 46.15 + printk(KERN_ALERT "%08lx -> *pde = %08lx:%08lx\n", page, p[1], p[0]); 46.16 + if (p[0] & 1) { 46.17 + page = p[0] & PAGE_MASK; 46.18 + address &= 0x3fffffff; 46.19 + page = machine_to_phys(page); 46.20 + p = (unsigned long *)__va(page); 46.21 + p += (address >> 21) * 2; 46.22 + printk(KERN_ALERT "%08lx -> *pme = %08lx:%08lx\n", page, p[1], p[0]); 46.23 +#ifndef CONFIG_HIGHPTE 46.24 + if (p[0] & 1) { 46.25 + page = p[0] & PAGE_MASK; 46.26 + address &= 0x001fffff; 46.27 + page = machine_to_phys(page); 46.28 + p = (unsigned long *) __va(page); 46.29 + p += (address >> 12) * 2; 46.30 + printk(KERN_ALERT "%08lx -> *pte = %08lx:%08lx\n", page, p[1], p[0]); 46.31 + } 46.32 +#endif 46.33 + } 46.34 +} 46.35 +#else 46.36 +static void dump_fault_path(unsigned long address) 46.37 +{ 46.38 + unsigned long page; 46.39 + 46.40 + page = ((unsigned long *) per_cpu(cur_pgd, smp_processor_id())) 46.41 + [address >> 22]; 46.42 + printk(KERN_ALERT "*pde = ma %08lx pa %08lx\n", page, 46.43 + machine_to_phys(page)); 46.44 + /* 46.45 + * We must not directly access the pte in the highpte 46.46 + * case, the page table might be allocated in highmem. 46.47 + * And lets rather not kmap-atomic the pte, just in case 46.48 + * it's allocated already. 46.49 + */ 46.50 +#ifndef CONFIG_HIGHPTE 46.51 + if (page & 1) { 46.52 + page &= PAGE_MASK; 46.53 + address &= 0x003ff000; 46.54 + page = machine_to_phys(page); 46.55 + page = ((unsigned long *) __va(page))[address >> PAGE_SHIFT]; 46.56 + printk(KERN_ALERT "*pte = ma %08lx pa %08lx\n", page, 46.57 + machine_to_phys(page)); 46.58 + } 46.59 +#endif 46.60 +} 46.61 +#endif 46.62 + 46.63 + 46.64 /* 46.65 * This routine handles page faults. It determines the address, 46.66 * and the problem, and then passes it off to one of the appropriate 46.67 @@ -220,7 +277,6 @@ fastcall void do_page_fault(struct pt_re 46.68 struct task_struct *tsk; 46.69 struct mm_struct *mm; 46.70 struct vm_area_struct * vma; 46.71 - unsigned long page; 46.72 int write; 46.73 siginfo_t info; 46.74 46.75 @@ -454,26 +510,7 @@ no_context: 46.76 printk(" at virtual address %08lx\n",address); 46.77 printk(KERN_ALERT " printing eip:\n"); 46.78 printk("%08lx\n", regs->eip); 46.79 - page = ((unsigned long *) per_cpu(cur_pgd, smp_processor_id())) 46.80 - [address >> 22]; 46.81 - printk(KERN_ALERT "*pde = ma %08lx pa %08lx\n", page, 46.82 - machine_to_phys(page)); 46.83 - /* 46.84 - * We must not directly access the pte in the highpte 46.85 - * case, the page table might be allocated in highmem. 46.86 - * And lets rather not kmap-atomic the pte, just in case 46.87 - * it's allocated already. 46.88 - */ 46.89 -#ifndef CONFIG_HIGHPTE 46.90 - if (page & 1) { 46.91 - page &= PAGE_MASK; 46.92 - address &= 0x003ff000; 46.93 - page = machine_to_phys(page); 46.94 - page = ((unsigned long *) __va(page))[address >> PAGE_SHIFT]; 46.95 - printk(KERN_ALERT "*pte = ma %08lx pa %08lx\n", page, 46.96 - machine_to_phys(page)); 46.97 - } 46.98 -#endif 46.99 + dump_fault_path(address); 46.100 die("Oops", regs, error_code); 46.101 bust_spinlocks(0); 46.102 do_exit(SIGKILL);
53.1 --- a/linux-2.6-xen-sparse/drivers/xen/balloon/balloon.c Tue Aug 02 02:47:41 2005 -0800 53.2 +++ b/linux-2.6-xen-sparse/drivers/xen/balloon/balloon.c Tue Aug 02 10:20:46 2005 -0700 53.3 @@ -5,6 +5,7 @@ 53.4 * 53.5 * Copyright (c) 2003, B Dragovic 53.6 * Copyright (c) 2003-2004, M Williamson, K Fraser 53.7 + * Copyright (c) 2005 Dan M. Smith, IBM Corporation 53.8 * 53.9 * This file may be distributed separately from the Linux kernel, or 53.10 * incorporated into other software packages, subject to the following license: 53.11 @@ -42,7 +43,6 @@ 53.12 #include <linux/vmalloc.h> 53.13 #include <asm-xen/xen_proc.h> 53.14 #include <asm-xen/hypervisor.h> 53.15 -#include <asm-xen/ctrl_if.h> 53.16 #include <asm-xen/balloon.h> 53.17 #include <asm/pgalloc.h> 53.18 #include <asm/pgtable.h> 53.19 @@ -50,6 +50,10 @@ 53.20 #include <asm/tlb.h> 53.21 #include <linux/list.h> 53.22 53.23 +#include<asm-xen/xenbus.h> 53.24 + 53.25 +#define PAGES2KB(_p) ((_p)<<(PAGE_SHIFT-10)) 53.26 + 53.27 static struct proc_dir_entry *balloon_pde; 53.28 53.29 static DECLARE_MUTEX(balloon_mutex); 53.30 @@ -77,11 +81,17 @@ static void balloon_process(void *unused 53.31 static DECLARE_WORK(balloon_worker, balloon_process, NULL); 53.32 static struct timer_list balloon_timer; 53.33 53.34 +/* Flag for dom0 xenstore workaround */ 53.35 +static int balloon_xenbus_init=0; 53.36 + 53.37 +/* Init Function */ 53.38 +void balloon_init_watcher(void); 53.39 + 53.40 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) 53.41 /* Use the private and mapping fields of struct page as a list. */ 53.42 #define PAGE_TO_LIST(p) ( (struct list_head *)&p->private ) 53.43 #define LIST_TO_PAGE(l) ( list_entry( ((unsigned long *)l), \ 53.44 - struct page, private ) ) 53.45 + struct page, private ) ) 53.46 #define UNLIST_PAGE(p) do { list_del(PAGE_TO_LIST(p)); \ 53.47 p->mapping = NULL; \ 53.48 p->private = 0; } while(0) 53.49 @@ -297,26 +307,97 @@ static void set_new_target(unsigned long 53.50 schedule_work(&balloon_worker); 53.51 } 53.52 53.53 -static void balloon_ctrlif_rx(ctrl_msg_t *msg, unsigned long id) 53.54 +static struct xenbus_watch xb_watch = 53.55 +{ 53.56 + .node = "memory" 53.57 +}; 53.58 + 53.59 +/* FIXME: This is part of a dom0 sequencing workaround */ 53.60 +static struct xenbus_watch root_watch = 53.61 { 53.62 - switch ( msg->subtype ) 53.63 - { 53.64 - case CMSG_MEM_REQUEST_SET: 53.65 + .node = "/" 53.66 +}; 53.67 + 53.68 +/* React to a change in the target key */ 53.69 +static void watch_target(struct xenbus_watch *watch, const char *node) 53.70 +{ 53.71 + unsigned long new_target; 53.72 + int err; 53.73 + 53.74 + if(watch == &root_watch) 53.75 { 53.76 - mem_request_t *req = (mem_request_t *)&msg->msg[0]; 53.77 - set_new_target(req->target); 53.78 - req->status = 0; 53.79 - } 53.80 - break; 53.81 - 53.82 - default: 53.83 - msg->length = 0; 53.84 - break; 53.85 + /* FIXME: This is part of a dom0 sequencing workaround */ 53.86 + if(register_xenbus_watch(&xb_watch) == 0) 53.87 + { 53.88 + /* 53.89 + We successfully set a watch on memory/target: 53.90 + now we can stop watching root 53.91 + */ 53.92 + unregister_xenbus_watch(&root_watch); 53.93 + balloon_xenbus_init=1; 53.94 + } 53.95 + else 53.96 + { 53.97 + return; 53.98 + } 53.99 } 53.100 53.101 - ctrl_if_send_response(msg); 53.102 + err = xenbus_scanf("memory", "target", "%lu", &new_target); 53.103 + 53.104 + if(err != 1) 53.105 + { 53.106 + IPRINTK("Unable to read memory/target\n"); 53.107 + return; 53.108 + } 53.109 + 53.110 + set_new_target(new_target >> PAGE_SHIFT); 53.111 + 53.112 } 53.113 53.114 +/* 53.115 + Try to set up our watcher, if not already set 53.116 + 53.117 +*/ 53.118 +void balloon_init_watcher(void) 53.119 +{ 53.120 + int err; 53.121 + 53.122 + if(!xen_start_info.store_evtchn) 53.123 + { 53.124 + IPRINTK("Delaying watcher init until xenstore is available\n"); 53.125 + return; 53.126 + } 53.127 + 53.128 + down(&xenbus_lock); 53.129 + 53.130 + if(! balloon_xenbus_init) 53.131 + { 53.132 + err = register_xenbus_watch(&xb_watch); 53.133 + if(err) 53.134 + { 53.135 + /* BIG FAT FIXME: dom0 sequencing workaround 53.136 + * dom0 can't set a watch on memory/target until 53.137 + * after the tools create it. So, we have to watch 53.138 + * the whole store until that happens. 53.139 + * 53.140 + * This will go away when we have the ability to watch 53.141 + * non-existant keys 53.142 + */ 53.143 + register_xenbus_watch(&root_watch); 53.144 + } 53.145 + else 53.146 + { 53.147 + IPRINTK("Balloon xenbus watcher initialized\n"); 53.148 + balloon_xenbus_init = 1; 53.149 + } 53.150 + } 53.151 + 53.152 + up(&xenbus_lock); 53.153 + 53.154 +} 53.155 + 53.156 +EXPORT_SYMBOL(balloon_init_watcher); 53.157 + 53.158 static int balloon_write(struct file *file, const char __user *buffer, 53.159 unsigned long count, void *data) 53.160 { 53.161 @@ -346,7 +427,6 @@ static int balloon_read(char *page, char 53.162 { 53.163 int len; 53.164 53.165 -#define K(_p) ((_p)<<(PAGE_SHIFT-10)) 53.166 len = sprintf( 53.167 page, 53.168 "Current allocation: %8lu kB\n" 53.169 @@ -354,13 +434,14 @@ static int balloon_read(char *page, char 53.170 "Low-mem balloon: %8lu kB\n" 53.171 "High-mem balloon: %8lu kB\n" 53.172 "Xen hard limit: ", 53.173 - K(current_pages), K(target_pages), K(balloon_low), K(balloon_high)); 53.174 + PAGES2KB(current_pages), PAGES2KB(target_pages), 53.175 + PAGES2KB(balloon_low), PAGES2KB(balloon_high)); 53.176 53.177 if ( hard_limit != ~0UL ) 53.178 len += sprintf( 53.179 page + len, 53.180 "%8lu kB (inc. %8lu kB driver headroom)\n", 53.181 - K(hard_limit), K(driver_pages)); 53.182 + PAGES2KB(hard_limit), PAGES2KB(driver_pages)); 53.183 else 53.184 len += sprintf( 53.185 page + len, 53.186 @@ -396,9 +477,7 @@ static int __init balloon_init(void) 53.187 53.188 balloon_pde->read_proc = balloon_read; 53.189 balloon_pde->write_proc = balloon_write; 53.190 - 53.191 - (void)ctrl_if_register_receiver(CMSG_MEM_REQUEST, balloon_ctrlif_rx, 0); 53.192 - 53.193 + 53.194 /* Initialise the balloon with excess memory space. */ 53.195 for ( pfn = xen_start_info.nr_pages; pfn < max_pfn; pfn++ ) 53.196 { 53.197 @@ -407,6 +486,11 @@ static int __init balloon_init(void) 53.198 balloon_append(page); 53.199 } 53.200 53.201 + xb_watch.callback = watch_target; 53.202 + root_watch.callback = watch_target; 53.203 + 53.204 + balloon_init_watcher(); 53.205 + 53.206 return 0; 53.207 } 53.208
64.1 --- a/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c Tue Aug 02 02:47:41 2005 -0800 64.2 +++ b/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c Tue Aug 02 10:20:46 2005 -0700 64.3 @@ -309,6 +309,9 @@ int do_xenbus_probe(void *unused) 64.4 return err; 64.5 } 64.6 64.7 + /* Initialize non-xenbus drivers */ 64.8 + balloon_init_watcher(); 64.9 + 64.10 down(&xenbus_lock); 64.11 /* Enumerate devices in xenstore. */ 64.12 xenbus_probe_devices("device");
73.1 --- a/linux-2.6-xen-sparse/kernel/ptrace.c Tue Aug 02 02:47:41 2005 -0800 73.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 73.3 @@ -1,391 +0,0 @@ 73.4 -/* 73.5 - * linux/kernel/ptrace.c 73.6 - * 73.7 - * (C) Copyright 1999 Linus Torvalds 73.8 - * 73.9 - * Common interfaces for "ptrace()" which we do not want 73.10 - * to continually duplicate across every architecture. 73.11 - */ 73.12 - 73.13 -#include <linux/module.h> 73.14 -#include <linux/sched.h> 73.15 -#include <linux/errno.h> 73.16 -#include <linux/mm.h> 73.17 -#include <linux/highmem.h> 73.18 -#include <linux/pagemap.h> 73.19 -#include <linux/smp_lock.h> 73.20 -#include <linux/ptrace.h> 73.21 -#include <linux/security.h> 73.22 -#include <linux/signal.h> 73.23 - 73.24 -#include <asm/pgtable.h> 73.25 -#include <asm/uaccess.h> 73.26 - 73.27 -/* 73.28 - * ptrace a task: make the debugger its new parent and 73.29 - * move it to the ptrace list. 73.30 - * 73.31 - * Must be called with the tasklist lock write-held. 73.32 - */ 73.33 -void __ptrace_link(task_t *child, task_t *new_parent) 73.34 -{ 73.35 - if (!list_empty(&child->ptrace_list)) 73.36 - BUG(); 73.37 - if (child->parent == new_parent) 73.38 - return; 73.39 - list_add(&child->ptrace_list, &child->parent->ptrace_children); 73.40 - REMOVE_LINKS(child); 73.41 - child->parent = new_parent; 73.42 - SET_LINKS(child); 73.43 -} 73.44 - 73.45 -/* 73.46 - * Turn a tracing stop into a normal stop now, since with no tracer there 73.47 - * would be no way to wake it up with SIGCONT or SIGKILL. If there was a 73.48 - * signal sent that would resume the child, but didn't because it was in 73.49 - * TASK_TRACED, resume it now. 73.50 - * Requires that irqs be disabled. 73.51 - */ 73.52 -void ptrace_untrace(task_t *child) 73.53 -{ 73.54 - spin_lock(&child->sighand->siglock); 73.55 - if (child->state == TASK_TRACED) { 73.56 - if (child->signal->flags & SIGNAL_STOP_STOPPED) { 73.57 - child->state = TASK_STOPPED; 73.58 - } else { 73.59 - signal_wake_up(child, 1); 73.60 - } 73.61 - } 73.62 - spin_unlock(&child->sighand->siglock); 73.63 -} 73.64 - 73.65 -/* 73.66 - * unptrace a task: move it back to its original parent and 73.67 - * remove it from the ptrace list. 73.68 - * 73.69 - * Must be called with the tasklist lock write-held. 73.70 - */ 73.71 -void __ptrace_unlink(task_t *child) 73.72 -{ 73.73 - if (!child->ptrace) 73.74 - BUG(); 73.75 - child->ptrace = 0; 73.76 - if (!list_empty(&child->ptrace_list)) { 73.77 - list_del_init(&child->ptrace_list); 73.78 - REMOVE_LINKS(child); 73.79 - child->parent = child->real_parent; 73.80 - SET_LINKS(child); 73.81 - } 73.82 - 73.83 - if (child->state == TASK_TRACED) 73.84 - ptrace_untrace(child); 73.85 -} 73.86 - 73.87 -/* 73.88 - * Check that we have indeed attached to the thing.. 73.89 - */ 73.90 -int ptrace_check_attach(struct task_struct *child, int kill) 73.91 -{ 73.92 - int ret = -ESRCH; 73.93 - 73.94 - /* 73.95 - * We take the read lock around doing both checks to close a 73.96 - * possible race where someone else was tracing our child and 73.97 - * detached between these two checks. After this locked check, 73.98 - * we are sure that this is our traced child and that can only 73.99 - * be changed by us so it's not changing right after this. 73.100 - */ 73.101 - read_lock(&tasklist_lock); 73.102 - if ((child->ptrace & PT_PTRACED) && child->parent == current && 73.103 - (!(child->ptrace & PT_ATTACHED) || child->real_parent != current) 73.104 - && child->signal != NULL) { 73.105 - ret = 0; 73.106 - spin_lock_irq(&child->sighand->siglock); 73.107 - if (child->state == TASK_STOPPED) { 73.108 - child->state = TASK_TRACED; 73.109 - } else if (child->state != TASK_TRACED && !kill) { 73.110 - ret = -ESRCH; 73.111 - } 73.112 - spin_unlock_irq(&child->sighand->siglock); 73.113 - } 73.114 - read_unlock(&tasklist_lock); 73.115 - 73.116 - if (!ret && !kill) { 73.117 - wait_task_inactive(child); 73.118 - } 73.119 - 73.120 - /* All systems go.. */ 73.121 - return ret; 73.122 -} 73.123 - 73.124 -int ptrace_attach(struct task_struct *task) 73.125 -{ 73.126 - int retval; 73.127 - task_lock(task); 73.128 - retval = -EPERM; 73.129 - if (task->pid <= 1) 73.130 - goto bad; 73.131 - if (task == current) 73.132 - goto bad; 73.133 - if (!task->mm) 73.134 - goto bad; 73.135 - if(((current->uid != task->euid) || 73.136 - (current->uid != task->suid) || 73.137 - (current->uid != task->uid) || 73.138 - (current->gid != task->egid) || 73.139 - (current->gid != task->sgid) || 73.140 - (current->gid != task->gid)) && !capable(CAP_SYS_PTRACE)) 73.141 - goto bad; 73.142 - smp_rmb(); 73.143 - if (!task->mm->dumpable && !capable(CAP_SYS_PTRACE)) 73.144 - goto bad; 73.145 - /* the same process cannot be attached many times */ 73.146 - if (task->ptrace & PT_PTRACED) 73.147 - goto bad; 73.148 - retval = security_ptrace(current, task); 73.149 - if (retval) 73.150 - goto bad; 73.151 - 73.152 - /* Go */ 73.153 - task->ptrace |= PT_PTRACED | ((task->real_parent != current) 73.154 - ? PT_ATTACHED : 0); 73.155 - if (capable(CAP_SYS_PTRACE)) 73.156 - task->ptrace |= PT_PTRACE_CAP; 73.157 - task_unlock(task); 73.158 - 73.159 - write_lock_irq(&tasklist_lock); 73.160 - __ptrace_link(task, current); 73.161 - write_unlock_irq(&tasklist_lock); 73.162 - 73.163 - force_sig_specific(SIGSTOP, task); 73.164 - return 0; 73.165 - 73.166 -bad: 73.167 - task_unlock(task); 73.168 - return retval; 73.169 -} 73.170 - 73.171 -int ptrace_detach(struct task_struct *child, unsigned int data) 73.172 -{ 73.173 - if (!valid_signal(data)) 73.174 - return -EIO; 73.175 - 73.176 - /* Architecture-specific hardware disable .. */ 73.177 - ptrace_disable(child); 73.178 - 73.179 - /* .. re-parent .. */ 73.180 - child->exit_code = data; 73.181 - 73.182 - write_lock_irq(&tasklist_lock); 73.183 - __ptrace_unlink(child); 73.184 - /* .. and wake it up. */ 73.185 - if (child->exit_state != EXIT_ZOMBIE) 73.186 - wake_up_process(child); 73.187 - write_unlock_irq(&tasklist_lock); 73.188 - 73.189 - return 0; 73.190 -} 73.191 - 73.192 -/* 73.193 - * Access another process' address space. 73.194 - * Source/target buffer must be kernel space, 73.195 - * Do not walk the page table directly, use get_user_pages 73.196 - */ 73.197 - 73.198 -int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write) 73.199 -{ 73.200 - struct mm_struct *mm; 73.201 - struct vm_area_struct *vma; 73.202 - struct page *page; 73.203 - void *old_buf = buf; 73.204 - 73.205 - mm = get_task_mm(tsk); 73.206 - if (!mm) 73.207 - return 0; 73.208 - 73.209 - down_read(&mm->mmap_sem); 73.210 - /* ignore errors, just check how much was sucessfully transfered */ 73.211 - while (len) { 73.212 - int bytes, ret, offset; 73.213 - void *maddr; 73.214 - 73.215 - ret = get_user_pages(tsk, mm, addr, 1, 73.216 - write, 1, &page, &vma); 73.217 - if (ret <= 0) 73.218 - break; 73.219 - 73.220 - bytes = len; 73.221 - offset = addr & (PAGE_SIZE-1); 73.222 - if (bytes > PAGE_SIZE-offset) 73.223 - bytes = PAGE_SIZE-offset; 73.224 - 73.225 - maddr = kmap(page); 73.226 - if (write) { 73.227 - copy_to_user_page(vma, page, addr, 73.228 - maddr + offset, buf, bytes); 73.229 - set_page_dirty_lock(page); 73.230 - } else { 73.231 - copy_from_user_page(vma, page, addr, 73.232 - buf, maddr + offset, bytes); 73.233 - } 73.234 - kunmap(page); 73.235 - page_cache_release(page); 73.236 - len -= bytes; 73.237 - buf += bytes; 73.238 - addr += bytes; 73.239 - } 73.240 - up_read(&mm->mmap_sem); 73.241 - mmput(mm); 73.242 - 73.243 - return buf - old_buf; 73.244 -} 73.245 -EXPORT_SYMBOL(access_process_vm); 73.246 - 73.247 -int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst, int len) 73.248 -{ 73.249 - int copied = 0; 73.250 - 73.251 - while (len > 0) { 73.252 - char buf[128]; 73.253 - int this_len, retval; 73.254 - 73.255 - this_len = (len > sizeof(buf)) ? sizeof(buf) : len; 73.256 - retval = access_process_vm(tsk, src, buf, this_len, 0); 73.257 - if (!retval) { 73.258 - if (copied) 73.259 - break; 73.260 - return -EIO; 73.261 - } 73.262 - if (copy_to_user(dst, buf, retval)) 73.263 - return -EFAULT; 73.264 - copied += retval; 73.265 - src += retval; 73.266 - dst += retval; 73.267 - len -= retval; 73.268 - } 73.269 - return copied; 73.270 -} 73.271 - 73.272 -int ptrace_writedata(struct task_struct *tsk, char __user *src, unsigned long dst, int len) 73.273 -{ 73.274 - int copied = 0; 73.275 - 73.276 - while (len > 0) { 73.277 - char buf[128]; 73.278 - int this_len, retval; 73.279 - 73.280 - this_len = (len > sizeof(buf)) ? sizeof(buf) : len; 73.281 - if (copy_from_user(buf, src, this_len)) 73.282 - return -EFAULT; 73.283 - retval = access_process_vm(tsk, dst, buf, this_len, 1); 73.284 - if (!retval) { 73.285 - if (copied) 73.286 - break; 73.287 - return -EIO; 73.288 - } 73.289 - copied += retval; 73.290 - src += retval; 73.291 - dst += retval; 73.292 - len -= retval; 73.293 - } 73.294 - return copied; 73.295 -} 73.296 - 73.297 -static int ptrace_setoptions(struct task_struct *child, long data) 73.298 -{ 73.299 - child->ptrace &= ~PT_TRACE_MASK; 73.300 - 73.301 - if (data & PTRACE_O_TRACESYSGOOD) 73.302 - child->ptrace |= PT_TRACESYSGOOD; 73.303 - 73.304 - if (data & PTRACE_O_TRACEFORK) 73.305 - child->ptrace |= PT_TRACE_FORK; 73.306 - 73.307 - if (data & PTRACE_O_TRACEVFORK) 73.308 - child->ptrace |= PT_TRACE_VFORK; 73.309 - 73.310 - if (data & PTRACE_O_TRACECLONE) 73.311 - child->ptrace |= PT_TRACE_CLONE; 73.312 - 73.313 - if (data & PTRACE_O_TRACEEXEC) 73.314 - child->ptrace |= PT_TRACE_EXEC; 73.315 - 73.316 - if (data & PTRACE_O_TRACEVFORKDONE) 73.317 - child->ptrace |= PT_TRACE_VFORK_DONE; 73.318 - 73.319 - if (data & PTRACE_O_TRACEEXIT) 73.320 - child->ptrace |= PT_TRACE_EXIT; 73.321 - 73.322 - return (data & ~PTRACE_O_MASK) ? -EINVAL : 0; 73.323 -} 73.324 - 73.325 -static int ptrace_getsiginfo(struct task_struct *child, siginfo_t __user * data) 73.326 -{ 73.327 - siginfo_t lastinfo; 73.328 - int error = -ESRCH; 73.329 - 73.330 - read_lock(&tasklist_lock); 73.331 - if (likely(child->sighand != NULL)) { 73.332 - error = -EINVAL; 73.333 - spin_lock_irq(&child->sighand->siglock); 73.334 - if (likely(child->last_siginfo != NULL)) { 73.335 - lastinfo = *child->last_siginfo; 73.336 - error = 0; 73.337 - } 73.338 - spin_unlock_irq(&child->sighand->siglock); 73.339 - } 73.340 - read_unlock(&tasklist_lock); 73.341 - if (!error) 73.342 - return copy_siginfo_to_user(data, &lastinfo); 73.343 - return error; 73.344 -} 73.345 - 73.346 -static int ptrace_setsiginfo(struct task_struct *child, siginfo_t __user * data) 73.347 -{ 73.348 - siginfo_t newinfo; 73.349 - int error = -ESRCH; 73.350 - 73.351 - if (copy_from_user(&newinfo, data, sizeof (siginfo_t))) 73.352 - return -EFAULT; 73.353 - 73.354 - read_lock(&tasklist_lock); 73.355 - if (likely(child->sighand != NULL)) { 73.356 - error = -EINVAL; 73.357 - spin_lock_irq(&child->sighand->siglock); 73.358 - if (likely(child->last_siginfo != NULL)) { 73.359 - *child->last_siginfo = newinfo; 73.360 - error = 0; 73.361 - } 73.362 - spin_unlock_irq(&child->sighand->siglock); 73.363 - } 73.364 - read_unlock(&tasklist_lock); 73.365 - return error; 73.366 -} 73.367 - 73.368 -int ptrace_request(struct task_struct *child, long request, 73.369 - long addr, long data) 73.370 -{ 73.371 - int ret = -EIO; 73.372 - 73.373 - switch (request) { 73.374 -#ifdef PTRACE_OLDSETOPTIONS 73.375 - case PTRACE_OLDSETOPTIONS: 73.376 -#endif 73.377 - case PTRACE_SETOPTIONS: 73.378 - ret = ptrace_setoptions(child, data); 73.379 - break; 73.380 - case PTRACE_GETEVENTMSG: 73.381 - ret = put_user(child->ptrace_message, (unsigned long __user *) data); 73.382 - break; 73.383 - case PTRACE_GETSIGINFO: 73.384 - ret = ptrace_getsiginfo(child, (siginfo_t __user *) data); 73.385 - break; 73.386 - case PTRACE_SETSIGINFO: 73.387 - ret = ptrace_setsiginfo(child, (siginfo_t __user *) data); 73.388 - break; 73.389 - default: 73.390 - break; 73.391 - } 73.392 - 73.393 - return ret; 73.394 -}
74.1 --- a/linux-2.6-xen-sparse/mm/memory.c Tue Aug 02 02:47:41 2005 -0800 74.2 +++ b/linux-2.6-xen-sparse/mm/memory.c Tue Aug 02 10:20:46 2005 -0700 74.3 @@ -1814,12 +1814,12 @@ do_anonymous_page(struct mm_struct *mm, 74.4 page_add_anon_rmap(page, vma, addr); 74.5 } 74.6 74.7 - set_pte_at(vma, addr, page_table, entry); 74.8 + set_pte_at(mm, addr, page_table, entry); 74.9 pte_unmap(page_table); 74.10 74.11 /* No need to invalidate - it was non-present before */ 74.12 update_mmu_cache(vma, addr, entry); 74.13 - lazy_mmu_prot_update(entry); 74.14 + lazy_mmu_prot_update(entry); 74.15 spin_unlock(&mm->page_table_lock); 74.16 out: 74.17 return VM_FAULT_MINOR; 74.18 @@ -1928,7 +1928,7 @@ retry: 74.19 entry = mk_pte(new_page, vma->vm_page_prot); 74.20 if (write_access) 74.21 entry = maybe_mkwrite(pte_mkdirty(entry), vma); 74.22 - set_pte_at(vma, address, page_table, entry); 74.23 + set_pte_at(mm, address, page_table, entry); 74.24 if (anon) { 74.25 lru_cache_add_active(new_page); 74.26 page_add_anon_rmap(new_page, vma, address);
76.1 --- a/tools/Makefile Tue Aug 02 02:47:41 2005 -0800 76.2 +++ b/tools/Makefile Tue Aug 02 10:20:46 2005 -0700 76.3 @@ -10,9 +10,10 @@ SUBDIRS += xentrace 76.4 SUBDIRS += python 76.5 SUBDIRS += xcs 76.6 SUBDIRS += xcutils 76.7 -SUBDIRS += pygrub 76.8 +#SUBDIRS += pygrub 76.9 SUBDIRS += firmware 76.10 -SUBDIRS += policy 76.11 +SUBDIRS += security 76.12 +#SUBDIRS += consoled 76.13 76.14 .PHONY: all install clean check check_clean ioemu eioemuinstall ioemuclean 76.15
77.1 --- a/tools/Rules.mk Tue Aug 02 02:47:41 2005 -0800 77.2 +++ b/tools/Rules.mk Tue Aug 02 10:20:46 2005 -0700 77.3 @@ -4,6 +4,8 @@ include $(XEN_ROOT)/Config.mk 77.4 77.5 XEN_XC = $(XEN_ROOT)/tools/python/xen/lowlevel/xc 77.6 XEN_LIBXC = $(XEN_ROOT)/tools/libxc 77.7 +XEN_XCS = $(XEN_ROOT)/tools/xcs 77.8 +XEN_XENSTORE = $(XEN_ROOT)/tools/xenstore 77.9 77.10 ifeq ($(XEN_TARGET_ARCH),x86_32) 77.11 CFLAGS += -m32 -march=i686
78.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 78.2 +++ b/tools/consoled/Makefile Tue Aug 02 10:20:46 2005 -0700 78.3 @@ -0,0 +1,48 @@ 78.4 +# Makefile for consoled 78.5 +# based on xcs Makefile 78.6 +# Anthony Liguori 2005 78.7 + 78.8 +XEN_ROOT=../.. 78.9 +include $(XEN_ROOT)/tools/Rules.mk 78.10 + 78.11 +CONSOLED_INSTALL_DIR = /usr/sbin 78.12 +XC_CONSOLE_INSTALL_DIR = /usr/libexec/xen 78.13 + 78.14 +INSTALL = install 78.15 +INSTALL_PROG = $(INSTALL) -m0755 78.16 +INSTALL_DIR = $(INSTALL) -d -m0755 78.17 + 78.18 +CC = gcc 78.19 +CFLAGS = -Wall -Werror -g3 78.20 + 78.21 +CFLAGS += -I $(XEN_XCS) 78.22 +CFLAGS += -I $(XEN_LIBXC) 78.23 +CFLAGS += -I $(XEN_XENSTORE) 78.24 + 78.25 +SRCS := 78.26 +SRCS += main.c utils.c io.c 78.27 + 78.28 +HDRS = $(wildcard *.h) 78.29 +OBJS = $(patsubst %.c,%.o,$(SRCS)) 78.30 +BIN = consoled xc_console 78.31 + 78.32 +all: $(BIN) 78.33 + 78.34 +clean: 78.35 + $(RM) *.a *.so *.o *.rpm $(BIN) 78.36 + 78.37 +consoled: $(OBJS) 78.38 + $(CC) $(CFLAGS) $^ -o $@ -L$(XEN_LIBXC) -L$(XEN_XENSTORE) \ 78.39 + -lxc -lxenstore 78.40 + 78.41 +xc_console: xc_console.o 78.42 + $(CC) $(CFLAGS) $^ -o $@ -L$(XEN_LIBXC) -L$(XEN_XENSTORE) \ 78.43 + -lxc -lxenstore 78.44 + 78.45 +$(OBJS): $(HDRS) 78.46 + 78.47 +install: $(BIN) 78.48 + $(INSTALL_DIR) -p $(DESTDIR)/$(CONSOLED_INSTALL_DIR) 78.49 + $(INSTALL_PROG) consoled $(DESTDIR)/$(CONSOLED_INSTALL_DIR) 78.50 + $(INSTALL_DIR) -p $(DESTDIR)/$(XC_CONSOLE_INSTALL_DIR) 78.51 + $(INSTALL_PROG) xc_console $(DESTDIR)/$(XC_CONSOLE_INSTALL_DIR)
79.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 79.2 +++ b/tools/consoled/io.c Tue Aug 02 10:20:46 2005 -0700 79.3 @@ -0,0 +1,328 @@ 79.4 +/*\ 79.5 + * Copyright (C) International Business Machines Corp., 2005 79.6 + * Author(s): Anthony Liguori <aliguori@us.ibm.com> 79.7 + * 79.8 + * Xen Console Daemon 79.9 + * 79.10 + * This program is free software; you can redistribute it and/or modify 79.11 + * it under the terms of the GNU General Public License as published by 79.12 + * the Free Software Foundation; under version 2 of the License. 79.13 + * 79.14 + * This program is distributed in the hope that it will be useful, 79.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 79.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 79.17 + * GNU General Public License for more details. 79.18 + * 79.19 + * You should have received a copy of the GNU General Public License 79.20 + * along with this program; if not, write to the Free Software 79.21 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 79.22 +\*/ 79.23 + 79.24 +#define _GNU_SOURCE 79.25 + 79.26 +#include "utils.h" 79.27 +#include "io.h" 79.28 + 79.29 +#include "xc.h" 79.30 +#include "xs.h" 79.31 +#include "xen/io/domain_controller.h" 79.32 +#include "xcs_proto.h" 79.33 + 79.34 +#include <malloc.h> 79.35 +#include <stdlib.h> 79.36 +#include <errno.h> 79.37 +#include <string.h> 79.38 +#include <sys/select.h> 79.39 +#include <fcntl.h> 79.40 +#include <unistd.h> 79.41 +#include <termios.h> 79.42 + 79.43 +#define MAX(a, b) (((a) > (b)) ? (a) : (b)) 79.44 +#define MIN(a, b) (((a) < (b)) ? (a) : (b)) 79.45 + 79.46 +struct buffer 79.47 +{ 79.48 + char *data; 79.49 + size_t size; 79.50 + size_t capacity; 79.51 + size_t max_capacity; 79.52 +}; 79.53 + 79.54 +void buffer_append(struct buffer *buffer, const void *data, size_t size) 79.55 +{ 79.56 + if ((buffer->capacity - buffer->size) < size) { 79.57 + buffer->capacity += (size + 1024); 79.58 + buffer->data = realloc(buffer->data, buffer->capacity); 79.59 + if (buffer->data == NULL) { 79.60 + dolog(LOG_ERR, "Memory allocation failed"); 79.61 + exit(ENOMEM); 79.62 + } 79.63 + } 79.64 + 79.65 + memcpy(buffer->data + buffer->size, data, size); 79.66 + buffer->size += size; 79.67 + 79.68 + if (buffer->max_capacity && 79.69 + buffer->size > buffer->max_capacity) { 79.70 + memmove(buffer->data + (buffer->size - buffer->max_capacity), 79.71 + buffer->data, buffer->max_capacity); 79.72 + buffer->data = realloc(buffer->data, buffer->max_capacity); 79.73 + buffer->capacity = buffer->max_capacity; 79.74 + } 79.75 +} 79.76 + 79.77 +bool buffer_empty(struct buffer *buffer) 79.78 +{ 79.79 + return buffer->size == 0; 79.80 +} 79.81 + 79.82 +void buffer_advance(struct buffer *buffer, size_t size) 79.83 +{ 79.84 + size = MIN(size, buffer->size); 79.85 + memmove(buffer->data, buffer + size, buffer->size - size); 79.86 + buffer->size -= size; 79.87 +} 79.88 + 79.89 +struct domain 79.90 +{ 79.91 + int domid; 79.92 + int tty_fd; 79.93 + struct buffer buffer; 79.94 + struct domain *next; 79.95 +}; 79.96 + 79.97 +static struct domain *dom_head; 79.98 + 79.99 +bool domain_is_valid(int domid) 79.100 +{ 79.101 + bool ret; 79.102 + xc_dominfo_t info; 79.103 + 79.104 + ret = (xc_domain_getinfo(xc, domid, 1, &info) == 1 && 79.105 + info.domid == domid); 79.106 + 79.107 + return ret; 79.108 +} 79.109 + 79.110 +int domain_create_tty(int domid) 79.111 +{ 79.112 + char path[1024]; 79.113 + int master; 79.114 + 79.115 + if ((master = getpt()) == -1 || 79.116 + grantpt(master) == -1 || unlockpt(master) == -1) { 79.117 + dolog(LOG_ERR, "Failed to create tty for domain-%d", domid); 79.118 + master = -1; 79.119 + } else { 79.120 + const char *slave = ptsname(master); 79.121 + struct termios term; 79.122 + 79.123 + if (tcgetattr(master, &term) != -1) { 79.124 + cfmakeraw(&term); 79.125 + tcsetattr(master, TCSAFLUSH, &term); 79.126 + } 79.127 + 79.128 + xs_mkdir(xs, "/console"); 79.129 + snprintf(path, sizeof(path), "/console/%d", domid); 79.130 + xs_mkdir(xs, path); 79.131 + strcat(path, "/tty"); 79.132 + 79.133 + xs_write(xs, path, slave, strlen(slave), O_CREAT); 79.134 + } 79.135 + 79.136 + return master; 79.137 +} 79.138 + 79.139 +struct domain *create_domain(int domid) 79.140 +{ 79.141 + struct domain *dom; 79.142 + char *data; 79.143 + unsigned int len; 79.144 + char path[1024]; 79.145 + 79.146 + dom = (struct domain *)malloc(sizeof(struct domain)); 79.147 + if (dom == NULL) { 79.148 + dolog(LOG_ERR, "Out of memory %s:%s():L%d", 79.149 + __FILE__, __FUNCTION__, __LINE__); 79.150 + exit(ENOMEM); 79.151 + } 79.152 + 79.153 + dom->domid = domid; 79.154 + dom->tty_fd = domain_create_tty(domid); 79.155 + dom->buffer.data = 0; 79.156 + dom->buffer.size = 0; 79.157 + dom->buffer.capacity = 0; 79.158 + dom->buffer.max_capacity = 0; 79.159 + 79.160 + snprintf(path, sizeof(path), "/console/%d/limit", domid); 79.161 + data = xs_read(xs, path, &len); 79.162 + if (data) { 79.163 + dom->buffer.max_capacity = strtoul(data, 0, 0); 79.164 + free(data); 79.165 + } 79.166 + 79.167 + dolog(LOG_DEBUG, "New domain %d", domid); 79.168 + 79.169 + return dom; 79.170 +} 79.171 + 79.172 +struct domain *lookup_domain(int domid) 79.173 +{ 79.174 + struct domain **pp; 79.175 + 79.176 + for (pp = &dom_head; *pp; pp = &(*pp)->next) { 79.177 + struct domain *dom = *pp; 79.178 + 79.179 + if (dom->domid == domid) { 79.180 + return dom; 79.181 + } else if (dom->domid > domid) { 79.182 + *pp = create_domain(domid); 79.183 + (*pp)->next = dom; 79.184 + return *pp; 79.185 + } 79.186 + } 79.187 + 79.188 + *pp = create_domain(domid); 79.189 + return *pp; 79.190 +} 79.191 + 79.192 +void remove_domain(struct domain *dom) 79.193 +{ 79.194 + struct domain **pp; 79.195 + 79.196 + dolog(LOG_DEBUG, "Removing domain-%d", dom->domid); 79.197 + 79.198 + for (pp = &dom_head; *pp; pp = &(*pp)->next) { 79.199 + struct domain *d = *pp; 79.200 + 79.201 + if (dom->domid == d->domid) { 79.202 + *pp = d->next; 79.203 + free(d); 79.204 + break; 79.205 + } 79.206 + } 79.207 +} 79.208 + 79.209 +void handle_tty_read(struct domain *dom) 79.210 +{ 79.211 + ssize_t len; 79.212 + xcs_msg_t msg; 79.213 + 79.214 + msg.type = XCS_REQUEST; 79.215 + msg.u.control.remote_dom = dom->domid; 79.216 + msg.u.control.msg.type = CMSG_CONSOLE; 79.217 + msg.u.control.msg.subtype = CMSG_CONSOLE_DATA; 79.218 + msg.u.control.msg.id = 1; 79.219 + 79.220 + len = read(dom->tty_fd, msg.u.control.msg.msg, 60); 79.221 + if (len < 1) { 79.222 + close(dom->tty_fd); 79.223 + 79.224 + if (domain_is_valid(dom->domid)) { 79.225 + dom->tty_fd = domain_create_tty(dom->domid); 79.226 + } else { 79.227 + remove_domain(dom); 79.228 + } 79.229 + } else if (domain_is_valid(dom->domid)) { 79.230 + msg.u.control.msg.length = len; 79.231 + 79.232 + if (!write_sync(xcs_data_fd, &msg, sizeof(msg))) { 79.233 + dolog(LOG_ERR, "Write to xcs failed: %m"); 79.234 + } 79.235 + } else { 79.236 + close(dom->tty_fd); 79.237 + remove_domain(dom); 79.238 + } 79.239 +} 79.240 + 79.241 +void handle_tty_write(struct domain *dom) 79.242 +{ 79.243 + ssize_t len; 79.244 + 79.245 + len = write(dom->tty_fd, dom->buffer.data, dom->buffer.size); 79.246 + if (len < 1) { 79.247 + close(dom->tty_fd); 79.248 + 79.249 + if (domain_is_valid(dom->domid)) { 79.250 + dom->tty_fd = domain_create_tty(dom->domid); 79.251 + } else { 79.252 + remove_domain(dom); 79.253 + } 79.254 + } else { 79.255 + buffer_advance(&dom->buffer, len); 79.256 + } 79.257 +} 79.258 + 79.259 +void handle_xcs_msg(int fd) 79.260 +{ 79.261 + xcs_msg_t msg; 79.262 + 79.263 + if (!read_sync(fd, &msg, sizeof(msg))) { 79.264 + dolog(LOG_ERR, "read from xcs failed! %m"); 79.265 + } else if (msg.type == XCS_REQUEST) { 79.266 + struct domain *dom; 79.267 + 79.268 + dom = lookup_domain(msg.u.control.remote_dom); 79.269 + buffer_append(&dom->buffer, 79.270 + msg.u.control.msg.msg, 79.271 + msg.u.control.msg.length); 79.272 + } 79.273 +} 79.274 + 79.275 +static void enum_domains(void) 79.276 +{ 79.277 + int domid = 0; 79.278 + xc_dominfo_t dominfo; 79.279 + 79.280 + while (xc_domain_getinfo(xc, domid, 1, &dominfo) == 1) { 79.281 + lookup_domain(dominfo.domid); 79.282 + domid = dominfo.domid + 1; 79.283 + } 79.284 +} 79.285 + 79.286 +void handle_io(void) 79.287 +{ 79.288 + fd_set readfds, writefds; 79.289 + int ret; 79.290 + int max_fd = -1; 79.291 + 79.292 + do { 79.293 + struct domain *d; 79.294 + struct timeval tv = { 1, 0 }; 79.295 + 79.296 + FD_ZERO(&readfds); 79.297 + FD_ZERO(&writefds); 79.298 + 79.299 + FD_SET(xcs_data_fd, &readfds); 79.300 + max_fd = MAX(xcs_data_fd, max_fd); 79.301 + 79.302 + for (d = dom_head; d; d = d->next) { 79.303 + if (d->tty_fd != -1) { 79.304 + FD_SET(d->tty_fd, &readfds); 79.305 + } 79.306 + 79.307 + if (d->tty_fd != -1 && !buffer_empty(&d->buffer)) { 79.308 + FD_SET(d->tty_fd, &writefds); 79.309 + } 79.310 + 79.311 + max_fd = MAX(d->tty_fd, max_fd); 79.312 + } 79.313 + 79.314 + ret = select(max_fd + 1, &readfds, &writefds, 0, &tv); 79.315 + enum_domains(); 79.316 + 79.317 + if (FD_ISSET(xcs_data_fd, &readfds)) { 79.318 + handle_xcs_msg(xcs_data_fd); 79.319 + } 79.320 + 79.321 + for (d = dom_head; d; d = d->next) { 79.322 + if (FD_ISSET(d->tty_fd, &readfds)) { 79.323 + handle_tty_read(d); 79.324 + } 79.325 + 79.326 + if (FD_ISSET(d->tty_fd, &writefds)) { 79.327 + handle_tty_write(d); 79.328 + } 79.329 + } 79.330 + } while (ret > -1); 79.331 +}
80.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 80.2 +++ b/tools/consoled/io.h Tue Aug 02 10:20:46 2005 -0700 80.3 @@ -0,0 +1,26 @@ 80.4 +/*\ 80.5 + * Copyright (C) International Business Machines Corp., 2005 80.6 + * Author(s): Anthony Liguori <aliguori@us.ibm.com> 80.7 + * 80.8 + * Xen Console Daemon 80.9 + * 80.10 + * This program is free software; you can redistribute it and/or modify 80.11 + * it under the terms of the GNU General Public License as published by 80.12 + * the Free Software Foundation; under version 2 of the License. 80.13 + * 80.14 + * This program is distributed in the hope that it will be useful, 80.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 80.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 80.17 + * GNU General Public License for more details. 80.18 + * 80.19 + * You should have received a copy of the GNU General Public License 80.20 + * along with this program; if not, write to the Free Software 80.21 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 80.22 +\*/ 80.23 + 80.24 +#ifndef CONSOLED_IO_H 80.25 +#define CONSOLED_IO_H 80.26 + 80.27 +void handle_io(void); 80.28 + 80.29 +#endif
81.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 81.2 +++ b/tools/consoled/main.c Tue Aug 02 10:20:46 2005 -0700 81.3 @@ -0,0 +1,93 @@ 81.4 +/*\ 81.5 + * Copyright (C) International Business Machines Corp., 2005 81.6 + * Author(s): Anthony Liguori <aliguori@us.ibm.com> 81.7 + * 81.8 + * Xen Console Daemon 81.9 + * 81.10 + * This program is free software; you can redistribute it and/or modify 81.11 + * it under the terms of the GNU General Public License as published by 81.12 + * the Free Software Foundation; under version 2 of the License. 81.13 + * 81.14 + * This program is distributed in the hope that it will be useful, 81.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 81.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 81.17 + * GNU General Public License for more details. 81.18 + * 81.19 + * You should have received a copy of the GNU General Public License 81.20 + * along with this program; if not, write to the Free Software 81.21 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 81.22 +\*/ 81.23 + 81.24 +#include <getopt.h> 81.25 +#include <stdlib.h> 81.26 +#include <stdio.h> 81.27 +#include <errno.h> 81.28 +#include <unistd.h> 81.29 +#include <sys/types.h> 81.30 + 81.31 +#include "xc.h" 81.32 +#include "xen/io/domain_controller.h" 81.33 +#include "xcs_proto.h" 81.34 + 81.35 +#include "utils.h" 81.36 +#include "io.h" 81.37 + 81.38 +int main(int argc, char **argv) 81.39 +{ 81.40 + const char *sopts = "hVvi"; 81.41 + struct option lopts[] = { 81.42 + { "help", 0, 0, 'h' }, 81.43 + { "version", 0, 0, 'V' }, 81.44 + { "verbose", 0, 0, 'v' }, 81.45 + { "interactive", 0, 0, 'i' }, 81.46 + { 0 }, 81.47 + }; 81.48 + bool is_interactive = false; 81.49 + int ch; 81.50 + int syslog_option = LOG_CONS; 81.51 + int syslog_mask = LOG_WARNING; 81.52 + int opt_ind = 0; 81.53 + 81.54 + while ((ch = getopt_long(argc, argv, sopts, lopts, &opt_ind)) != -1) { 81.55 + switch (ch) { 81.56 + case 'h': 81.57 + //usage(argv[0]); 81.58 + exit(0); 81.59 + case 'V': 81.60 + //version(argv[0]); 81.61 + exit(0); 81.62 + case 'v': 81.63 + syslog_option |= LOG_PERROR; 81.64 + syslog_mask = LOG_DEBUG; 81.65 + break; 81.66 + case 'i': 81.67 + is_interactive = true; 81.68 + break; 81.69 + case '?': 81.70 + fprintf(stderr, 81.71 + "Try `%s --help' for more information\n", 81.72 + argv[0]); 81.73 + exit(EINVAL); 81.74 + } 81.75 + } 81.76 + 81.77 + if (geteuid() != 0) { 81.78 + fprintf(stderr, "%s requires root to run.\n", argv[0]); 81.79 + exit(EPERM); 81.80 + } 81.81 + 81.82 + openlog("consoled", syslog_option, LOG_DAEMON); 81.83 + setlogmask(syslog_mask); 81.84 + 81.85 + if (!is_interactive) { 81.86 + daemonize("/var/run/consoled.pid"); 81.87 + } 81.88 + 81.89 + xen_setup(); 81.90 + 81.91 + handle_io(); 81.92 + 81.93 + closelog(); 81.94 + 81.95 + return 0; 81.96 +}
82.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 82.2 +++ b/tools/consoled/utils.c Tue Aug 02 10:20:46 2005 -0700 82.3 @@ -0,0 +1,251 @@ 82.4 +/*\ 82.5 + * Copyright (C) International Business Machines Corp., 2005 82.6 + * Author(s): Anthony Liguori <aliguori@us.ibm.com> 82.7 + * 82.8 + * Xen Console Daemon 82.9 + * 82.10 + * This program is free software; you can redistribute it and/or modify 82.11 + * it under the terms of the GNU General Public License as published by 82.12 + * the Free Software Foundation; under version 2 of the License. 82.13 + * 82.14 + * This program is distributed in the hope that it will be useful, 82.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 82.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 82.17 + * GNU General Public License for more details. 82.18 + * 82.19 + * You should have received a copy of the GNU General Public License 82.20 + * along with this program; if not, write to the Free Software 82.21 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 82.22 +\*/ 82.23 + 82.24 +#include <sys/types.h> 82.25 +#include <sys/stat.h> 82.26 +#include <sys/wait.h> 82.27 +#include <unistd.h> 82.28 +#include <stdlib.h> 82.29 +#include <fcntl.h> 82.30 +#include <err.h> 82.31 +#include <errno.h> 82.32 +#include <stdio.h> 82.33 +#include <getopt.h> 82.34 +#include <stdbool.h> 82.35 +#include <sys/socket.h> 82.36 +#include <sys/un.h> 82.37 +#include <string.h> 82.38 + 82.39 +#include "xc.h" 82.40 +#include "xen/io/domain_controller.h" 82.41 +#include "xcs_proto.h" 82.42 + 82.43 +#include "utils.h" 82.44 + 82.45 +struct xs_handle *xs; 82.46 +int xc; 82.47 + 82.48 +int xcs_ctrl_fd = -1; 82.49 +int xcs_data_fd = -1; 82.50 + 82.51 +bool _read_write_sync(int fd, void *data, size_t size, bool do_read) 82.52 +{ 82.53 + size_t offset = 0; 82.54 + ssize_t len; 82.55 + 82.56 + while (offset < size) { 82.57 + if (do_read) { 82.58 + len = read(fd, data + offset, size - offset); 82.59 + } else { 82.60 + len = write(fd, data + offset, size - offset); 82.61 + } 82.62 + 82.63 + if (len < 1) { 82.64 + if (len == -1 && (errno == EAGAIN || errno == EINTR)) { 82.65 + return false; 82.66 + } 82.67 + } else { 82.68 + offset += len; 82.69 + } 82.70 + } 82.71 + 82.72 + return true; 82.73 +} 82.74 + 82.75 +static int open_domain_socket(const char *path) 82.76 +{ 82.77 + struct sockaddr_un addr; 82.78 + int sock; 82.79 + size_t addr_len; 82.80 + 82.81 + if ((sock = socket(PF_UNIX, SOCK_STREAM, 0)) == -1) { 82.82 + goto out; 82.83 + } 82.84 + 82.85 + addr.sun_family = AF_UNIX; 82.86 + strcpy(addr.sun_path, path); 82.87 + addr_len = sizeof(addr.sun_family) + strlen(XCS_SUN_PATH) + 1; 82.88 + 82.89 + if (connect(sock, (struct sockaddr *)&addr, addr_len) == -1) { 82.90 + goto out_close_sock; 82.91 + } 82.92 + 82.93 + return sock; 82.94 + 82.95 + out_close_sock: 82.96 + close(sock); 82.97 + out: 82.98 + return -1; 82.99 +} 82.100 + 82.101 +static void child_exit(int sig) 82.102 +{ 82.103 + while (waitpid(-1, NULL, WNOHANG) > 0); 82.104 +} 82.105 + 82.106 +void daemonize(const char *pidfile) 82.107 +{ 82.108 + pid_t pid; 82.109 + int fd; 82.110 + int len; 82.111 + int i; 82.112 + char buf[100]; 82.113 + 82.114 + if (getppid() == 1) { 82.115 + return; 82.116 + } 82.117 + 82.118 + if ((pid = fork()) > 0) { 82.119 + exit(0); 82.120 + } else if (pid == -1) { 82.121 + err(errno, "fork() failed"); 82.122 + } 82.123 + 82.124 + setsid(); 82.125 + 82.126 + /* redirect fd 0,1,2 to /dev/null */ 82.127 + if ((fd = open("/dev/null",O_RDWR)) == -1) { 82.128 + exit(1); 82.129 + } 82.130 + 82.131 + for (i = 0; i <= 2; i++) { 82.132 + close(i); 82.133 + dup2(fd, i); 82.134 + } 82.135 + 82.136 + close(fd); 82.137 + 82.138 + umask(027); 82.139 + chdir("/"); 82.140 + 82.141 + fd = open(pidfile, O_RDWR | O_CREAT); 82.142 + if (fd == -1) { 82.143 + exit(1); 82.144 + } 82.145 + 82.146 + if (lockf(fd, F_TLOCK, 0) == -1) { 82.147 + exit(1); 82.148 + } 82.149 + 82.150 + len = sprintf(buf, "%d\n", getpid()); 82.151 + write(fd, buf, len); 82.152 + 82.153 + signal(SIGCHLD, child_exit); 82.154 + signal(SIGTSTP, SIG_IGN); 82.155 + signal(SIGTTOU, SIG_IGN); 82.156 + signal(SIGTTIN, SIG_IGN); 82.157 +} 82.158 + 82.159 +/* synchronized send/recv strictly for setting up xcs */ 82.160 +/* always use asychronize callbacks any other time */ 82.161 +static bool xcs_send_recv(int fd, xcs_msg_t *msg) 82.162 +{ 82.163 + bool ret = false; 82.164 + 82.165 + if (!write_sync(fd, msg, sizeof(*msg))) { 82.166 + dolog(LOG_ERR, "Write failed at %s:%s():L%d? Possible bug.", 82.167 + __FILE__, __FUNCTION__, __LINE__); 82.168 + goto out; 82.169 + } 82.170 + 82.171 + if (!read_sync(fd, msg, sizeof(*msg))) { 82.172 + dolog(LOG_ERR, "Read failed at %s:%s():L%d? Possible bug.", 82.173 + __FILE__, __FUNCTION__, __LINE__); 82.174 + goto out; 82.175 + } 82.176 + 82.177 + ret = true; 82.178 + 82.179 + out: 82.180 + return ret; 82.181 +} 82.182 + 82.183 +bool xen_setup(void) 82.184 +{ 82.185 + int sock; 82.186 + xcs_msg_t msg; 82.187 + 82.188 + xs = xs_daemon_open(); 82.189 + if (xs == NULL) { 82.190 + dolog(LOG_ERR, 82.191 + "Failed to contact xenstore (%m). Is it running?"); 82.192 + goto out; 82.193 + } 82.194 + 82.195 + xc = xc_interface_open(); 82.196 + if (xc == -1) { 82.197 + dolog(LOG_ERR, "Failed to contact hypervisor (%m)"); 82.198 + goto out; 82.199 + } 82.200 + 82.201 + sock = open_domain_socket(XCS_SUN_PATH); 82.202 + if (sock == -1) { 82.203 + dolog(LOG_ERR, "Failed to contact xcs (%m). Is it running?"); 82.204 + goto out_close_store; 82.205 + } 82.206 + 82.207 + xcs_ctrl_fd = sock; 82.208 + 82.209 + sock = open_domain_socket(XCS_SUN_PATH); 82.210 + if (sock == -1) { 82.211 + dolog(LOG_ERR, "Failed to contact xcs (%m). Is it running?"); 82.212 + goto out_close_ctrl; 82.213 + } 82.214 + 82.215 + xcs_data_fd = sock; 82.216 + 82.217 + memset(&msg, 0, sizeof(msg)); 82.218 + msg.type = XCS_CONNECT_CTRL; 82.219 + if (!xcs_send_recv(xcs_ctrl_fd, &msg) || msg.result != XCS_RSLT_OK) { 82.220 + dolog(LOG_ERR, "xcs control connect failed. Possible bug."); 82.221 + goto out_close_data; 82.222 + } 82.223 + 82.224 + msg.type = XCS_CONNECT_DATA; 82.225 + if (!xcs_send_recv(xcs_data_fd, &msg) || msg.result != XCS_RSLT_OK) { 82.226 + dolog(LOG_ERR, "xcs data connect failed. Possible bug."); 82.227 + goto out_close_data; 82.228 + } 82.229 + 82.230 + /* Since the vast majority of control messages are console messages 82.231 + it's just easier to ignore other messages that try to bind to 82.232 + a specific type. */ 82.233 + msg.type = XCS_MSG_BIND; 82.234 + msg.u.bind.port = PORT_WILDCARD; 82.235 + msg.u.bind.type = TYPE_WILDCARD; 82.236 + if (!xcs_send_recv(xcs_ctrl_fd, &msg) || msg.result != XCS_RSLT_OK) { 82.237 + dolog(LOG_ERR, "xcs vind failed. Possible bug."); 82.238 + goto out_close_data; 82.239 + } 82.240 + 82.241 + return true; 82.242 + 82.243 + out_close_data: 82.244 + close(xcs_ctrl_fd); 82.245 + xcs_data_fd = -1; 82.246 + out_close_ctrl: 82.247 + close(xcs_ctrl_fd); 82.248 + xcs_ctrl_fd = -1; 82.249 + out_close_store: 82.250 + xs_daemon_close(xs); 82.251 + out: 82.252 + return false; 82.253 +} 82.254 +
83.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 83.2 +++ b/tools/consoled/utils.h Tue Aug 02 10:20:46 2005 -0700 83.3 @@ -0,0 +1,47 @@ 83.4 +/*\ 83.5 + * Copyright (C) International Business Machines Corp., 2005 83.6 + * Author(s): Anthony Liguori <aliguori@us.ibm.com> 83.7 + * 83.8 + * Xen Console Daemon 83.9 + * 83.10 + * This program is free software; you can redistribute it and/or modify 83.11 + * it under the terms of the GNU General Public License as published by 83.12 + * the Free Software Foundation; under version 2 of the License. 83.13 + * 83.14 + * This program is distributed in the hope that it will be useful, 83.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 83.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 83.17 + * GNU General Public License for more details. 83.18 + * 83.19 + * You should have received a copy of the GNU General Public License 83.20 + * along with this program; if not, write to the Free Software 83.21 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 83.22 +\*/ 83.23 + 83.24 +#ifndef CONSOLED_UTILS_H 83.25 +#define CONSOLED_UTILS_H 83.26 + 83.27 +#include <stdbool.h> 83.28 +#include <syslog.h> 83.29 +#include <stdio.h> 83.30 + 83.31 +#include "xs.h" 83.32 + 83.33 +void daemonize(const char *pidfile); 83.34 +bool xen_setup(void); 83.35 +#define read_sync(fd, buffer, size) _read_write_sync(fd, buffer, size, true) 83.36 +#define write_sync(fd, buffer, size) _read_write_sync(fd, buffer, size, false) 83.37 +bool _read_write_sync(int fd, void *data, size_t size, bool do_read); 83.38 + 83.39 +extern int xcs_ctrl_fd; 83.40 +extern int xcs_data_fd; 83.41 +extern struct xs_handle *xs; 83.42 +extern int xc; 83.43 + 83.44 +#if 1 83.45 +#define dolog(val, fmt, ...) syslog(val, fmt, ## __VA_ARGS__) 83.46 +#else 83.47 +#define dolog(val, fmt, ...) fprintf(stderr, fmt "\n", ## __VA_ARGS__) 83.48 +#endif 83.49 + 83.50 +#endif
84.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 84.2 +++ b/tools/consoled/xc_console.c Tue Aug 02 10:20:46 2005 -0700 84.3 @@ -0,0 +1,236 @@ 84.4 +/*\ 84.5 + * Copyright (C) International Business Machines Corp., 2005 84.6 + * Author(s): Anthony Liguori <aliguori@us.ibm.com> 84.7 + * 84.8 + * Xen Console Daemon 84.9 + * 84.10 + * This program is free software; you can redistribute it and/or modify 84.11 + * it under the terms of the GNU General Public License as published by 84.12 + * the Free Software Foundation; under version 2 of the License. 84.13 + * 84.14 + * This program is distributed in the hope that it will be useful, 84.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 84.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 84.17 + * GNU General Public License for more details. 84.18 + * 84.19 + * You should have received a copy of the GNU General Public License 84.20 + * along with this program; if not, write to the Free Software 84.21 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 84.22 +\*/ 84.23 + 84.24 +#include <sys/types.h> 84.25 +#include <sys/socket.h> 84.26 +#include <sys/un.h> 84.27 +#include <stdio.h> 84.28 +#include <unistd.h> 84.29 +#include <errno.h> 84.30 +#include <stdlib.h> 84.31 +#include <time.h> 84.32 +#include <fcntl.h> 84.33 +#include <sys/wait.h> 84.34 +#include <termios.h> 84.35 +#include <signal.h> 84.36 +#include <getopt.h> 84.37 +#include <sys/select.h> 84.38 +#include <err.h> 84.39 +#include <errno.h> 84.40 +#include <pty.h> 84.41 + 84.42 +#include "xc.h" 84.43 +#include "xs.h" 84.44 + 84.45 +#define ESCAPE_CHARACTER 0x1d 84.46 + 84.47 +static volatile sig_atomic_t received_signal = 0; 84.48 + 84.49 +static void sighandler(int signum) 84.50 +{ 84.51 + received_signal = 1; 84.52 +} 84.53 + 84.54 +static bool write_sync(int fd, const void *data, size_t size) 84.55 +{ 84.56 + size_t offset = 0; 84.57 + ssize_t len; 84.58 + 84.59 + while (offset < size) { 84.60 + len = write(fd, data + offset, size - offset); 84.61 + if (len < 1) { 84.62 + return false; 84.63 + } 84.64 + offset += len; 84.65 + } 84.66 + 84.67 + return true; 84.68 +} 84.69 + 84.70 +static void usage(const char *program) { 84.71 + printf("Usage: %s [OPTION] DOMID\n" 84.72 + "Attaches to a virtual domain console\n" 84.73 + "\n" 84.74 + " -h, --help display this help and exit\n" 84.75 + , program); 84.76 +} 84.77 + 84.78 +/* don't worry too much if setting terminal attributes fail */ 84.79 +static void init_term(int fd, struct termios *old) 84.80 +{ 84.81 + struct termios new_term; 84.82 + 84.83 + if (tcgetattr(fd, old) == -1) { 84.84 + perror("tcgetattr() failed"); 84.85 + return; 84.86 + } 84.87 + 84.88 + new_term = *old; 84.89 + cfmakeraw(&new_term); 84.90 + 84.91 + if (tcsetattr(fd, TCSAFLUSH, &new_term) == -1) { 84.92 + perror("tcsetattr() failed"); 84.93 + } 84.94 +} 84.95 + 84.96 +static void restore_term(int fd, struct termios *old) 84.97 +{ 84.98 + if (tcsetattr(fd, TCSAFLUSH, old) == -1) { 84.99 + perror("tcsetattr() failed"); 84.100 + } 84.101 +} 84.102 + 84.103 +static int console_loop(int xc_handle, domid_t domid, int fd) 84.104 +{ 84.105 + int ret; 84.106 + 84.107 + do { 84.108 + fd_set fds; 84.109 + 84.110 + FD_ZERO(&fds); 84.111 + FD_SET(STDIN_FILENO, &fds); 84.112 + FD_SET(fd, &fds); 84.113 + 84.114 + ret = select(fd + 1, &fds, NULL, NULL, NULL); 84.115 + if (ret == -1) { 84.116 + if (errno == EINTR || errno == EAGAIN) { 84.117 + continue; 84.118 + } 84.119 + perror("select() failed"); 84.120 + return -1; 84.121 + } 84.122 + 84.123 + if (FD_ISSET(STDIN_FILENO, &fds)) { 84.124 + ssize_t len; 84.125 + char msg[60]; 84.126 + 84.127 + len = read(STDIN_FILENO, msg, sizeof(msg)); 84.128 + if (len == 1 && msg[0] == ESCAPE_CHARACTER) { 84.129 + return 0; 84.130 + } 84.131 + 84.132 + if (len == 0 && len == -1) { 84.133 + if (len == -1 && 84.134 + (errno == EINTR || errno == EAGAIN)) { 84.135 + continue; 84.136 + } 84.137 + perror("select() failed"); 84.138 + return -1; 84.139 + } 84.140 + 84.141 + if (!write_sync(fd, msg, len)) { 84.142 + perror("write() failed"); 84.143 + return -1; 84.144 + } 84.145 + } 84.146 + 84.147 + if (FD_ISSET(fd, &fds)) { 84.148 + ssize_t len; 84.149 + char msg[512]; 84.150 + 84.151 + len = read(fd, msg, sizeof(msg)); 84.152 + if (len == 0 || len == -1) { 84.153 + if (len == -1 && 84.154 + (errno == EINTR || errno == EAGAIN)) { 84.155 + continue; 84.156 + } 84.157 + perror("select() failed"); 84.158 + return -1; 84.159 + } 84.160 + 84.161 + if (!write_sync(STDOUT_FILENO, msg, len)) { 84.162 + perror("write() failed"); 84.163 + return -1; 84.164 + } 84.165 + } 84.166 + } while (received_signal == 0); 84.167 + 84.168 + return 0; 84.169 +} 84.170 + 84.171 +int main(int argc, char **argv) 84.172 +{ 84.173 + struct termios attr; 84.174 + int domid; 84.175 + int xc_handle; 84.176 + char *sopt = "hf:pc"; 84.177 + int ch; 84.178 + int opt_ind=0; 84.179 + struct option lopt[] = { 84.180 + { "help", 0, 0, 'h' }, 84.181 + { "file", 1, 0, 'f' }, 84.182 + { "pty", 0, 0, 'p' }, 84.183 + { "ctty", 0, 0, 'c' }, 84.184 + { 0 }, 84.185 + 84.186 + }; 84.187 + char *str_pty; 84.188 + char path[1024]; 84.189 + int spty; 84.190 + unsigned int len = 0; 84.191 + struct xs_handle *xs; 84.192 + 84.193 + while((ch = getopt_long(argc, argv, sopt, lopt, &opt_ind)) != -1) { 84.194 + switch(ch) { 84.195 + case 'h': 84.196 + usage(argv[0]); 84.197 + exit(0); 84.198 + break; 84.199 + } 84.200 + } 84.201 + 84.202 + if ((argc - optind) != 1) { 84.203 + fprintf(stderr, "Invalid number of arguments\n"); 84.204 + fprintf(stderr, "Try `%s --help' for more information.\n", 84.205 + argv[0]); 84.206 + exit(EINVAL); 84.207 + } 84.208 + 84.209 + domid = atoi(argv[optind]); 84.210 + 84.211 + xs = xs_daemon_open(); 84.212 + if (xs == NULL) { 84.213 + err(errno, "Could not contact XenStore"); 84.214 + } 84.215 + 84.216 + xc_handle = xc_interface_open(); 84.217 + if (xc_handle == -1) { 84.218 + err(errno, "xc_interface_open()"); 84.219 + } 84.220 + 84.221 + signal(SIGTERM, sighandler); 84.222 + 84.223 + snprintf(path, sizeof(path), "/console/%d/tty", domid); 84.224 + str_pty = xs_read(xs, path, &len); 84.225 + if (str_pty == NULL) { 84.226 + err(errno, "Could not read tty from store"); 84.227 + } 84.228 + spty = open(str_pty, O_RDWR | O_NOCTTY); 84.229 + if (spty == -1) { 84.230 + err(errno, "Could not open tty `%s'", str_pty); 84.231 + } 84.232 + free(str_pty); 84.233 + 84.234 + init_term(STDIN_FILENO, &attr); 84.235 + console_loop(xc_handle, domid, spty); 84.236 + restore_term(STDIN_FILENO, &attr); 84.237 + 84.238 + return 0; 84.239 + }
119.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 119.2 +++ b/tools/libxc/xc_ia64_stubs.c Tue Aug 02 10:20:46 2005 -0700 119.3 @@ -0,0 +1,39 @@ 119.4 +#include "xc_private.h" 119.5 + 119.6 +int xc_linux_save(int xc_handle, int io_fd, u32 dom) 119.7 +{ 119.8 + PERROR("xc_linux_save not implemented\n"); 119.9 + return -1; 119.10 +} 119.11 + 119.12 +int xc_linux_restore(int xc_handle, int io_fd, u32 dom, unsigned long nr_pfns) 119.13 +{ 119.14 + PERROR("xc_linux_restore not implemented\n"); 119.15 + return -1; 119.16 +} 119.17 + 119.18 +int xc_vmx_build(int xc_handle, 119.19 + u32 domid, 119.20 + int memsize, 119.21 + const char *image_name, 119.22 + struct mem_map *mem_mapp, 119.23 + const char *ramdisk_name, 119.24 + const char *cmdline, 119.25 + unsigned int control_evtchn, 119.26 + unsigned long flags) 119.27 +{ 119.28 + PERROR("xc_vmx_build not implemented\n"); 119.29 + return -1; 119.30 +} 119.31 + 119.32 +int 119.33 +xc_plan9_build(int xc_handle, 119.34 + u32 domid, 119.35 + const char *image_name, 119.36 + const char *cmdline, 119.37 + unsigned int control_evtchn, unsigned long flags) 119.38 +{ 119.39 + PERROR("xc_plan9_build not implemented\n"); 119.40 + return -1; 119.41 +} 119.42 +
126.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 126.2 +++ b/tools/misc/policyprocessor/Makefile Tue Aug 02 10:20:46 2005 -0700 126.3 @@ -0,0 +1,42 @@ 126.4 +XEN_ROOT = ../../.. 126.5 +include $(XEN_ROOT)/tools/Rules.mk 126.6 + 126.7 +CFLAGS += -static 126.8 +CFLAGS += -Wall 126.9 +CFLAGS += -Werror 126.10 +CFLAGS += -O3 126.11 +CFLAGS += -fno-strict-aliasing 126.12 +CFLAGS += -I. 126.13 + 126.14 +all: build 126.15 + 126.16 +build: mk-symlinks 126.17 + $(MAKE) xml_to_bin 126.18 + 126.19 +default: all 126.20 + 126.21 +install: all 126.22 + 126.23 +xml_to_bin : make_include XmlToBin.java XmlToBinInterface.java SsidsEntry.java SecurityLabel.java myHandler.java 126.24 + javac XmlToBin.java 126.25 + 126.26 +make_include : c2j_include 126.27 + ./c2j_include 126.28 + 126.29 +c2j_include: c2j_include.c 126.30 + $(CC) $(CPPFLAGS) $(CFLAGS) -o $@ $< 126.31 + 126.32 +clean: 126.33 + rm -rf *.class xen c2j_include policy_version.java *.bin 126.34 + 126.35 + 126.36 +LINUX_ROOT := $(XEN_ROOT)/linux-2.6-xen-sparse 126.37 +mk-symlinks: 126.38 + [ -e xen/linux ] || mkdir -p xen/linux 126.39 + [ -e xen/io ] || mkdir -p xen/io 126.40 + ( cd xen >/dev/null ; \ 126.41 + ln -sf ../$(XEN_ROOT)/xen/include/public/*.h . ) 126.42 + ( cd xen/io >/dev/null ; \ 126.43 + ln -sf ../../$(XEN_ROOT)/xen/include/public/io/*.h . ) 126.44 + ( cd xen/linux >/dev/null ; \ 126.45 + ln -sf ../../$(LINUX_ROOT)/include/asm-xen/linux-public/*.h . )
127.1 --- a/tools/misc/policyprocessor/XmlToBin.java Tue Aug 02 02:47:41 2005 -0800 127.2 +++ b/tools/misc/policyprocessor/XmlToBin.java Tue Aug 02 10:20:46 2005 -0700 127.3 @@ -5,6 +5,9 @@ 127.4 * 127.5 * Author: Ray Valdez 127.6 * 127.7 + * Contributors: 127.8 + * Reiner Sailer - adjust type-lengths 127.9 + * 127.10 * This program is free software; you can redistribute it and/or 127.11 * modify it under the terms of the GNU General Public License as 127.12 * published by the Free Software Foundation, version 2 of the 127.13 @@ -490,175 +493,139 @@ public class XmlToBin 127.14 127.15 127.16 try { 127.17 - /* Write magic */ 127.18 - writeIntToStream(binBuffer,ACM_MAGIC,index); 127.19 - index = u32Size; 127.20 + index = 0; 127.21 + /* fill in General Policy Version */ 127.22 + writeIntToStream(binBuffer, ACM_POLICY_VERSION, index); 127.23 + index += u32Size; 127.24 127.25 - /* Write policy version */ 127.26 - writeIntToStream(binBuffer,POLICY_INTERFACE_VERSION,index); 127.27 - index = index + u32Size; 127.28 + /* Write magic */ 127.29 + writeIntToStream(binBuffer, ACM_MAGIC, index); 127.30 + index += u32Size; 127.31 127.32 - /* write len */ 127.33 - writeIntToStream(binBuffer,binBuffer.length,index); 127.34 - index = index + u32Size; 127.35 + /* write len */ 127.36 + writeIntToStream(binBuffer, binBuffer.length, index); 127.37 + index += u32Size; 127.38 127.39 } catch (IOException ee) { 127.40 - System.out.println(" GBPB:: got exception : " + ee); 127.41 - return null; 127.42 + System.out.println(" GBPB:: got exception : " + ee); 127.43 + return null; 127.44 } 127.45 127.46 int offset, address; 127.47 address = index; 127.48 127.49 if (null != partMap) 127.50 - offset = binaryBufferHeaderSz + resourceOffsetSz; 127.51 + offset = binaryBufferHeaderSz + resourceOffsetSz; 127.52 else 127.53 - offset = binaryBufferHeaderSz; 127.54 + offset = binaryBufferHeaderSz; 127.55 127.56 try { 127.57 - 127.58 - if (null == chwPolicy || null == stePolicy) 127.59 - { 127.60 - writeShortToStream(binBuffer,ACM_NULL_POLICY,index); 127.61 - index = index + u16Size; 127.62 - 127.63 - writeShortToStream(binBuffer,(short) 0,index); 127.64 - index = index + u16Size; 127.65 - 127.66 - writeShortToStream(binBuffer,ACM_NULL_POLICY,index); 127.67 - index = index + u16Size; 127.68 - 127.69 - writeShortToStream(binBuffer,(short) 0,index); 127.70 - index = index + u16Size; 127.71 + int skip = 0; 127.72 127.73 - } 127.74 - index = address; 127.75 - if (null != chwPolicy) 127.76 - { 127.77 + /* init with NULL policy setting */ 127.78 + writeIntToStream(binBuffer, ACM_NULL_POLICY, index); 127.79 + writeIntToStream(binBuffer, 0, index + u32Size); 127.80 + writeIntToStream(binBuffer, ACM_NULL_POLICY, index + 2*u32Size); 127.81 + writeIntToStream(binBuffer, 0, index + 3*u32Size); 127.82 127.83 - /* Write policy name */ 127.84 - writeShortToStream(binBuffer,ACM_CHINESE_WALL_POLICY,index); 127.85 - index = index + u16Size; 127.86 + index = address; 127.87 + if (null != chwPolicy) { 127.88 + 127.89 + /* Write policy name */ 127.90 + writeIntToStream(binBuffer, ACM_CHINESE_WALL_POLICY, index); 127.91 + index += u32Size; 127.92 127.93 - /* Write offset */ 127.94 - writeShortToStream(binBuffer,(short) offset,index); 127.95 - index = index + u16Size; 127.96 + /* Write offset */ 127.97 + writeIntToStream(binBuffer, offset, index); 127.98 + index += u32Size; 127.99 127.100 - /* Write payload. No need increment index */ 127.101 - address = offset; 127.102 - System.arraycopy(chwPolicy, 0, binBuffer,address, chwPolicy.length); 127.103 - address = address + chwPolicy.length; 127.104 - 127.105 + /* Write payload. No need increment index */ 127.106 + address = offset; 127.107 + System.arraycopy(chwPolicy, 0, binBuffer,address, chwPolicy.length); 127.108 + address = address + chwPolicy.length; 127.109 + } else 127.110 + skip += 2*u32Size; 127.111 + 127.112 if (null != stePolicy) 127.113 { 127.114 /* Write policy name */ 127.115 - writeShortToStream(binBuffer,ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY,index); 127.116 - index = index + u16Size; 127.117 + writeIntToStream(binBuffer, ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY, index); 127.118 + index += u32Size; 127.119 127.120 /* Write offset */ 127.121 - writeShortToStream(binBuffer,(short) address,index); 127.122 - index = index + u16Size; 127.123 + writeIntToStream(binBuffer, address, index); 127.124 + index += u32Size; 127.125 127.126 /* Copy array */ 127.127 System.arraycopy(stePolicy, 0, binBuffer,address, stePolicy.length); 127.128 /* Update address */ 127.129 address = address + stePolicy.length; 127.130 - } else { 127.131 - /* Skip writing policy name and offset */ 127.132 - index = index + 2 * u16Size; 127.133 + } else 127.134 + skip += 2*u32Size; 127.135 127.136 - } 127.137 + /* Skip writing policy name and offset for each null policy*/ 127.138 + index += skip; 127.139 127.140 - } else { 127.141 + int size; 127.142 + /* Assumes that you will always have a partition defined in policy */ 127.143 + if ( 0 < partMap.length) { 127.144 + writeIntToStream(binBuffer, address, index); 127.145 + index = address; 127.146 127.147 - if (null != stePolicy) 127.148 - { 127.149 - /* Write policy name */ 127.150 - writeShortToStream(binBuffer,ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY,index); 127.151 - index = index + u16Size; 127.152 + /* Compute num of VMs */ 127.153 + size = partMap.length / (3 * u16Size); 127.154 127.155 - /* Write offset */ 127.156 - address = offset; 127.157 - writeShortToStream(binBuffer, (short) offset,index); 127.158 - index = index + u16Size; 127.159 - 127.160 - /* Copy array */ 127.161 - System.arraycopy(stePolicy, 0, binBuffer,address, stePolicy.length); 127.162 - /* Update address */ 127.163 - address = address + stePolicy.length; 127.164 + writeShortToStream(binBuffer, (short)size,index); 127.165 + index = index + u16Size; 127.166 127.167 - /* Increment index, since there is no secondary */ 127.168 - index = index + secondaryPolicyCodeSz + secondaryBufferOffsetSz; 127.169 - 127.170 - } 127.171 + /* part, vlan and slot: each one consists of two entries */ 127.172 + offset = 3 * (2 * u16Size); 127.173 + writeShortToStream(binBuffer, (short) offset,index); 127.174 127.175 - } 127.176 - int size; 127.177 - /* Assumes that you will always have a partition defined in policy */ 127.178 - if ( 0 < partMap.length) 127.179 - { 127.180 - writeShortToStream(binBuffer, (short) address,index); 127.181 - index = address; 127.182 + /* Write partition array at offset */ 127.183 + System.arraycopy(partMap, 0, binBuffer,(offset + address), partMap.length); 127.184 + index = index + u16Size; 127.185 + offset = offset + partMap.length; 127.186 + } 127.187 127.188 - /* Compute num of VMs */ 127.189 - size = partMap.length / (3 * u16Size); 127.190 - 127.191 - writeShortToStream(binBuffer, (short)size,index); 127.192 - index = index + u16Size; 127.193 - 127.194 - /* part, vlan and slot: each one consists of two entries */ 127.195 - offset = 3 * (2 * u16Size); 127.196 - writeShortToStream(binBuffer, (short) offset,index); 127.197 + if ( 0 < vlanMap.length) { 127.198 + size = vlanMap.length / (2 * u16Size); 127.199 + writeShortToStream(binBuffer, (short) size,index); 127.200 + index = index + u16Size; 127.201 127.202 - /* Write partition array at offset */ 127.203 - System.arraycopy(partMap, 0, binBuffer,(offset + address), partMap.length); 127.204 - index = index + u16Size; 127.205 - offset = offset + partMap.length; 127.206 - } 127.207 - 127.208 - if ( 0 < vlanMap.length) 127.209 - { 127.210 - size = vlanMap.length / (2 * u16Size); 127.211 - writeShortToStream(binBuffer, (short) size,index); 127.212 - index = index + u16Size; 127.213 - 127.214 - writeShortToStream(binBuffer, (short) offset,index); 127.215 - index = index + u16Size; 127.216 - System.arraycopy(vlanMap, 0, binBuffer,(offset + address), vlanMap.length); 127.217 - } else { 127.218 - /* Write vlan max */ 127.219 - writeShortToStream(binBuffer, (short) 0,index); 127.220 - index = index + u16Size; 127.221 + writeShortToStream(binBuffer, (short) offset,index); 127.222 + index = index + u16Size; 127.223 + System.arraycopy(vlanMap, 0, binBuffer,(offset + address), vlanMap.length); 127.224 + } else { 127.225 + /* Write vlan max */ 127.226 + writeShortToStream(binBuffer, (short) 0,index); 127.227 + index = index + u16Size; 127.228 127.229 - /* Write vlan offset */ 127.230 - writeShortToStream(binBuffer, (short) 0,index); 127.231 - index = index + u16Size; 127.232 - 127.233 - } 127.234 + /* Write vlan offset */ 127.235 + writeShortToStream(binBuffer, (short) 0,index); 127.236 + index = index + u16Size; 127.237 + } 127.238 127.239 - offset = offset + vlanMap.length; 127.240 - if ( 0 < slotMap.length) 127.241 - { 127.242 - size = slotMap.length / (3 * u16Size); 127.243 - writeShortToStream(binBuffer, (short) size,index); 127.244 - index = index + u16Size; 127.245 + offset = offset + vlanMap.length; 127.246 + if ( 0 < slotMap.length) { 127.247 + size = slotMap.length / (3 * u16Size); 127.248 + writeShortToStream(binBuffer, (short) size,index); 127.249 + index = index + u16Size; 127.250 127.251 - writeShortToStream(binBuffer, (short) offset,index); 127.252 - index = index + u16Size; 127.253 - System.arraycopy(slotMap, 0, binBuffer,(offset + address), slotMap.length); 127.254 - } 127.255 + writeShortToStream(binBuffer, (short) offset,index); 127.256 + index = index + u16Size; 127.257 + System.arraycopy(slotMap, 0, binBuffer,(offset + address), slotMap.length); 127.258 + } 127.259 + } catch (IOException ee) { 127.260 + System.out.println(" GBPB:: got exception : " + ee); 127.261 + return null; 127.262 + } 127.263 127.264 - } catch (IOException ee) 127.265 - { 127.266 - System.out.println(" GBPB:: got exception : " + ee); 127.267 - return null; 127.268 - } 127.269 + printDebug(" GBP:: Binary Policy ==> length " + binBuffer.length); 127.270 + if (debug) 127.271 + printHex(binBuffer,binBuffer.length); 127.272 127.273 - printDebug(" GBP:: Binary Policy ==> length " + binBuffer.length); 127.274 - if (debug) 127.275 - printHex(binBuffer,binBuffer.length); 127.276 - 127.277 - return binBuffer; 127.278 + return binBuffer; 127.279 } 127.280 127.281 public byte[] generateChwBuffer(Vector Ssids, Vector ConflictSsids, Vector ColorTypes) 127.282 @@ -668,28 +635,20 @@ public class XmlToBin 127.283 int position = 0; 127.284 127.285 /* Get number of rTypes */ 127.286 - short maxTypes = (short) ColorTypes.size(); 127.287 + int maxTypes = ColorTypes.size(); 127.288 127.289 /* Get number of SSids entry */ 127.290 - short maxSsids = (short) Ssids.size(); 127.291 + int maxSsids = Ssids.size(); 127.292 127.293 /* Get number of conflict sets */ 127.294 - short maxConflict = (short) ConflictSsids.size(); 127.295 + int maxConflict = ConflictSsids.size(); 127.296 127.297 127.298 if (maxTypes * maxSsids == 0) 127.299 return null; 127.300 /* 127.301 - data structure acm_chwall_policy_buffer_t; 127.302 - 127.303 - uint16 policy_code; 127.304 - uint16 chwall_max_types; 127.305 - uint16 chwall_max_ssidrefs; 127.306 - uint16 chwall_max_conflictsets; 127.307 - uint16 chwall_ssid_offset; 127.308 - uint16 chwall_conflict_sets_offset; 127.309 - uint16 chwall_running_types_offset; 127.310 - uint16 chwall_conflict_aggregate_offset; 127.311 + data structure acm_chwall_policy_buffer 127.312 + se XmlToBinInterface.java 127.313 */ 127.314 int totalBytes = chwHeaderSize + u16Size *(maxTypes * (maxSsids + maxConflict)); 127.315 127.316 @@ -699,34 +658,38 @@ public class XmlToBin 127.317 printDebug(" gCB:: chwall totalbytes : "+totalBytes); 127.318 127.319 try { 127.320 - index = 0; 127.321 - writeShortToStream(chwBuffer,ACM_CHINESE_WALL_POLICY,index); 127.322 - index = u16Size; 127.323 + index = 0; 127.324 + /* fill in General Policy Version */ 127.325 + writeIntToStream(chwBuffer, ACM_CHWALL_VERSION, index); 127.326 + index += u32Size; 127.327 127.328 - writeShortToStream(chwBuffer,maxTypes,index); 127.329 - index = index + u16Size; 127.330 + writeIntToStream(chwBuffer, ACM_CHINESE_WALL_POLICY, index); 127.331 + index += u32Size; 127.332 127.333 - writeShortToStream(chwBuffer,maxSsids,index); 127.334 - index = index + u16Size; 127.335 + writeIntToStream(chwBuffer, maxTypes, index); 127.336 + index += u32Size; 127.337 127.338 - writeShortToStream(chwBuffer,maxConflict,index); 127.339 - index = index + u16Size; 127.340 + writeIntToStream(chwBuffer, maxSsids, index); 127.341 + index += u32Size; 127.342 127.343 - /* Write chwall_ssid_offset */ 127.344 - writeShortToStream(chwBuffer,chwHeaderSize,index); 127.345 - index = index + u16Size; 127.346 + writeIntToStream(chwBuffer, maxConflict, index); 127.347 + index += u32Size; 127.348 127.349 - /* Write chwall_conflict_sets_offset */ 127.350 - writeShortToStream(chwBuffer,(short) address,index); 127.351 - index = index + u16Size; 127.352 + /* Write chwall_ssid_offset */ 127.353 + writeIntToStream(chwBuffer, chwHeaderSize, index); 127.354 + index += u32Size; 127.355 127.356 - /* Write chwall_running_types_offset */ 127.357 - writeShortToStream(chwBuffer,(short) 0,index); 127.358 - index = index + u16Size; 127.359 + /* Write chwall_conflict_sets_offset */ 127.360 + writeIntToStream(chwBuffer, address, index); 127.361 + index += u32Size; 127.362 127.363 - /* Write chwall_conflict_aggregate_offset */ 127.364 - writeShortToStream(chwBuffer,(short) 0,index); 127.365 - index = index + u16Size; 127.366 + /* Write chwall_running_types_offset */ 127.367 + writeIntToStream(chwBuffer, 0, index); 127.368 + index += u32Size; 127.369 + 127.370 + /* Write chwall_conflict_aggregate_offset */ 127.371 + writeIntToStream(chwBuffer, 0, index); 127.372 + index += u32Size; 127.373 127.374 } catch (IOException ee) { 127.375 System.out.println(" gCB:: got exception : " + ee); 127.376 @@ -737,7 +700,6 @@ public class XmlToBin 127.377 /* Create the SSids entry */ 127.378 for (int i = 0; i < maxSsids; i++) 127.379 { 127.380 - 127.381 SecurityLabel ssidEntry = (SecurityLabel) Ssids.elementAt(i); 127.382 /* Get chwall types */ 127.383 ssidEntry.chwSsidPosition = i; 127.384 @@ -821,22 +783,16 @@ public class XmlToBin 127.385 int position = 0; 127.386 127.387 /* Get number of colorTypes */ 127.388 - short numColorTypes = (short) ColorTypes.size(); 127.389 + int numColorTypes = ColorTypes.size(); 127.390 127.391 /* Get number of SSids entry */ 127.392 - short numSsids = (short) Ssids.size(); 127.393 + int numSsids = Ssids.size(); 127.394 127.395 if (numColorTypes * numSsids == 0) 127.396 return null; 127.397 127.398 - /* data structure: acm_ste_policy_buffer_t 127.399 - * 127.400 - * policy code (uint16) > 127.401 - * max_types (uint16) > 127.402 - * max_ssidrefs (uint16) > steHeaderSize 127.403 - * ssid_offset (uint16) > 127.404 - * DATA (colorTypes(size) * Ssids(size) *unit16) 127.405 - * 127.406 + /* data structure: acm_ste_policy_buffer 127.407 + * see XmlToBinInterface.java 127.408 * total bytes: steHeaderSize * 2B + colorTypes(size) * Ssids(size) 127.409 * 127.410 */ 127.411 @@ -844,18 +800,22 @@ public class XmlToBin 127.412 127.413 try { 127.414 127.415 - index = 0; 127.416 - writeShortToStream(steBuffer,ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY,index); 127.417 - index = u16Size; 127.418 + index = 0; 127.419 + writeIntToStream(steBuffer, ACM_STE_VERSION, index); 127.420 + index += u32Size; 127.421 + 127.422 + writeIntToStream(steBuffer, ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY, index); 127.423 + index += u32Size; 127.424 127.425 - writeShortToStream(steBuffer,numColorTypes,index); 127.426 - index = index + u16Size; 127.427 + writeIntToStream(steBuffer, numColorTypes, index); 127.428 + index += u32Size; 127.429 127.430 - writeShortToStream(steBuffer,numSsids,index); 127.431 - index = index + u16Size; 127.432 + writeIntToStream(steBuffer, numSsids, index); 127.433 + index += u32Size; 127.434 127.435 - writeShortToStream(steBuffer,(short)steHeaderSize,index); 127.436 - index = index + u16Size; 127.437 + writeIntToStream(steBuffer, steHeaderSize, index); 127.438 + index += u32Size; 127.439 + 127.440 127.441 } catch (IOException ee) { 127.442 System.out.println(" gSB:: got exception : " + ee); 127.443 @@ -1469,6 +1429,17 @@ public class XmlToBin 127.444 127.445 XmlToBin genObj = new XmlToBin(); 127.446 127.447 + policy_version active_policy = new policy_version(); 127.448 + 127.449 + if ((active_policy.ACM_POLICY_VERSION != ACM_POLICY_VERSION) || 127.450 + (active_policy.ACM_CHWALL_VERSION != ACM_CHWALL_VERSION) || 127.451 + (active_policy.ACM_STE_VERSION != ACM_STE_VERSION)) { 127.452 + System.out.println("ACM policy versions differ."); 127.453 + System.out.println("Please verify that data structures are correct"); 127.454 + System.out.println("and then adjust the version numbers in XmlToBinInterface.java."); 127.455 + return; 127.456 + } 127.457 + 127.458 127.459 for (int i = 0 ; i < args.length ; i++) { 127.460
128.1 --- a/tools/misc/policyprocessor/XmlToBinInterface.java Tue Aug 02 02:47:41 2005 -0800 128.2 +++ b/tools/misc/policyprocessor/XmlToBinInterface.java Tue Aug 02 10:20:46 2005 -0700 128.3 @@ -19,37 +19,37 @@ 128.4 * 128.5 * policy binary structures 128.6 * 128.7 - * typedef struct { 128.8 - * u32 magic; 128.9 - * 128.10 - * u32 policyversion; 128.11 - * u32 len; 128.12 + * struct acm_policy_buffer { 128.13 + * u32 policy_version; * ACM_POLICY_VERSION * 128.14 + * u32 magic; 128.15 + * u32 len; 128.16 + * u32 primary_policy_code; 128.17 + * u32 primary_buffer_offset; 128.18 + * u32 secondary_policy_code; 128.19 + * u32 secondary_buffer_offset; 128.20 + * +u32 resource offset (not used yet in Xen) 128.21 + * }; 128.22 * 128.23 - * u16 primary_policy_code; 128.24 - * u16 primary_buffer_offset; 128.25 - * u16 secondary_policy_code; 128.26 - * u16 secondary_buffer_offset; 128.27 - * u16 resource_offset; 128.28 - * 128.29 - * } acm_policy_buffer_t; 128.30 * 128.31 - * typedef struct { 128.32 - * u16 policy_code; 128.33 - * u16 ste_max_types; 128.34 - * u16 ste_max_ssidrefs; 128.35 - * u16 ste_ssid_offset; 128.36 - * } acm_ste_policy_buffer_t; 128.37 + * struct acm_ste_policy_buffer { 128.38 + * u32 policy_version; * ACM_STE_VERSION * 128.39 + * u32 policy_code; 128.40 + * u32 ste_max_types; 128.41 + * u32 ste_max_ssidrefs; 128.42 + * u32 ste_ssid_offset; 128.43 + * }; 128.44 * 128.45 - * typedef struct { 128.46 - * uint16 policy_code; 128.47 - * uint16 chwall_max_types; 128.48 - * uint16 chwall_max_ssidrefs; 128.49 - * uint16 chwall_max_conflictsets; 128.50 - * uint16 chwall_ssid_offset; 128.51 - * uint16 chwall_conflict_sets_offset; 128.52 - * uint16 chwall_running_types_offset; 128.53 - * uint16 chwall_conflict_aggregate_offset; 128.54 - * } acm_chwall_policy_buffer_t; 128.55 + * struct acm_chwall_policy_buffer { 128.56 + * u32 policy_version; * ACM_CHWALL_VERSION * 128.57 + * u32 policy_code; 128.58 + * u32 chwall_max_types; 128.59 + * u32 chwall_max_ssidrefs; 128.60 + * u32 chwall_max_conflictsets; 128.61 + * u32 chwall_ssid_offset; 128.62 + * u32 chwall_conflict_sets_offset; 128.63 + * u32 chwall_running_types_offset; 128.64 + * u32 chwall_conflict_aggregate_offset; 128.65 + * }; 128.66 * 128.67 * typedef struct { 128.68 * u16 partition_max; 128.69 @@ -100,16 +100,17 @@ public interface XmlToBinInterface 128.70 final int u16Size = 2; 128.71 128.72 /* num of bytes for acm_ste_policy_buffer_t */ 128.73 - final short steHeaderSize = (4 * u16Size); 128.74 + final int steHeaderSize = (5 * u32Size); 128.75 + 128.76 /* byte for acm_chinese_wall_policy_buffer_t */ 128.77 - final short chwHeaderSize = (8 * u16Size); 128.78 + final int chwHeaderSize = (9 * u32Size); 128.79 128.80 - final short primaryPolicyCodeSize = u16Size; 128.81 - final short primaryBufferOffsetSize = u16Size ; 128.82 + final int primaryPolicyCodeSize = u32Size; 128.83 + final int primaryBufferOffsetSize = u32Size ; 128.84 128.85 - final int secondaryPolicyCodeSz = u16Size; 128.86 - final int secondaryBufferOffsetSz = u16Size; 128.87 - final short resourceOffsetSz = u16Size; 128.88 + final int secondaryPolicyCodeSz = u32Size; 128.89 + final int secondaryBufferOffsetSz = u32Size; 128.90 + final int resourceOffsetSz = u32Size; 128.91 128.92 final short partitionBufferSz = (2 * u16Size); 128.93 final short partitionEntrySz = (3 * u16Size); 128.94 @@ -120,16 +121,18 @@ public interface XmlToBinInterface 128.95 final short vlanBufferSz = (2 * u16Size); 128.96 final short vlanEntrySz = (2 * u16Size); 128.97 128.98 - final short binaryBufferHeaderSz = (3 * u32Size + 4* u16Size); 128.99 - 128.100 - /* copied directlty from policy_ops.h */ 128.101 - final int POLICY_INTERFACE_VERSION = 0xAAAA0003; 128.102 + final int binaryBufferHeaderSz = (8 * u32Size); /* 8th not used in Xen */ 128.103 128.104 /* copied directly from acm.h */ 128.105 final int ACM_MAGIC = 0x0001debc; 128.106 - final short ACM_NULL_POLICY = 0; 128.107 - final short ACM_CHINESE_WALL_POLICY = 1; 128.108 - final short ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY = 2; 128.109 - final short ACM_CHINESE_WALL_AND_SIMPLE_TYPE_ENFORCEMENT_POLICY = 3; 128.110 - final short ACM_EMPTY_POLICY = 4; 128.111 + final int ACM_NULL_POLICY = 0; 128.112 + final int ACM_CHINESE_WALL_POLICY = 1; 128.113 + final int ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY = 2; 128.114 + final int ACM_CHINESE_WALL_AND_SIMPLE_TYPE_ENFORCEMENT_POLICY = 3; 128.115 + final int ACM_EMPTY_POLICY = 4; 128.116 + 128.117 + /* version for compatibility check */ 128.118 + final int ACM_POLICY_VERSION = 1; 128.119 + final int ACM_STE_VERSION = 1; 128.120 + final int ACM_CHWALL_VERSION = 1; 128.121 }
129.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 129.2 +++ b/tools/misc/policyprocessor/c2j_include.c Tue Aug 02 10:20:46 2005 -0700 129.3 @@ -0,0 +1,57 @@ 129.4 +/**************************************************************** 129.5 + * c2j_include.c 129.6 + * 129.7 + * Copyright (C) 2005 IBM Corporation 129.8 + * 129.9 + * Authors: 129.10 + * Reiner Sailer <sailer@watson.ibm.com> 129.11 + * 129.12 + * This program is free software; you can redistribute it and/or 129.13 + * modify it under the terms of the GNU General Public License as 129.14 + * published by the Free Software Foundation, version 2 of the 129.15 + * License. 129.16 + * 129.17 + * This tool makes some constants from acm.h available to the 129.18 + * java policyprocessor for version checking. 129.19 + */ 129.20 +#include <stdio.h> 129.21 +#include <errno.h> 129.22 +#include <stdlib.h> 129.23 +#include <stdint.h> 129.24 + 129.25 +typedef uint8_t u8; 129.26 +typedef uint16_t u16; 129.27 +typedef uint32_t u32; 129.28 +typedef uint64_t u64; 129.29 +typedef int8_t s8; 129.30 +typedef int16_t s16; 129.31 +typedef int32_t s32; 129.32 +typedef int64_t s64; 129.33 + 129.34 +#include <xen/acm.h> 129.35 + 129.36 +char *filename = "policy_version.java"; 129.37 + 129.38 +int main(int argc, char **argv) 129.39 +{ 129.40 + 129.41 + FILE *fd; 129.42 + if ((fd = fopen(filename, "w")) <= 0) 129.43 + { 129.44 + printf("File %s not found.\n", filename); 129.45 + exit(-ENOENT); 129.46 + } 129.47 + 129.48 + fprintf(fd, "/*\n * This file was automatically generated\n"); 129.49 + fprintf(fd, " * Do not change it manually!\n */\n"); 129.50 + fprintf(fd, "public class policy_version {\n"); 129.51 + fprintf(fd, " final int ACM_POLICY_VERSION = %x;\n", 129.52 + ACM_POLICY_VERSION); 129.53 + fprintf(fd, " final int ACM_CHWALL_VERSION = %x;\n", 129.54 + ACM_CHWALL_VERSION); 129.55 + fprintf(fd, " final int ACM_STE_VERSION = %x;\n", 129.56 + ACM_STE_VERSION); 129.57 + fprintf(fd, "}\n"); 129.58 + fclose(fd); 129.59 + return 0; 129.60 +}
130.1 --- a/tools/misc/policyprocessor/xen_sample_def.xml Tue Aug 02 02:47:41 2005 -0800 130.2 +++ b/tools/misc/policyprocessor/xen_sample_def.xml Tue Aug 02 10:20:46 2005 -0700 130.3 @@ -37,7 +37,7 @@ xsi:schemaLocation="http://www.ibm.com S 130.4 </ConflictSet> 130.5 130.6 <ConflictSet> 130.7 - <ChWall>Q-Company</ChWall> 130.8 + <ChWall>R-Company</ChWall> 130.9 <ChWall>V-Company</ChWall> 130.10 <ChWall>W-Company</ChWall> 130.11 </ConflictSet>
131.1 --- a/tools/policy/Makefile Tue Aug 02 02:47:41 2005 -0800 131.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 131.3 @@ -1,36 +0,0 @@ 131.4 -XEN_ROOT = ../.. 131.5 -include $(XEN_ROOT)/tools/Rules.mk 131.6 - 131.7 -SRCS = policy_tool.c 131.8 -CFLAGS += -static 131.9 -CFLAGS += -Wall 131.10 -CFLAGS += -Werror 131.11 -CFLAGS += -O3 131.12 -CFLAGS += -fno-strict-aliasing 131.13 -CFLAGS += -I. 131.14 - 131.15 -all: build 131.16 -build: mk-symlinks 131.17 - $(MAKE) policy_tool 131.18 - 131.19 -default: all 131.20 - 131.21 -install: all 131.22 - 131.23 -policy_tool : policy_tool.c 131.24 - $(CC) $(CPPFLAGS) $(CFLAGS) -o $@ $< 131.25 - 131.26 -clean: 131.27 - rm -rf policy_tool xen 131.28 - 131.29 - 131.30 -LINUX_ROOT := $(XEN_ROOT)/linux-2.6-xen-sparse 131.31 -mk-symlinks: 131.32 - [ -e xen/linux ] || mkdir -p xen/linux 131.33 - [ -e xen/io ] || mkdir -p xen/io 131.34 - ( cd xen >/dev/null ; \ 131.35 - ln -sf ../$(XEN_ROOT)/xen/include/public/*.h . ) 131.36 - ( cd xen/io >/dev/null ; \ 131.37 - ln -sf ../../$(XEN_ROOT)/xen/include/public/io/*.h . ) 131.38 - ( cd xen/linux >/dev/null ; \ 131.39 - ln -sf ../../$(LINUX_ROOT)/include/asm-xen/linux-public/*.h . )
132.1 --- a/tools/policy/policy_tool.c Tue Aug 02 02:47:41 2005 -0800 132.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 132.3 @@ -1,552 +0,0 @@ 132.4 -/**************************************************************** 132.5 - * policy_tool.c 132.6 - * 132.7 - * Copyright (C) 2005 IBM Corporation 132.8 - * 132.9 - * Authors: 132.10 - * Reiner Sailer <sailer@watson.ibm.com> 132.11 - * Stefan Berger <stefanb@watson.ibm.com> 132.12 - * 132.13 - * This program is free software; you can redistribute it and/or 132.14 - * modify it under the terms of the GNU General Public License as 132.15 - * published by the Free Software Foundation, version 2 of the 132.16 - * License. 132.17 - * 132.18 - * sHype policy management tool. This code runs in a domain and 132.19 - * manages the Xen security policy by interacting with the 132.20 - * Xen access control module via a /proc/xen/privcmd proc-ioctl, 132.21 - * which is translated into a policy_op hypercall into Xen. 132.22 - * 132.23 - * todo: implement setpolicy to dynamically set a policy cache. 132.24 - */ 132.25 -#include <unistd.h> 132.26 -#include <stdio.h> 132.27 -#include <errno.h> 132.28 -#include <fcntl.h> 132.29 -#include <sys/mman.h> 132.30 -#include <sys/types.h> 132.31 -#include <sys/stat.h> 132.32 -#include <stdlib.h> 132.33 -#include <sys/ioctl.h> 132.34 -#include <string.h> 132.35 -#include <stdint.h> 132.36 -#include <netinet/in.h> 132.37 - 132.38 -typedef uint8_t u8; 132.39 -typedef uint16_t u16; 132.40 -typedef uint32_t u32; 132.41 -typedef uint64_t u64; 132.42 -typedef int8_t s8; 132.43 -typedef int16_t s16; 132.44 -typedef int32_t s32; 132.45 -typedef int64_t s64; 132.46 - 132.47 -#include <xen/acm.h> 132.48 - 132.49 -#include <xen/policy_ops.h> 132.50 - 132.51 -#include <xen/linux/privcmd.h> 132.52 - 132.53 -#define ERROR(_m, _a...) \ 132.54 - fprintf(stderr, "ERROR: " _m "\n" , ## _a ) 132.55 - 132.56 -#define PERROR(_m, _a...) \ 132.57 - fprintf(stderr, "ERROR: " _m " (%d = %s)\n" , ## _a , \ 132.58 - errno, strerror(errno)) 132.59 - 132.60 -static inline int do_policycmd(int xc_handle, 132.61 - unsigned int cmd, 132.62 - unsigned long data) 132.63 -{ 132.64 - return ioctl(xc_handle, cmd, data); 132.65 -} 132.66 - 132.67 -static inline int do_xen_hypercall(int xc_handle, 132.68 - privcmd_hypercall_t *hypercall) 132.69 -{ 132.70 - return do_policycmd(xc_handle, 132.71 - IOCTL_PRIVCMD_HYPERCALL, 132.72 - (unsigned long)hypercall); 132.73 -} 132.74 - 132.75 -static inline int do_policy_op(int xc_handle, policy_op_t *op) 132.76 -{ 132.77 - int ret = -1; 132.78 - privcmd_hypercall_t hypercall; 132.79 - 132.80 - op->interface_version = POLICY_INTERFACE_VERSION; 132.81 - 132.82 - hypercall.op = __HYPERVISOR_policy_op; 132.83 - hypercall.arg[0] = (unsigned long)op; 132.84 - 132.85 - if ( mlock(op, sizeof(*op)) != 0 ) 132.86 - { 132.87 - PERROR("Could not lock memory for Xen policy hypercall"); 132.88 - goto out1; 132.89 - } 132.90 - 132.91 - if ( (ret = do_xen_hypercall(xc_handle, &hypercall)) < 0 ) 132.92 - { 132.93 - if ( errno == EACCES ) 132.94 - fprintf(stderr, "POLICY operation failed -- need to" 132.95 - " rebuild the user-space tool set?\n"); 132.96 - goto out2; 132.97 - } 132.98 - 132.99 - out2: (void)munlock(op, sizeof(*op)); 132.100 - out1: return ret; 132.101 -} 132.102 - 132.103 -/*************************** DUMPS *******************************/ 132.104 - 132.105 -void acm_dump_chinesewall_buffer(void *buf, int buflen) { 132.106 - 132.107 - struct acm_chwall_policy_buffer *cwbuf = (struct acm_chwall_policy_buffer *)buf; 132.108 - domaintype_t *ssids, *conflicts, *running_types, *conflict_aggregate; 132.109 - int i,j; 132.110 - 132.111 - 132.112 - if (htons(cwbuf->policy_code) != ACM_CHINESE_WALL_POLICY) { 132.113 - printf("CHINESE WALL POLICY CODE not found ERROR!!\n"); 132.114 - return; 132.115 - } 132.116 - printf("\n\nChinese Wall policy:\n"); 132.117 - printf("====================\n"); 132.118 - printf("Max Types = %x.\n", ntohs(cwbuf->chwall_max_types)); 132.119 - printf("Max Ssidrefs = %x.\n", ntohs(cwbuf->chwall_max_ssidrefs)); 132.120 - printf("Max ConfSets = %x.\n", ntohs(cwbuf->chwall_max_conflictsets)); 132.121 - printf("Ssidrefs Off = %x.\n", ntohs(cwbuf->chwall_ssid_offset)); 132.122 - printf("Conflicts Off = %x.\n", ntohs(cwbuf->chwall_conflict_sets_offset)); 132.123 - printf("Runing T. Off = %x.\n", ntohs(cwbuf->chwall_running_types_offset)); 132.124 - printf("C. Agg. Off = %x.\n", ntohs(cwbuf->chwall_conflict_aggregate_offset)); 132.125 - printf("\nSSID To CHWALL-Type matrix:\n"); 132.126 - 132.127 - ssids = (domaintype_t *)(buf + ntohs(cwbuf->chwall_ssid_offset)); 132.128 - for(i=0; i< ntohs(cwbuf->chwall_max_ssidrefs); i++) { 132.129 - printf("\n ssidref%2x: ", i); 132.130 - for(j=0; j< ntohs(cwbuf->chwall_max_types); j++) 132.131 - printf("%02x ", ntohs(ssids[i*ntohs(cwbuf->chwall_max_types) + j])); 132.132 - } 132.133 - printf("\n\nConfict Sets:\n"); 132.134 - conflicts = (domaintype_t *)(buf + ntohs(cwbuf->chwall_conflict_sets_offset)); 132.135 - for(i=0; i< ntohs(cwbuf->chwall_max_conflictsets); i++) { 132.136 - printf("\n c-set%2x: ", i); 132.137 - for(j=0; j< ntohs(cwbuf->chwall_max_types); j++) 132.138 - printf("%02x ", ntohs(conflicts[i*ntohs(cwbuf->chwall_max_types) +j])); 132.139 - } 132.140 - printf("\n"); 132.141 - 132.142 - printf("\nRunning\nTypes: "); 132.143 - if (ntohs(cwbuf->chwall_running_types_offset)) { 132.144 - running_types = (domaintype_t *)(buf + ntohs(cwbuf->chwall_running_types_offset)); 132.145 - for(i=0; i< ntohs(cwbuf->chwall_max_types); i++) { 132.146 - printf("%02x ", ntohs(running_types[i])); 132.147 - } 132.148 - printf("\n"); 132.149 - } else { 132.150 - printf("Not Reported!\n"); 132.151 - } 132.152 - printf("\nConflict\nAggregate Set: "); 132.153 - if (ntohs(cwbuf->chwall_conflict_aggregate_offset)) { 132.154 - conflict_aggregate = (domaintype_t *)(buf + ntohs(cwbuf->chwall_conflict_aggregate_offset)); 132.155 - for(i=0; i< ntohs(cwbuf->chwall_max_types); i++) { 132.156 - printf("%02x ", ntohs(conflict_aggregate[i])); 132.157 - } 132.158 - printf("\n\n"); 132.159 - } else { 132.160 - printf("Not Reported!\n"); 132.161 - } 132.162 -} 132.163 - 132.164 -void acm_dump_ste_buffer(void *buf, int buflen) { 132.165 - 132.166 - struct acm_ste_policy_buffer *stebuf = (struct acm_ste_policy_buffer *)buf; 132.167 - domaintype_t *ssids; 132.168 - int i,j; 132.169 - 132.170 - 132.171 - if (ntohs(stebuf->policy_code) != ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY) { 132.172 - printf("SIMPLE TYPE ENFORCEMENT POLICY CODE not found ERROR!!\n"); 132.173 - return; 132.174 - } 132.175 - printf("\nSimple Type Enforcement policy:\n"); 132.176 - printf("===============================\n"); 132.177 - printf("Max Types = %x.\n", ntohs(stebuf->ste_max_types)); 132.178 - printf("Max Ssidrefs = %x.\n", ntohs(stebuf->ste_max_ssidrefs)); 132.179 - printf("Ssidrefs Off = %x.\n", ntohs(stebuf->ste_ssid_offset)); 132.180 - printf("\nSSID To STE-Type matrix:\n"); 132.181 - 132.182 - ssids = (domaintype_t *)(buf + ntohs(stebuf->ste_ssid_offset)); 132.183 - for(i=0; i< ntohs(stebuf->ste_max_ssidrefs); i++) { 132.184 - printf("\n ssidref%2x: ", i); 132.185 - for(j=0; j< ntohs(stebuf->ste_max_types); j++) 132.186 - printf("%02x ", ntohs(ssids[i*ntohs(stebuf->ste_max_types) +j])); 132.187 - } 132.188 - printf("\n\n"); 132.189 -} 132.190 - 132.191 -void acm_dump_policy_buffer(void *buf, int buflen) { 132.192 - struct acm_policy_buffer *pol = (struct acm_policy_buffer *)buf; 132.193 - 132.194 - printf("\nPolicy dump:\n"); 132.195 - printf("============\n"); 132.196 - printf("Magic = %x.\n", ntohl(pol->magic)); 132.197 - printf("PolVer = %x.\n", ntohl(pol->policyversion)); 132.198 - printf("Len = %x.\n", ntohl(pol->len)); 132.199 - printf("Primary = %s (c=%x, off=%x).\n", 132.200 - ACM_POLICY_NAME(ntohs(pol->primary_policy_code)), 132.201 - ntohs(pol->primary_policy_code), ntohs(pol->primary_buffer_offset)); 132.202 - printf("Secondary = %s (c=%x, off=%x).\n", 132.203 - ACM_POLICY_NAME(ntohs(pol->secondary_policy_code)), 132.204 - ntohs(pol->secondary_policy_code), ntohs(pol->secondary_buffer_offset)); 132.205 - switch (ntohs(pol->primary_policy_code)) { 132.206 - case ACM_CHINESE_WALL_POLICY: 132.207 - acm_dump_chinesewall_buffer(buf+ntohs(pol->primary_buffer_offset), 132.208 - ntohl(pol->len) - ntohs(pol->primary_buffer_offset)); 132.209 - break; 132.210 - case ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY: 132.211 - acm_dump_ste_buffer(buf+ntohs(pol->primary_buffer_offset), 132.212 - ntohl(pol->len) - ntohs(pol->primary_buffer_offset)); 132.213 - break; 132.214 - case ACM_NULL_POLICY: 132.215 - printf("Primary policy is NULL Policy (n/a).\n"); 132.216 - break; 132.217 - default: 132.218 - printf("UNKNOWN POLICY!\n"); 132.219 - } 132.220 - switch (ntohs(pol->secondary_policy_code)) { 132.221 - case ACM_CHINESE_WALL_POLICY: 132.222 - acm_dump_chinesewall_buffer(buf+ntohs(pol->secondary_buffer_offset), 132.223 - ntohl(pol->len) - ntohs(pol->secondary_buffer_offset)); 132.224 - break; 132.225 - case ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY: 132.226 - acm_dump_ste_buffer(buf+ntohs(pol->secondary_buffer_offset), 132.227 - ntohl(pol->len) - ntohs(pol->secondary_buffer_offset)); 132.228 - break; 132.229 - case ACM_NULL_POLICY: 132.230 - printf("Secondary policy is NULL Policy (n/a).\n"); 132.231 - break; 132.232 - default: 132.233 - printf("UNKNOWN POLICY!\n"); 132.234 - } 132.235 -} 132.236 - 132.237 -/*************************** set policy ****************************/ 132.238 - 132.239 -int acm_domain_set_chwallpolicy(void *bufstart, int buflen) { 132.240 -#define CWALL_MAX_SSIDREFS 6 132.241 -#define CWALL_MAX_TYPES 10 132.242 -#define CWALL_MAX_CONFLICTSETS 2 132.243 - 132.244 - struct acm_chwall_policy_buffer *chwall_bin_pol = (struct acm_chwall_policy_buffer *)bufstart; 132.245 - domaintype_t *ssidrefs, *conflicts; 132.246 - int ret = 0; 132.247 - int j; 132.248 - 132.249 - chwall_bin_pol->chwall_max_types = htons(CWALL_MAX_TYPES); 132.250 - chwall_bin_pol->chwall_max_ssidrefs = htons(CWALL_MAX_SSIDREFS); 132.251 - chwall_bin_pol->policy_code = htons(ACM_CHINESE_WALL_POLICY); 132.252 - chwall_bin_pol->chwall_ssid_offset = htons(sizeof(struct acm_chwall_policy_buffer)); 132.253 - chwall_bin_pol->chwall_max_conflictsets = htons(CWALL_MAX_CONFLICTSETS); 132.254 - chwall_bin_pol->chwall_conflict_sets_offset = 132.255 - htons( 132.256 - ntohs(chwall_bin_pol->chwall_ssid_offset) + 132.257 - sizeof(domaintype_t)*CWALL_MAX_SSIDREFS*CWALL_MAX_TYPES); 132.258 - chwall_bin_pol->chwall_running_types_offset = 0; /* not set */ 132.259 - chwall_bin_pol->chwall_conflict_aggregate_offset = 0; /* not set */ 132.260 - ret += sizeof(struct acm_chwall_policy_buffer); 132.261 - /* now push example ssids into the buffer (max_ssidrefs x max_types entries) */ 132.262 - /* check buffer size */ 132.263 - if ((buflen - ret) < (CWALL_MAX_TYPES*CWALL_MAX_SSIDREFS*sizeof(domaintype_t))) 132.264 - return -1; /* not enough space */ 132.265 - 132.266 - ssidrefs = (domaintype_t *)(bufstart+ntohs(chwall_bin_pol->chwall_ssid_offset)); 132.267 - memset(ssidrefs, 0, CWALL_MAX_TYPES*CWALL_MAX_SSIDREFS*sizeof(domaintype_t)); 132.268 - 132.269 - /* now set type j-1 for ssidref i+1 */ 132.270 - for(j=0; j<= CWALL_MAX_SSIDREFS; j++) 132.271 - if ((0 < j) &&( j <= CWALL_MAX_TYPES)) 132.272 - ssidrefs[j*CWALL_MAX_TYPES + j - 1] = htons(1); 132.273 - 132.274 - ret += CWALL_MAX_TYPES*CWALL_MAX_SSIDREFS*sizeof(domaintype_t); 132.275 - if ((buflen - ret) < (CWALL_MAX_CONFLICTSETS*CWALL_MAX_TYPES*sizeof(domaintype_t))) 132.276 - return -1; /* not enough space */ 132.277 - 132.278 - /* now the chinese wall policy conflict sets*/ 132.279 - conflicts = (domaintype_t *)(bufstart + 132.280 - ntohs(chwall_bin_pol->chwall_conflict_sets_offset)); 132.281 - memset((void *)conflicts, 0, CWALL_MAX_CONFLICTSETS*CWALL_MAX_TYPES*sizeof(domaintype_t)); 132.282 - /* just 1 conflict set [0]={2,3}, [1]={1,5,6} */ 132.283 - if (CWALL_MAX_TYPES > 3) { 132.284 - conflicts[2] = htons(1); conflicts[3] = htons(1); /* {2,3} */ 132.285 - conflicts[CWALL_MAX_TYPES+1] = htons(1); conflicts[CWALL_MAX_TYPES+5] = htons(1); 132.286 - conflicts[CWALL_MAX_TYPES+6] = htons(1);/* {0,5,6} */ 132.287 - } 132.288 - ret += sizeof(domaintype_t)*CWALL_MAX_CONFLICTSETS*CWALL_MAX_TYPES; 132.289 - return ret; 132.290 -} 132.291 - 132.292 -int acm_domain_set_stepolicy(void *bufstart, int buflen) { 132.293 -#define STE_MAX_SSIDREFS 6 132.294 -#define STE_MAX_TYPES 5 132.295 - 132.296 - struct acm_ste_policy_buffer *ste_bin_pol = (struct acm_ste_policy_buffer *)bufstart; 132.297 - domaintype_t *ssidrefs; 132.298 - int j, ret = 0; 132.299 - 132.300 - ste_bin_pol->ste_max_types = htons(STE_MAX_TYPES); 132.301 - ste_bin_pol->ste_max_ssidrefs = htons(STE_MAX_SSIDREFS); 132.302 - ste_bin_pol->policy_code = htons(ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY); 132.303 - ste_bin_pol->ste_ssid_offset = htons(sizeof(struct acm_ste_policy_buffer)); 132.304 - ret += sizeof(struct acm_ste_policy_buffer); 132.305 - /* check buffer size */ 132.306 - if ((buflen - ret) < (STE_MAX_TYPES*STE_MAX_SSIDREFS*sizeof(domaintype_t))) 132.307 - return -1; /* not enough space */ 132.308 - 132.309 - ssidrefs = (domaintype_t *)(bufstart+ntohs(ste_bin_pol->ste_ssid_offset)); 132.310 - memset(ssidrefs, 0, STE_MAX_TYPES*STE_MAX_SSIDREFS*sizeof(domaintype_t)); 132.311 - /* all types 1 for ssidref 1 */ 132.312 - for(j=0; j< STE_MAX_TYPES; j++) 132.313 - ssidrefs[1*STE_MAX_TYPES +j] = htons(1); 132.314 - /* now set type j-1 for ssidref j */ 132.315 - for(j=0; j< STE_MAX_SSIDREFS; j++) 132.316 - if ((0 < j) &&( j <= STE_MAX_TYPES)) 132.317 - ssidrefs[j*STE_MAX_TYPES + j - 1] = htons(1); 132.318 - ret += STE_MAX_TYPES*STE_MAX_SSIDREFS*sizeof(domaintype_t); 132.319 - return ret; 132.320 -} 132.321 - 132.322 -#define MAX_PUSH_BUFFER 16384 132.323 -u8 push_buffer[MAX_PUSH_BUFFER]; 132.324 - 132.325 -int acm_domain_setpolicy(int xc_handle) 132.326 -{ 132.327 - int ret; 132.328 - struct acm_policy_buffer *bin_pol; 132.329 - policy_op_t op; 132.330 - 132.331 - /* future: read policy from file and set it */ 132.332 - bin_pol = (struct acm_policy_buffer *)push_buffer; 132.333 - bin_pol->magic = htonl(ACM_MAGIC); 132.334 - bin_pol->policyversion = htonl(POLICY_INTERFACE_VERSION); 132.335 - bin_pol->primary_policy_code = htons(ACM_CHINESE_WALL_POLICY); 132.336 - bin_pol->secondary_policy_code = htons(ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY); 132.337 - 132.338 - bin_pol->len = htonl(sizeof(struct acm_policy_buffer)); 132.339 - bin_pol->primary_buffer_offset = htons(ntohl(bin_pol->len)); 132.340 - ret = acm_domain_set_chwallpolicy(push_buffer + ntohs(bin_pol->primary_buffer_offset), 132.341 - MAX_PUSH_BUFFER - ntohs(bin_pol->primary_buffer_offset)); 132.342 - if (ret < 0) { 132.343 - printf("ERROR creating chwallpolicy buffer.\n"); 132.344 - return -1; 132.345 - } 132.346 - bin_pol->len = htonl(ntohl(bin_pol->len) + ret); 132.347 - bin_pol->secondary_buffer_offset = htons(ntohl(bin_pol->len)); 132.348 - ret = acm_domain_set_stepolicy(push_buffer + ntohs(bin_pol->secondary_buffer_offset), 132.349 - MAX_PUSH_BUFFER - ntohs(bin_pol->secondary_buffer_offset)); 132.350 - if (ret < 0) { 132.351 - printf("ERROR creating chwallpolicy buffer.\n"); 132.352 - return -1; 132.353 - } 132.354 - bin_pol->len = htonl(ntohl(bin_pol->len) + ret); 132.355 - 132.356 - /* dump it and then push it down into xen/acm */ 132.357 - acm_dump_policy_buffer(push_buffer, ntohl(bin_pol->len)); 132.358 - op.cmd = POLICY_SETPOLICY; 132.359 - op.u.setpolicy.pushcache = (void *)push_buffer; 132.360 - op.u.setpolicy.pushcache_size = ntohl(bin_pol->len); 132.361 - op.u.setpolicy.policy_type = ACM_CHINESE_WALL_AND_SIMPLE_TYPE_ENFORCEMENT_POLICY; 132.362 - ret = do_policy_op(xc_handle, &op); 132.363 - 132.364 - if (ret) 132.365 - printf("ERROR setting policy. Use 'xm dmesg' to see details.\n"); 132.366 - else 132.367 - printf("Successfully changed policy.\n"); 132.368 - return ret; 132.369 -} 132.370 - 132.371 -/******************************* get policy ******************************/ 132.372 - 132.373 -#define PULL_CACHE_SIZE 8192 132.374 -u8 pull_buffer[PULL_CACHE_SIZE]; 132.375 -int acm_domain_getpolicy(int xc_handle) 132.376 -{ 132.377 - policy_op_t op; 132.378 - int ret; 132.379 - 132.380 - memset(pull_buffer, 0x00, sizeof(pull_buffer)); 132.381 - op.cmd = POLICY_GETPOLICY; 132.382 - op.u.getpolicy.pullcache = (void *)pull_buffer; 132.383 - op.u.getpolicy.pullcache_size = sizeof(pull_buffer); 132.384 - ret = do_policy_op(xc_handle, &op); 132.385 - /* dump policy */ 132.386 - acm_dump_policy_buffer(pull_buffer, sizeof(pull_buffer)); 132.387 - return ret; 132.388 -} 132.389 - 132.390 -/************************ load binary policy ******************************/ 132.391 - 132.392 -int acm_domain_loadpolicy(int xc_handle, 132.393 - const char *filename) 132.394 -{ 132.395 - struct stat mystat; 132.396 - int ret, fd; 132.397 - off_t len; 132.398 - u8 *buffer; 132.399 - 132.400 - if ((ret = stat(filename, &mystat))) { 132.401 - printf("File %s not found.\n",filename); 132.402 - goto out; 132.403 - } 132.404 - 132.405 - len = mystat.st_size; 132.406 - if ((buffer = malloc(len)) == NULL) { 132.407 - ret = -ENOMEM; 132.408 - goto out; 132.409 - } 132.410 - if ((fd = open(filename, O_RDONLY)) <= 0) { 132.411 - ret = -ENOENT; 132.412 - printf("File %s not found.\n",filename); 132.413 - goto free_out; 132.414 - } 132.415 - if (len == read(fd, buffer, len)) { 132.416 - policy_op_t op; 132.417 - /* dump it and then push it down into xen/acm */ 132.418 - acm_dump_policy_buffer(buffer, len); 132.419 - op.cmd = POLICY_SETPOLICY; 132.420 - op.u.setpolicy.pushcache = (void *)buffer; 132.421 - op.u.setpolicy.pushcache_size = len; 132.422 - op.u.setpolicy.policy_type = ACM_CHINESE_WALL_AND_SIMPLE_TYPE_ENFORCEMENT_POLICY; 132.423 - ret = do_policy_op(xc_handle, &op); 132.424 - 132.425 - if (ret) 132.426 - printf("ERROR setting policy. Use 'xm dmesg' to see details.\n"); 132.427 - else 132.428 - printf("Successfully changed policy.\n"); 132.429 - 132.430 - } else { 132.431 - ret = -1; 132.432 - } 132.433 - close(fd); 132.434 - free_out: 132.435 - free(buffer); 132.436 - out: 132.437 - return ret; 132.438 -} 132.439 - 132.440 -/************************ dump hook statistics ******************************/ 132.441 -void 132.442 -dump_ste_stats(struct acm_ste_stats_buffer *ste_stats) 132.443 -{ 132.444 - printf("STE-Policy Security Hook Statistics:\n"); 132.445 - printf("ste: event_channel eval_count = %d\n", ntohl(ste_stats->ec_eval_count)); 132.446 - printf("ste: event_channel denied_count = %d\n", ntohl(ste_stats->ec_denied_count)); 132.447 - printf("ste: event_channel cache_hit_count = %d\n", ntohl(ste_stats->ec_cachehit_count)); 132.448 - printf("ste:\n"); 132.449 - printf("ste: grant_table eval_count = %d\n", ntohl(ste_stats->gt_eval_count)); 132.450 - printf("ste: grant_table denied_count = %d\n", ntohl(ste_stats->gt_denied_count)); 132.451 - printf("ste: grant_table cache_hit_count = %d\n", ntohl(ste_stats->gt_cachehit_count)); 132.452 -} 132.453 - 132.454 -#define PULL_STATS_SIZE 8192 132.455 -int acm_domain_dumpstats(int xc_handle) 132.456 -{ 132.457 - u8 stats_buffer[PULL_STATS_SIZE]; 132.458 - policy_op_t op; 132.459 - int ret; 132.460 - struct acm_stats_buffer *stats; 132.461 - 132.462 - memset(stats_buffer, 0x00, sizeof(stats_buffer)); 132.463 - op.cmd = POLICY_DUMPSTATS; 132.464 - op.u.dumpstats.pullcache = (void *)stats_buffer; 132.465 - op.u.dumpstats.pullcache_size = sizeof(stats_buffer); 132.466 - ret = do_policy_op(xc_handle, &op); 132.467 - 132.468 - if (ret < 0) { 132.469 - printf("ERROR dumping policy stats. Use 'xm dmesg' to see details.\n"); 132.470 - return ret; 132.471 - } 132.472 - stats = (struct acm_stats_buffer *)stats_buffer; 132.473 - 132.474 - printf("\nPolicy dump:\n"); 132.475 - printf("============\n"); 132.476 - printf("Magic = %x.\n", ntohl(stats->magic)); 132.477 - printf("PolVer = %x.\n", ntohl(stats->policyversion)); 132.478 - printf("Len = %x.\n", ntohl(stats->len)); 132.479 - 132.480 - switch(ntohs(stats->primary_policy_code)) { 132.481 - case ACM_NULL_POLICY: 132.482 - printf("NULL Policy: No statistics apply.\n"); 132.483 - break; 132.484 - case ACM_CHINESE_WALL_POLICY: 132.485 - printf("Chinese Wall Policy: No statistics apply.\n"); 132.486 - break; 132.487 - case ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY: 132.488 - dump_ste_stats((struct acm_ste_stats_buffer *)(stats_buffer + ntohs(stats->primary_stats_offset))); 132.489 - break; 132.490 - default: 132.491 - printf("UNKNOWN PRIMARY POLICY ERROR!\n"); 132.492 - } 132.493 - switch(ntohs(stats->secondary_policy_code)) { 132.494 - case ACM_NULL_POLICY: 132.495 - printf("NULL Policy: No statistics apply.\n"); 132.496 - break; 132.497 - case ACM_CHINESE_WALL_POLICY: 132.498 - printf("Chinese Wall Policy: No statistics apply.\n"); 132.499 - break; 132.500 - case ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY: 132.501 - dump_ste_stats((struct acm_ste_stats_buffer *)(stats_buffer + ntohs(stats->secondary_stats_offset))); 132.502 - break; 132.503 - default: 132.504 - printf("UNKNOWN SECONDARY POLICY ERROR!\n"); 132.505 - } 132.506 - return ret; 132.507 -} 132.508 - 132.509 -/***************************** main **************************************/ 132.510 - 132.511 -void 132.512 -usage(char *progname){ 132.513 - printf("Use: %s \n" 132.514 - "\t setpolicy\n" 132.515 - "\t getpolicy\n" 132.516 - "\t dumpstats\n" 132.517 - "\t loadpolicy <binary policy file>\n", progname); 132.518 - exit(-1); 132.519 -} 132.520 - 132.521 -int 132.522 -main(int argc, char **argv) { 132.523 - 132.524 - int policycmd_fd, ret; 132.525 - 132.526 - if (argc < 2) 132.527 - usage(argv[0]); 132.528 - 132.529 - if ((policycmd_fd = open("/proc/xen/privcmd", O_RDONLY)) <= 0) { 132.530 - printf("ERROR: Could not open xen privcmd device!\n"); 132.531 - exit(-1); 132.532 - } 132.533 - 132.534 - if (!strcmp(argv[1], "setpolicy")) { 132.535 - if (argc != 2) 132.536 - usage(argv[0]); 132.537 - ret = acm_domain_setpolicy(policycmd_fd); 132.538 - } else if (!strcmp(argv[1], "getpolicy")) { 132.539 - if (argc != 2) 132.540 - usage(argv[0]); 132.541 - ret = acm_domain_getpolicy(policycmd_fd); 132.542 - } else if (!strcmp(argv[1], "loadpolicy")) { 132.543 - if (argc != 3) 132.544 - usage(argv[0]); 132.545 - ret = acm_domain_loadpolicy(policycmd_fd, argv[2]); 132.546 - } else if (!strcmp(argv[1], "dumpstats")) { 132.547 - if (argc != 2) 132.548 - usage(argv[0]); 132.549 - ret = acm_domain_dumpstats(policycmd_fd); 132.550 - } else 132.551 - usage(argv[0]); 132.552 - 132.553 - close(policycmd_fd); 132.554 - return ret; 132.555 -}
133.1 --- a/tools/pygrub/setup.py Tue Aug 02 02:47:41 2005 -0800 133.2 +++ b/tools/pygrub/setup.py Tue Aug 02 10:20:46 2005 -0700 133.3 @@ -23,7 +23,7 @@ if os.path.exists("/usr/include/reiserfs 133.4 fsys_pkgs.append("grub.fsys.reiser") 133.5 133.6 setup(name='pygrub', 133.7 - version='0.2', 133.8 + version='0.3', 133.9 description='Boot loader that looks a lot like grub for Xen', 133.10 author='Jeremy Katz', 133.11 author_email='katzj@redhat.com',
134.1 --- a/tools/pygrub/src/fsys/ext2/__init__.py Tue Aug 02 02:47:41 2005 -0800 134.2 +++ b/tools/pygrub/src/fsys/ext2/__init__.py Tue Aug 02 10:20:46 2005 -0700 134.3 @@ -32,7 +32,7 @@ class Ext2FileSystemType(FileSystemType) 134.4 def open_fs(self, fn, offset = 0): 134.5 if not self.sniff_magic(fn, offset): 134.6 raise ValueError, "Not an ext2 filesystem" 134.7 - return Ext2Fs(fn) 134.8 + return Ext2Fs(fn, offset = offset) 134.9 134.10 register_fstype(Ext2FileSystemType()) 134.11
135.1 --- a/tools/pygrub/src/fsys/ext2/ext2module.c Tue Aug 02 02:47:41 2005 -0800 135.2 +++ b/tools/pygrub/src/fsys/ext2/ext2module.c Tue Aug 02 10:20:46 2005 -0700 135.3 @@ -208,23 +208,29 @@ static PyObject * 135.4 ext2_fs_open (Ext2Fs *fs, PyObject *args, PyObject *kwargs) 135.5 { 135.6 static char *kwlist[] = { "name", "flags", "superblock", 135.7 - "block_size", NULL }; 135.8 + "block_size", "offset", NULL }; 135.9 char * name; 135.10 - int flags = 0, superblock = 0, err; 135.11 + int flags = 0, superblock = 0, offset = 0, err; 135.12 unsigned int block_size = 0; 135.13 ext2_filsys efs; 135.14 + char offsetopt[30]; 135.15 135.16 - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|iii", kwlist, 135.17 - &name, &flags, &superblock, &block_size)) 135.18 - return NULL; 135.19 + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|iiii", kwlist, 135.20 + &name, &flags, &superblock, 135.21 + &block_size, &offset)) 135.22 + return NULL; 135.23 135.24 if (fs->fs != NULL) { 135.25 PyErr_SetString(PyExc_ValueError, "already have an fs object"); 135.26 return NULL; 135.27 } 135.28 135.29 - err = ext2fs_open(name, flags, superblock, block_size, 135.30 - unix_io_manager, &efs); 135.31 + if (offset != 0) { 135.32 + snprintf(offsetopt, 29, "offset=%d", offset); 135.33 + } 135.34 + 135.35 + err = ext2fs_open2(name, offsetopt, flags, superblock, block_size, 135.36 + unix_io_manager, &efs); 135.37 if (err) { 135.38 PyErr_SetString(PyExc_ValueError, "unable to open file"); 135.39 return NULL; 135.40 @@ -323,14 +329,15 @@ static PyObject * 135.41 ext2_fs_new(PyObject *o, PyObject *args, PyObject *kwargs) 135.42 { 135.43 static char *kwlist[] = { "name", "flags", "superblock", 135.44 - "block_size", NULL }; 135.45 + "block_size", "offset", NULL }; 135.46 char * name; 135.47 - int flags = 0, superblock = 0; 135.48 + int flags = 0, superblock = 0, offset; 135.49 unsigned int block_size = 0; 135.50 Ext2Fs *pfs; 135.51 135.52 - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|iii", kwlist, 135.53 - &name, &flags, &superblock, &block_size)) 135.54 + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|iiii", kwlist, 135.55 + &name, &flags, &superblock, &block_size, 135.56 + &offset)) 135.57 return NULL; 135.58 135.59 pfs = (Ext2Fs *) PyObject_NEW(Ext2Fs, &Ext2FsType); 135.60 @@ -339,8 +346,8 @@ ext2_fs_new(PyObject *o, PyObject *args, 135.61 pfs->fs = NULL; 135.62 135.63 if (!ext2_fs_open(pfs, 135.64 - Py_BuildValue("siii", name, flags, superblock, block_size), 135.65 - NULL)) 135.66 + Py_BuildValue("siiii", name, flags, superblock, 135.67 + block_size, offset), NULL)) 135.68 return NULL; 135.69 135.70 return (PyObject *)pfs;
136.1 --- a/tools/pygrub/src/pygrub Tue Aug 02 02:47:41 2005 -0800 136.2 +++ b/tools/pygrub/src/pygrub Tue Aug 02 10:20:46 2005 -0700 136.3 @@ -24,7 +24,7 @@ sys.path = [ '/usr/lib/python' ] + sys.p 136.4 import grub.GrubConf 136.5 import grub.fsys 136.6 136.7 -PYGRUB_VER = 0.02 136.8 +PYGRUB_VER = 0.3 136.9 136.10 136.11 def draw_window(): 136.12 @@ -77,24 +77,39 @@ def is_disk_image(file): 136.13 buf = os.read(fd, 512) 136.14 os.close(fd) 136.15 136.16 - if len(buf) >= 512 and struct.unpack("H", buf[0x1fe: 0x200]) == (0xaaff): 136.17 + if len(buf) >= 512 and struct.unpack("H", buf[0x1fe: 0x200]) == (0xaa55,): 136.18 return True 136.19 return False 136.20 136.21 +SECTOR_SIZE=512 136.22 +def get_active_offset(file): 136.23 + """Find the offset for the start of the first active partition in the 136.24 + disk image file.""" 136.25 + fd = os.open(file, os.O_RDONLY) 136.26 + buf = os.read(fd, 512) 136.27 + for poff in (446, 462, 478, 494): # partition offsets 136.28 + # active partition has 0x80 as the first byte 136.29 + if struct.unpack("<c", buf[p:p+1]) == ('\x80',): 136.30 + return struct.unpack("<", buf[p+8:p+12])[0] * SECTOR_SIZE 136.31 + return -1 136.32 + 136.33 def get_config(fn): 136.34 if not os.access(fn, os.R_OK): 136.35 raise RuntimeError, "Unable to access %s" %(fn,) 136.36 136.37 cf = grub.GrubConf.GrubConfigFile() 136.38 136.39 + offset = 0 136.40 if is_disk_image(fn): 136.41 - raise RuntimeError, "appears to be a full disk image... unable to handle this yet" 136.42 + offset = get_active_offset(fn) 136.43 + if offset == -1: 136.44 + raise RuntimeError, "Unable to find active partition on disk" 136.45 136.46 # open the image and read the grub config 136.47 fs = None 136.48 for fstype in grub.fsys.fstypes.values(): 136.49 - if fstype.sniff_magic(fn): 136.50 - fs = fstype.open_fs(fn) 136.51 + if fstype.sniff_magic(fn, offset): 136.52 + fs = fstype.open_fs(fn, offset) 136.53 break 136.54 136.55 if fs is not None: 136.56 @@ -244,14 +259,17 @@ if __name__ == "__main__": 136.57 if img.initrd: 136.58 print " initrd: %s" %(img.initrd[1],) 136.59 136.60 + offset = 0 136.61 if is_disk_image(file): 136.62 - raise RuntimeError, "unable to handle full disk images yet" 136.63 + offset = get_active_offset(fn) 136.64 + if offset == -1: 136.65 + raise RuntimeError, "Unable to find active partition on disk" 136.66 136.67 # read the kernel and initrd onto the hostfs 136.68 fs = None 136.69 for fstype in grub.fsys.fstypes.values(): 136.70 - if fstype.sniff_magic(file): 136.71 - fs = fstype.open_fs(file) 136.72 + if fstype.sniff_magic(file, offset): 136.73 + fs = fstype.open_fs(file, offset) 136.74 break 136.75 136.76 if fs is None:
157.1 --- a/tools/python/xen/util/blkif.py Tue Aug 02 02:47:41 2005 -0800 157.2 +++ b/tools/python/xen/util/blkif.py Tue Aug 02 10:20:46 2005 -0700 157.3 @@ -24,8 +24,8 @@ def blkdev_name_to_number(name): 157.4 log.debug("exception looking up device number for %s: %s", name, ex) 157.5 pass 157.6 157.7 - if re.match( '/dev/sd[a-p]([0-9]|1[0-5])', n): 157.8 - return 8 * 256 + 16 * (ord(n[7:8]) - ord('a')) + int(n[8:]) 157.9 + if re.match( '/dev/sd[a-p]([1-9]|1[0-5])?', n): 157.10 + return 8 * 256 + 16 * (ord(n[7:8]) - ord('a')) + int(n[8:] or 0) 157.11 157.12 if re.match( '/dev/hd[a-t]([1-9]|[1-5][0-9]|6[0-3])?', n): 157.13 ide_majors = [ 3, 22, 33, 34, 56, 57, 88, 89, 90, 91 ] 157.14 @@ -33,6 +33,9 @@ def blkdev_name_to_number(name): 157.15 minor = ((ord(n[7:8]) - ord('a')) % 2) * 64 + int(n[8:] or 0) 157.16 return major * 256 + minor 157.17 157.18 + if re.match( '/dev/xvd[a-p]([1-9]|1[0-5])?', n): 157.19 + return 202 * 256 + 16 * (ord(n[8:9]) - ord('a')) + int(n[9:] or 0) 157.20 + 157.21 # see if this is a hex device number 157.22 if re.match( '^(0x)?[0-9a-fA-F]+$', name ): 157.23 return string.atoi(name,16)
160.1 --- a/tools/python/xen/xend/XendDomainInfo.py Tue Aug 02 02:47:41 2005 -0800 160.2 +++ b/tools/python/xen/xend/XendDomainInfo.py Tue Aug 02 10:20:46 2005 -0700 160.3 @@ -152,6 +152,9 @@ class XendDomainInfo: 160.4 vm = cls(db) 160.5 vm.construct(config) 160.6 vm.saveToDB(sync=True) 160.7 + # Flush info to xenstore immediately 160.8 + vm.exportToDB() 160.9 + 160.10 return vm 160.11 160.12 create = classmethod(create) 160.13 @@ -172,6 +175,7 @@ class XendDomainInfo: 160.14 log.debug('config=' + prettyprintstring(config)) 160.15 160.16 vm.memory = info['mem_kb']/1024 160.17 + vm.target = info['mem_kb'] * 1024 160.18 160.19 if config: 160.20 try: 160.21 @@ -222,6 +226,7 @@ class XendDomainInfo: 160.22 DBVar('restart_state', ty='str'), 160.23 DBVar('restart_time', ty='float'), 160.24 DBVar('restart_count', ty='int'), 160.25 + DBVar('target', ty='long', path="memory/target"), 160.26 ] 160.27 160.28 def __init__(self, db): 160.29 @@ -240,6 +245,8 @@ class XendDomainInfo: 160.30 self.ssidref = None 160.31 self.image = None 160.32 160.33 + self.target = None 160.34 + 160.35 self.channel = None 160.36 self.store_channel = None 160.37 self.store_mfn = None 160.38 @@ -315,6 +322,7 @@ class XendDomainInfo: 160.39 self.info = info 160.40 self.memory = self.info['mem_kb'] / 1024 160.41 self.ssidref = self.info['ssidref'] 160.42 + self.target = self.info['mem_kb'] * 1024 160.43 160.44 def state_set(self, state): 160.45 self.state_updated.acquire() 160.46 @@ -399,7 +407,8 @@ class XendDomainInfo: 160.47 ['id', self.id], 160.48 ['name', self.name], 160.49 ['memory', self.memory], 160.50 - ['ssidref', self.ssidref] ] 160.51 + ['ssidref', self.ssidref], 160.52 + ['target', self.target] ] 160.53 if self.uuid: 160.54 sxpr.append(['uuid', self.uuid]) 160.55 if self.info: 160.56 @@ -536,6 +545,7 @@ class XendDomainInfo: 160.57 self.memory = int(sxp.child_value(config, 'memory')) 160.58 if self.memory is None: 160.59 raise VmError('missing memory size') 160.60 + self.target = self.memory * (1 << 20) 160.61 self.ssidref = int(sxp.child_value(config, 'ssidref')) 160.62 cpu = sxp.child_value(config, 'cpu') 160.63 if self.recreate and self.id and cpu is not None and int(cpu) >= 0: 160.64 @@ -947,11 +957,12 @@ class XendDomainInfo: 160.65 index[field_name] = field_index + 1 160.66 160.67 def mem_target_set(self, target): 160.68 - """Set domain memory target in pages. 160.69 + """Set domain memory target in bytes. 160.70 """ 160.71 - if self.channel: 160.72 - msg = messages.packMsg('mem_request_t', { 'target' : target * (1 << 8)} ) 160.73 - self.channel.writeRequest(msg) 160.74 + if target: 160.75 + self.target = target * (1 << 20) 160.76 + # Commit to XenStore immediately 160.77 + self.exportToDB() 160.78 160.79 def vcpu_hotplug(self, vcpu, state): 160.80 """Disable or enable VCPU in domain.
168.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 168.2 +++ b/tools/security/Makefile Tue Aug 02 10:20:46 2005 -0700 168.3 @@ -0,0 +1,36 @@ 168.4 +XEN_ROOT = ../.. 168.5 +include $(XEN_ROOT)/tools/Rules.mk 168.6 + 168.7 +SRCS = secpol_tool.c 168.8 +CFLAGS += -static 168.9 +CFLAGS += -Wall 168.10 +CFLAGS += -Werror 168.11 +CFLAGS += -O3 168.12 +CFLAGS += -fno-strict-aliasing 168.13 +CFLAGS += -I. 168.14 + 168.15 +all: build 168.16 +build: mk-symlinks 168.17 + $(MAKE) secpol_tool 168.18 + 168.19 +default: all 168.20 + 168.21 +install: all 168.22 + 168.23 +secpol_tool : secpol_tool.c 168.24 + $(CC) $(CPPFLAGS) $(CFLAGS) -o $@ $< 168.25 + 168.26 +clean: 168.27 + rm -rf secpol_tool xen 168.28 + 168.29 + 168.30 +LINUX_ROOT := $(XEN_ROOT)/linux-2.6-xen-sparse 168.31 +mk-symlinks: 168.32 + [ -e xen/linux ] || mkdir -p xen/linux 168.33 + [ -e xen/io ] || mkdir -p xen/io 168.34 + ( cd xen >/dev/null ; \ 168.35 + ln -sf ../$(XEN_ROOT)/xen/include/public/*.h . ) 168.36 + ( cd xen/io >/dev/null ; \ 168.37 + ln -sf ../../$(XEN_ROOT)/xen/include/public/io/*.h . ) 168.38 + ( cd xen/linux >/dev/null ; \ 168.39 + ln -sf ../../$(LINUX_ROOT)/include/asm-xen/linux-public/*.h . )
169.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 169.2 +++ b/tools/security/secpol_tool.c Tue Aug 02 10:20:46 2005 -0700 169.3 @@ -0,0 +1,648 @@ 169.4 +/**************************************************************** 169.5 + * secpol_tool.c 169.6 + * 169.7 + * Copyright (C) 2005 IBM Corporation 169.8 + * 169.9 + * Authors: 169.10 + * Reiner Sailer <sailer@watson.ibm.com> 169.11 + * Stefan Berger <stefanb@watson.ibm.com> 169.12 + * 169.13 + * This program is free software; you can redistribute it and/or 169.14 + * modify it under the terms of the GNU General Public License as 169.15 + * published by the Free Software Foundation, version 2 of the 169.16 + * License. 169.17 + * 169.18 + * sHype policy management tool. This code runs in a domain and 169.19 + * manages the Xen security policy by interacting with the 169.20 + * Xen access control module via a /proc/xen/privcmd proc-ioctl, 169.21 + * which is translated into a acm_op hypercall into Xen. 169.22 + * 169.23 + * indent -i4 -kr -nut 169.24 + */ 169.25 + 169.26 + 169.27 +#include <unistd.h> 169.28 +#include <stdio.h> 169.29 +#include <errno.h> 169.30 +#include <fcntl.h> 169.31 +#include <sys/mman.h> 169.32 +#include <sys/types.h> 169.33 +#include <sys/stat.h> 169.34 +#include <stdlib.h> 169.35 +#include <sys/ioctl.h> 169.36 +#include <string.h> 169.37 +#include <stdint.h> 169.38 +#include <netinet/in.h> 169.39 + 169.40 +typedef uint8_t u8; 169.41 +typedef uint16_t u16; 169.42 +typedef uint32_t u32; 169.43 +typedef uint64_t u64; 169.44 +typedef int8_t s8; 169.45 +typedef int16_t s16; 169.46 +typedef int32_t s32; 169.47 +typedef int64_t s64; 169.48 + 169.49 +#include <xen/acm.h> 169.50 +#include <xen/acm_ops.h> 169.51 +#include <xen/linux/privcmd.h> 169.52 + 169.53 +#define PERROR(_m, _a...) \ 169.54 +fprintf(stderr, "ERROR: " _m " (%d = %s)\n" , ## _a , \ 169.55 + errno, strerror(errno)) 169.56 + 169.57 +static inline int do_policycmd(int xc_handle, unsigned int cmd, 169.58 + unsigned long data) 169.59 +{ 169.60 + return ioctl(xc_handle, cmd, data); 169.61 +} 169.62 + 169.63 +static inline int do_xen_hypercall(int xc_handle, 169.64 + privcmd_hypercall_t * hypercall) 169.65 +{ 169.66 + return do_policycmd(xc_handle, 169.67 + IOCTL_PRIVCMD_HYPERCALL, 169.68 + (unsigned long) hypercall); 169.69 +} 169.70 + 169.71 +static inline int do_acm_op(int xc_handle, acm_op_t * op) 169.72 +{ 169.73 + int ret = -1; 169.74 + privcmd_hypercall_t hypercall; 169.75 + 169.76 + op->interface_version = ACM_INTERFACE_VERSION; 169.77 + 169.78 + hypercall.op = __HYPERVISOR_acm_op; 169.79 + hypercall.arg[0] = (unsigned long) op; 169.80 + 169.81 + if (mlock(op, sizeof(*op)) != 0) 169.82 + { 169.83 + PERROR("Could not lock memory for Xen policy hypercall"); 169.84 + goto out1; 169.85 + } 169.86 + 169.87 + if ((ret = do_xen_hypercall(xc_handle, &hypercall)) < 0) 169.88 + { 169.89 + if (errno == EACCES) 169.90 + fprintf(stderr, "ACM operation failed -- need to" 169.91 + " rebuild the user-space tool set?\n"); 169.92 + goto out2; 169.93 + } 169.94 + 169.95 + out2:(void) munlock(op, sizeof(*op)); 169.96 + out1:return ret; 169.97 +} 169.98 + 169.99 +/*************************** DUMPS *******************************/ 169.100 + 169.101 +void acm_dump_chinesewall_buffer(void *buf, int buflen) 169.102 +{ 169.103 + 169.104 + struct acm_chwall_policy_buffer *cwbuf = 169.105 + (struct acm_chwall_policy_buffer *) buf; 169.106 + domaintype_t *ssids, *conflicts, *running_types, *conflict_aggregate; 169.107 + int i, j; 169.108 + 169.109 + 169.110 + if (htonl(cwbuf->policy_code) != ACM_CHINESE_WALL_POLICY) 169.111 + { 169.112 + printf("CHINESE WALL POLICY CODE not found ERROR!!\n"); 169.113 + return; 169.114 + } 169.115 + printf("\n\nChinese Wall policy:\n"); 169.116 + printf("====================\n"); 169.117 + printf("Policy version= %x.\n", ntohl(cwbuf->policy_version)); 169.118 + printf("Max Types = %x.\n", ntohl(cwbuf->chwall_max_types)); 169.119 + printf("Max Ssidrefs = %x.\n", ntohl(cwbuf->chwall_max_ssidrefs)); 169.120 + printf("Max ConfSets = %x.\n", ntohl(cwbuf->chwall_max_conflictsets)); 169.121 + printf("Ssidrefs Off = %x.\n", ntohl(cwbuf->chwall_ssid_offset)); 169.122 + printf("Conflicts Off = %x.\n", 169.123 + ntohl(cwbuf->chwall_conflict_sets_offset)); 169.124 + printf("Runing T. Off = %x.\n", 169.125 + ntohl(cwbuf->chwall_running_types_offset)); 169.126 + printf("C. Agg. Off = %x.\n", 169.127 + ntohl(cwbuf->chwall_conflict_aggregate_offset)); 169.128 + printf("\nSSID To CHWALL-Type matrix:\n"); 169.129 + 169.130 + ssids = (domaintype_t *) (buf + ntohl(cwbuf->chwall_ssid_offset)); 169.131 + for (i = 0; i < ntohl(cwbuf->chwall_max_ssidrefs); i++) 169.132 + { 169.133 + printf("\n ssidref%2x: ", i); 169.134 + for (j = 0; j < ntohl(cwbuf->chwall_max_types); j++) 169.135 + printf("%02x ", 169.136 + ntohs(ssids[i * ntohl(cwbuf->chwall_max_types) + j])); 169.137 + } 169.138 + printf("\n\nConfict Sets:\n"); 169.139 + conflicts = 169.140 + (domaintype_t *) (buf + ntohl(cwbuf->chwall_conflict_sets_offset)); 169.141 + for (i = 0; i < ntohl(cwbuf->chwall_max_conflictsets); i++) 169.142 + { 169.143 + printf("\n c-set%2x: ", i); 169.144 + for (j = 0; j < ntohl(cwbuf->chwall_max_types); j++) 169.145 + printf("%02x ", 169.146 + ntohs(conflicts 169.147 + [i * ntohl(cwbuf->chwall_max_types) + j])); 169.148 + } 169.149 + printf("\n"); 169.150 + 169.151 + printf("\nRunning\nTypes: "); 169.152 + if (ntohl(cwbuf->chwall_running_types_offset)) 169.153 + { 169.154 + running_types = 169.155 + (domaintype_t *) (buf + 169.156 + ntohl(cwbuf->chwall_running_types_offset)); 169.157 + for (i = 0; i < ntohl(cwbuf->chwall_max_types); i++) 169.158 + { 169.159 + printf("%02x ", ntohs(running_types[i])); 169.160 + } 169.161 + printf("\n"); 169.162 + } else { 169.163 + printf("Not Reported!\n"); 169.164 + } 169.165 + printf("\nConflict\nAggregate Set: "); 169.166 + if (ntohl(cwbuf->chwall_conflict_aggregate_offset)) 169.167 + { 169.168 + conflict_aggregate = 169.169 + (domaintype_t *) (buf + 169.170 + ntohl(cwbuf->chwall_conflict_aggregate_offset)); 169.171 + for (i = 0; i < ntohl(cwbuf->chwall_max_types); i++) 169.172 + { 169.173 + printf("%02x ", ntohs(conflict_aggregate[i])); 169.174 + } 169.175 + printf("\n\n"); 169.176 + } else { 169.177 + printf("Not Reported!\n"); 169.178 + } 169.179 +} 169.180 + 169.181 +void acm_dump_ste_buffer(void *buf, int buflen) 169.182 +{ 169.183 + 169.184 + struct acm_ste_policy_buffer *stebuf = 169.185 + (struct acm_ste_policy_buffer *) buf; 169.186 + domaintype_t *ssids; 169.187 + int i, j; 169.188 + 169.189 + 169.190 + if (ntohl(stebuf->policy_code) != ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY) { 169.191 + printf("SIMPLE TYPE ENFORCEMENT POLICY CODE not found ERROR!!\n"); 169.192 + return; 169.193 + } 169.194 + printf("\nSimple Type Enforcement policy:\n"); 169.195 + printf("===============================\n"); 169.196 + printf("Policy version= %x.\n", ntohl(stebuf->policy_version)); 169.197 + printf("Max Types = %x.\n", ntohl(stebuf->ste_max_types)); 169.198 + printf("Max Ssidrefs = %x.\n", ntohl(stebuf->ste_max_ssidrefs)); 169.199 + printf("Ssidrefs Off = %x.\n", ntohl(stebuf->ste_ssid_offset)); 169.200 + printf("\nSSID To STE-Type matrix:\n"); 169.201 + 169.202 + ssids = (domaintype_t *) (buf + ntohl(stebuf->ste_ssid_offset)); 169.203 + for (i = 0; i < ntohl(stebuf->ste_max_ssidrefs); i++) 169.204 + { 169.205 + printf("\n ssidref%2x: ", i); 169.206 + for (j = 0; j < ntohl(stebuf->ste_max_types); j++) 169.207 + printf("%02x ", ntohs(ssids[i * ntohl(stebuf->ste_max_types) + j])); 169.208 + } 169.209 + printf("\n\n"); 169.210 +} 169.211 + 169.212 +void acm_dump_policy_buffer(void *buf, int buflen) 169.213 +{ 169.214 + struct acm_policy_buffer *pol = (struct acm_policy_buffer *) buf; 169.215 + 169.216 + printf("\nPolicy dump:\n"); 169.217 + printf("============\n"); 169.218 + printf("PolicyVer = %x.\n", ntohl(pol->policy_version)); 169.219 + printf("Magic = %x.\n", ntohl(pol->magic)); 169.220 + printf("Len = %x.\n", ntohl(pol->len)); 169.221 + printf("Primary = %s (c=%x, off=%x).\n", 169.222 + ACM_POLICY_NAME(ntohl(pol->primary_policy_code)), 169.223 + ntohl(pol->primary_policy_code), 169.224 + ntohl(pol->primary_buffer_offset)); 169.225 + printf("Secondary = %s (c=%x, off=%x).\n", 169.226 + ACM_POLICY_NAME(ntohl(pol->secondary_policy_code)), 169.227 + ntohl(pol->secondary_policy_code), 169.228 + ntohl(pol->secondary_buffer_offset)); 169.229 + switch (ntohl(pol->primary_policy_code)) 169.230 + { 169.231 + case ACM_CHINESE_WALL_POLICY: 169.232 + acm_dump_chinesewall_buffer(buf + 169.233 + ntohl(pol->primary_buffer_offset), 169.234 + ntohl(pol->len) - 169.235 + ntohl(pol->primary_buffer_offset)); 169.236 + break; 169.237 + 169.238 + case ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY: 169.239 + acm_dump_ste_buffer(buf + ntohl(pol->primary_buffer_offset), 169.240 + ntohl(pol->len) - 169.241 + ntohl(pol->primary_buffer_offset)); 169.242 + break; 169.243 + 169.244 + case ACM_NULL_POLICY: 169.245 + printf("Primary policy is NULL Policy (n/a).\n"); 169.246 + break; 169.247 + 169.248 + default: 169.249 + printf("UNKNOWN POLICY!\n"); 169.250 + } 169.251 + 169.252 + switch (ntohl(pol->secondary_policy_code)) 169.253 + { 169.254 + case ACM_CHINESE_WALL_POLICY: 169.255 + acm_dump_chinesewall_buffer(buf + 169.256 + ntohl(pol->secondary_buffer_offset), 169.257 + ntohl(pol->len) - 169.258 + ntohl(pol->secondary_buffer_offset)); 169.259 + break; 169.260 + 169.261 + case ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY: 169.262 + acm_dump_ste_buffer(buf + ntohl(pol->secondary_buffer_offset), 169.263 + ntohl(pol->len) - 169.264 + ntohl(pol->secondary_buffer_offset)); 169.265 + break; 169.266 + 169.267 + case ACM_NULL_POLICY: 169.268 + printf("Secondary policy is NULL Policy (n/a).\n"); 169.269 + break; 169.270 + 169.271 + default: 169.272 + printf("UNKNOWN POLICY!\n"); 169.273 + } 169.274 +} 169.275 + 169.276 +/*************************** set policy ****************************/ 169.277 + 169.278 +int acm_domain_set_chwallpolicy(void *bufstart, int buflen) 169.279 +{ 169.280 +#define CWALL_MAX_SSIDREFS 6 169.281 +#define CWALL_MAX_TYPES 10 169.282 +#define CWALL_MAX_CONFLICTSETS 2 169.283 + 169.284 + struct acm_chwall_policy_buffer *chwall_bin_pol = 169.285 + (struct acm_chwall_policy_buffer *) bufstart; 169.286 + domaintype_t *ssidrefs, *conflicts; 169.287 + int ret = 0; 169.288 + int j; 169.289 + 169.290 + chwall_bin_pol->chwall_max_types = htonl(CWALL_MAX_TYPES); 169.291 + chwall_bin_pol->chwall_max_ssidrefs = htonl(CWALL_MAX_SSIDREFS); 169.292 + chwall_bin_pol->policy_code = htonl(ACM_CHINESE_WALL_POLICY); 169.293 + chwall_bin_pol->policy_version = htonl(ACM_CHWALL_VERSION); 169.294 + chwall_bin_pol->chwall_ssid_offset = 169.295 + htonl(sizeof(struct acm_chwall_policy_buffer)); 169.296 + chwall_bin_pol->chwall_max_conflictsets = 169.297 + htonl(CWALL_MAX_CONFLICTSETS); 169.298 + chwall_bin_pol->chwall_conflict_sets_offset = 169.299 + htonl(ntohl(chwall_bin_pol->chwall_ssid_offset) + 169.300 + sizeof(domaintype_t) * CWALL_MAX_SSIDREFS * CWALL_MAX_TYPES); 169.301 + chwall_bin_pol->chwall_running_types_offset = 0; /* not set */ 169.302 + chwall_bin_pol->chwall_conflict_aggregate_offset = 0; /* not set */ 169.303 + ret += sizeof(struct acm_chwall_policy_buffer); 169.304 + /* now push example ssids into the buffer (max_ssidrefs x max_types entries) */ 169.305 + /* check buffer size */ 169.306 + if ((buflen - ret) < 169.307 + (CWALL_MAX_TYPES * CWALL_MAX_SSIDREFS * sizeof(domaintype_t))) 169.308 + return -1; /* not enough space */ 169.309 + 169.310 + ssidrefs = (domaintype_t *) (bufstart + 169.311 + ntohl(chwall_bin_pol->chwall_ssid_offset)); 169.312 + memset(ssidrefs, 0, 169.313 + CWALL_MAX_TYPES * CWALL_MAX_SSIDREFS * sizeof(domaintype_t)); 169.314 + 169.315 + /* now set type j-1 for ssidref i+1 */ 169.316 + for (j = 0; j <= CWALL_MAX_SSIDREFS; j++) 169.317 + if ((0 < j) && (j <= CWALL_MAX_TYPES)) 169.318 + ssidrefs[j * CWALL_MAX_TYPES + j - 1] = htons(1); 169.319 + 169.320 + ret += CWALL_MAX_TYPES * CWALL_MAX_SSIDREFS * sizeof(domaintype_t); 169.321 + if ((buflen - ret) < 169.322 + (CWALL_MAX_CONFLICTSETS * CWALL_MAX_TYPES * sizeof(domaintype_t))) 169.323 + return -1; /* not enough space */ 169.324 + 169.325 + /* now the chinese wall policy conflict sets */ 169.326 + conflicts = (domaintype_t *) (bufstart + 169.327 + ntohl(chwall_bin_pol-> 169.328 + chwall_conflict_sets_offset)); 169.329 + memset((void *) conflicts, 0, 169.330 + CWALL_MAX_CONFLICTSETS * CWALL_MAX_TYPES * 169.331 + sizeof(domaintype_t)); 169.332 + /* just 1 conflict set [0]={2,3}, [1]={1,5,6} */ 169.333 + if (CWALL_MAX_TYPES > 3) 169.334 + { 169.335 + conflicts[2] = htons(1); 169.336 + conflicts[3] = htons(1); /* {2,3} */ 169.337 + conflicts[CWALL_MAX_TYPES + 1] = htons(1); 169.338 + conflicts[CWALL_MAX_TYPES + 5] = htons(1); 169.339 + conflicts[CWALL_MAX_TYPES + 6] = htons(1); /* {0,5,6} */ 169.340 + } 169.341 + ret += sizeof(domaintype_t) * CWALL_MAX_CONFLICTSETS * CWALL_MAX_TYPES; 169.342 + return ret; 169.343 +} 169.344 + 169.345 +int acm_domain_set_stepolicy(void *bufstart, int buflen) 169.346 +{ 169.347 +#define STE_MAX_SSIDREFS 6 169.348 +#define STE_MAX_TYPES 5 169.349 + 169.350 + struct acm_ste_policy_buffer *ste_bin_pol = 169.351 + (struct acm_ste_policy_buffer *) bufstart; 169.352 + domaintype_t *ssidrefs; 169.353 + int j, ret = 0; 169.354 + 169.355 + ste_bin_pol->ste_max_types = htonl(STE_MAX_TYPES); 169.356 + ste_bin_pol->ste_max_ssidrefs = htonl(STE_MAX_SSIDREFS); 169.357 + ste_bin_pol->policy_code = htonl(ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY); 169.358 + ste_bin_pol->policy_version = htonl(ACM_STE_VERSION); 169.359 + ste_bin_pol->ste_ssid_offset = 169.360 + htonl(sizeof(struct acm_ste_policy_buffer)); 169.361 + ret += sizeof(struct acm_ste_policy_buffer); 169.362 + /* check buffer size */ 169.363 + if ((buflen - ret) < 169.364 + (STE_MAX_TYPES * STE_MAX_SSIDREFS * sizeof(domaintype_t))) 169.365 + return -1; /* not enough space */ 169.366 + 169.367 + ssidrefs = 169.368 + (domaintype_t *) (bufstart + ntohl(ste_bin_pol->ste_ssid_offset)); 169.369 + memset(ssidrefs, 0, 169.370 + STE_MAX_TYPES * STE_MAX_SSIDREFS * sizeof(domaintype_t)); 169.371 + /* all types 1 for ssidref 1 */ 169.372 + for (j = 0; j < STE_MAX_TYPES; j++) 169.373 + ssidrefs[1 * STE_MAX_TYPES + j] = htons(1); 169.374 + /* now set type j-1 for ssidref j */ 169.375 + for (j = 0; j < STE_MAX_SSIDREFS; j++) 169.376 + if ((0 < j) && (j <= STE_MAX_TYPES)) 169.377 + ssidrefs[j * STE_MAX_TYPES + j - 1] = htons(1); 169.378 + ret += STE_MAX_TYPES * STE_MAX_SSIDREFS * sizeof(domaintype_t); 169.379 + return ret; 169.380 +} 169.381 + 169.382 +#define MAX_PUSH_BUFFER 16384 169.383 +u8 push_buffer[MAX_PUSH_BUFFER]; 169.384 + 169.385 +int acm_domain_setpolicy(int xc_handle) 169.386 +{ 169.387 + int ret; 169.388 + struct acm_policy_buffer *bin_pol; 169.389 + acm_op_t op; 169.390 + 169.391 + /* future: read policy from file and set it */ 169.392 + bin_pol = (struct acm_policy_buffer *) push_buffer; 169.393 + bin_pol->policy_version = htonl(ACM_POLICY_VERSION); 169.394 + bin_pol->magic = htonl(ACM_MAGIC); 169.395 + bin_pol->primary_policy_code = htonl(ACM_CHINESE_WALL_POLICY); 169.396 + bin_pol->secondary_policy_code = 169.397 + htonl(ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY); 169.398 + 169.399 + bin_pol->len = htonl(sizeof(struct acm_policy_buffer)); 169.400 + bin_pol->primary_buffer_offset = htonl(ntohl(bin_pol->len)); 169.401 + ret = 169.402 + acm_domain_set_chwallpolicy(push_buffer + 169.403 + ntohl(bin_pol->primary_buffer_offset), 169.404 + MAX_PUSH_BUFFER - 169.405 + ntohl(bin_pol->primary_buffer_offset)); 169.406 + if (ret < 0) 169.407 + { 169.408 + printf("ERROR creating chwallpolicy buffer.\n"); 169.409 + return -1; 169.410 + } 169.411 + bin_pol->len = htonl(ntohl(bin_pol->len) + ret); 169.412 + bin_pol->secondary_buffer_offset = htonl(ntohl(bin_pol->len)); 169.413 + ret = acm_domain_set_stepolicy(push_buffer + 169.414 + ntohl(bin_pol->secondary_buffer_offset), 169.415 + MAX_PUSH_BUFFER - 169.416 + ntohl(bin_pol->secondary_buffer_offset)); 169.417 + if (ret < 0) 169.418 + { 169.419 + printf("ERROR creating chwallpolicy buffer.\n"); 169.420 + return -1; 169.421 + } 169.422 + bin_pol->len = htonl(ntohl(bin_pol->len) + ret); 169.423 + 169.424 + /* dump it and then push it down into xen/acm */ 169.425 + acm_dump_policy_buffer(push_buffer, ntohl(bin_pol->len)); 169.426 + 169.427 + op.cmd = ACM_SETPOLICY; 169.428 + op.interface_version = ACM_INTERFACE_VERSION; 169.429 + op.u.setpolicy.pushcache = (void *) push_buffer; 169.430 + op.u.setpolicy.pushcache_size = ntohl(bin_pol->len); 169.431 + ret = do_acm_op(xc_handle, &op); 169.432 + 169.433 + if (ret) 169.434 + printf("ERROR setting policy. Use 'xm dmesg' to see details.\n"); 169.435 + else 169.436 + printf("Successfully changed policy.\n"); 169.437 + 169.438 + return ret; 169.439 +} 169.440 + 169.441 +/******************************* get policy ******************************/ 169.442 + 169.443 +#define PULL_CACHE_SIZE 8192 169.444 +u8 pull_buffer[PULL_CACHE_SIZE]; 169.445 +int acm_domain_getpolicy(int xc_handle) 169.446 +{ 169.447 + acm_op_t op; 169.448 + int ret; 169.449 + 169.450 + memset(pull_buffer, 0x00, sizeof(pull_buffer)); 169.451 + op.cmd = ACM_GETPOLICY; 169.452 + op.interface_version = ACM_INTERFACE_VERSION; 169.453 + op.u.getpolicy.pullcache = (void *) pull_buffer; 169.454 + op.u.getpolicy.pullcache_size = sizeof(pull_buffer); 169.455 + ret = do_acm_op(xc_handle, &op); 169.456 + /* dump policy */ 169.457 + acm_dump_policy_buffer(pull_buffer, sizeof(pull_buffer)); 169.458 + return ret; 169.459 +} 169.460 + 169.461 +/************************ load binary policy ******************************/ 169.462 + 169.463 +int acm_domain_loadpolicy(int xc_handle, const char *filename) 169.464 +{ 169.465 + struct stat mystat; 169.466 + int ret, fd; 169.467 + off_t len; 169.468 + u8 *buffer; 169.469 + 169.470 + if ((ret = stat(filename, &mystat))) 169.471 + { 169.472 + printf("File %s not found.\n", filename); 169.473 + goto out; 169.474 + } 169.475 + 169.476 + len = mystat.st_size; 169.477 + if ((buffer = malloc(len)) == NULL) 169.478 + { 169.479 + ret = -ENOMEM; 169.480 + goto out; 169.481 + } 169.482 + if ((fd = open(filename, O_RDONLY)) <= 0) 169.483 + { 169.484 + ret = -ENOENT; 169.485 + printf("File %s not found.\n", filename); 169.486 + goto free_out; 169.487 + } 169.488 + if (len == read(fd, buffer, len)) 169.489 + { 169.490 + acm_op_t op; 169.491 + /* dump it and then push it down into xen/acm */ 169.492 + acm_dump_policy_buffer(buffer, len); 169.493 + op.cmd = ACM_SETPOLICY; 169.494 + op.interface_version = ACM_INTERFACE_VERSION; 169.495 + op.u.setpolicy.pushcache = (void *) buffer; 169.496 + op.u.setpolicy.pushcache_size = len; 169.497 + ret = do_acm_op(xc_handle, &op); 169.498 + 169.499 + if (ret) 169.500 + printf 169.501 + ("ERROR setting policy. Use 'xm dmesg' to see details.\n"); 169.502 + else 169.503 + printf("Successfully changed policy.\n"); 169.504 + 169.505 + } else { 169.506 + ret = -1; 169.507 + } 169.508 + close(fd); 169.509 + free_out: 169.510 + free(buffer); 169.511 + out: 169.512 + return ret; 169.513 +} 169.514 + 169.515 +/************************ dump hook statistics ******************************/ 169.516 +void dump_ste_stats(struct acm_ste_stats_buffer *ste_stats) 169.517 +{ 169.518 + printf("STE-Policy Security Hook Statistics:\n"); 169.519 + printf("ste: event_channel eval_count = %d\n", 169.520 + ntohl(ste_stats->ec_eval_count)); 169.521 + printf("ste: event_channel denied_count = %d\n", 169.522 + ntohl(ste_stats->ec_denied_count)); 169.523 + printf("ste: event_channel cache_hit_count = %d\n", 169.524 + ntohl(ste_stats->ec_cachehit_count)); 169.525 + printf("ste:\n"); 169.526 + printf("ste: grant_table eval_count = %d\n", 169.527 + ntohl(ste_stats->gt_eval_count)); 169.528 + printf("ste: grant_table denied_count = %d\n", 169.529 + ntohl(ste_stats->gt_denied_count)); 169.530 + printf("ste: grant_table cache_hit_count = %d\n", 169.531 + ntohl(ste_stats->gt_cachehit_count)); 169.532 +} 169.533 + 169.534 +#define PULL_STATS_SIZE 8192 169.535 +int acm_domain_dumpstats(int xc_handle) 169.536 +{ 169.537 + u8 stats_buffer[PULL_STATS_SIZE]; 169.538 + acm_op_t op; 169.539 + int ret; 169.540 + struct acm_stats_buffer *stats; 169.541 + 169.542 + memset(stats_buffer, 0x00, sizeof(stats_buffer)); 169.543 + op.cmd = ACM_DUMPSTATS; 169.544 + op.interface_version = ACM_INTERFACE_VERSION; 169.545 + op.u.dumpstats.pullcache = (void *) stats_buffer; 169.546 + op.u.dumpstats.pullcache_size = sizeof(stats_buffer); 169.547 + ret = do_acm_op(xc_handle, &op); 169.548 + 169.549 + if (ret < 0) 169.550 + { 169.551 + printf("ERROR dumping policy stats. Use 'xm dmesg' to see details.\n"); 169.552 + return ret; 169.553 + } 169.554 + stats = (struct acm_stats_buffer *) stats_buffer; 169.555 + 169.556 + printf("\nPolicy dump:\n"); 169.557 + printf("============\n"); 169.558 + printf("Magic = %x.\n", ntohl(stats->magic)); 169.559 + printf("Len = %x.\n", ntohl(stats->len)); 169.560 + 169.561 + switch (ntohl(stats->primary_policy_code)) 169.562 + { 169.563 + case ACM_NULL_POLICY: 169.564 + printf("NULL Policy: No statistics apply.\n"); 169.565 + break; 169.566 + 169.567 + case ACM_CHINESE_WALL_POLICY: 169.568 + printf("Chinese Wall Policy: No statistics apply.\n"); 169.569 + break; 169.570 + 169.571 + case ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY: 169.572 + dump_ste_stats((struct acm_ste_stats_buffer *) (stats_buffer + 169.573 + ntohl(stats-> 169.574 + primary_stats_offset))); 169.575 + break; 169.576 + 169.577 + default: 169.578 + printf("UNKNOWN PRIMARY POLICY ERROR!\n"); 169.579 + } 169.580 + 169.581 + switch (ntohl(stats->secondary_policy_code)) 169.582 + { 169.583 + case ACM_NULL_POLICY: 169.584 + printf("NULL Policy: No statistics apply.\n"); 169.585 + break; 169.586 + 169.587 + case ACM_CHINESE_WALL_POLICY: 169.588 + printf("Chinese Wall Policy: No statistics apply.\n"); 169.589 + break; 169.590 + 169.591 + case ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY: 169.592 + dump_ste_stats((struct acm_ste_stats_buffer *) (stats_buffer + 169.593 + ntohl(stats-> 169.594 + secondary_stats_offset))); 169.595 + break; 169.596 + 169.597 + default: 169.598 + printf("UNKNOWN SECONDARY POLICY ERROR!\n"); 169.599 + } 169.600 + return ret; 169.601 +} 169.602 + 169.603 +/***************************** main **************************************/ 169.604 + 169.605 +void usage(char *progname) 169.606 +{ 169.607 + printf("Use: %s \n" 169.608 + "\t setpolicy\n" 169.609 + "\t getpolicy\n" 169.610 + "\t dumpstats\n" 169.611 + "\t loadpolicy <binary policy file>\n", progname); 169.612 + exit(-1); 169.613 +} 169.614 + 169.615 +int main(int argc, char **argv) 169.616 +{ 169.617 + 169.618 + int acm_cmd_fd, ret; 169.619 + 169.620 + if (argc < 2) 169.621 + usage(argv[0]); 169.622 + 169.623 + if ((acm_cmd_fd = open("/proc/xen/privcmd", O_RDONLY)) <= 0) 169.624 + { 169.625 + printf("ERROR: Could not open xen privcmd device!\n"); 169.626 + exit(-1); 169.627 + } 169.628 + 169.629 + if (!strcmp(argv[1], "setpolicy")) 169.630 + { 169.631 + if (argc != 2) 169.632 + usage(argv[0]); 169.633 + ret = acm_domain_setpolicy(acm_cmd_fd); 169.634 + } else if (!strcmp(argv[1], "getpolicy")) { 169.635 + if (argc != 2) 169.636 + usage(argv[0]); 169.637 + ret = acm_domain_getpolicy(acm_cmd_fd); 169.638 + } else if (!strcmp(argv[1], "loadpolicy")) { 169.639 + if (argc != 3) 169.640 + usage(argv[0]); 169.641 + ret = acm_domain_loadpolicy(acm_cmd_fd, argv[2]); 169.642 + } else if (!strcmp(argv[1], "dumpstats")) { 169.643 + if (argc != 2) 169.644 + usage(argv[0]); 169.645 + ret = acm_domain_dumpstats(acm_cmd_fd); 169.646 + } else 169.647 + usage(argv[0]); 169.648 + 169.649 + close(acm_cmd_fd); 169.650 + return ret; 169.651 +}
218.1 --- a/xen/acm/acm_chinesewall_hooks.c Tue Aug 02 02:47:41 2005 -0800 218.2 +++ b/xen/acm/acm_chinesewall_hooks.c Tue Aug 02 10:20:46 2005 -0700 218.3 @@ -110,45 +110,45 @@ chwall_dump_policy(u8 *buf, u16 buf_size 218.4 struct acm_chwall_policy_buffer *chwall_buf = (struct acm_chwall_policy_buffer *)buf; 218.5 int ret = 0; 218.6 218.7 - chwall_buf->chwall_max_types = htons(chwall_bin_pol.max_types); 218.8 - chwall_buf->chwall_max_ssidrefs = htons(chwall_bin_pol.max_ssidrefs); 218.9 - chwall_buf->policy_code = htons(ACM_CHINESE_WALL_POLICY); 218.10 - chwall_buf->chwall_ssid_offset = htons(sizeof(struct acm_chwall_policy_buffer)); 218.11 - chwall_buf->chwall_max_conflictsets = htons(chwall_bin_pol.max_conflictsets); 218.12 + chwall_buf->chwall_max_types = htonl(chwall_bin_pol.max_types); 218.13 + chwall_buf->chwall_max_ssidrefs = htonl(chwall_bin_pol.max_ssidrefs); 218.14 + chwall_buf->policy_code = htonl(ACM_CHINESE_WALL_POLICY); 218.15 + chwall_buf->chwall_ssid_offset = htonl(sizeof(struct acm_chwall_policy_buffer)); 218.16 + chwall_buf->chwall_max_conflictsets = htonl(chwall_bin_pol.max_conflictsets); 218.17 chwall_buf->chwall_conflict_sets_offset = 218.18 - htons( 218.19 - ntohs(chwall_buf->chwall_ssid_offset) + 218.20 + htonl( 218.21 + ntohl(chwall_buf->chwall_ssid_offset) + 218.22 sizeof(domaintype_t) * chwall_bin_pol.max_ssidrefs * 218.23 chwall_bin_pol.max_types); 218.24 218.25 chwall_buf->chwall_running_types_offset = 218.26 - htons( 218.27 - ntohs(chwall_buf->chwall_conflict_sets_offset) + 218.28 + htonl( 218.29 + ntohl(chwall_buf->chwall_conflict_sets_offset) + 218.30 sizeof(domaintype_t) * chwall_bin_pol.max_conflictsets * 218.31 chwall_bin_pol.max_types); 218.32 218.33 chwall_buf->chwall_conflict_aggregate_offset = 218.34 - htons( 218.35 - ntohs(chwall_buf->chwall_running_types_offset) + 218.36 + htonl( 218.37 + ntohl(chwall_buf->chwall_running_types_offset) + 218.38 sizeof(domaintype_t) * chwall_bin_pol.max_types); 218.39 218.40 - ret = ntohs(chwall_buf->chwall_conflict_aggregate_offset) + 218.41 + ret = ntohl(chwall_buf->chwall_conflict_aggregate_offset) + 218.42 sizeof(domaintype_t) * chwall_bin_pol.max_types; 218.43 218.44 /* now copy buffers over */ 218.45 - arrcpy16((u16 *)(buf + ntohs(chwall_buf->chwall_ssid_offset)), 218.46 + arrcpy16((u16 *)(buf + ntohl(chwall_buf->chwall_ssid_offset)), 218.47 chwall_bin_pol.ssidrefs, 218.48 chwall_bin_pol.max_ssidrefs * chwall_bin_pol.max_types); 218.49 218.50 - arrcpy16((u16 *)(buf + ntohs(chwall_buf->chwall_conflict_sets_offset)), 218.51 + arrcpy16((u16 *)(buf + ntohl(chwall_buf->chwall_conflict_sets_offset)), 218.52 chwall_bin_pol.conflict_sets, 218.53 chwall_bin_pol.max_conflictsets * chwall_bin_pol.max_types); 218.54 218.55 - arrcpy16((u16 *)(buf + ntohs(chwall_buf->chwall_running_types_offset)), 218.56 + arrcpy16((u16 *)(buf + ntohl(chwall_buf->chwall_running_types_offset)), 218.57 chwall_bin_pol.running_types, 218.58 chwall_bin_pol.max_types); 218.59 218.60 - arrcpy16((u16 *)(buf + ntohs(chwall_buf->chwall_conflict_aggregate_offset)), 218.61 + arrcpy16((u16 *)(buf + ntohl(chwall_buf->chwall_conflict_aggregate_offset)), 218.62 chwall_bin_pol.conflict_aggregate_set, 218.63 chwall_bin_pol.max_types); 218.64 return ret; 218.65 @@ -226,14 +226,20 @@ chwall_set_policy(u8 *buf, u16 buf_size) 218.66 void *ssids = NULL, *conflict_sets = NULL, *running_types = NULL, *conflict_aggregate_set = NULL; 218.67 218.68 /* rewrite the policy due to endianess */ 218.69 - chwall_buf->policy_code = ntohs(chwall_buf->policy_code); 218.70 - chwall_buf->chwall_max_types = ntohs(chwall_buf->chwall_max_types); 218.71 - chwall_buf->chwall_max_ssidrefs = ntohs(chwall_buf->chwall_max_ssidrefs); 218.72 - chwall_buf->chwall_max_conflictsets = ntohs(chwall_buf->chwall_max_conflictsets); 218.73 - chwall_buf->chwall_ssid_offset = ntohs(chwall_buf->chwall_ssid_offset); 218.74 - chwall_buf->chwall_conflict_sets_offset = ntohs(chwall_buf->chwall_conflict_sets_offset); 218.75 - chwall_buf->chwall_running_types_offset = ntohs(chwall_buf->chwall_running_types_offset); 218.76 - chwall_buf->chwall_conflict_aggregate_offset = ntohs(chwall_buf->chwall_conflict_aggregate_offset); 218.77 + chwall_buf->policy_code = ntohl(chwall_buf->policy_code); 218.78 + chwall_buf->policy_version = ntohl(chwall_buf->policy_version); 218.79 + chwall_buf->chwall_max_types = ntohl(chwall_buf->chwall_max_types); 218.80 + chwall_buf->chwall_max_ssidrefs = ntohl(chwall_buf->chwall_max_ssidrefs); 218.81 + chwall_buf->chwall_max_conflictsets = ntohl(chwall_buf->chwall_max_conflictsets); 218.82 + chwall_buf->chwall_ssid_offset = ntohl(chwall_buf->chwall_ssid_offset); 218.83 + chwall_buf->chwall_conflict_sets_offset = ntohl(chwall_buf->chwall_conflict_sets_offset); 218.84 + chwall_buf->chwall_running_types_offset = ntohl(chwall_buf->chwall_running_types_offset); 218.85 + chwall_buf->chwall_conflict_aggregate_offset = ntohl(chwall_buf->chwall_conflict_aggregate_offset); 218.86 + 218.87 + /* policy type and version checks */ 218.88 + if ((chwall_buf->policy_code != ACM_CHINESE_WALL_POLICY) || 218.89 + (chwall_buf->policy_version != ACM_CHWALL_VERSION)) 218.90 + return -EINVAL; 218.91 218.92 /* 1. allocate new buffers */ 218.93 ssids = xmalloc_array(domaintype_t, chwall_buf->chwall_max_types*chwall_buf->chwall_max_ssidrefs);
219.1 --- a/xen/acm/acm_core.c Tue Aug 02 02:47:41 2005 -0800 219.2 +++ b/xen/acm/acm_core.c Tue Aug 02 10:20:46 2005 -0700 219.3 @@ -120,7 +120,6 @@ acm_setup(unsigned int *initrdidx, 219.4 if (ntohl(pol->magic) == ACM_MAGIC) { 219.5 rc = acm_set_policy((void *)_policy_start, 219.6 (u16)_policy_len, 219.7 - ACM_USE_SECURITY_POLICY, 219.8 0); 219.9 if (rc == ACM_OK) { 219.10 printf("Policy len 0x%lx, start at %p.\n",_policy_len,_policy_start);
220.1 --- a/xen/acm/acm_policy.c Tue Aug 02 02:47:41 2005 -0800 220.2 +++ b/xen/acm/acm_policy.c Tue Aug 02 10:20:46 2005 -0700 220.3 @@ -6,9 +6,8 @@ 220.4 * Author: 220.5 * Reiner Sailer <sailer@watson.ibm.com> 220.6 * 220.7 - * Contributions: 220.8 + * Contributors: 220.9 * Stefan Berger <stefanb@watson.ibm.com> 220.10 - * support for network-byte-order binary policies 220.11 * 220.12 * This program is free software; you can redistribute it and/or 220.13 * modify it under the terms of the GNU General Public License as 220.14 @@ -27,29 +26,20 @@ 220.15 #include <xen/lib.h> 220.16 #include <xen/delay.h> 220.17 #include <xen/sched.h> 220.18 -#include <public/policy_ops.h> 220.19 +#include <public/acm_ops.h> 220.20 #include <acm/acm_core.h> 220.21 #include <acm/acm_hooks.h> 220.22 #include <acm/acm_endian.h> 220.23 220.24 int 220.25 -acm_set_policy(void *buf, u16 buf_size, u16 policy, int isuserbuffer) 220.26 +acm_set_policy(void *buf, u16 buf_size, int isuserbuffer) 220.27 { 220.28 u8 *policy_buffer = NULL; 220.29 struct acm_policy_buffer *pol; 220.30 220.31 - if (policy != ACM_USE_SECURITY_POLICY) { 220.32 - printk("%s: Loading incompatible policy (running: %s).\n", __func__, 220.33 - ACM_POLICY_NAME(ACM_USE_SECURITY_POLICY)); 220.34 - return -EFAULT; 220.35 - } 220.36 - /* now check correct buffer sizes for policy combinations */ 220.37 - if (policy == ACM_NULL_POLICY) { 220.38 - printkd("%s: NULL Policy, no policy needed.\n", __func__); 220.39 - goto out; 220.40 - } 220.41 if (buf_size < sizeof(struct acm_policy_buffer)) 220.42 return -EFAULT; 220.43 + 220.44 /* 1. copy buffer from domain */ 220.45 if ((policy_buffer = xmalloc_array(u8, buf_size)) == NULL) 220.46 goto error_free; 220.47 @@ -58,17 +48,17 @@ acm_set_policy(void *buf, u16 buf_size, 220.48 printk("%s: Error copying!\n",__func__); 220.49 goto error_free; 220.50 } 220.51 - } else { 220.52 + } else 220.53 memcpy(policy_buffer, buf, buf_size); 220.54 - } 220.55 + 220.56 /* 2. some sanity checking */ 220.57 pol = (struct acm_policy_buffer *)policy_buffer; 220.58 220.59 if ((ntohl(pol->magic) != ACM_MAGIC) || 220.60 - (ntohs(pol->primary_policy_code) != acm_bin_pol.primary_policy_code) || 220.61 - (ntohs(pol->secondary_policy_code) != acm_bin_pol.secondary_policy_code) || 220.62 - (ntohl(pol->policyversion) != POLICY_INTERFACE_VERSION)) { 220.63 - printkd("%s: Wrong policy magics!\n", __func__); 220.64 + (ntohl(pol->policy_version) != ACM_POLICY_VERSION) || 220.65 + (ntohl(pol->primary_policy_code) != acm_bin_pol.primary_policy_code) || 220.66 + (ntohl(pol->secondary_policy_code) != acm_bin_pol.secondary_policy_code)) { 220.67 + printkd("%s: Wrong policy magics or versions!\n", __func__); 220.68 goto error_free; 220.69 } 220.70 if (buf_size != ntohl(pol->len)) { 220.71 @@ -79,21 +69,19 @@ acm_set_policy(void *buf, u16 buf_size, 220.72 /* get bin_policy lock and rewrite policy (release old one) */ 220.73 write_lock(&acm_bin_pol_rwlock); 220.74 220.75 - /* 3. now get/set primary policy data */ 220.76 - if (acm_primary_ops->set_binary_policy(buf + ntohs(pol->primary_buffer_offset), 220.77 - ntohs(pol->secondary_buffer_offset) - 220.78 - ntohs(pol->primary_buffer_offset))) { 220.79 + /* 3. set primary policy data */ 220.80 + if (acm_primary_ops->set_binary_policy(buf + ntohl(pol->primary_buffer_offset), 220.81 + ntohl(pol->secondary_buffer_offset) - 220.82 + ntohl(pol->primary_buffer_offset))) { 220.83 goto error_lock_free; 220.84 } 220.85 - /* 4. now get/set secondary policy data */ 220.86 - if (acm_secondary_ops->set_binary_policy(buf + ntohs(pol->secondary_buffer_offset), 220.87 + /* 4. set secondary policy data */ 220.88 + if (acm_secondary_ops->set_binary_policy(buf + ntohl(pol->secondary_buffer_offset), 220.89 ntohl(pol->len) - 220.90 - ntohs(pol->secondary_buffer_offset))) { 220.91 + ntohl(pol->secondary_buffer_offset))) { 220.92 goto error_lock_free; 220.93 } 220.94 write_unlock(&acm_bin_pol_rwlock); 220.95 - out: 220.96 - printk("%s: Done .\n", __func__); 220.97 if (policy_buffer != NULL) 220.98 xfree(policy_buffer); 220.99 return ACM_OK; 220.100 @@ -121,26 +109,25 @@ acm_get_policy(void *buf, u16 buf_size) 220.101 /* future: read policy from file and set it */ 220.102 bin_pol = (struct acm_policy_buffer *)policy_buffer; 220.103 bin_pol->magic = htonl(ACM_MAGIC); 220.104 - bin_pol->policyversion = htonl(POLICY_INTERFACE_VERSION); 220.105 - bin_pol->primary_policy_code = htons(acm_bin_pol.primary_policy_code); 220.106 - bin_pol->secondary_policy_code = htons(acm_bin_pol.secondary_policy_code); 220.107 + bin_pol->primary_policy_code = htonl(acm_bin_pol.primary_policy_code); 220.108 + bin_pol->secondary_policy_code = htonl(acm_bin_pol.secondary_policy_code); 220.109 220.110 bin_pol->len = htonl(sizeof(struct acm_policy_buffer)); 220.111 - bin_pol->primary_buffer_offset = htons(ntohl(bin_pol->len)); 220.112 - bin_pol->secondary_buffer_offset = htons(ntohl(bin_pol->len)); 220.113 + bin_pol->primary_buffer_offset = htonl(ntohl(bin_pol->len)); 220.114 + bin_pol->secondary_buffer_offset = htonl(ntohl(bin_pol->len)); 220.115 220.116 - ret = acm_primary_ops->dump_binary_policy (policy_buffer + ntohs(bin_pol->primary_buffer_offset), 220.117 - buf_size - ntohs(bin_pol->primary_buffer_offset)); 220.118 + ret = acm_primary_ops->dump_binary_policy (policy_buffer + ntohl(bin_pol->primary_buffer_offset), 220.119 + buf_size - ntohl(bin_pol->primary_buffer_offset)); 220.120 if (ret < 0) { 220.121 printk("%s: ERROR creating chwallpolicy buffer.\n", __func__); 220.122 read_unlock(&acm_bin_pol_rwlock); 220.123 return -1; 220.124 } 220.125 bin_pol->len = htonl(ntohl(bin_pol->len) + ret); 220.126 - bin_pol->secondary_buffer_offset = htons(ntohl(bin_pol->len)); 220.127 + bin_pol->secondary_buffer_offset = htonl(ntohl(bin_pol->len)); 220.128 220.129 - ret = acm_secondary_ops->dump_binary_policy(policy_buffer + ntohs(bin_pol->secondary_buffer_offset), 220.130 - buf_size - ntohs(bin_pol->secondary_buffer_offset)); 220.131 + ret = acm_secondary_ops->dump_binary_policy(policy_buffer + ntohl(bin_pol->secondary_buffer_offset), 220.132 + buf_size - ntohl(bin_pol->secondary_buffer_offset)); 220.133 if (ret < 0) { 220.134 printk("%s: ERROR creating chwallpolicy buffer.\n", __func__); 220.135 read_unlock(&acm_bin_pol_rwlock); 220.136 @@ -178,11 +165,10 @@ acm_dump_statistics(void *buf, u16 buf_s 220.137 goto error_lock_free; 220.138 220.139 acm_stats.magic = htonl(ACM_MAGIC); 220.140 - acm_stats.policyversion = htonl(POLICY_INTERFACE_VERSION); 220.141 - acm_stats.primary_policy_code = htons(acm_bin_pol.primary_policy_code); 220.142 - acm_stats.secondary_policy_code = htons(acm_bin_pol.secondary_policy_code); 220.143 - acm_stats.primary_stats_offset = htons(sizeof(struct acm_stats_buffer)); 220.144 - acm_stats.secondary_stats_offset = htons(sizeof(struct acm_stats_buffer) + len1); 220.145 + acm_stats.primary_policy_code = htonl(acm_bin_pol.primary_policy_code); 220.146 + acm_stats.secondary_policy_code = htonl(acm_bin_pol.secondary_policy_code); 220.147 + acm_stats.primary_stats_offset = htonl(sizeof(struct acm_stats_buffer)); 220.148 + acm_stats.secondary_stats_offset = htonl(sizeof(struct acm_stats_buffer) + len1); 220.149 acm_stats.len = htonl(sizeof(struct acm_stats_buffer) + len1 + len2); 220.150 memcpy(stats_buffer, &acm_stats, sizeof(struct acm_stats_buffer)); 220.151
221.1 --- a/xen/acm/acm_simple_type_enforcement_hooks.c Tue Aug 02 02:47:41 2005 -0800 221.2 +++ b/xen/acm/acm_simple_type_enforcement_hooks.c Tue Aug 02 10:20:46 2005 -0700 221.3 @@ -140,15 +140,15 @@ ste_dump_policy(u8 *buf, u16 buf_size) { 221.4 struct acm_ste_policy_buffer *ste_buf = (struct acm_ste_policy_buffer *)buf; 221.5 int ret = 0; 221.6 221.7 - ste_buf->ste_max_types = htons(ste_bin_pol.max_types); 221.8 - ste_buf->ste_max_ssidrefs = htons(ste_bin_pol.max_ssidrefs); 221.9 - ste_buf->policy_code = htons(ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY); 221.10 - ste_buf->ste_ssid_offset = htons(sizeof(struct acm_ste_policy_buffer)); 221.11 - ret = ntohs(ste_buf->ste_ssid_offset) + 221.12 + ste_buf->ste_max_types = htonl(ste_bin_pol.max_types); 221.13 + ste_buf->ste_max_ssidrefs = htonl(ste_bin_pol.max_ssidrefs); 221.14 + ste_buf->policy_code = htonl(ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY); 221.15 + ste_buf->ste_ssid_offset = htonl(sizeof(struct acm_ste_policy_buffer)); 221.16 + ret = ntohl(ste_buf->ste_ssid_offset) + 221.17 sizeof(domaintype_t)*ste_bin_pol.max_ssidrefs*ste_bin_pol.max_types; 221.18 221.19 /* now copy buffer over */ 221.20 - arrcpy(buf + ntohs(ste_buf->ste_ssid_offset), 221.21 + arrcpy(buf + ntohl(ste_buf->ste_ssid_offset), 221.22 ste_bin_pol.ssidrefs, 221.23 sizeof(domaintype_t), 221.24 ste_bin_pol.max_ssidrefs*ste_bin_pol.max_types); 221.25 @@ -276,10 +276,16 @@ ste_set_policy(u8 *buf, u16 buf_size) 221.26 int i; 221.27 221.28 /* Convert endianess of policy */ 221.29 - ste_buf->policy_code = ntohs(ste_buf->policy_code); 221.30 - ste_buf->ste_max_types = ntohs(ste_buf->ste_max_types); 221.31 - ste_buf->ste_max_ssidrefs = ntohs(ste_buf->ste_max_ssidrefs); 221.32 - ste_buf->ste_ssid_offset = ntohs(ste_buf->ste_ssid_offset); 221.33 + ste_buf->policy_code = ntohl(ste_buf->policy_code); 221.34 + ste_buf->policy_version = ntohl(ste_buf->policy_version); 221.35 + ste_buf->ste_max_types = ntohl(ste_buf->ste_max_types); 221.36 + ste_buf->ste_max_ssidrefs = ntohl(ste_buf->ste_max_ssidrefs); 221.37 + ste_buf->ste_ssid_offset = ntohl(ste_buf->ste_ssid_offset); 221.38 + 221.39 + /* policy type and version checks */ 221.40 + if ((ste_buf->policy_code != ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY) || 221.41 + (ste_buf->policy_version != ACM_STE_VERSION)) 221.42 + return -EINVAL; 221.43 221.44 /* 1. create and copy-in new ssidrefs buffer */ 221.45 ssidrefsbuf = xmalloc_array(u8, sizeof(domaintype_t)*ste_buf->ste_max_types*ste_buf->ste_max_ssidrefs);
262.1 --- a/xen/arch/x86/shadow_public.c Tue Aug 02 02:47:41 2005 -0800 262.2 +++ b/xen/arch/x86/shadow_public.c Tue Aug 02 10:20:46 2005 -0700 262.3 @@ -30,7 +30,7 @@ 262.4 #include <xen/sched.h> 262.5 #include <xen/trace.h> 262.6 262.7 -#if CONFIG_PAGING_LEVELS >= 4 262.8 +#if CONFIG_PAGING_LEVELS >= 3 262.9 #include <asm/shadow_64.h> 262.10 262.11 extern struct shadow_ops MODE_F_HANDLER; 262.12 @@ -233,7 +233,20 @@ void free_monitor_pagetable(struct vcpu 262.13 v->arch.monitor_vtable = 0; 262.14 } 262.15 262.16 +#elif CONFIG_PAGING_LEVELS == 3 262.17 + 262.18 +static void alloc_monitor_pagetable(struct vcpu *v) 262.19 +{ 262.20 + BUG(); /* PAE not implemented yet */ 262.21 +} 262.22 + 262.23 +void free_monitor_pagetable(struct vcpu *v) 262.24 +{ 262.25 + BUG(); /* PAE not implemented yet */ 262.26 +} 262.27 + 262.28 #elif CONFIG_PAGING_LEVELS == 2 262.29 + 262.30 static void alloc_monitor_pagetable(struct vcpu *v) 262.31 { 262.32 unsigned long mmfn;
271.1 --- a/xen/arch/x86/x86_32/entry.S Tue Aug 02 02:47:41 2005 -0800 271.2 +++ b/xen/arch/x86/x86_32/entry.S Tue Aug 02 10:20:46 2005 -0700 271.3 @@ -751,7 +751,7 @@ ENTRY(hypercall_table) 271.4 .long do_boot_vcpu 271.5 .long do_ni_hypercall /* 25 */ 271.6 .long do_mmuext_op 271.7 - .long do_policy_op /* 27 */ 271.8 + .long do_acm_op /* 27 */ 271.9 .rept NR_hypercalls-((.-hypercall_table)/4) 271.10 .long do_ni_hypercall 271.11 .endr
274.1 --- a/xen/arch/x86/x86_64/entry.S Tue Aug 02 02:47:41 2005 -0800 274.2 +++ b/xen/arch/x86/x86_64/entry.S Tue Aug 02 10:20:46 2005 -0700 274.3 @@ -587,7 +587,7 @@ ENTRY(hypercall_table) 274.4 .quad do_boot_vcpu 274.5 .quad do_set_segment_base /* 25 */ 274.6 .quad do_mmuext_op 274.7 - .quad do_policy_op 274.8 + .quad do_acm_op 274.9 .rept NR_hypercalls-((.-hypercall_table)/4) 274.10 .quad do_ni_hypercall 274.11 .endr
278.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 278.2 +++ b/xen/common/acm_ops.c Tue Aug 02 10:20:46 2005 -0700 278.3 @@ -0,0 +1,127 @@ 278.4 +/****************************************************************************** 278.5 + * acm_ops.c 278.6 + * 278.7 + * Copyright (C) 2005 IBM Corporation 278.8 + * 278.9 + * Author: 278.10 + * Reiner Sailer <sailer@watson.ibm.com> 278.11 + * 278.12 + * This program is free software; you can redistribute it and/or 278.13 + * modify it under the terms of the GNU General Public License as 278.14 + * published by the Free Software Foundation, version 2 of the 278.15 + * License. 278.16 + * 278.17 + * Process acm command requests from guest OS. 278.18 + * 278.19 + */ 278.20 + 278.21 +#include <xen/config.h> 278.22 +#include <xen/types.h> 278.23 +#include <xen/lib.h> 278.24 +#include <xen/mm.h> 278.25 +#include <public/acm_ops.h> 278.26 +#include <xen/sched.h> 278.27 +#include <xen/event.h> 278.28 +#include <xen/trace.h> 278.29 +#include <xen/console.h> 278.30 +#include <asm/shadow.h> 278.31 +#include <public/sched_ctl.h> 278.32 +#include <acm/acm_hooks.h> 278.33 + 278.34 +#if (ACM_USE_SECURITY_POLICY == ACM_NULL_POLICY) 278.35 + 278.36 +long do_acm_op(acm_op_t * u_acm_op) 278.37 +{ 278.38 + return -ENOSYS; 278.39 +} 278.40 + 278.41 +#else 278.42 + 278.43 +typedef enum acm_operation { 278.44 + POLICY, /* access to policy interface (early drop) */ 278.45 + GETPOLICY, /* dump policy cache */ 278.46 + SETPOLICY, /* set policy cache (controls security) */ 278.47 + DUMPSTATS /* dump policy statistics */ 278.48 +} acm_operation_t; 278.49 + 278.50 +int acm_authorize_acm_ops(struct domain *d, acm_operation_t pops) 278.51 +{ 278.52 + /* all policy management functions are restricted to privileged domains, 278.53 + * soon we will introduce finer-grained privileges for policy operations 278.54 + */ 278.55 + if (!IS_PRIV(d)) 278.56 + { 278.57 + printk("%s: ACM management authorization denied ERROR!\n", __func__); 278.58 + return ACM_ACCESS_DENIED; 278.59 + } 278.60 + return ACM_ACCESS_PERMITTED; 278.61 +} 278.62 + 278.63 +long do_acm_op(acm_op_t * u_acm_op) 278.64 +{ 278.65 + long ret = 0; 278.66 + acm_op_t curop, *op = &curop; 278.67 + 278.68 + /* check here policy decision for policy commands */ 278.69 + /* for now allow DOM0 only, later indepedently */ 278.70 + if (acm_authorize_acm_ops(current->domain, POLICY)) 278.71 + return -EACCES; 278.72 + 278.73 + if (copy_from_user(op, u_acm_op, sizeof(*op))) 278.74 + return -EFAULT; 278.75 + 278.76 + if (op->interface_version != ACM_INTERFACE_VERSION) 278.77 + return -EACCES; 278.78 + 278.79 + switch (op->cmd) 278.80 + { 278.81 + case ACM_SETPOLICY: 278.82 + { 278.83 + if (acm_authorize_acm_ops(current->domain, SETPOLICY)) 278.84 + return -EACCES; 278.85 + printkd("%s: setting policy.\n", __func__); 278.86 + ret = acm_set_policy(op->u.setpolicy.pushcache, 278.87 + op->u.setpolicy.pushcache_size, 1); 278.88 + if (ret == ACM_OK) 278.89 + ret = 0; 278.90 + else 278.91 + ret = -ESRCH; 278.92 + } 278.93 + break; 278.94 + 278.95 + case ACM_GETPOLICY: 278.96 + { 278.97 + if (acm_authorize_acm_ops(current->domain, GETPOLICY)) 278.98 + return -EACCES; 278.99 + printkd("%s: getting policy.\n", __func__); 278.100 + ret = acm_get_policy(op->u.getpolicy.pullcache, 278.101 + op->u.getpolicy.pullcache_size); 278.102 + if (ret == ACM_OK) 278.103 + ret = 0; 278.104 + else 278.105 + ret = -ESRCH; 278.106 + } 278.107 + break; 278.108 + 278.109 + case ACM_DUMPSTATS: 278.110 + { 278.111 + if (acm_authorize_acm_ops(current->domain, DUMPSTATS)) 278.112 + return -EACCES; 278.113 + printkd("%s: dumping statistics.\n", __func__); 278.114 + ret = acm_dump_statistics(op->u.dumpstats.pullcache, 278.115 + op->u.dumpstats.pullcache_size); 278.116 + if (ret == ACM_OK) 278.117 + ret = 0; 278.118 + else 278.119 + ret = -ESRCH; 278.120 + } 278.121 + break; 278.122 + 278.123 + default: 278.124 + ret = -ESRCH; 278.125 + 278.126 + } 278.127 + return ret; 278.128 +} 278.129 + 278.130 +#endif
283.1 --- a/xen/common/policy_ops.c Tue Aug 02 02:47:41 2005 -0800 283.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 283.3 @@ -1,133 +0,0 @@ 283.4 -/****************************************************************************** 283.5 - * policy_ops.c 283.6 - * 283.7 - * Copyright (C) 2005 IBM Corporation 283.8 - * 283.9 - * Author: 283.10 - * Reiner Sailer <sailer@watson.ibm.com> 283.11 - * 283.12 - * This program is free software; you can redistribute it and/or 283.13 - * modify it under the terms of the GNU General Public License as 283.14 - * published by the Free Software Foundation, version 2 of the 283.15 - * License. 283.16 - * 283.17 - * Process policy command requests from guest OS. 283.18 - * 283.19 - */ 283.20 - 283.21 -#include <xen/config.h> 283.22 -#include <xen/types.h> 283.23 -#include <xen/lib.h> 283.24 -#include <xen/mm.h> 283.25 -#include <public/policy_ops.h> 283.26 -#include <xen/sched.h> 283.27 -#include <xen/event.h> 283.28 -#include <xen/trace.h> 283.29 -#include <xen/console.h> 283.30 -#include <asm/shadow.h> 283.31 -#include <public/sched_ctl.h> 283.32 -#include <acm/acm_hooks.h> 283.33 - 283.34 -#if (ACM_USE_SECURITY_POLICY == ACM_NULL_POLICY) 283.35 - 283.36 -long do_policy_op(policy_op_t *u_policy_op) 283.37 -{ 283.38 - return -ENOSYS; 283.39 -} 283.40 - 283.41 -#else 283.42 - 283.43 -typedef enum policyoperation { 283.44 - POLICY, /* access to policy interface (early drop) */ 283.45 - GETPOLICY, /* dump policy cache */ 283.46 - SETPOLICY, /* set policy cache (controls security) */ 283.47 - DUMPSTATS /* dump policy statistics */ 283.48 -} policyoperation_t; 283.49 - 283.50 -int 283.51 -acm_authorize_policyops(struct domain *d, policyoperation_t pops) 283.52 -{ 283.53 - /* all policy management functions are restricted to privileged domains, 283.54 - * soon we will introduce finer-grained privileges for policy operations 283.55 - */ 283.56 - if (!IS_PRIV(d)) { 283.57 - printk("%s: Policy management authorization denied ERROR!\n", 283.58 - __func__); 283.59 - return ACM_ACCESS_DENIED; 283.60 - } 283.61 - return ACM_ACCESS_PERMITTED; 283.62 -} 283.63 - 283.64 -long do_policy_op(policy_op_t *u_policy_op) 283.65 -{ 283.66 - long ret = 0; 283.67 - policy_op_t curop, *op = &curop; 283.68 - 283.69 - /* check here policy decision for policy commands */ 283.70 - /* for now allow DOM0 only, later indepedently */ 283.71 - if (acm_authorize_policyops(current->domain, POLICY)) 283.72 - return -EACCES; 283.73 - 283.74 - if ( copy_from_user(op, u_policy_op, sizeof(*op)) ) 283.75 - return -EFAULT; 283.76 - 283.77 - if ( op->interface_version != POLICY_INTERFACE_VERSION ) 283.78 - return -EACCES; 283.79 - 283.80 - switch ( op->cmd ) 283.81 - { 283.82 - case POLICY_SETPOLICY: 283.83 - { 283.84 - if (acm_authorize_policyops(current->domain, SETPOLICY)) 283.85 - return -EACCES; 283.86 - printkd("%s: setting policy.\n", __func__); 283.87 - ret = acm_set_policy( 283.88 - op->u.setpolicy.pushcache, 283.89 - op->u.setpolicy.pushcache_size, 283.90 - op->u.setpolicy.policy_type, 283.91 - 1); 283.92 - if (ret == ACM_OK) 283.93 - ret = 0; 283.94 - else 283.95 - ret = -ESRCH; 283.96 - } 283.97 - break; 283.98 - 283.99 - case POLICY_GETPOLICY: 283.100 - { 283.101 - if (acm_authorize_policyops(current->domain, GETPOLICY)) 283.102 - return -EACCES; 283.103 - printkd("%s: getting policy.\n", __func__); 283.104 - ret = acm_get_policy( 283.105 - op->u.getpolicy.pullcache, 283.106 - op->u.getpolicy.pullcache_size); 283.107 - if (ret == ACM_OK) 283.108 - ret = 0; 283.109 - else 283.110 - ret = -ESRCH; 283.111 - } 283.112 - break; 283.113 - 283.114 - case POLICY_DUMPSTATS: 283.115 - { 283.116 - if (acm_authorize_policyops(current->domain, DUMPSTATS)) 283.117 - return -EACCES; 283.118 - printkd("%s: dumping statistics.\n", __func__); 283.119 - ret = acm_dump_statistics( 283.120 - op->u.dumpstats.pullcache, 283.121 - op->u.dumpstats.pullcache_size); 283.122 - if (ret == ACM_OK) 283.123 - ret = 0; 283.124 - else 283.125 - ret = -ESRCH; 283.126 - } 283.127 - break; 283.128 - 283.129 - default: 283.130 - ret = -ESRCH; 283.131 - 283.132 - } 283.133 - return ret; 283.134 -} 283.135 - 283.136 -#endif
288.1 --- a/xen/include/acm/acm_core.h Tue Aug 02 02:47:41 2005 -0800 288.2 +++ b/xen/include/acm/acm_core.h Tue Aug 02 10:20:46 2005 -0700 288.3 @@ -21,7 +21,7 @@ 288.4 #include <xen/spinlock.h> 288.5 #include <public/acm.h> 288.6 #include <xen/acm_policy.h> 288.7 -#include <public/policy_ops.h> 288.8 +#include <public/acm_ops.h> 288.9 288.10 /* Xen-internal representation of the binary policy */ 288.11 struct acm_binary_policy { 288.12 @@ -113,7 +113,7 @@ struct ste_ssid { 288.13 /* protos */ 288.14 int acm_init_domain_ssid(domid_t id, ssidref_t ssidref); 288.15 int acm_free_domain_ssid(struct acm_ssid_domain *ssid); 288.16 -int acm_set_policy(void *buf, u16 buf_size, u16 policy, int isuserbuffer); 288.17 +int acm_set_policy(void *buf, u16 buf_size, int isuserbuffer); 288.18 int acm_get_policy(void *buf, u16 buf_size); 288.19 int acm_dump_statistics(void *buf, u16 buf_size); 288.20
321.1 --- a/xen/include/public/acm.h Tue Aug 02 02:47:41 2005 -0800 321.2 +++ b/xen/include/public/acm.h Tue Aug 02 10:20:46 2005 -0700 321.3 @@ -71,6 +71,14 @@ 321.4 (X == ACM_CHINESE_WALL_AND_SIMPLE_TYPE_ENFORCEMENT_POLICY) ? "CHINESE WALL AND SIMPLE TYPE ENFORCEMENT policy" : \ 321.5 "UNDEFINED policy" 321.6 321.7 +/* the following policy versions must be increased 321.8 + * whenever the interpretation of the related 321.9 + * policy's data structure changes 321.10 + */ 321.11 +#define ACM_POLICY_VERSION 1 321.12 +#define ACM_CHWALL_VERSION 1 321.13 +#define ACM_STE_VERSION 1 321.14 + 321.15 /* defines a ssid reference used by xen */ 321.16 typedef u32 ssidref_t; 321.17 321.18 @@ -102,46 +110,53 @@ typedef u16 domaintype_t; 321.19 #define ACM_MAGIC 0x0001debc 321.20 321.21 /* each offset in bytes from start of the struct they 321.22 - * the are part of */ 321.23 + * are part of */ 321.24 + 321.25 /* each buffer consists of all policy information for 321.26 * the respective policy given in the policy code 321.27 + * 321.28 + * acm_policy_buffer, acm_chwall_policy_buffer, 321.29 + * and acm_ste_policy_buffer need to stay 32-bit aligned 321.30 + * because we create binary policies also with external 321.31 + * tools that assume packed representations (e.g. the java tool) 321.32 */ 321.33 struct acm_policy_buffer { 321.34 + u32 policy_version; /* ACM_POLICY_VERSION */ 321.35 u32 magic; 321.36 - u32 policyversion; 321.37 u32 len; 321.38 - u16 primary_policy_code; 321.39 - u16 primary_buffer_offset; 321.40 - u16 secondary_policy_code; 321.41 - u16 secondary_buffer_offset; 321.42 + u32 primary_policy_code; 321.43 + u32 primary_buffer_offset; 321.44 + u32 secondary_policy_code; 321.45 + u32 secondary_buffer_offset; 321.46 }; 321.47 321.48 struct acm_chwall_policy_buffer { 321.49 - u16 policy_code; 321.50 - u16 chwall_max_types; 321.51 - u16 chwall_max_ssidrefs; 321.52 - u16 chwall_max_conflictsets; 321.53 - u16 chwall_ssid_offset; 321.54 - u16 chwall_conflict_sets_offset; 321.55 - u16 chwall_running_types_offset; 321.56 - u16 chwall_conflict_aggregate_offset; 321.57 + u32 policy_version; /* ACM_CHWALL_VERSION */ 321.58 + u32 policy_code; 321.59 + u32 chwall_max_types; 321.60 + u32 chwall_max_ssidrefs; 321.61 + u32 chwall_max_conflictsets; 321.62 + u32 chwall_ssid_offset; 321.63 + u32 chwall_conflict_sets_offset; 321.64 + u32 chwall_running_types_offset; 321.65 + u32 chwall_conflict_aggregate_offset; 321.66 }; 321.67 321.68 struct acm_ste_policy_buffer { 321.69 - u16 policy_code; 321.70 - u16 ste_max_types; 321.71 - u16 ste_max_ssidrefs; 321.72 - u16 ste_ssid_offset; 321.73 + u32 policy_version; /* ACM_STE_VERSION */ 321.74 + u32 policy_code; 321.75 + u32 ste_max_types; 321.76 + u32 ste_max_ssidrefs; 321.77 + u32 ste_ssid_offset; 321.78 }; 321.79 321.80 struct acm_stats_buffer { 321.81 u32 magic; 321.82 - u32 policyversion; 321.83 u32 len; 321.84 - u16 primary_policy_code; 321.85 - u16 primary_stats_offset; 321.86 - u16 secondary_policy_code; 321.87 - u16 secondary_stats_offset; 321.88 + u32 primary_policy_code; 321.89 + u32 primary_stats_offset; 321.90 + u32 secondary_policy_code; 321.91 + u32 secondary_stats_offset; 321.92 }; 321.93 321.94 struct acm_ste_stats_buffer {
322.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 322.2 +++ b/xen/include/public/acm_ops.h Tue Aug 02 10:20:46 2005 -0700 322.3 @@ -0,0 +1,66 @@ 322.4 +/****************************************************************************** 322.5 + * acm_ops.h 322.6 + * 322.7 + * Copyright (C) 2005 IBM Corporation 322.8 + * 322.9 + * Author: 322.10 + * Reiner Sailer <sailer@watson.ibm.com> 322.11 + * 322.12 + * This program is free software; you can redistribute it and/or 322.13 + * modify it under the terms of the GNU General Public License as 322.14 + * published by the Free Software Foundation, version 2 of the 322.15 + * License. 322.16 + * 322.17 + * Process acm policy command requests from guest OS. 322.18 + * access checked by policy; not restricted to DOM0 322.19 + * 322.20 + */ 322.21 + 322.22 +#ifndef __XEN_PUBLIC_ACM_OPS_H__ 322.23 +#define __XEN_PUBLIC_ACM_OPS_H__ 322.24 + 322.25 +#include "xen.h" 322.26 +#include "sched_ctl.h" 322.27 + 322.28 +/* 322.29 + * Make sure you increment the interface version whenever you modify this file! 322.30 + * This makes sure that old versions of acm tools will stop working in a 322.31 + * well-defined way (rather than crashing the machine, for instance). 322.32 + */ 322.33 +#define ACM_INTERFACE_VERSION 0xAAAA0003 322.34 + 322.35 +/************************************************************************/ 322.36 + 322.37 +#define ACM_SETPOLICY 4 322.38 +typedef struct acm_setpolicy { 322.39 + /* OUT variables */ 322.40 + void *pushcache; 322.41 + u16 pushcache_size; 322.42 +} acm_setpolicy_t; 322.43 + 322.44 + 322.45 +#define ACM_GETPOLICY 5 322.46 +typedef struct acm_getpolicy { 322.47 + /* OUT variables */ 322.48 + void *pullcache; 322.49 + u16 pullcache_size; 322.50 +} acm_getpolicy_t; 322.51 + 322.52 +#define ACM_DUMPSTATS 6 322.53 +typedef struct acm_dumpstats { 322.54 + void *pullcache; 322.55 + u16 pullcache_size; 322.56 +} acm_dumpstats_t; 322.57 + 322.58 + 322.59 +typedef struct acm_op { 322.60 + u32 cmd; 322.61 + u32 interface_version; /* ACM_INTERFACE_VERSION */ 322.62 + union { 322.63 + acm_setpolicy_t setpolicy; 322.64 + acm_getpolicy_t getpolicy; 322.65 + acm_dumpstats_t dumpstats; 322.66 + } u; 322.67 +} acm_op_t; 322.68 + 322.69 +#endif /* __XEN_PUBLIC_ACM_OPS_H__ */
327.1 --- a/xen/include/public/policy_ops.h Tue Aug 02 02:47:41 2005 -0800 327.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 327.3 @@ -1,70 +0,0 @@ 327.4 -/****************************************************************************** 327.5 - * policy_ops.h 327.6 - * 327.7 - * Copyright (C) 2005 IBM Corporation 327.8 - * 327.9 - * Author: 327.10 - * Reiner Sailer <sailer@watson.ibm.com> 327.11 - * 327.12 - * This program is free software; you can redistribute it and/or 327.13 - * modify it under the terms of the GNU General Public License as 327.14 - * published by the Free Software Foundation, version 2 of the 327.15 - * License. 327.16 - * 327.17 - * Process policy command requests from guest OS. 327.18 - * access checked by policy; not restricted to DOM0 327.19 - * 327.20 - */ 327.21 - 327.22 -#ifndef __XEN_PUBLIC_POLICY_OPS_H__ 327.23 -#define __XEN_PUBLIC_POLICY_OPS_H__ 327.24 - 327.25 -#include "xen.h" 327.26 -#include "sched_ctl.h" 327.27 - 327.28 -/* 327.29 - * Make sure you increment the interface version whenever you modify this file! 327.30 - * This makes sure that old versions of policy tools will stop working in a 327.31 - * well-defined way (rather than crashing the machine, for instance). 327.32 - */ 327.33 -#define POLICY_INTERFACE_VERSION 0xAAAA0003 327.34 - 327.35 -/************************************************************************/ 327.36 - 327.37 -#define POLICY_SETPOLICY 4 327.38 -typedef struct policy_setpolicy { 327.39 - /* IN variables. */ 327.40 - u16 policy_type; 327.41 - /* OUT variables */ 327.42 - void *pushcache; 327.43 - u16 pushcache_size; 327.44 -} policy_setpolicy_t; 327.45 - 327.46 - 327.47 -#define POLICY_GETPOLICY 5 327.48 -typedef struct policy_getpolicy { 327.49 - /* IN variables. */ 327.50 - u16 policy_type; 327.51 - /* OUT variables */ 327.52 - void *pullcache; 327.53 - u16 pullcache_size; 327.54 -} policy_getpolicy_t; 327.55 - 327.56 -#define POLICY_DUMPSTATS 6 327.57 -typedef struct policy_dumpstats { 327.58 - void *pullcache; 327.59 - u16 pullcache_size; 327.60 -} policy_dumpstats_t; 327.61 - 327.62 - 327.63 -typedef struct policy_op { 327.64 - u32 cmd; 327.65 - u32 interface_version; /* POLICY_INTERFACE_VERSION */ 327.66 - union { 327.67 - policy_setpolicy_t setpolicy; 327.68 - policy_getpolicy_t getpolicy; 327.69 - policy_dumpstats_t dumpstats; 327.70 - } u; 327.71 -} policy_op_t; 327.72 - 327.73 -#endif /* __XEN_PUBLIC_POLICY_OPS_H__ */
328.1 --- a/xen/include/public/xen.h Tue Aug 02 02:47:41 2005 -0800 328.2 +++ b/xen/include/public/xen.h Tue Aug 02 10:20:46 2005 -0700 328.3 @@ -58,7 +58,7 @@ 328.4 #define __HYPERVISOR_boot_vcpu 24 328.5 #define __HYPERVISOR_set_segment_base 25 /* x86/64 only */ 328.6 #define __HYPERVISOR_mmuext_op 26 328.7 -#define __HYPERVISOR_policy_op 27 328.8 +#define __HYPERVISOR_acm_op 27 328.9 328.10 /* 328.11 * VIRTUAL INTERRUPTS